configurable update interval
[WhereAmI.git] / src / org / average / whereami / WhereAmI.java
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);