]> cvs.zerfleddert.de Git - FreeShisen/blob - src/de/cwde/freeshisen/SettingsActivity.java
fix name
[FreeShisen] / src / de / cwde / freeshisen / SettingsActivity.java
1 package de.cwde.freeshisen;
2
3 import android.content.SharedPreferences;
4 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
5 import android.content.res.Resources;
6 import android.os.Bundle;
7 import android.preference.*;
8
9 public class SettingsActivity extends PreferenceActivity
10 implements OnSharedPreferenceChangeListener {
11
12 private ShisenSho app;
13
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";
18
19 @SuppressWarnings("deprecation")
20 @Override
21 public void onCreate(Bundle savedInstanceState) {
22 super.onCreate(savedInstanceState);
23 app = ShisenSho.app();
24 addPreferencesFromResource(R.xml.preferences);
25 SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
26
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 }
31
32 @Override
33 public void onBackPressed() {
34 app.setOptions();
35 super.onBackPressed();
36 }
37
38 @SuppressWarnings("deprecation")
39 @Override
40 protected void onResume() {
41 super.onResume();
42 getPreferenceScreen().getSharedPreferences()
43 .registerOnSharedPreferenceChangeListener(this);
44 }
45
46 @SuppressWarnings("deprecation")
47 @Override
48 protected void onPause() {
49 super.onPause();
50 getPreferenceScreen().getSharedPreferences()
51 .unregisterOnSharedPreferenceChangeListener(this);
52 }
53
54
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 }
74 }
Impressum, Datenschutz