From a831b35c9bb19f248929aa47b4ff67f2adabcc8d Mon Sep 17 00:00:00 2001 From: "isaac.jones" Date: Sun, 18 Jan 2009 01:43:08 +0000 Subject: [PATCH] Switched to using a BroadcastIntent for restarting the timer. Simplifies things a bit. git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1761 72b678ce-9140-0410-bee8-679b907dd61a --- AndroidManifest.xml | 4 --- src/org/openintents/safe/CategoryList.java | 6 ++-- src/org/openintents/safe/FrontDoor.java | 12 +------ src/org/openintents/safe/PassList.java | 2 +- .../safe/service/ServiceDispatch.aidl | 1 - .../safe/service/ServiceDispatchImpl.java | 34 ++++++++++++++----- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 8c7e872..1caa869 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -49,10 +49,6 @@ - - - - diff --git a/src/org/openintents/safe/CategoryList.java b/src/org/openintents/safe/CategoryList.java index 5543724..bcd239b 100644 --- a/src/org/openintents/safe/CategoryList.java +++ b/src/org/openintents/safe/CategoryList.java @@ -469,7 +469,7 @@ public class CategoryList extends ListActivity { } public boolean onOptionsItemSelected(MenuItem item) { - startActivity (restartTimerIntent); + sendBroadcast (restartTimerIntent); AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int position=-1; @@ -602,7 +602,7 @@ public class CategoryList extends ListActivity { protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); - startActivity (restartTimerIntent); + sendBroadcast (restartTimerIntent); launchPassList(rows.get(position).id); } @@ -629,7 +629,7 @@ public class CategoryList extends ListActivity { if ((name==null) || (name=="")) return -1; CategoryEntry entry = new CategoryEntry(); - startActivity (restartTimerIntent); + sendBroadcast (restartTimerIntent); String namePlain = name; try { diff --git a/src/org/openintents/safe/FrontDoor.java b/src/org/openintents/safe/FrontDoor.java index aa747ff..a15ff76 100644 --- a/src/org/openintents/safe/FrontDoor.java +++ b/src/org/openintents/safe/FrontDoor.java @@ -148,17 +148,7 @@ public class FrontDoor extends Activity { } else if (externalAccess){ // which action? - if (action.equals (CryptoIntents.ACTION_RESTART_TIMER)) { - if (service != null) { - try { - service.restartTimer(); - callbackResult = RESULT_OK; - } catch (RemoteException e) { - // TODO Auto-generated catch block - Log.e (TAG, "remoteException in Restart Timer"); - } - } - } else if (action.equals (CryptoIntents.ACTION_ENCRYPT)) { + if (action.equals (CryptoIntents.ACTION_ENCRYPT)) { callbackResult = encryptIntent(thisIntent, callbackIntent); } else if (action.equals (CryptoIntents.ACTION_DECRYPT)) { callbackResult = decryptIntent(thisIntent, callbackIntent); diff --git a/src/org/openintents/safe/PassList.java b/src/org/openintents/safe/PassList.java index f97f435..2e639ce 100644 --- a/src/org/openintents/safe/PassList.java +++ b/src/org/openintents/safe/PassList.java @@ -347,7 +347,7 @@ public class PassList extends ListActivity { } public boolean onOptionsItemSelected(MenuItem item) { - startActivity (restartTimerIntent); + sendBroadcast (restartTimerIntent); AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int position=-1; if (info==null) { diff --git a/src/org/openintents/safe/service/ServiceDispatch.aidl b/src/org/openintents/safe/service/ServiceDispatch.aidl index 631be0d..ba06008 100644 --- a/src/org/openintents/safe/service/ServiceDispatch.aidl +++ b/src/org/openintents/safe/service/ServiceDispatch.aidl @@ -22,5 +22,4 @@ interface ServiceDispatch { String encrypt (String clearText); String decrypt (String cryptoText); void setTimeoutMinutes(int timeoutMinutesIn); - void restartTimer(); } diff --git a/src/org/openintents/safe/service/ServiceDispatchImpl.java b/src/org/openintents/safe/service/ServiceDispatchImpl.java index 8b9033d..f7ffb30 100644 --- a/src/org/openintents/safe/service/ServiceDispatchImpl.java +++ b/src/org/openintents/safe/service/ServiceDispatchImpl.java @@ -26,7 +26,10 @@ import org.openintents.safe.CryptoHelperException; import android.app.Service; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.os.IBinder; import android.util.Log; import android.os.CountDownTimer; @@ -51,6 +54,18 @@ public class ServiceDispatchImpl extends Service { public void onCreate() { super.onCreate(); + BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(CryptoIntents.ACTION_RESTART_TIMER)) { + restartTimer(); + } + } + }; + + IntentFilter filter = new IntentFilter(); + filter.addAction (CryptoIntents.ACTION_RESTART_TIMER); + registerReceiver(mIntentReceiver, filter); + Log.d( TAG,"onCreate" ); } @@ -83,7 +98,15 @@ public class ServiceDispatchImpl extends Service { t.start(); Log.d(TAG, "Timer started with: " + timeoutUntilStop ); } - + + public void restartTimer () { + // must be started with startTimer first. + Log.d(TAG,"timer restarted"); + if (t != null) { + t.cancel(); + t.start(); + } + } /** * The ServiceDispatch is defined through IDL @@ -132,14 +155,7 @@ public class ServiceDispatchImpl extends Service { timeoutUntilStop = timeoutMinutes * 60000; Log.d(TAG,"set timeout to "+timeoutMinutes); } - - public void restartTimer () { - // must be started with startTimer first. - if (t != null) { - t.cancel(); - t.start(); - } - } + }; } -- 2.50.1