]> cvs.zerfleddert.de Git - FreeShisen/blame - src/de/cwde/shisensho/SettingsActivity.java
remove "sample" files, fix classpath.
[FreeShisen] / src / de / cwde / shisensho / SettingsActivity.java
CommitLineData
42aa846a 1package de.cwde.shisensho;
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
54
a320f5ea 55 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
56 updateSummary(sharedPreferences, key, KEY_PREF_DIFF, R.array.difficulties);
57 updateSummary(sharedPreferences, key, KEY_PREF_SIZE, R.array.sizes);
58 }
59
60 private void updateSummary(SharedPreferences sharedPreferences, String changedkey, String mykey, int myresource) {
61 if (changedkey.equals(mykey)) {
62 // FIXME: handle NumberFormatException here?
63 int i = Integer.parseInt(sharedPreferences.getString(changedkey, "1"));
64
65 Resources res = getResources();
66 String[] mystrings = res.getStringArray(myresource);
67 String name = mystrings[i-1];
68
69 @SuppressWarnings("deprecation")
70 Preference myPref = findPreference(changedkey);
71 myPref.setSummary("Currently: " + name);
72 }
73 }
42aa846a 74}
Impressum, Datenschutz