]>
Commit | Line | Data |
---|---|---|
92b19250 | 1 | package de.cwde.freeshisen; |
d0e04237 | 2 | |
c6f3dff3 | 3 | import android.app.Activity; |
4 | import android.app.AlertDialog; | |
d8d223b4 | 5 | import android.content.DialogInterface; |
c6f3dff3 | 6 | import android.content.Intent; |
7 | import android.content.pm.PackageInfo; | |
8 | import android.content.pm.PackageManager; | |
9 | import android.content.pm.PackageManager.NameNotFoundException; | |
10 | import android.os.Bundle; | |
42aa846a | 11 | import android.preference.PreferenceManager; |
c6f3dff3 | 12 | import android.text.SpannableString; |
13 | import android.text.util.Linkify; | |
14 | import android.view.Menu; | |
15 | import android.view.MenuInflater; | |
16 | import android.view.MenuItem; | |
17 | import android.view.ViewGroup; | |
18 | import android.view.Window; | |
19 | import android.widget.TextView; | |
20 | ||
21 | public class ShisenShoActivity extends Activity { | |
22 | private ShisenShoView view; | |
23 | ||
24 | /** Called when the activity is first created. */ | |
655c3517 | 25 | @Override |
26 | public void onCreate(Bundle savedInstanceState) { | |
27 | super.onCreate(savedInstanceState); | |
28 | ||
29 | PreferenceManager.setDefaultValues(this, R.xml.preferences, false); | |
c6f3dff3 | 30 | |
655c3517 | 31 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
c6f3dff3 | 32 | |
655c3517 | 33 | view = ShisenSho.app().getView(); |
34 | ShisenSho.app().activity = this; | |
35 | setContentView(view); | |
36 | } | |
c6f3dff3 | 37 | |
38 | @Override | |
39 | protected void onDestroy() { | |
40 | ViewGroup vg = (ViewGroup)(view.getParent()); | |
41 | vg.removeView(view); | |
655c3517 | 42 | ShisenSho.app().activity = null; |
c6f3dff3 | 43 | super.onDestroy(); |
44 | } | |
45 | ||
46 | @Override | |
47 | protected void onPause() { | |
48 | if (view!=null) { | |
49 | view.pauseTime(); | |
50 | } | |
51 | super.onPause(); | |
52 | } | |
53 | ||
54 | @Override | |
55 | protected void onResume() { | |
56 | super.onResume(); | |
57 | if (view!=null) { | |
58 | view.resumeTime(); | |
59 | } | |
60 | } | |
61 | ||
62 | @Override | |
63 | public boolean onCreateOptionsMenu(Menu menu) { | |
655c3517 | 64 | MenuInflater inflater = getMenuInflater(); |
65 | inflater.inflate(R.menu.menu, menu); | |
66 | return true; | |
c6f3dff3 | 67 | } |
68 | ||
69 | @Override | |
70 | public boolean onOptionsItemSelected(MenuItem item) { | |
655c3517 | 71 | // Handle item selection |
72 | switch (item.getItemId()) { | |
73 | case R.id.hint: | |
74 | case R.id.undo: | |
75 | case R.id.clean: | |
76 | return view.onOptionsItemSelected(item); | |
a364582d | 77 | case R.id.hiscore: |
78 | startActivity(new Intent("de.cwde.freeshisen.HISCORE", null)); | |
79 | return true; | |
655c3517 | 80 | case R.id.options: |
a364582d | 81 | startActivity(new Intent("de.cwde.freeshisen.SETTINGS", null)); |
655c3517 | 82 | return true; |
83 | case R.id.about: | |
84 | onAboutActivate(); | |
85 | return true; | |
86 | default: | |
87 | return super.onOptionsItemSelected(item); | |
88 | } | |
c6f3dff3 | 89 | } |
90 | ||
91 | private void onAboutActivate() { | |
655c3517 | 92 | // Try to load the a package matching the name of our own package |
93 | PackageInfo pInfo; | |
c6f3dff3 | 94 | try { |
95 | pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA); | |
54d308ad | 96 | String appname = getString(R.string.app_name); |
97 | String aboutTitle = "About " + appname; | |
98 | String versionString = appname + " "+ pInfo.versionName; | |
655c3517 | 99 | String aboutText = getString(R.string.aboutText); |
c6f3dff3 | 100 | |
655c3517 | 101 | // Set up the TextView |
102 | final TextView message = new TextView(this); | |
103 | // We'll use a spannablestring to be able to make links clickable | |
104 | final SpannableString s = new SpannableString(aboutText); | |
c6f3dff3 | 105 | |
655c3517 | 106 | // Set some padding |
107 | message.setPadding(5, 5, 5, 5); | |
108 | // Set up the final string | |
54d308ad | 109 | message.setText(versionString + s); |
655c3517 | 110 | // Now linkify the text |
111 | Linkify.addLinks(message, Linkify.ALL); | |
c6f3dff3 | 112 | |
655c3517 | 113 | new AlertDialog.Builder(this) |
114 | .setTitle(aboutTitle) | |
115 | .setCancelable(true) | |
116 | .setIcon(R.drawable.icon) | |
0727dd16 | 117 | .setPositiveButton(android.R.string.ok, null) |
655c3517 | 118 | .setView(message).create() |
119 | .show(); | |
c6f3dff3 | 120 | } catch (NameNotFoundException e) { |
121 | e.printStackTrace(); | |
122 | } | |
123 | } | |
d8d223b4 | 124 | |
125 | public void onOptionsChanged() | |
126 | { | |
127 | new AlertDialog.Builder(this) | |
128 | .setTitle("Preferences changed!") // FIXME: hardcoded string | |
129 | .setCancelable(true) | |
130 | .setIcon(R.drawable.icon) | |
131 | .setPositiveButton(android.R.string.yes, | |
132 | new DialogInterface.OnClickListener() { | |
133 | public void onClick(DialogInterface dialog, int id) { | |
134 | // User clicked OK button - reset game | |
135 | view.reset(); | |
136 | } | |
137 | }) | |
138 | .setNegativeButton(android.R.string.no, null) | |
139 | .setMessage("Changes in Preferences will only have an effect if" + | |
140 | " a new game is started. Abort current game and start" + | |
141 | " a new one?") // FIXME: hardcoded string | |
142 | .create() | |
143 | .show(); | |
144 | } | |
c6f3dff3 | 145 | } |