]>
Commit | Line | Data |
---|---|---|
1 | package org.proofofconcept.shisensho; | |
2 | ||
3 | import android.app.Activity; | |
4 | import android.app.AlertDialog; | |
5 | import android.content.Intent; | |
6 | import android.content.pm.PackageInfo; | |
7 | import android.content.pm.PackageManager; | |
8 | import android.content.pm.PackageManager.NameNotFoundException; | |
9 | import android.os.Bundle; | |
10 | import android.text.SpannableString; | |
11 | import android.text.util.Linkify; | |
12 | import android.view.Menu; | |
13 | import android.view.MenuInflater; | |
14 | import android.view.MenuItem; | |
15 | import android.view.ViewGroup; | |
16 | import android.view.Window; | |
17 | import android.widget.TextView; | |
18 | ||
19 | public class ShisenShoActivity extends Activity { | |
20 | private ShisenShoView view; | |
21 | ||
22 | /** Called when the activity is first created. */ | |
23 | @Override | |
24 | public void onCreate(Bundle savedInstanceState) { | |
25 | super.onCreate(savedInstanceState); | |
26 | ||
27 | requestWindowFeature(Window.FEATURE_NO_TITLE); | |
28 | //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | |
29 | // WindowManager.LayoutParams.FLAG_FULLSCREEN); | |
30 | ||
31 | view = ShisenSho.app().getView(); | |
32 | ShisenSho.app().activity = this; | |
33 | setContentView(view); | |
34 | } | |
35 | ||
36 | @Override | |
37 | protected void onDestroy() { | |
38 | ViewGroup vg = (ViewGroup)(view.getParent()); | |
39 | vg.removeView(view); | |
40 | ShisenSho.app().activity = null; | |
41 | super.onDestroy(); | |
42 | } | |
43 | ||
44 | @Override | |
45 | protected void onPause() { | |
46 | if (view!=null) { | |
47 | view.pauseTime(); | |
48 | } | |
49 | super.onPause(); | |
50 | } | |
51 | ||
52 | @Override | |
53 | protected void onResume() { | |
54 | super.onResume(); | |
55 | if (view!=null) { | |
56 | view.resumeTime(); | |
57 | } | |
58 | } | |
59 | ||
60 | @Override | |
61 | public boolean onCreateOptionsMenu(Menu menu) { | |
62 | MenuInflater inflater = getMenuInflater(); | |
63 | inflater.inflate(R.menu.menu, menu); | |
64 | return true; | |
65 | } | |
66 | ||
67 | @Override | |
68 | public boolean onOptionsItemSelected(MenuItem item) { | |
69 | // Handle item selection | |
70 | switch (item.getItemId()) { | |
71 | case R.id.hint: | |
72 | case R.id.undo: | |
73 | case R.id.clean: | |
74 | return view.onOptionsItemSelected(item); | |
75 | case R.id.options: | |
76 | startActivityForResult(new Intent("org.proofofconcept.shisensho.SETTINGS", null), 0); | |
77 | return true; | |
78 | case R.id.about: | |
79 | onAboutActivate(); | |
80 | return true; | |
81 | default: | |
82 | return super.onOptionsItemSelected(item); | |
83 | } | |
84 | } | |
85 | ||
86 | private void onAboutActivate() { | |
87 | // Try to load the a package matching the name of our own package | |
88 | PackageInfo pInfo; | |
89 | try { | |
90 | pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA); | |
91 | String aboutTitle = String.format("About %s", getString(R.string.app_name)); | |
92 | String versionString = String.format("Version: %s", pInfo.versionName); | |
93 | String aboutText = getString(R.string.aboutText); | |
94 | ||
95 | // Set up the TextView | |
96 | final TextView message = new TextView(this); | |
97 | // We'll use a spannablestring to be able to make links clickable | |
98 | final SpannableString s = new SpannableString(aboutText); | |
99 | ||
100 | // Set some padding | |
101 | message.setPadding(5, 5, 5, 5); | |
102 | // Set up the final string | |
103 | message.setText(versionString + "\n" + s); | |
104 | // Now linkify the text | |
105 | Linkify.addLinks(message, Linkify.ALL); | |
106 | ||
107 | new AlertDialog.Builder(this) | |
108 | .setTitle(aboutTitle) | |
109 | .setCancelable(true) | |
110 | .setIcon(R.drawable.icon) | |
111 | .setPositiveButton(getString(android.R.string.ok), null) | |
112 | .setView(message).create() | |
113 | .show(); | |
114 | } catch (NameNotFoundException e) { | |
115 | e.printStackTrace(); | |
116 | } | |
117 | } | |
118 | } |