]> git.zerfleddert.de Git - FreeShisen/blob - src/de/cwde/freeshisen/ShisenShoActivity.java
0478d07416286e8bf7172bebd64f96f4bdfee43a
[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.options:
79 startActivityForResult(new Intent("de.cwde.freeshisen.SETTINGS", null), 0);
80 return true;
81 case R.id.about:
82 onAboutActivate();
83 return true;
84 default:
85 return super.onOptionsItemSelected(item);
86 }
87 }
88
89 private void onAboutActivate() {
90 // Try to load the a package matching the name of our own package
91 PackageInfo pInfo;
92 try {
93 pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
94 String aboutTitle = String.format("About %s", getString(R.string.app_name));
95 String versionString = String.format("Version: %s", pInfo.versionName);
96 String aboutText = getString(R.string.aboutText);
97
98 // Set up the TextView
99 final TextView message = new TextView(this);
100 // We'll use a spannablestring to be able to make links clickable
101 final SpannableString s = new SpannableString(aboutText);
102
103 // Set some padding
104 message.setPadding(5, 5, 5, 5);
105 // Set up the final string
106 message.setText(versionString + "\n" + s);
107 // Now linkify the text
108 Linkify.addLinks(message, Linkify.ALL);
109
110 new AlertDialog.Builder(this)
111 .setTitle(aboutTitle)
112 .setCancelable(true)
113 .setIcon(R.drawable.icon)
114 .setPositiveButton(getString(android.R.string.ok), null)
115 .setView(message).create()
116 .show();
117 } catch (NameNotFoundException e) {
118 e.printStackTrace();
119 }
120 }
121 }
Impressum, Datenschutz