diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3d88946..46ab5e4 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="3" + android:versionName="1.1" > diff --git a/bin/AndroidManifest.xml b/bin/AndroidManifest.xml index 3dd2f13..46ab5e4 100644 --- a/bin/AndroidManifest.xml +++ b/bin/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="3" + android:versionName="1.1" > diff --git a/bin/StatusReader.apk b/bin/StatusReader.apk index dd5fcc6..e7e8597 100644 Binary files a/bin/StatusReader.apk and b/bin/StatusReader.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index eef6032..15ad180 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/jarlist.cache b/bin/jarlist.cache index a47ae06..c9d42a9 100644 --- a/bin/jarlist.cache +++ b/bin/jarlist.cache @@ -2,4 +2,4 @@ # format is # Encoding is UTF-8 1427838941000 1074044 33b27a8d2a5b87e6eb6c60e87a5374ffbfeacc3a /weight/Code/appcompat_v7/libs/android-support-v4.jar -1427839433000 1074044 33b27a8d2a5b87e6eb6c60e87a5374ffbfeacc3a /weight/Code/StatusReader/libs/android-support-v4.jar +1428604187000 1074044 33b27a8d2a5b87e6eb6c60e87a5374ffbfeacc3a /weight/Code/StatusReader/libs/android-support-v4.jar diff --git a/bin/resources.ap_ b/bin/resources.ap_ index 08bd145..e0836f7 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/res/values/prefs_arrays.xml b/res/values/prefs_arrays.xml index f5807e7..3a255fd 100755 --- a/res/values/prefs_arrays.xml +++ b/res/values/prefs_arrays.xml @@ -1,6 +1,7 @@ + 30 sec (debug) 3 minuti 5 minuti 10 minuti @@ -8,6 +9,7 @@ 30 minuti + 30 180 300 600 diff --git a/res/xml/prefs.xml b/res/xml/prefs.xml index 41b5942..e842055 100755 --- a/res/xml/prefs.xml +++ b/res/xml/prefs.xml @@ -26,7 +26,7 @@ android:summary="@string/prefs_server_name_summary" android:key="@string/key_server_name" android:persistent="true" - android:defaultValue="isopen.hacklabbo.indivia.net/hacklabbo/state.json" + android:defaultValue="http://isopen.hacklabbo.indivia.net/hacklabbo/state.json" /> Build.VERSION_CODES.FROYO) + if(Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO){ editor.apply(); - else + } else { commitShared(editor); + } } @TargetApi(Build.VERSION_CODES.FROYO) diff --git a/src/net/indivia/hacklabbo/statusreader/StatusUpdate.java b/src/net/indivia/hacklabbo/statusreader/StatusUpdate.java index 332e73e..15215ad 100644 --- a/src/net/indivia/hacklabbo/statusreader/StatusUpdate.java +++ b/src/net/indivia/hacklabbo/statusreader/StatusUpdate.java @@ -17,24 +17,27 @@ import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.net.ConnectivityManager; -import android.net.Uri; import android.os.Build; import android.os.IBinder; import android.provider.Settings; +import android.support.v4.content.LocalBroadcastManager; import android.util.Log; @SuppressLint("NewApi") public class StatusUpdate extends Service { - // private final static String app_site = - // "http://isopen.hacklabbo.indivia.net/"; - private final static String app_site = "http://ginex.indivia.net/"; + public static boolean active = false; + private final static String LOG_TAG = "StatusUpdate"; public final static String DEF_SITE = "http://isopen.hacklabbo.indivia.net/hacklabbo/state.json"; + + // private final static String app_site = + // "http://isopen.hacklabbo.indivia.net/"; + //private final static String app_site = "http://ginex.indivia.net/"; //public final static String DEF_SITE = "http://ginex.indivia.net/state.json"; - private final static String app_www_current_apk = "latest.apk"; + //private final static String app_www_current_apk = "latest.apk"; - public final static int NOTIFY_APP_UPDATE = 2; + public final static int NOTIFY_STATUS_UPDATE = 3; private BgThread bgThread; private NotificationManager notificationManager; @@ -43,9 +46,17 @@ public class StatusUpdate extends Service { private int notificationNumber; private Resources res; private static String serverName; - private static Boolean oldStatus, isCicleService; + private static Boolean oldStatus, isCicleService; private static int refreshTime; private ConnectivityManager cm; + private final static int MSG_NO_CONN = 0; + private final static int MSG_DONE = 1; + + @Override + public IBinder onBind(Intent intent) { + return null; + } + @Override public void onCreate() { super.onCreate(); @@ -55,11 +66,12 @@ public class StatusUpdate extends Service { bgThread = new BgThread(); bgThread.start(); - String app_uri = app_site + app_www_current_apk; Intent i = new Intent(this, MainActivity.class); - i.putExtra("checkUpdate", NOTIFY_APP_UPDATE); - i.setData(Uri.parse(app_uri)); - i.putExtra("urlpath", app_uri); + i.putExtra("statusUpdate", NOTIFY_STATUS_UPDATE); + //TODO: sta roba non dovrebbe servire + //String app_uri = app_site + app_www_current_apk; + //i.setData(Uri.parse(app_uri)); + //i.putExtra("urlpath", app_uri); pIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); @@ -69,6 +81,29 @@ public class StatusUpdate extends Service { Log.i(LOG_TAG, "Service Created"); } + + //Send an Intent with an action named "custom-event-name". + //The Intent sent should be received by the ReceiverActivity. + private void sendMessage(int msg) { + Log.i(LOG_TAG, "Send msg to UI"); + Intent intent = new Intent("filter-updated"); + + String msg_str=""; + switch(msg){ + case MSG_NO_CONN: + msg_str="Manca connessione"; + break; + default: + //msg_str="done"; + break; + } + + intent.putExtra("msg", msg_str); + intent.putExtra("isCicleService", isCicleService); + + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); + } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void notifyBuilder(String status) { notification = new Notification.Builder(this) @@ -99,10 +134,10 @@ public class StatusUpdate extends Service { res.getString(R.string.app_update_notify_title), res.getString(R.string.app_update_new_version), pIntent); - notificationManager.notify(NOTIFY_APP_UPDATE, notification); + notificationManager.notify(NOTIFY_STATUS_UPDATE, notification); } - private final class BgThread extends Thread { + public final class BgThread extends Thread { public void run() { do { if (SNetwork.isConnected(cm)) { @@ -111,37 +146,44 @@ public class StatusUpdate extends Service { try { JSONObject jObject = new JSONObject(json); boolean newStatus = jObject.getBoolean("open"); - String statusChange = jObject.getString("date"); + String newChange = jObject.getString("date"); Calendar c = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.ITALY); String last_refresh = dateFormat.format(c.getTime()); - + if (newStatus != oldStatus) { String status = res.getString(R.string.close); if (newStatus) status = res.getString(R.string.open); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - notifyBuilder(status); - notificationManager.notify(0, notification); - } else { - getNotify(); - sendNotification(1); + //Se è il service automatico e la finestra principale + //non è attiva emmetti la notifica + if (isCicleService && !MainActivity.active) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + notifyBuilder(status); + notificationManager.notify(0, notification); + } else { + getNotify(); + sendNotification(1); + } } } + + //Salva lo stato dell'applicazione SUtility.saveState(getApplicationContext(), newStatus, - last_refresh, statusChange); + last_refresh, newChange); - if (!isCicleService) { - stopSelf(); - Log.i(LOG_TAG, "Service stop"); - // setDisplay(newStatus, last_refresh, statusChange); - } + //Avvisa la finestra principale di aggiornarsi + //o emettere un Toast di sentenza + if (isCicleService==false || MainActivity.active) + sendMessage(MSG_DONE); + //Addormento il service in millisecondi try { - Thread.sleep(refreshTime); + Log.d(LOG_TAG,"Dormo per: "+refreshTime+" sec"); + Thread.sleep(refreshTime*1000); } catch (InterruptedException ie) { Log.d(LOG_TAG, "Qualcosa è andato storto con il timer.\n" @@ -152,6 +194,10 @@ public class StatusUpdate extends Service { } } else { Log.d(LOG_TAG, "Non c'è connessione"); + if(! isCicleService){ + sendMessage(MSG_NO_CONN); + stopSelf(); + } } } while (isCicleService); } @@ -159,6 +205,7 @@ public class StatusUpdate extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + active=true; isCicleService = intent.getBooleanExtra("isCicleService", false); if (isCicleService) refreshTime = intent.getIntExtra("refreshTime", 0); @@ -166,19 +213,14 @@ public class StatusUpdate extends Service { serverName = intent.getStringExtra("serverName"); oldStatus = intent.getBooleanExtra("oldStatus", false); - Log.i(LOG_TAG, "Service Started"); + Log.i(LOG_TAG, "Os Service Start Command"); return super.onStartCommand(intent, flags, startId); } @Override public void onDestroy() { super.onDestroy(); + active = false; Log.i(LOG_TAG, "Service Destroyed"); } - - @Override - public IBinder onBind(Intent intent) { - return null; - } - -} +} \ No newline at end of file