]>
Commit | Line | Data |
---|---|---|
92b19250 | 1 | package de.cwde.freeshisen; |
94761ea5 | 2 | |
3 | import android.os.Bundle; | |
4e38ce41 | 4 | import android.preference.PreferenceManager; |
94761ea5 | 5 | import android.view.View; |
4e38ce41 | 6 | import android.widget.TextView; |
94761ea5 | 7 | import android.app.Activity; |
4e38ce41 | 8 | import android.app.AlertDialog; |
9 | import android.content.DialogInterface; | |
10 | import android.content.SharedPreferences; | |
224fb86f | 11 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
94761ea5 | 12 | |
224fb86f | 13 | public class HighscoreActivity extends Activity implements |
14 | OnSharedPreferenceChangeListener { | |
94761ea5 | 15 | |
16 | @Override | |
17 | protected void onCreate(Bundle savedInstanceState) { | |
18 | super.onCreate(savedInstanceState); | |
19 | setContentView(R.layout.highscore); | |
224fb86f | 20 | updateTextViews(); |
21 | ||
22 | PreferenceManager.getDefaultSharedPreferences(this) | |
23 | .registerOnSharedPreferenceChangeListener(this); | |
24 | } | |
25 | ||
26 | @Override | |
27 | protected void onResume() { | |
28 | super.onResume(); | |
29 | PreferenceManager.getDefaultSharedPreferences(this) | |
30 | .registerOnSharedPreferenceChangeListener(this); | |
31 | } | |
32 | ||
33 | @Override | |
34 | protected void onPause() { | |
35 | super.onPause(); | |
36 | PreferenceManager.getDefaultSharedPreferences(this) | |
37 | .unregisterOnSharedPreferenceChangeListener(this); | |
38 | } | |
39 | ||
40 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, | |
41 | String key) { | |
42 | updateTextViews(); | |
43 | } | |
44 | ||
45 | private void updateTextViews() { | |
46 | // argh... | |
47 | SharedPreferences sp = PreferenceManager | |
48 | .getDefaultSharedPreferences(this); | |
4e38ce41 | 49 | fillTextView(sp, R.id.textViewHL1, "hiscore_HL1"); |
50 | fillTextView(sp, R.id.textViewHL2, "hiscore_HL2"); | |
51 | fillTextView(sp, R.id.textViewHM1, "hiscore_HM1"); | |
52 | fillTextView(sp, R.id.textViewHM2, "hiscore_HM2"); | |
53 | fillTextView(sp, R.id.textViewHS1, "hiscore_HS1"); | |
54 | fillTextView(sp, R.id.textViewHS2, "hiscore_HS2"); | |
55 | fillTextView(sp, R.id.textViewEL1, "hiscore_EL1"); | |
56 | fillTextView(sp, R.id.textViewEL2, "hiscore_EL2"); | |
57 | fillTextView(sp, R.id.textViewEM1, "hiscore_EM1"); | |
58 | fillTextView(sp, R.id.textViewEM2, "hiscore_EM2"); | |
59 | fillTextView(sp, R.id.textViewES1, "hiscore_ES1"); | |
60 | fillTextView(sp, R.id.textViewES2, "hiscore_ES2"); | |
61 | } | |
62 | ||
63 | private void fillTextView(SharedPreferences sp, int id, String key) { | |
64 | TextView tv = (TextView) findViewById(id); | |
65 | tv.setText(sp.getString(key, "9:99:99")); | |
94761ea5 | 66 | } |
67 | ||
68 | public void clearHiscore(View view) { | |
4e38ce41 | 69 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
70 | ||
71 | builder.setMessage(R.string.clearhiscore_confirm_text); | |
72 | builder.setTitle(R.string.clearhiscore_confirm_title); | |
73 | ||
27afcc39 | 74 | builder.setPositiveButton(android.R.string.ok, |
4e38ce41 | 75 | new DialogInterface.OnClickListener() { |
224fb86f | 76 | public void onClick(DialogInterface dialog, int id) { |
77 | // User clicked OK button - delete hiscores | |
78 | SharedPreferences sp = PreferenceManager | |
79 | .getDefaultSharedPreferences(((AlertDialog) dialog) | |
80 | .getContext()); | |
81 | SharedPreferences.Editor editor = sp.edit(); | |
82 | editor.remove("hiscore_HL1"); | |
83 | editor.remove("hiscore_HL2"); | |
84 | editor.remove("hiscore_HM1"); | |
85 | editor.remove("hiscore_HM2"); | |
86 | editor.remove("hiscore_HS1"); | |
87 | editor.remove("hiscore_HS2"); | |
88 | editor.remove("hiscore_EL1"); | |
89 | editor.remove("hiscore_EL2"); | |
90 | editor.remove("hiscore_EM1"); | |
91 | editor.remove("hiscore_EM2"); | |
92 | editor.remove("hiscore_ES1"); | |
93 | editor.remove("hiscore_ES2"); | |
94 | editor.commit(); | |
95 | } | |
96 | }); | |
a8b770d4 | 97 | builder.setNegativeButton(android.R.string.cancel, null); |
4e38ce41 | 98 | |
99 | AlertDialog dialog = builder.create(); | |
100 | dialog.show(); | |
224fb86f | 101 | updateTextViews(); |
94761ea5 | 102 | } |
103 | } |