]>
Commit | Line | Data |
---|---|---|
92b19250 | 1 | package de.cwde.freeshisen; |
d0e04237 | 2 | |
c6f3dff3 | 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; | |
42aa846a | 10 | import android.preference.PreferenceManager; |
c6f3dff3 | 11 | import android.text.SpannableString; |
12 | import android.text.util.Linkify; | |
13 | import android.view.Menu; | |
14 | import android.view.MenuInflater; | |
15 | import android.view.MenuItem; | |
16 | import android.view.ViewGroup; | |
17 | import android.view.Window; | |
18 | import android.widget.TextView; | |
19 | ||
20 | public class ShisenShoActivity extends Activity { | |
21 | private ShisenShoView view; | |
22 | ||
23 | /** Called when the activity is first created. */ | |
655c3517 | 24 | @Override |
25 | public void onCreate(Bundle savedInstanceState) { | |
26 | super.onCreate(savedInstanceState); | |
27 | ||
28 | PreferenceManager.setDefaultValues(this, R.xml.preferences, false); | |
c6f3dff3 | 29 | |
655c3517 | 30 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
31 | //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | |
32 | // WindowManager.LayoutParams.FLAG_FULLSCREEN); | |
c6f3dff3 | 33 | |
655c3517 | 34 | view = ShisenSho.app().getView(); |
35 | ShisenSho.app().activity = this; | |
36 | setContentView(view); | |
37 | } | |
c6f3dff3 | 38 | |
39 | @Override | |
40 | protected void onDestroy() { | |
41 | ViewGroup vg = (ViewGroup)(view.getParent()); | |
42 | vg.removeView(view); | |
655c3517 | 43 | ShisenSho.app().activity = null; |
c6f3dff3 | 44 | super.onDestroy(); |
45 | } | |
46 | ||
47 | @Override | |
48 | protected void onPause() { | |
49 | if (view!=null) { | |
50 | view.pauseTime(); | |
51 | } | |
52 | super.onPause(); | |
53 | } | |
54 | ||
55 | @Override | |
56 | protected void onResume() { | |
57 | super.onResume(); | |
58 | if (view!=null) { | |
59 | view.resumeTime(); | |
60 | } | |
61 | } | |
62 | ||
63 | @Override | |
64 | public boolean onCreateOptionsMenu(Menu menu) { | |
655c3517 | 65 | MenuInflater inflater = getMenuInflater(); |
66 | inflater.inflate(R.menu.menu, menu); | |
67 | return true; | |
c6f3dff3 | 68 | } |
69 | ||
70 | @Override | |
71 | public boolean onOptionsItemSelected(MenuItem item) { | |
655c3517 | 72 | // Handle item selection |
73 | switch (item.getItemId()) { | |
74 | case R.id.hint: | |
75 | case R.id.undo: | |
76 | case R.id.clean: | |
77 | return view.onOptionsItemSelected(item); | |
a364582d | 78 | case R.id.hiscore: |
79 | startActivity(new Intent("de.cwde.freeshisen.HISCORE", null)); | |
80 | return true; | |
655c3517 | 81 | case R.id.options: |
a364582d | 82 | startActivity(new Intent("de.cwde.freeshisen.SETTINGS", null)); |
655c3517 | 83 | return true; |
84 | case R.id.about: | |
85 | onAboutActivate(); | |
86 | return true; | |
87 | default: | |
88 | return super.onOptionsItemSelected(item); | |
89 | } | |
c6f3dff3 | 90 | } |
91 | ||
92 | private void onAboutActivate() { | |
655c3517 | 93 | // Try to load the a package matching the name of our own package |
94 | PackageInfo pInfo; | |
c6f3dff3 | 95 | try { |
96 | pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA); | |
655c3517 | 97 | String aboutTitle = String.format("About %s", getString(R.string.app_name)); |
98 | String versionString = String.format("Version: %s", pInfo.versionName); | |
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 | |
109 | message.setText(versionString + "\n" + s); | |
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) | |
117 | .setPositiveButton(getString(android.R.string.ok), null) | |
118 | .setView(message).create() | |
119 | .show(); | |
c6f3dff3 | 120 | } catch (NameNotFoundException e) { |
121 | e.printStackTrace(); | |
122 | } | |
123 | } | |
124 | } |