1 package de
.cwde
.freeshisen
;
3 import android
.app
.Activity
;
4 import android
.app
.AlertDialog
;
5 import android
.content
.DialogInterface
;
6 import android
.content
.Intent
;
7 import android
.content
.pm
.PackageInfo
;
8 import android
.content
.pm
.PackageManager
;
9 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
10 import android
.os
.Bundle
;
11 import android
.preference
.PreferenceManager
;
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
;
21 public class ShisenShoActivity
extends Activity
{
22 private ShisenShoView view
;
24 /** Called when the activity is first created. */
26 public void onCreate(Bundle savedInstanceState
) {
27 super.onCreate(savedInstanceState
);
29 PreferenceManager
.setDefaultValues(this, R
.xml
.preferences
, false);
31 requestWindowFeature(Window
.FEATURE_NO_TITLE
);
33 view
= ShisenSho
.app().getView();
34 ShisenSho
.app().activity
= this;
39 protected void onDestroy() {
40 ViewGroup vg
= (ViewGroup
)(view
.getParent());
42 ShisenSho
.app().activity
= null;
47 protected void onPause() {
55 protected void onResume() {
63 public boolean onCreateOptionsMenu(Menu menu
) {
64 MenuInflater inflater
= getMenuInflater();
65 inflater
.inflate(R
.menu
.menu
, menu
);
70 public boolean onOptionsItemSelected(MenuItem item
) {
71 // Handle item selection
72 switch (item
.getItemId()) {
76 return view
.onOptionsItemSelected(item
);
78 startActivity(new Intent("de.cwde.freeshisen.HISCORE", null));
81 startActivity(new Intent("de.cwde.freeshisen.SETTINGS", null));
87 return super.onOptionsItemSelected(item
);
91 private void onAboutActivate() {
92 // Try to load the a package matching the name of our own package
95 pInfo
= getPackageManager().getPackageInfo(getPackageName(), PackageManager
.GET_META_DATA
);
96 String appname
= getString(R
.string
.app_name
);
97 String aboutTitle
= "About " + appname
;
98 String versionString
= appname
+ " "+ pInfo
.versionName
;
99 String aboutText
= getString(R
.string
.aboutText
);
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
);
107 message
.setPadding(5, 5, 5, 5);
108 // Set up the final string
109 message
.setText(versionString
+ s
);
110 // Now linkify the text
111 Linkify
.addLinks(message
, Linkify
.ALL
);
113 new AlertDialog
.Builder(this)
114 .setTitle(aboutTitle
)
116 .setIcon(R
.drawable
.icon
)
117 .setPositiveButton(android
.R
.string
.ok
, null)
118 .setView(message
).create()
120 } catch (NameNotFoundException e
) {
125 public void onOptionsChanged()
127 new AlertDialog
.Builder(this)
128 .setTitle(R
.string
.prefchange_confirm_title
)
130 .setIcon(R
.drawable
.icon
)
131 .setPositiveButton(android
.R
.string
.yes
,
132 new DialogInterface
.OnClickListener() {
133 public void onClick(DialogInterface dialog
, int id
) {
134 // User clicked OK button - reset game
138 .setNegativeButton(android
.R
.string
.no
, null)
139 .setMessage(R
.string
.prefchange_confirm_text
)