From: gitknilch Date: Fri, 8 Mar 2013 19:19:34 +0000 (+0100) Subject: more hiscore stuff... X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/FreeShisen/commitdiff_plain/4e38ce41b804c39fcf12c0ceda84a46c445b0672?ds=inline;hp=--cc more hiscore stuff... Change-Id: Ie1de1c67374e151c548be39c822ce8daed7ce0ce Signed-off-by: gitknilch --- 4e38ce41b804c39fcf12c0ceda84a46c445b0672 diff --git a/res/values/strings.xml b/res/values/strings.xml index 2d1f10d..0ffa59f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,6 +1,5 @@ - FreeShisen Clean Hint @@ -35,5 +34,9 @@ Get the source code: https://code.google.com/p/freeshisen/ "Medium: 1st " "Small: 1st " 00:00:00 + Really clear best times? + This will clear all saved times. Hit "OK" if you really want to do this. + OK + Cancel \ No newline at end of file diff --git a/src/de/cwde/freeshisen/HighscoreActivity.java b/src/de/cwde/freeshisen/HighscoreActivity.java index 9caf497..0af0372 100644 --- a/src/de/cwde/freeshisen/HighscoreActivity.java +++ b/src/de/cwde/freeshisen/HighscoreActivity.java @@ -1,8 +1,13 @@ package de.cwde.freeshisen; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.View; +import android.widget.TextView; import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.SharedPreferences; public class HighscoreActivity extends Activity { @@ -10,9 +15,64 @@ public class HighscoreActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.highscore); + // now fill the values, 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"); + fillTextView(sp, R.id.textViewHM2, "hiscore_HM2"); + fillTextView(sp, R.id.textViewHS1, "hiscore_HS1"); + fillTextView(sp, R.id.textViewHS2, "hiscore_HS2"); + fillTextView(sp, R.id.textViewEL1, "hiscore_EL1"); + fillTextView(sp, R.id.textViewEL2, "hiscore_EL2"); + fillTextView(sp, R.id.textViewEM1, "hiscore_EM1"); + fillTextView(sp, R.id.textViewEM2, "hiscore_EM2"); + fillTextView(sp, R.id.textViewES1, "hiscore_ES1"); + fillTextView(sp, R.id.textViewES2, "hiscore_ES2"); + } + + private void fillTextView(SharedPreferences sp, int id, String key) { + TextView tv = (TextView) findViewById(id); + tv.setText(sp.getString(key, "9:99:99")); } public void clearHiscore(View view) { - // TODO + AlertDialog.Builder builder = new AlertDialog.Builder(this); + + builder.setMessage(R.string.clearhiscore_confirm_text); + builder.setTitle(R.string.clearhiscore_confirm_title); + + builder.setPositiveButton(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(); + } + }); + builder.setNegativeButton(R.string.cancel, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog - nothing to do + } + }); + + AlertDialog dialog = builder.create(); + dialog.show(); } }