X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/FreeShisen/blobdiff_plain/27afcc3975e4251c42d5262f01191635c2eaa060..88d6d77f2bcf4dd81d20ba11d376f57b5c3b2215:/src/de/cwde/freeshisen/HighscoreActivity.java diff --git a/src/de/cwde/freeshisen/HighscoreActivity.java b/src/de/cwde/freeshisen/HighscoreActivity.java index 70d5f3d..bf94458 100644 --- a/src/de/cwde/freeshisen/HighscoreActivity.java +++ b/src/de/cwde/freeshisen/HighscoreActivity.java @@ -8,15 +8,44 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -public class HighscoreActivity extends Activity { +public class HighscoreActivity extends Activity implements +OnSharedPreferenceChangeListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.highscore); - // now fill the values, argh... - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + updateTextViews(); + + PreferenceManager.getDefaultSharedPreferences(this) + .registerOnSharedPreferenceChangeListener(this); + } + + @Override + protected void onResume() { + super.onResume(); + PreferenceManager.getDefaultSharedPreferences(this) + .registerOnSharedPreferenceChangeListener(this); + } + + @Override + protected void onPause() { + super.onPause(); + PreferenceManager.getDefaultSharedPreferences(this) + .unregisterOnSharedPreferenceChangeListener(this); + } + + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, + String key) { + updateTextViews(); + } + + private void updateTextViews() { + // argh... + SharedPreferences sp = PreferenceManager + .getDefaultSharedPreferences(this); fillTextView(sp, R.id.textViewHL1, "hiscore_HL1"); fillTextView(sp, R.id.textViewHL2, "hiscore_HL2"); fillTextView(sp, R.id.textViewHM1, "hiscore_HM1"); @@ -44,35 +73,36 @@ public class HighscoreActivity extends Activity { builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // User clicked OK button - delete hiscores - SharedPreferences sp = PreferenceManager - .getDefaultSharedPreferences( - ((AlertDialog) dialog).getContext()); - SharedPreferences.Editor editor = sp.edit(); - editor.remove("hiscore_HL1"); - editor.remove("hiscore_HL2"); - editor.remove("hiscore_HM1"); - editor.remove("hiscore_HM2"); - editor.remove("hiscore_HS1"); - editor.remove("hiscore_HS2"); - editor.remove("hiscore_EL1"); - editor.remove("hiscore_EL2"); - editor.remove("hiscore_EM1"); - editor.remove("hiscore_EM2"); - editor.remove("hiscore_ES1"); - editor.remove("hiscore_ES2"); - editor.commit(); - } - }); + public void onClick(DialogInterface dialog, int id) { + // User clicked OK button - delete hiscores + SharedPreferences sp = PreferenceManager + .getDefaultSharedPreferences(((AlertDialog) dialog) + .getContext()); + SharedPreferences.Editor editor = sp.edit(); + editor.remove("hiscore_HL1"); + editor.remove("hiscore_HL2"); + editor.remove("hiscore_HM1"); + editor.remove("hiscore_HM2"); + editor.remove("hiscore_HS1"); + editor.remove("hiscore_HS2"); + editor.remove("hiscore_EL1"); + editor.remove("hiscore_EL2"); + editor.remove("hiscore_EM1"); + editor.remove("hiscore_EM2"); + editor.remove("hiscore_ES1"); + editor.remove("hiscore_ES2"); + editor.commit(); + } + }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // User cancelled the dialog - nothing to do - } - }); + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog - nothing to do + } + }); AlertDialog dialog = builder.create(); dialog.show(); + updateTextViews(); } }