]> git.zerfleddert.de Git - FreeShisen/blob - src/de/cwde/freeshisen/ShisenShoActivity.java
88666da2697ddd567fb9f44b0ac51b370880daa0
[FreeShisen] / src / de / cwde / freeshisen / ShisenShoActivity.java
1 package de.cwde.freeshisen;
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.preference.PreferenceManager;
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. */
24 @Override
25 public void onCreate(Bundle savedInstanceState) {
26 super.onCreate(savedInstanceState);
27
28 PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
29
30 requestWindowFeature(Window.FEATURE_NO_TITLE);
31 //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
32 // WindowManager.LayoutParams.FLAG_FULLSCREEN);
33
34 view = ShisenSho.app().getView();
35 ShisenSho.app().activity = this;
36 setContentView(view);
37 }
38
39 @Override
40 protected void onDestroy() {
41 ViewGroup vg = (ViewGroup)(view.getParent());
42 vg.removeView(view);
43 ShisenSho.app().activity = null;
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) {
65 MenuInflater inflater = getMenuInflater();
66 inflater.inflate(R.menu.menu, menu);
67 return true;
68 }
69
70 @Override
71 public boolean onOptionsItemSelected(MenuItem item) {
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);
78 case R.id.hiscore:
79 startActivity(new Intent("de.cwde.freeshisen.HISCORE", null));
80 return true;
81 case R.id.options:
82 startActivity(new Intent("de.cwde.freeshisen.SETTINGS", null));
83 return true;
84 case R.id.about:
85 onAboutActivate();
86 return true;
87 default:
88 return super.onOptionsItemSelected(item);
89 }
90 }
91
92 private void onAboutActivate() {
93 // Try to load the a package matching the name of our own package
94 PackageInfo pInfo;
95 try {
96 pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
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);
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 + "\n" + 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(getString(android.R.string.ok), null)
118 .setView(message).create()
119 .show();
120 } catch (NameNotFoundException e) {
121 e.printStackTrace();
122 }
123 }
124 }
Impressum, Datenschutz