]> cvs.zerfleddert.de Git - FreeShisen/blame - src/de/cwde/freeshisen/HighscoreActivity.java
add hiscore stuff.
[FreeShisen] / src / de / cwde / freeshisen / HighscoreActivity.java
CommitLineData
92b19250 1package de.cwde.freeshisen;
94761ea5 2
3import android.os.Bundle;
4e38ce41 4import android.preference.PreferenceManager;
94761ea5 5import android.view.View;
4e38ce41 6import android.widget.TextView;
94761ea5 7import android.app.Activity;
4e38ce41 8import android.app.AlertDialog;
9import android.content.DialogInterface;
10import android.content.SharedPreferences;
94761ea5 11
12public class HighscoreActivity extends Activity {
13
14 @Override
15 protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.highscore);
4e38ce41 18 // now fill the values, argh...
19 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
20 fillTextView(sp, R.id.textViewHL1, "hiscore_HL1");
21 fillTextView(sp, R.id.textViewHL2, "hiscore_HL2");
22 fillTextView(sp, R.id.textViewHM1, "hiscore_HM1");
23 fillTextView(sp, R.id.textViewHM2, "hiscore_HM2");
24 fillTextView(sp, R.id.textViewHS1, "hiscore_HS1");
25 fillTextView(sp, R.id.textViewHS2, "hiscore_HS2");
26 fillTextView(sp, R.id.textViewEL1, "hiscore_EL1");
27 fillTextView(sp, R.id.textViewEL2, "hiscore_EL2");
28 fillTextView(sp, R.id.textViewEM1, "hiscore_EM1");
29 fillTextView(sp, R.id.textViewEM2, "hiscore_EM2");
30 fillTextView(sp, R.id.textViewES1, "hiscore_ES1");
31 fillTextView(sp, R.id.textViewES2, "hiscore_ES2");
32 }
33
34 private void fillTextView(SharedPreferences sp, int id, String key) {
35 TextView tv = (TextView) findViewById(id);
36 tv.setText(sp.getString(key, "9:99:99"));
94761ea5 37 }
38
39 public void clearHiscore(View view) {
4e38ce41 40 AlertDialog.Builder builder = new AlertDialog.Builder(this);
41
42 builder.setMessage(R.string.clearhiscore_confirm_text);
43 builder.setTitle(R.string.clearhiscore_confirm_title);
44
27afcc39 45 builder.setPositiveButton(android.R.string.ok,
4e38ce41 46 new DialogInterface.OnClickListener() {
47 public void onClick(DialogInterface dialog, int id) {
48 // User clicked OK button - delete hiscores
49 SharedPreferences sp = PreferenceManager
50 .getDefaultSharedPreferences(
51 ((AlertDialog) dialog).getContext());
52 SharedPreferences.Editor editor = sp.edit();
53 editor.remove("hiscore_HL1");
54 editor.remove("hiscore_HL2");
55 editor.remove("hiscore_HM1");
56 editor.remove("hiscore_HM2");
57 editor.remove("hiscore_HS1");
58 editor.remove("hiscore_HS2");
59 editor.remove("hiscore_EL1");
60 editor.remove("hiscore_EL2");
61 editor.remove("hiscore_EM1");
62 editor.remove("hiscore_EM2");
63 editor.remove("hiscore_ES1");
64 editor.remove("hiscore_ES2");
65 editor.commit();
66 }
67 });
27afcc39 68 builder.setNegativeButton(android.R.string.cancel,
4e38ce41 69 new DialogInterface.OnClickListener() {
70 public void onClick(DialogInterface dialog, int id) {
71 // User cancelled the dialog - nothing to do
72 }
73 });
74
75 AlertDialog dialog = builder.create();
76 dialog.show();
94761ea5 77 }
78}
Impressum, Datenschutz