From: Eugene Crosser Date: Mon, 30 Jan 2012 17:29:32 +0000 (+0400) Subject: configurable update interval X-Git-Url: http://average.org/gitweb/?a=commitdiff_plain;h=4e67198f228c17d21e071e7f89f67c42e213bc11;p=WhereAmI.git configurable update interval --- diff --git a/res/values/arrays.xml b/res/values/arrays.xml new file mode 100644 index 0000000..4463e72 --- /dev/null +++ b/res/values/arrays.xml @@ -0,0 +1,13 @@ + + + + Раз в минуту + Раз в 20 минут + Раз в час + + + 60000 + 1200000 + 3600000 + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 91ad670..f78b682 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -7,6 +7,10 @@ Неудачная попытка Выход Конфигурация + Полный экран + Полный экран или с индикаторами + Периодичность обновления + Как часто обновлять информацию января февраля diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 8ebb456..5d9eece 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -2,7 +2,16 @@ xmlns:android="http://schemas.android.com/apk/res/android"> + diff --git a/src/org/average/whereami/WhereAmI.java b/src/org/average/whereami/WhereAmI.java index 1d3c268..49abbe2 100644 --- a/src/org/average/whereami/WhereAmI.java +++ b/src/org/average/whereami/WhereAmI.java @@ -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);