]> cvs.zerfleddert.de Git - FreeShisen/blame - src/de/cwde/freeshisen/ShisenShoActivity.java
Allow selecting tileset.
[FreeShisen] / src / de / cwde / freeshisen / ShisenShoActivity.java
CommitLineData
92b19250 1package de.cwde.freeshisen;
d0e04237 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);
c6f3dff3 31
655c3517 32 view = ShisenSho.app().getView();
33 ShisenSho.app().activity = this;
34 setContentView(view);
35 }
c6f3dff3 36
37 @Override
38 protected void onDestroy() {
39 ViewGroup vg = (ViewGroup)(view.getParent());
40 vg.removeView(view);
655c3517 41 ShisenSho.app().activity = null;
c6f3dff3 42 super.onDestroy();
43 }
44
45 @Override
46 protected void onPause() {
47 if (view!=null) {
48 view.pauseTime();
49 }
50 super.onPause();
51 }
52
53 @Override
54 protected void onResume() {
55 super.onResume();
56 if (view!=null) {
57 view.resumeTime();
58 }
59 }
60
61 @Override
62 public boolean onCreateOptionsMenu(Menu menu) {
655c3517 63 MenuInflater inflater = getMenuInflater();
64 inflater.inflate(R.menu.menu, menu);
65 return true;
c6f3dff3 66 }
67
68 @Override
69 public boolean onOptionsItemSelected(MenuItem item) {
655c3517 70 // Handle item selection
71 switch (item.getItemId()) {
72 case R.id.hint:
73 case R.id.undo:
74 case R.id.clean:
75 return view.onOptionsItemSelected(item);
a364582d 76 case R.id.hiscore:
77 startActivity(new Intent("de.cwde.freeshisen.HISCORE", null));
78 return true;
655c3517 79 case R.id.options:
a364582d 80 startActivity(new Intent("de.cwde.freeshisen.SETTINGS", null));
655c3517 81 return true;
82 case R.id.about:
83 onAboutActivate();
84 return true;
85 default:
86 return super.onOptionsItemSelected(item);
87 }
c6f3dff3 88 }
89
90 private void onAboutActivate() {
655c3517 91 // Try to load the a package matching the name of our own package
92 PackageInfo pInfo;
c6f3dff3 93 try {
94 pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
54d308ad 95 String appname = getString(R.string.app_name);
96 String aboutTitle = "About " + appname;
97 String versionString = appname + " "+ pInfo.versionName;
655c3517 98 String aboutText = getString(R.string.aboutText);
c6f3dff3 99
655c3517 100 // Set up the TextView
101 final TextView message = new TextView(this);
102 // We'll use a spannablestring to be able to make links clickable
103 final SpannableString s = new SpannableString(aboutText);
c6f3dff3 104
655c3517 105 // Set some padding
106 message.setPadding(5, 5, 5, 5);
107 // Set up the final string
54d308ad 108 message.setText(versionString + s);
655c3517 109 // Now linkify the text
110 Linkify.addLinks(message, Linkify.ALL);
c6f3dff3 111
655c3517 112 new AlertDialog.Builder(this)
113 .setTitle(aboutTitle)
114 .setCancelable(true)
115 .setIcon(R.drawable.icon)
0727dd16 116 .setPositiveButton(android.R.string.ok, null)
655c3517 117 .setView(message).create()
118 .show();
c6f3dff3 119 } catch (NameNotFoundException e) {
120 e.printStackTrace();
121 }
122 }
123}
Impressum, Datenschutz