]> git.zerfleddert.de Git - FreeShisen/blame - src/de/cwde/shisensho/ShisenShoActivity.java
remove "sample" files, fix classpath.
[FreeShisen] / src / de / cwde / shisensho / ShisenShoActivity.java
CommitLineData
d0e04237 1package de.cwde.shisensho;
2
c6f3dff3 3import android.app.Activity;
4import android.app.AlertDialog;
5import android.content.Intent;
6import android.content.pm.PackageInfo;
7import android.content.pm.PackageManager;
8import android.content.pm.PackageManager.NameNotFoundException;
9import android.os.Bundle;
42aa846a 10import android.preference.PreferenceManager;
c6f3dff3 11import android.text.SpannableString;
12import android.text.util.Linkify;
13import android.view.Menu;
14import android.view.MenuInflater;
15import android.view.MenuItem;
16import android.view.ViewGroup;
17import android.view.Window;
18import android.widget.TextView;
19
20public 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);
78 case R.id.options:
79 startActivityForResult(new Intent("de.cwde.shisensho.SETTINGS", null), 0);
80 return true;
81 case R.id.about:
82 onAboutActivate();
83 return true;
84 default:
85 return super.onOptionsItemSelected(item);
86 }
c6f3dff3 87 }
88
89 private void onAboutActivate() {
655c3517 90 // Try to load the a package matching the name of our own package
91 PackageInfo pInfo;
c6f3dff3 92 try {
93 pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
655c3517 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);
c6f3dff3 97
655c3517 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);
c6f3dff3 102
655c3517 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);
c6f3dff3 109
655c3517 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();
c6f3dff3 117 } catch (NameNotFoundException e) {
118 e.printStackTrace();
119 }
120 }
121}
Impressum, Datenschutz