70d5f3dc6b1b704196a8fc9b4faa9dde3629b978
[FreeShisen] / src / de / cwde / freeshisen / HighscoreActivity.java
1 package de.cwde.freeshisen;
2
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
12 public class HighscoreActivity extends Activity {
13
14 @Override
15 protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.highscore);
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"));
37 }
38
39 public void clearHiscore(View view) {
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
45 builder.setPositiveButton(android.R.string.ok,
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 });
68 builder.setNegativeButton(android.R.string.cancel,
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();
77 }
78 }
Impressum, Datenschutz