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_TILE
= "pref_tile";
17 //private static final String KEY_PREF_GRAV = "pref_grav";
18 //private static final String KEY_PREF_TIME = "pref_time";
20 @SuppressWarnings("deprecation")
22 public void onCreate(Bundle savedInstanceState
) {
23 super.onCreate(savedInstanceState
);
24 app
= ShisenSho
.app();
25 addPreferencesFromResource(R
.xml
.preferences
);
26 SharedPreferences sharedPreferences
= getPreferenceScreen().getSharedPreferences();
28 sharedPreferences
.registerOnSharedPreferenceChangeListener(this);
29 updateSummary(sharedPreferences
, KEY_PREF_DIFF
, KEY_PREF_DIFF
, R
.array
.difficulties
);
30 updateSummary(sharedPreferences
, KEY_PREF_SIZE
, KEY_PREF_SIZE
, R
.array
.sizes
);
31 updateTileSummary(sharedPreferences
, KEY_PREF_TILE
);
35 public void onBackPressed() {
37 super.onBackPressed();
40 @SuppressWarnings("deprecation")
42 protected void onResume() {
44 getPreferenceScreen().getSharedPreferences()
45 .registerOnSharedPreferenceChangeListener(this);
48 @SuppressWarnings("deprecation")
50 protected void onPause() {
52 getPreferenceScreen().getSharedPreferences()
53 .unregisterOnSharedPreferenceChangeListener(this);
56 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences
, String key
) {
57 updateSummary(sharedPreferences
, key
, KEY_PREF_DIFF
, R
.array
.difficulties
);
58 updateSummary(sharedPreferences
, key
, KEY_PREF_SIZE
, R
.array
.sizes
);
59 updateTileSummary(sharedPreferences
, key
);
62 private void updateSummary(SharedPreferences sharedPreferences
, String changedkey
, String mykey
, int myresource
) {
63 if (changedkey
.equals(mykey
)) {
64 // FIXME: handle NumberFormatException here?
65 int i
= Integer
.parseInt(sharedPreferences
.getString(changedkey
, "1"));
67 Resources res
= getResources();
68 String
[] mystrings
= res
.getStringArray(myresource
);
69 String name
= mystrings
[i
-1];
71 @SuppressWarnings("deprecation")
72 Preference myPref
= findPreference(changedkey
);
73 myPref
.setSummary("Currently: " + name
);
77 private void updateTileSummary(SharedPreferences sharedPreferences
, String changedkey
) {
78 if (changedkey
.equals(KEY_PREF_TILE
)) {
79 String name
= sharedPreferences
.getString(KEY_PREF_TILE
, "classic");
81 @SuppressWarnings("deprecation")
82 Preference myPref
= findPreference(KEY_PREF_TILE
);
83 myPref
.setSummary("Current Tileset: " + name
);