]>
Commit | Line | Data |
---|---|---|
1 | package de.cwde.freeshisen; | |
2 | ||
3 | import android.app.Activity; | |
4 | import android.app.AlertDialog; | |
5 | import android.content.DialogInterface; | |
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; | |
11 | import android.preference.PreferenceManager; | |
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. */ | |
25 | @Override | |
26 | public void onCreate(Bundle savedInstanceState) { | |
27 | super.onCreate(savedInstanceState); | |
28 | ||
29 | PreferenceManager.setDefaultValues(this, R.xml.preferences, false); | |
30 | ||
31 | requestWindowFeature(Window.FEATURE_NO_TITLE); | |
32 | ||
33 | view = ShisenSho.app().getView(); | |
34 | ShisenSho.app().activity = this; | |
35 | setContentView(view); | |
36 | } | |
37 | ||
38 | @Override | |
39 | protected void onDestroy() { | |
40 | ViewGroup vg = (ViewGroup)(view.getParent()); | |
41 | vg.removeView(view); | |
42 | ShisenSho.app().activity = null; | |
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) { | |
64 | MenuInflater inflater = getMenuInflater(); | |
65 | inflater.inflate(R.menu.menu, menu); | |
66 | return true; | |
67 | } | |
68 | ||
69 | @Override | |
70 | public boolean onOptionsItemSelected(MenuItem item) { | |
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); | |
77 | case R.id.hiscore: | |
78 | startActivity(new Intent("de.cwde.freeshisen.HISCORE", null)); | |
79 | return true; | |
80 | case R.id.options: | |
81 | startActivity(new Intent("de.cwde.freeshisen.SETTINGS", null)); | |
82 | return true; | |
83 | case R.id.about: | |
84 | onAboutActivate(); | |
85 | return true; | |
86 | default: | |
87 | return super.onOptionsItemSelected(item); | |
88 | } | |
89 | } | |
90 | ||
91 | private void onAboutActivate() { | |
92 | // Try to load the a package matching the name of our own package | |
93 | PackageInfo pInfo; | |
94 | try { | |
95 | pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA); | |
96 | String appname = getString(R.string.app_name); | |
97 | String aboutTitle = "About " + appname; | |
98 | String versionString = appname + " "+ pInfo.versionName; | |
99 | String aboutText = getString(R.string.aboutText); | |
100 | ||
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); | |
105 | ||
106 | // Set some padding | |
107 | message.setPadding(5, 5, 5, 5); | |
108 | // Set up the final string | |
109 | message.setText(versionString + s); | |
110 | // Now linkify the text | |
111 | Linkify.addLinks(message, Linkify.ALL); | |
112 | ||
113 | new AlertDialog.Builder(this) | |
114 | .setTitle(aboutTitle) | |
115 | .setCancelable(true) | |
116 | .setIcon(R.drawable.icon) | |
117 | .setPositiveButton(android.R.string.ok, null) | |
118 | .setView(message).create() | |
119 | .show(); | |
120 | } catch (NameNotFoundException e) { | |
121 | e.printStackTrace(); | |
122 | } | |
123 | } | |
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 | } | |
145 | } |