// Path: lib/src/main/java/io/xpush/chat/ApplicationController.java
// public class ApplicationController extends Application {
// 
//     public static final String TAG = ApplicationController.class.getSimpleName();
//     private static ApplicationController mInstance;
// 
//     public static synchronized ApplicationController getInstance() {
//         return mInstance;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         mInstance = this;
//         XPushCore.initialize(this);
//     }
// }
// 
// Path: lib/src/main/java/io/xpush/chat/network/StringRequest.java
// public class StringRequest extends Request<JSONObject> {
// 
//     public static final String TAG = StringRequest.class.getSimpleName();
// 
//     private final Response.Listener<JSONObject> mListener;
// 
//     private Map<String, String> params;
// 
//     private String mUrl;
// 
// 
//     public StringRequest(String url, Response.Listener<JSONObject> listener,
//                          Response.ErrorListener errorListener) {
//         super(Method.GET, url, errorListener);
//         this.mListener = listener;
//         this.params = null;
// 
//     }
// 
//     public StringRequest(String url, Map<String,String> params, Response.Listener<JSONObject> listener,
//                          Response.ErrorListener errorListener) {
//         super(Method.POST, url, errorListener);
//         this.mListener = listener;
//         this.params = params;
// 
//     }
// 
//     @Override
//     protected void deliverResponse(JSONObject response) {
//         mListener.onResponse(response);
//     }
// 
//     @Override
//     protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
//         JSONObject parsed;
//         try {
//             parsed = new JSONObject( new String(response.data) );
//         } catch (JSONException e) {
//             parsed = null;
//         }
// 
//         return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
//     }
// 
//     @Override
//     protected Map<String,String> getParams(){
//         return this.params;
//     }
// }
// 
// Path: lib/src/main/java/io/xpush/chat/persist/QuickstartPreferences.java
// public class QuickstartPreferences {
// 
//     public static final String SENT_TOKEN_TO_SERVER = "sentTokenToServer";
//     public static final String REGISTRATION_COMPLETE = "registrationComplete";
// 
// }


import android.app.IntentService;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.gcm.GcmPubSub;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.android.gms.iid.InstanceID;
import org.json.JSONObject;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.xpush.chat.ApplicationController;
import io.xpush.chat.R;
import io.xpush.chat.network.StringRequest;
import io.xpush.chat.persist.QuickstartPreferences;
package io.xpush.chat.services;






public class RegistrationIntentService extends IntentService {

    private static final String TAG = "RegIntentService";
    private static final String[] TOPICS = {"global"};

    public RegistrationIntentService() {
        super(TAG);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

        try {
            // In the (unlikely) event that multiple refresh operations occur simultaneously,
            // ensure that they are processed sequentially.
            synchronized (TAG) {
                // [START register_for_gcm]
                // Initially this call goes out to the network to retrieve the token, subsequent calls
                // are local.
                // [START get_token]
                InstanceID instanceID = InstanceID.getInstance(this);
                String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                        GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
                // [END get_token]
                Log.i(TAG, "GCM Registration Token: " + token);

                sendRegistrationToServer(token);

                // Subscribe to topic channels
                subscribeTopics(token);

                // You should store a boolean that indicates whether the generated token has been
                // sent to your server. If the boolean is false, send the token to your server,
                // otherwise your server should have already received the token.
// Path: lib/src/main/java/io/xpush/chat/ApplicationController.java
// public class ApplicationController extends Application {
// 
//     public static final String TAG = ApplicationController.class.getSimpleName();
//     private static ApplicationController mInstance;
// 
//     public static synchronized ApplicationController getInstance() {
//         return mInstance;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         mInstance = this;
//         XPushCore.initialize(this);
//     }
// }
// 
// Path: lib/src/main/java/io/xpush/chat/network/StringRequest.java
// public class StringRequest extends Request<JSONObject> {
// 
//     public static final String TAG = StringRequest.class.getSimpleName();
// 
//     private final Response.Listener<JSONObject> mListener;
// 
//     private Map<String, String> params;
// 
//     private String mUrl;
// 
// 
//     public StringRequest(String url, Response.Listener<JSONObject> listener,
//                          Response.ErrorListener errorListener) {
//         super(Method.GET, url, errorListener);
//         this.mListener = listener;
//         this.params = null;
// 
//     }
// 
//     public StringRequest(String url, Map<String,String> params, Response.Listener<JSONObject> listener,
//                          Response.ErrorListener errorListener) {
//         super(Method.POST, url, errorListener);
//         this.mListener = listener;
//         this.params = params;
// 
//     }
// 
//     @Override
//     protected void deliverResponse(JSONObject response) {
//         mListener.onResponse(response);
//     }
// 
//     @Override
//     protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
//         JSONObject parsed;
//         try {
//             parsed = new JSONObject( new String(response.data) );
//         } catch (JSONException e) {
//             parsed = null;
//         }
// 
//         return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
//     }
// 
//     @Override
//     protected Map<String,String> getParams(){
//         return this.params;
//     }
// }
// 
// Path: lib/src/main/java/io/xpush/chat/persist/QuickstartPreferences.java
// public class QuickstartPreferences {
// 
//     public static final String SENT_TOKEN_TO_SERVER = "sentTokenToServer";
//     public static final String REGISTRATION_COMPLETE = "registrationComplete";
// 
// }


// Path: lib/src/main/java/io/xpush/chat/services/RegistrationIntentService.java
import android.app.IntentService;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.gcm.GcmPubSub;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.android.gms.iid.InstanceID;
import org.json.JSONObject;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.xpush.chat.ApplicationController;
import io.xpush.chat.R;
import io.xpush.chat.network.StringRequest;
import io.xpush.chat.persist.QuickstartPreferences;

package io.xpush.chat.services;






public class RegistrationIntentService extends IntentService {

    private static final String TAG = "RegIntentService";
    private static final String[] TOPICS = {"global"};

    public RegistrationIntentService() {
        super(TAG);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

        try {
            // In the (unlikely) event that multiple refresh operations occur simultaneously,
            // ensure that they are processed sequentially.
            synchronized (TAG) {
                // [START register_for_gcm]
                // Initially this call goes out to the network to retrieve the token, subsequent calls
                // are local.
                // [START get_token]
                InstanceID instanceID = InstanceID.getInstance(this);
                String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                        GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
                // [END get_token]
                Log.i(TAG, "GCM Registration Token: " + token);

                sendRegistrationToServer(token);

                // Subscribe to topic channels
                subscribeTopics(token);

                // You should store a boolean that indicates whether the generated token has been
                // sent to your server. If the boolean is false, send the token to your server,
                // otherwise your server should have already received the token.
                sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();