1 package de
.cwde
.freeshisen
;
3 import android
.os
.Bundle
;
4 import android
.preference
.PreferenceManager
;
5 import android
.view
.View
;
6 import android
.widget
.TextView
;
7 import android
.app
.Activity
;
8 import android
.app
.AlertDialog
;
9 import android
.content
.DialogInterface
;
10 import android
.content
.SharedPreferences
;
11 import android
.content
.SharedPreferences
.OnSharedPreferenceChangeListener
;
13 public class HighscoreActivity
extends Activity
implements
14 OnSharedPreferenceChangeListener
{
17 protected void onCreate(Bundle savedInstanceState
) {
18 super.onCreate(savedInstanceState
);
19 setContentView(R
.layout
.highscore
);
22 PreferenceManager
.getDefaultSharedPreferences(this)
23 .registerOnSharedPreferenceChangeListener(this);
27 protected void onResume() {
29 PreferenceManager
.getDefaultSharedPreferences(this)
30 .registerOnSharedPreferenceChangeListener(this);
34 protected void onPause() {
36 PreferenceManager
.getDefaultSharedPreferences(this)
37 .unregisterOnSharedPreferenceChangeListener(this);
40 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences
,
45 private void updateTextViews() {
47 SharedPreferences sp
= PreferenceManager
48 .getDefaultSharedPreferences(this);
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");
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"));
68 public void clearHiscore(View view
) {
69 AlertDialog
.Builder builder
= new AlertDialog
.Builder(this);
71 builder
.setMessage(R
.string
.clearhiscore_confirm_text
);
72 builder
.setTitle(R
.string
.clearhiscore_confirm_title
);
74 builder
.setPositiveButton(android
.R
.string
.ok
,
75 new DialogInterface
.OnClickListener() {
76 public void onClick(DialogInterface dialog
, int id
) {
77 // User clicked OK button - delete hiscores
78 SharedPreferences sp
= PreferenceManager
79 .getDefaultSharedPreferences(((AlertDialog
) dialog
)
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");
97 builder
.setNegativeButton(android
.R
.string
.cancel
,
98 new DialogInterface
.OnClickListener() {
99 public void onClick(DialogInterface dialog
, int id
) {
100 // User cancelled the dialog - nothing to do
104 AlertDialog dialog
= builder
.create();