]> average.org Git - WhereAmI.git/commitdiff
configurable update interval
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Mon, 30 Jan 2012 17:29:32 +0000 (21:29 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Mon, 30 Jan 2012 17:29:32 +0000 (21:29 +0400)
res/values/arrays.xml [new file with mode: 0644]
res/values/strings.xml
res/xml/preferences.xml
src/org/average/whereami/WhereAmI.java

diff --git a/res/values/arrays.xml b/res/values/arrays.xml
new file mode 100644 (file)
index 0000000..4463e72
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+  <string-array name="updatenames">
+    <item>Раз в минуту</item>
+    <item>Раз в 20 минут</item>
+    <item>Раз в час</item>
+  </string-array>
+  <string-array name="updatevals">
+    <item>60000</item>
+    <item>1200000</item>
+    <item>3600000</item>
+  </string-array>
+</resources>
index 91ad670eeb12bcc8043e1a997356a7be4a87b656..f78b682ada5613b193aeae49f603f21a114eac54 100644 (file)
@@ -7,6 +7,10 @@
     <string name="failtry">Неудачная попытка</string>
     <string name="quit">Выход</string>
     <string name="settings">Конфигурация</string>
+    <string name="fullscreentitle">Полный экран</string>
+    <string name="fullscreensummary">Полный экран или с индикаторами</string>
+    <string name="updatetitle">Периодичность обновления</string>
+    <string name="updatesummary">Как часто обновлять информацию</string>
     <string-array name="month">
         <item>января</item>
         <item>февраля</item>
index 8ebb456175c8d069c6dc678a90fd6d1722175eaa..5d9eece5ea46ea92b980d961ba8829c66715e3e1 100644 (file)
@@ -2,7 +2,16 @@
   xmlns:android="http://schemas.android.com/apk/res/android">
     <CheckBoxPreference
       android:key="fullscreen"
-      android:title="Use full screen display"
-      android:summary="Check it on, check it off"
+      android:title="@string/fullscreentitle"
+      android:summary="@string/fullscreensummary"
+      android:defaultValue="false"
+    />
+    <ListPreference
+      android:key="updateperiod"
+      android:title="@string/updatetitle"
+      android:summary="@string/updatesummary"
+      android:defaultValue="120000"
+      android:entries="@array/updatenames"
+      android:entryValues="@array/updatevals"
     />
 </PreferenceScreen>
index 1d3c2686e26da6b773d8da8b0042efab0bbc6bd8..49abbe2919af7262b22fcabe30b5629f9bfc2b43 100644 (file)
@@ -16,6 +16,7 @@ import android.content.IntentFilter;
 import android.content.Context;
 import android.content.res.Resources;
 import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
 import android.text.format.Time;
 import android.util.Log;
 import android.view.View;
@@ -29,6 +30,7 @@ import android.widget.TextView;
 public class WhereAmI extends Activity
 {
     private WifiManager wifiman;
+    private Long updatedelay = 60000L;
     private Integer runningtasks = 0;
     private SharedPreferences prefs;
 
@@ -133,7 +135,7 @@ public class WhereAmI extends Activity
             connChangedRegistered = true;
             boolean wifion = wifiman.setWifiEnabled(true);
             Log.w("WhereAmI", "enabling wifi result " + wifion);
-            mHandler.postDelayed(resetInfo, 30000);
+            mHandler.postDelayed(resetInfo, updatedelay);
             mHandler.postDelayed(this, 60000);
         }
     };
@@ -180,19 +182,11 @@ public class WhereAmI extends Activity
 
     /** Called when the activity is first created. */
     @Override
-    public void onCreate(Bundle savedInstanceState)
-    {
+    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        prefs = getSharedPreferences("WhereAmI", MODE_PRIVATE);
         wifiman = (WifiManager)getSystemService(Context.WIFI_SERVICE);
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
-        boolean fullscreen = prefs.getBoolean("fullscreen", false);
-        if (fullscreen) {
-            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
-            getWindow().clearFlags(WindowManager.LayoutParams.
-                                                  FLAG_FORCE_NOT_FULLSCREEN);
-        }
         setContentView(R.layout.main);
         res = getResources();
         month = res.getStringArray(R.array.month);
@@ -211,18 +205,32 @@ public class WhereAmI extends Activity
         Log.w("WhereAmI", "created UI, update task created");
     }
 
+    /** Called when reactivated */
+    @Override
+    public void onResume() {
+        super.onResume();
+        prefs = PreferenceManager.getDefaultSharedPreferences(this);
+        boolean fullscreen = prefs.getBoolean("fullscreen", false);
+        updatedelay = Long.parseLong(prefs.getString("updateperiod", "1200000"));
+        if (fullscreen) {
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+            getWindow().clearFlags(WindowManager.LayoutParams.
+                                                  FLAG_FORCE_NOT_FULLSCREEN);
+        } else {
+            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+        }
+    }
+
     /** Called when put to background */
     @Override
-    public void onPause()
-    {
+    public void onPause() {
         super.onPause();
         Log.w("WhereAmI", "going background");
     }
 
     /** Called when the activity is destroyed. */
     @Override
-    public void onDestroy()
-    {
+    public void onDestroy() {
         super.onDestroy();
         Log.w("WhereAmI", "going down");
        mHandler.removeCallbacks(updateClock);