From 61d24b2f64c3d1c4e27a737eab798e8c422e36f2 Mon Sep 17 00:00:00 2001 From: Jesse Young Date: Tue, 13 Sep 2011 16:06:50 -0700 Subject: [PATCH] add setting to enable/disable sms gateway --- res/xml/prefs.xml | 9 +++++++ src/org/envaya/kalsms/App.java | 26 ++++++++++++------- src/org/envaya/kalsms/BootReceiver.java | 6 ++++- .../kalsms/IncomingMessageForwarder.java | 5 ++++ src/org/envaya/kalsms/Main.java | 15 ++++++----- src/org/envaya/kalsms/Prefs.java | 5 ++++ 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/res/xml/prefs.xml b/res/xml/prefs.xml index 478996c..3005176 100755 --- a/res/xml/prefs.xml +++ b/res/xml/prefs.xml @@ -1,6 +1,15 @@ + + + 0) { - alarm.setRepeating( - AlarmManager.ELAPSED_REALTIME_WAKEUP, - SystemClock.elapsedRealtime(), - pollSeconds * 1000, - pendingIntent); - log("Checking for outgoing messages every " + pollSeconds + " sec"); - } else { - log("Not checking for outgoing messages."); + if (isEnabled()) + { + if (pollSeconds > 0) { + alarm.setRepeating( + AlarmManager.ELAPSED_REALTIME_WAKEUP, + SystemClock.elapsedRealtime(), + pollSeconds * 1000, + pendingIntent); + log("Checking for outgoing messages every " + pollSeconds + " sec"); + } else { + log("Not checking for outgoing messages."); + } } } @@ -103,6 +106,11 @@ public class App { return settings.getBoolean("launch_on_boot", false); } + public boolean isEnabled() + { + return settings.getBoolean("enabled", false); + } + public boolean getKeepInInbox() { return settings.getBoolean("keep_in_inbox", false); diff --git a/src/org/envaya/kalsms/BootReceiver.java b/src/org/envaya/kalsms/BootReceiver.java index 407ed66..bacf187 100755 --- a/src/org/envaya/kalsms/BootReceiver.java +++ b/src/org/envaya/kalsms/BootReceiver.java @@ -11,7 +11,11 @@ public class BootReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { App app = App.getInstance(context.getApplicationContext()); - + if (!app.isEnabled()) + { + return; + } + app.setOutgoingMessageAlarm(); if (app.getLaunchOnBoot()) diff --git a/src/org/envaya/kalsms/IncomingMessageForwarder.java b/src/org/envaya/kalsms/IncomingMessageForwarder.java index 3c4d43d..85a44b0 100755 --- a/src/org/envaya/kalsms/IncomingMessageForwarder.java +++ b/src/org/envaya/kalsms/IncomingMessageForwarder.java @@ -18,6 +18,11 @@ public class IncomingMessageForwarder extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { app = App.getInstance(context.getApplicationContext()); + if (!app.isEnabled()) + { + return; + } + try { String action = intent.getAction(); diff --git a/src/org/envaya/kalsms/Main.java b/src/org/envaya/kalsms/Main.java index fac47fc..644135a 100755 --- a/src/org/envaya/kalsms/Main.java +++ b/src/org/envaya/kalsms/Main.java @@ -104,18 +104,19 @@ public class Main extends Activity { TextView info = (TextView) this.findViewById(R.id.info); - info.setText(Html.fromHtml("SMS Gateway running.
")); - info.append(Html.fromHtml("Press Menu to edit settings.
")); - - showLogMessage("Server URL is: " + app.getDisplayString(app.getServerUrl())); - showLogMessage("Your phone number is: " + app.getDisplayString(app.getPhoneNumber())); - info.setMovementMethod(new ScrollingMovementMethod()); IntentFilter logReceiverFilter = new IntentFilter(); logReceiverFilter.addAction(App.LOG_INTENT); - registerReceiver(logReceiver, logReceiverFilter); + registerReceiver(logReceiver, logReceiverFilter); + + info.append(Html.fromHtml( + app.isEnabled() ? "SMS gateway running.
" : "SMS gateway disabled.
")); + info.append("Server URL is: " + app.getDisplayString(app.getServerUrl()) + "\n"); + info.append("Your phone number is: " + app.getDisplayString(app.getPhoneNumber()) + "\n"); + info.append(Html.fromHtml("Press Menu to edit settings.
")); + app.setOutgoingMessageAlarm(); } diff --git a/src/org/envaya/kalsms/Prefs.java b/src/org/envaya/kalsms/Prefs.java index 4c2c905..de1c98a 100755 --- a/src/org/envaya/kalsms/Prefs.java +++ b/src/org/envaya/kalsms/Prefs.java @@ -60,6 +60,11 @@ public class Prefs extends PreferenceActivity implements OnSharedPreferenceChang { app.log("Password changed"); } + else if (key.equals("enabled")) + { + app.log(app.isEnabled() ? "SMS Gateway started." : "SMS Gateway stopped."); + app.setOutgoingMessageAlarm(); + } updatePrefSummary(findPreference(key)); }