5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-09-18 21:39:34 +00:00

add setting to enable/disable sms gateway

This commit is contained in:
Jesse Young 2011-09-13 16:06:50 -07:00
parent e79fe7ce23
commit 61d24b2f64
6 changed files with 49 additions and 17 deletions

View File

@ -1,6 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="enabled"
android:title="Enable KalSMS?"
android:defaultValue='false'
android:summaryOn="All new SMS will be forwarded between phone and server"
android:summaryOff="New SMS will not be forwarded between phone and server"
></CheckBoxPreference>
<EditTextPreference <EditTextPreference
android:key="server_url" android:key="server_url"
android:title="Server URL" android:title="Server URL"

View File

@ -67,15 +67,18 @@ public class App {
int pollSeconds = getOutgoingPollSeconds(); int pollSeconds = getOutgoingPollSeconds();
if (pollSeconds > 0) { if (isEnabled())
alarm.setRepeating( {
AlarmManager.ELAPSED_REALTIME_WAKEUP, if (pollSeconds > 0) {
SystemClock.elapsedRealtime(), alarm.setRepeating(
pollSeconds * 1000, AlarmManager.ELAPSED_REALTIME_WAKEUP,
pendingIntent); SystemClock.elapsedRealtime(),
log("Checking for outgoing messages every " + pollSeconds + " sec"); pollSeconds * 1000,
} else { pendingIntent);
log("Not checking for outgoing messages."); 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); return settings.getBoolean("launch_on_boot", false);
} }
public boolean isEnabled()
{
return settings.getBoolean("enabled", false);
}
public boolean getKeepInInbox() public boolean getKeepInInbox()
{ {
return settings.getBoolean("keep_in_inbox", false); return settings.getBoolean("keep_in_inbox", false);

View File

@ -11,7 +11,11 @@ public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) public void onReceive(Context context, Intent intent)
{ {
App app = App.getInstance(context.getApplicationContext()); App app = App.getInstance(context.getApplicationContext());
if (!app.isEnabled())
{
return;
}
app.setOutgoingMessageAlarm(); app.setOutgoingMessageAlarm();
if (app.getLaunchOnBoot()) if (app.getLaunchOnBoot())

View File

@ -18,6 +18,11 @@ public class IncomingMessageForwarder extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
app = App.getInstance(context.getApplicationContext()); app = App.getInstance(context.getApplicationContext());
if (!app.isEnabled())
{
return;
}
try { try {
String action = intent.getAction(); String action = intent.getAction();

View File

@ -104,18 +104,19 @@ public class Main extends Activity {
TextView info = (TextView) this.findViewById(R.id.info); TextView info = (TextView) this.findViewById(R.id.info);
info.setText(Html.fromHtml("<b>SMS Gateway running.</b><br />"));
info.append(Html.fromHtml("<b>Press Menu to edit settings.</b><br />"));
showLogMessage("Server URL is: " + app.getDisplayString(app.getServerUrl()));
showLogMessage("Your phone number is: " + app.getDisplayString(app.getPhoneNumber()));
info.setMovementMethod(new ScrollingMovementMethod()); info.setMovementMethod(new ScrollingMovementMethod());
IntentFilter logReceiverFilter = new IntentFilter(); IntentFilter logReceiverFilter = new IntentFilter();
logReceiverFilter.addAction(App.LOG_INTENT); logReceiverFilter.addAction(App.LOG_INTENT);
registerReceiver(logReceiver, logReceiverFilter); registerReceiver(logReceiver, logReceiverFilter);
info.append(Html.fromHtml(
app.isEnabled() ? "<b>SMS gateway running.</b><br />" : "<b>SMS gateway disabled.</b><br />"));
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("<b>Press Menu to edit settings.</b><br />"));
app.setOutgoingMessageAlarm(); app.setOutgoingMessageAlarm();
} }

View File

@ -60,6 +60,11 @@ public class Prefs extends PreferenceActivity implements OnSharedPreferenceChang
{ {
app.log("Password changed"); app.log("Password changed");
} }
else if (key.equals("enabled"))
{
app.log(app.isEnabled() ? "SMS Gateway started." : "SMS Gateway stopped.");
app.setOutgoingMessageAlarm();
}
updatePrefSummary(findPreference(key)); updatePrefSummary(findPreference(key));
} }