mirror of
https://github.com/cwinfo/envayasms.git
synced 2024-11-08 18:00:27 +00:00
simplify polling UI to use fixed, 15 min intervals
This commit is contained in:
parent
8e31033862
commit
ec1dc62631
@ -2,8 +2,25 @@
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<EditTextPreference android:key="pref_target_url" android:title="Target URL" android:summary="URL to load when the SMS is received" android:defaultValue="http://pune.admin.tastykhana.in/admin/index.php/realtime_alerts/smsqueue"></EditTextPreference>
|
||||
<EditTextPreference android:key="pref_identifier" android:title="SMS Identifier" android:defaultValue="TK " android:summary="Handle only SMS messages starting with this string (leave empty to handle all messages)"></EditTextPreference>
|
||||
<CheckBoxPreference android:key="pref_poll_switch" android:title="Server Polling" android:disableDependentsState="false" android:summaryOff="Polling is disabled" android:summaryOn="Polling is enabled"></CheckBoxPreference>
|
||||
<EditTextPreference android:key="pref_poll_interval" android:title="Poll interval" android:defaultValue="5000" android:summary="Polling interval time in minutes"></EditTextPreference>
|
||||
<EditTextPreference
|
||||
android:key="pref_target_url"
|
||||
android:title="Target URL"
|
||||
android:summary="URL to load when the SMS is received"
|
||||
android:defaultValue="http://qkhack.appspot.com/kalsms_demo"
|
||||
></EditTextPreference>
|
||||
|
||||
<EditTextPreference
|
||||
android:key="pref_identifier"
|
||||
android:title="SMS Identifier"
|
||||
android:summary="Handle only SMS messages starting with this string (leave empty to handle all messages)"
|
||||
android:defaultValue="kal "
|
||||
></EditTextPreference>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_poll_switch"
|
||||
android:title="Server Polling"
|
||||
android:disableDependentsState="false"
|
||||
android:summary="Poll target URL every 15 minutes (Note: Polling increased power consumption, and is not supported by all phone models)"
|
||||
></CheckBoxPreference>
|
||||
|
||||
</PreferenceScreen>
|
@ -17,7 +17,7 @@ public class Main extends Activity {
|
||||
|
||||
public String identifier = "";
|
||||
public String targetUrl = "";
|
||||
|
||||
public Boolean polling = false;
|
||||
|
||||
public void onResume() {
|
||||
Log.d("KALSMS", "RESUME");
|
||||
@ -27,11 +27,14 @@ public class Main extends Activity {
|
||||
|
||||
this.identifier = settings.getString("pref_identifier", "");
|
||||
this.targetUrl = settings.getString("pref_target_url", "");
|
||||
|
||||
this.polling = settings.getBoolean("pref_poll_switch", false);
|
||||
|
||||
Log.d("KALSMS", "onResume ident:" + this.identifier +"\ntarget:" + this.targetUrl);
|
||||
|
||||
String infoText = new String();
|
||||
|
||||
// Home Screen text
|
||||
|
||||
infoText = "All SMS messages";
|
||||
|
||||
if (this.identifier.trim() != "") {
|
||||
@ -40,11 +43,16 @@ public class Main extends Activity {
|
||||
|
||||
infoText += " are now sent to <b>" + this.targetUrl +"</b> in the following format:";
|
||||
infoText += "<p><tt>GET " + this.targetUrl + "?sender=<phone#>&msg=<message></tt></p>";
|
||||
infoText += "If the response body contains text, it will SMSed back to the sender.";
|
||||
infoText += "If the response body contains text, it will SMS back to the originating phone.";
|
||||
|
||||
if (this.polling) {
|
||||
infoText += "<p>The target URL will be polled every 15 minutes</p>";
|
||||
}
|
||||
|
||||
infoText += "<br /><br /><b>Press Menu to set SMS identifier or target URL.</b>";
|
||||
|
||||
infoText += "<br /><br /><br />Questions/feedback: niryariv@gmail.com";
|
||||
// /Home Screen text
|
||||
|
||||
TextView info = (TextView) this.findViewById(R.id.info);
|
||||
info.setText(Html.fromHtml(infoText));
|
||||
|
@ -13,7 +13,6 @@ import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
||||
@ -54,11 +53,9 @@ public class Prefs extends PreferenceActivity implements OnSharedPreferenceChang
|
||||
Intent pintent = new Intent(this, SMSSender.class);
|
||||
PendingIntent pIntent = PendingIntent.getBroadcast(this,0,pintent, 0);
|
||||
if(checkbox.isChecked()) {
|
||||
long interval = 60*Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(this).getString("pref_poll_interval", "5000"));//5mins;//5mins
|
||||
long firstPoll = SystemClock.elapsedRealtime() + 60*Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(this).getString("pref_poll_interval", "5000"));
|
||||
alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstPoll, interval, pIntent);
|
||||
Log.d("KALSMS", "alarm manager turned on "+interval);
|
||||
}else {
|
||||
alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pIntent);
|
||||
Log.d("KALSMS", "alarm manager turned on");
|
||||
} else {
|
||||
alarm.cancel(pIntent);
|
||||
Log.d("SMS_GATEWAY", "alarm manager turned off");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user