5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-11-08 09:50:26 +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"?>
<PreferenceScreen
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
android:key="server_url"
android:title="Server URL"

View File

@ -67,15 +67,18 @@ public class App {
int pollSeconds = getOutgoingPollSeconds();
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.");
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);

View File

@ -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())

View File

@ -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();

View File

@ -104,18 +104,19 @@ public class Main extends Activity {
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());
IntentFilter logReceiverFilter = new IntentFilter();
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();
}

View File

@ -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));
}