1 package de
.cwde
.freeshisen
;
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
.*;
9 public class SettingsActivity
extends PreferenceActivity
10 implements OnSharedPreferenceChangeListener
{
12 private ShisenSho app
;
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";
19 @SuppressWarnings("deprecation")
21 public void onCreate(Bundle savedInstanceState
) {
22 super.onCreate(savedInstanceState
);
23 app
= ShisenSho
.app();
24 addPreferencesFromResource(R
.xml
.preferences
);
25 SharedPreferences sharedPreferences
= getPreferenceScreen().getSharedPreferences();
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
);
33 public void onBackPressed() {
35 super.onBackPressed();
38 @SuppressWarnings("deprecation")
40 protected void onResume() {
42 getPreferenceScreen().getSharedPreferences()
43 .registerOnSharedPreferenceChangeListener(this);
46 @SuppressWarnings("deprecation")
48 protected void onPause() {
50 getPreferenceScreen().getSharedPreferences()
51 .unregisterOnSharedPreferenceChangeListener(this);
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
);
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"));
65 Resources res
= getResources();
66 String
[] mystrings
= res
.getStringArray(myresource
);
67 String name
= mystrings
[i
-1];
69 @SuppressWarnings("deprecation")
70 Preference myPref
= findPreference(changedkey
);
71 myPref
.setSummary("Currently: " + name
);