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