From: Marius Gavrilescu Date: Wed, 6 Mar 2013 22:08:38 +0000 (+0200) Subject: Make custom server work when polling X-Git-Tag: 0.000_001~60 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=a97d31fb5c1bc1725079b5329168b22db3cf9cf3;p=fonbot.git Make custom server work when polling Until now, the custom server hostname:port were only used in SendHttpMessageAsyncTask, while PollServerAsyncTask used the hardcoded http://ieval.ro:7777/get. --- diff --git a/src/ro/ieval/fonbot/DynamicEventReceiver.java b/src/ro/ieval/fonbot/DynamicEventReceiver.java index 926280b..d7acf54 100644 --- a/src/ro/ieval/fonbot/DynamicEventReceiver.java +++ b/src/ro/ieval/fonbot/DynamicEventReceiver.java @@ -47,7 +47,7 @@ public final class DynamicEventReceiver extends BroadcastReceiver { if(action.equals(Intent.ACTION_SCREEN_ON)){ if(PreferenceManager.getDefaultSharedPreferences(context).getBoolean("poll_on_screen_on", false)) - new PollServerAsyncTask().execute(); + new PollServerAsyncTask(context).execute(); } else if(action.equals(Intent.ACTION_BATTERY_CHANGED)) Heavy.describeBatteryLevel(context, null, toNonNull(MessageType.BATTERY_CHANGED)); else if(action.equals(Intent.ACTION_HEADSET_PLUG)){ diff --git a/src/ro/ieval/fonbot/FonBotApplication.java b/src/ro/ieval/fonbot/FonBotApplication.java index 46a0328..38b5b40 100644 --- a/src/ro/ieval/fonbot/FonBotApplication.java +++ b/src/ro/ieval/fonbot/FonBotApplication.java @@ -57,7 +57,7 @@ public final class FonBotApplication extends Application { tman.listen(new FonBotPhoneStateListener(this), PhoneStateListener.LISTEN_CALL_STATE); instance=this; - new PollServerAsyncTask().execute(); + new PollServerAsyncTask(this).execute(); startService(new Intent(this, FonBotMainService.class)); diff --git a/src/ro/ieval/fonbot/GCMIntentService.java b/src/ro/ieval/fonbot/GCMIntentService.java index de38208..aea7202 100644 --- a/src/ro/ieval/fonbot/GCMIntentService.java +++ b/src/ro/ieval/fonbot/GCMIntentService.java @@ -51,10 +51,13 @@ public class GCMIntentService extends GCMBaseIntentService { @Override protected void onMessage(@Nullable final Context context, @Nullable final Intent intent) { + if(context==null) + return; + handler.post(new Runnable(){ @Override public void run() { - new PollServerAsyncTask().execute(); + new PollServerAsyncTask(context).execute(); } }); } diff --git a/src/ro/ieval/fonbot/Heavy.java b/src/ro/ieval/fonbot/Heavy.java index df48722..905b577 100644 --- a/src/ro/ieval/fonbot/Heavy.java +++ b/src/ro/ieval/fonbot/Heavy.java @@ -1507,7 +1507,7 @@ final class Heavy { */ public static void poll(final Context context, final Address replyTo) { Utils.sendMessage(context, replyTo, polling_server); - new PollServerAsyncTask().execute(); + new PollServerAsyncTask(context).execute(); } /** diff --git a/src/ro/ieval/fonbot/LocalBroadcastReceiver.java b/src/ro/ieval/fonbot/LocalBroadcastReceiver.java index 6605e3d..88cf462 100644 --- a/src/ro/ieval/fonbot/LocalBroadcastReceiver.java +++ b/src/ro/ieval/fonbot/LocalBroadcastReceiver.java @@ -38,12 +38,12 @@ public final class LocalBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(final @Nullable Context context, final @Nullable Intent intent) { - if(intent==null) + if(context==null || intent==null) return; final String action=intent.getAction(); if(action.equals(LocalBroadcastReceiver.ACTION_POLL_ALARM)) - new PollServerAsyncTask().execute(); + new PollServerAsyncTask(context).execute(); } } diff --git a/src/ro/ieval/fonbot/PollServerAsyncTask.java b/src/ro/ieval/fonbot/PollServerAsyncTask.java index 7e95303..2a4a21d 100644 --- a/src/ro/ieval/fonbot/PollServerAsyncTask.java +++ b/src/ro/ieval/fonbot/PollServerAsyncTask.java @@ -15,6 +15,7 @@ import org.json.JSONException; import org.json.JSONObject; import ro.ieval.fonbot.Address.Protocol; +import android.content.Context; import android.os.AsyncTask; import android.util.Log; @@ -76,12 +77,24 @@ public final class PollServerAsyncTask extends AsyncTask doInBackground(final @Nullable Void... params) { Log.d(getClass().getName(), "Polling server"); final List commands=new ArrayList(10); try { - final URL url=new URL("http://ieval.ro:7777/get"); + final URL url=Utils.getServerURL(toNonNull(context),"/get"); final HttpURLConnection conn=(HttpURLConnection) url.openConnection(); conn.setRequestProperty("X-ID", FonBotApplication.instance.regID); conn.connect(); diff --git a/src/ro/ieval/fonbot/SendHttpMessageAsyncTask.java b/src/ro/ieval/fonbot/SendHttpMessageAsyncTask.java index e278481..5087b0b 100644 --- a/src/ro/ieval/fonbot/SendHttpMessageAsyncTask.java +++ b/src/ro/ieval/fonbot/SendHttpMessageAsyncTask.java @@ -1,7 +1,6 @@ package ro.ieval.fonbot; import static ro.ieval.fonbot.R.string.*; - import static ro.ieval.fonbot.Utils.toNonNull; import java.io.OutputStream; @@ -14,7 +13,6 @@ import org.eclipse.jdt.annotation.Nullable; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; -import android.preference.PreferenceManager; import android.util.Log; /* @@ -128,9 +126,7 @@ public final class SendHttpMessageAsyncTask extends AsyncTask