]> git.zerfleddert.de Git - FreeShisen/commitdiff
more hiscore stuff...
authorgitknilch <gitknilch@cwde.de>
Fri, 8 Mar 2013 19:19:34 +0000 (20:19 +0100)
committergitknilch <gitknilch@cwde.de>
Fri, 8 Mar 2013 19:19:34 +0000 (20:19 +0100)
Change-Id: Ie1de1c67374e151c548be39c822ce8daed7ce0ce
Signed-off-by: gitknilch <gitknilch@cwde.de>
res/values/strings.xml
src/de/cwde/freeshisen/HighscoreActivity.java

index 2d1f10daa125cfd07f6604df46503c7fc280e673..0ffa59fb25d9af46c3ffea23a6ba4f84b6ead585 100644 (file)
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-
     <string name="app_name">FreeShisen</string>
     <string name="clean">Clean</string>
     <string name="hint">Hint</string>
@@ -35,5 +34,9 @@ Get the source code: https://code.google.com/p/freeshisen/</string>
     <string name="hiscore_medium1st">"Medium: 1st "</string>
     <string name="hiscore_small1">"Small: 1st "</string>
     <string name="zerotime">00:00:00</string>
+    <string name="clearhiscore_confirm_title">Really clear best times?</string>
+    <string name="clearhiscore_confirm_text">This will clear all saved times. Hit &quot;OK&quot; if you really want to do this.</string>
+    <string name="ok">OK</string>
+    <string name="cancel">Cancel</string>
 
 </resources>
\ No newline at end of file
index 9caf4976c762601405584372d89eda3d53e4f916..0af037228ae3375d8326335323623f2b7caf46e6 100644 (file)
@@ -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();
        }
 }
Impressum, Datenschutz