]> git.zerfleddert.de Git - FreeShisen/blame - src/de/cwde/freeshisen/SettingsActivity.java
update about box a bit.
[FreeShisen] / src / de / cwde / freeshisen / SettingsActivity.java
CommitLineData
92b19250 1package de.cwde.freeshisen;
42aa846a 2
3import android.content.SharedPreferences;
4import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
a320f5ea 5import android.content.res.Resources;
42aa846a 6import android.os.Bundle;
7import android.preference.*;
8
9public class SettingsActivity extends PreferenceActivity
655c3517 10implements OnSharedPreferenceChangeListener {
11
42aa846a 12 private ShisenSho app;
655c3517 13
42aa846a 14 private static final String KEY_PREF_DIFF = "pref_diff";
15 private static final String KEY_PREF_SIZE = "pref_size";
16 //private static final String KEY_PREF_GRAV = "pref_grav";
17 //private static final String KEY_PREF_TIME = "pref_time";
655c3517 18
42aa846a 19 @SuppressWarnings("deprecation")
20 @Override
a320f5ea 21 public void onCreate(Bundle savedInstanceState) {
22 super.onCreate(savedInstanceState);
23 app = ShisenSho.app();
24 addPreferencesFromResource(R.xml.preferences);
25 SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
655c3517 26
a320f5ea 27 sharedPreferences.registerOnSharedPreferenceChangeListener(this);
28 updateSummary(sharedPreferences, KEY_PREF_DIFF, KEY_PREF_DIFF, R.array.difficulties);
29 updateSummary(sharedPreferences, KEY_PREF_SIZE, KEY_PREF_SIZE, R.array.sizes);
30 }
42aa846a 31
32 @Override
33 public void onBackPressed() {
34 app.setOptions();
35 super.onBackPressed();
36 }
37
38 @SuppressWarnings("deprecation")
39 @Override
40 protected void onResume() {
a320f5ea 41 super.onResume();
42 getPreferenceScreen().getSharedPreferences()
655c3517 43 .registerOnSharedPreferenceChangeListener(this);
42aa846a 44 }
45
46 @SuppressWarnings("deprecation")
47 @Override
48 protected void onPause() {
a320f5ea 49 super.onPause();
50 getPreferenceScreen().getSharedPreferences()
655c3517 51 .unregisterOnSharedPreferenceChangeListener(this);
42aa846a 52 }
655c3517 53
a320f5ea 54 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
55 updateSummary(sharedPreferences, key, KEY_PREF_DIFF, R.array.difficulties);
56 updateSummary(sharedPreferences, key, KEY_PREF_SIZE, R.array.sizes);
57 }
58
59 private void updateSummary(SharedPreferences sharedPreferences, String changedkey, String mykey, int myresource) {
60 if (changedkey.equals(mykey)) {
61 // FIXME: handle NumberFormatException here?
62 int i = Integer.parseInt(sharedPreferences.getString(changedkey, "1"));
63
64 Resources res = getResources();
65 String[] mystrings = res.getStringArray(myresource);
66 String name = mystrings[i-1];
67
68 @SuppressWarnings("deprecation")
69 Preference myPref = findPreference(changedkey);
70 myPref.setSummary("Currently: " + name);
71 }
72 }
42aa846a 73}
Impressum, Datenschutz