From 508ba39c1ee0ebe43e473e4f5ac63c36c0a8ec45 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Tue, 28 Feb 2012 10:59:05 +0100 Subject: [PATCH] Working on an update service that check the latest version. --- android/AndroidManifest.xml | 4 ++ android/res/values/strings.xml | 4 ++ .../org/transdroid/gui/TorrentsFragment.java | 15 ++++--- .../org/transdroid/service/BootReceiver.java | 41 +++++++++++++------ 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 5cf87a0c..7db6aace 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -201,5 +201,9 @@ + + + + diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index 94d18ec3..c0931ab4 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -331,6 +331,10 @@ Color Picker Press on Color to apply +New Transdroid version available +New Transdroid search module available +You can now update to %1$s + Error during communication with server Error building request Error parsing of server response (please check your settings) diff --git a/android/src/org/transdroid/gui/TorrentsFragment.java b/android/src/org/transdroid/gui/TorrentsFragment.java index e423b27a..dd409074 100644 --- a/android/src/org/transdroid/gui/TorrentsFragment.java +++ b/android/src/org/transdroid/gui/TorrentsFragment.java @@ -86,26 +86,24 @@ import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; -import android.support.v4.app.ActionBar.OnNavigationListener; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; +import android.support.v4.app.ActionBar.OnNavigationListener; import android.support.v4.view.Menu; import android.support.v4.view.MenuItem; import android.support.v4.view.SubMenu; import android.view.ContextMenu; -import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector; -import android.view.GestureDetector.SimpleOnGestureListener; import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnClickListener; import android.view.View.OnTouchListener; -import android.view.ViewGroup; import android.widget.AdapterView; -import android.widget.AdapterView.AdapterContextMenuInfo; -import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; @@ -116,6 +114,8 @@ import android.widget.SpinnerAdapter; import android.widget.TableLayout; import android.widget.TextView; import android.widget.Toast; +import android.widget.AdapterView.AdapterContextMenuInfo; +import android.widget.AdapterView.OnItemClickListener; /** * The main screen for the Transdroid application and provides most on-the-surface functionality @@ -335,6 +335,9 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou // Start the alarm service, if needed BootReceiver.startAlarm(getActivity().getApplicationContext()); + // Check for new app version, if needed + BootReceiver.startUpdateCheck(getActivity().getApplicationContext()); + handleIntent(getActivity().getIntent()); } diff --git a/android/src/org/transdroid/service/BootReceiver.java b/android/src/org/transdroid/service/BootReceiver.java index c2906c09..68ed4ee6 100644 --- a/android/src/org/transdroid/service/BootReceiver.java +++ b/android/src/org/transdroid/service/BootReceiver.java @@ -29,42 +29,59 @@ import android.os.SystemClock; import android.preference.PreferenceManager; /** - * Receives a broadcast message when the device has started and - * is used to manually start/stop the alarm service. + * Receives a broadcast message when the device has started and is used to manually start/stop the alarm + * service. * * @author erickok - * + * */ public class BootReceiver extends BroadcastReceiver { private static final String LOG_NAME = "Boot receiver"; - - private static AlarmManager mgr; + + private static AlarmManager mgr = null; private static PendingIntent pi = null; + private static PendingIntent pui = null; @Override public void onReceive(Context context, Intent intent) { TLog.d(LOG_NAME, "Received fresh boot broadcast; start alarm service"); startAlarm(context); + startUpdateCheck(context); } - public static void cancelAlarm(){ + public static void cancelAlarm() { if (mgr != null) { mgr.cancel(pi); } } - - public static void startAlarm(Context context){ + + public static void startAlarm(Context context) { AlarmSettings settings = Preferences.readAlarmSettings(PreferenceManager.getDefaultSharedPreferences(context)); - + if (settings.isAlarmEnabled()) { // Set up PendingIntent for the alarm service - mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); + if (mgr == null) + mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, AlarmReceiver.class); pi = PendingIntent.getBroadcast(context, 0, i, 0); // First intent after a small (2 second) delay and repeat at the user-set intervals - mgr.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 2000, settings.getAlarmIntervalInMilliseconds(), pi); + mgr.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 2000, settings + .getAlarmIntervalInMilliseconds(), pi); } } - + + public static void startUpdateCheck(Context context) { + // Set up PendingIntent for the alarm service + if (mgr == null) + mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + mgr.cancel(pui); + + Intent i = new Intent(context, UpdateReceiver.class); + pui = PendingIntent.getBroadcast(context, 0, i, 0); + // First intent after a small (2 second) delay and repeat every day + mgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 2000, + AlarmManager.INTERVAL_DAY, pui); + } + }