From 382b479bbddb1733c98bbfe79711a677ae82c392 Mon Sep 17 00:00:00 2001
From: Xavier Ducrohet <>
Date: Fri, 3 Apr 2009 17:49:02 -0700
Subject: [PATCH] AI 144567: am: CL 144565 Improve the JetBoy samples - use
theme instead of window feature to remove titlebar - remove useless Layouts
- Make custom view works in layout editor. - remove some warnings
Original author: xav Merged from: //branches/cupcake/...
Automated import of CL 144567
---
samples/JetBoy/AndroidManifest.xml | 63 +++++-----
samples/JetBoy/res/layout/main.xml | 116 ++++--------------
.../com/example/android/jetboy/JetBoy.java | 10 +-
.../example/android/jetboy/JetBoyView.java | 66 +++++-----
4 files changed, 94 insertions(+), 161 deletions(-)
diff --git a/samples/JetBoy/AndroidManifest.xml b/samples/JetBoy/AndroidManifest.xml
index ccd3518f1..bba069d4c 100755
--- a/samples/JetBoy/AndroidManifest.xml
+++ b/samples/JetBoy/AndroidManifest.xml
@@ -1,38 +1,37 @@
-
-
-
+ used by the system to determine how to start the application and
+ integrate it with the rest of the system. -->
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+ package="com.example.android.jetboy" android:versionCode="1"
+ android:versionName="1.0.0">
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/JetBoy/res/layout/main.xml b/samples/JetBoy/res/layout/main.xml
index b5309db53..ea2277f71 100755
--- a/samples/JetBoy/res/layout/main.xml
+++ b/samples/JetBoy/res/layout/main.xml
@@ -1,93 +1,31 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/samples/JetBoy/src/com/example/android/jetboy/JetBoy.java b/samples/JetBoy/src/com/example/android/jetboy/JetBoy.java
index ac12d3c3f..88693afeb 100755
--- a/samples/JetBoy/src/com/example/android/jetboy/JetBoy.java
+++ b/samples/JetBoy/src/com/example/android/jetboy/JetBoy.java
@@ -25,7 +25,6 @@ import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
-import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
@@ -55,12 +54,8 @@ public class JetBoy extends Activity implements View.OnClickListener {
* @param savedInstanceState - The previous instance of this app
*/
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
- // turn off the window's title bar
- requestWindowFeature(Window.FEATURE_NO_TITLE);
-
setContentView(R.layout.main);
// get handles to the JetView from XML and the JET thread.
@@ -91,9 +86,8 @@ public class JetBoy extends Activity implements View.OnClickListener {
* @param v The object which has been clicked
*/
public void onClick(View v) {
-
// this is the first screen
- if (mJetBoyThread.getGameState() == mJetBoyThread.STATE_START) {
+ if (mJetBoyThread.getGameState() == JetBoyThread.STATE_START) {
mButton.setText("PLAY!");
mTextView.setVisibility(View.VISIBLE);
@@ -102,7 +96,7 @@ public class JetBoy extends Activity implements View.OnClickListener {
}
// we have entered game play, now we about to start running
- else if (mJetBoyThread.getGameState() == mJetBoyThread.STATE_PLAY) {
+ else if (mJetBoyThread.getGameState() == JetBoyThread.STATE_PLAY) {
mButton.setVisibility(View.INVISIBLE);
mTextView.setVisibility(View.INVISIBLE);
mTimerView.setVisibility(View.VISIBLE);
diff --git a/samples/JetBoy/src/com/example/android/jetboy/JetBoyView.java b/samples/JetBoy/src/com/example/android/jetboy/JetBoyView.java
index 72142a978..c51f661ea 100755
--- a/samples/JetBoy/src/com/example/android/jetboy/JetBoyView.java
+++ b/samples/JetBoy/src/com/example/android/jetboy/JetBoyView.java
@@ -174,7 +174,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// in this game 80 is used for sending asteroid
// 82 is used as game time for 1/4 note beat.
private final String mSendEvent = "80";
-
private final String mTimerEvent = "82";
// used to track beat for synch of mute/unmute actions
@@ -1360,38 +1359,41 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
holder.addCallback(this);
// create thread only; it's started in surfaceCreated()
- thread = new JetBoyThread(holder, context, new Handler() {
-
- public void handleMessage(Message m) {
-
- mTimerView.setText(m.getData().getString("text"));
-
- //ok so maybe it isn't really a "lose"
- //this bit was borrowed from lunar lander and then evolved.
- //too close to deadline to mess with now.
- if (m.getData().getString("STATE_LOSE") != null) {
- //mButtonRestart.setVisibility(View.VISIBLE);
- mButtonRetry.setVisibility(View.VISIBLE);
-
- mTimerView.setVisibility(View.INVISIBLE);
-
- mTextView.setVisibility(View.VISIBLE);
-
- Log.d(TAG, "the total was " + mHitTotal);
-
- if (mHitTotal >= mSuccessThreshold) {
- mTextView.setText(R.string.winText);
- } else {
- mTextView.setText("Sorry, You Lose! You got " + mHitTotal
- + ". You need 50 to win.");
+ // except if used in the layout editor.
+ if (isInEditMode() == false) {
+ thread = new JetBoyThread(holder, context, new Handler() {
+
+ public void handleMessage(Message m) {
+
+ mTimerView.setText(m.getData().getString("text"));
+
+ //ok so maybe it isn't really a "lose"
+ //this bit was borrowed from lunar lander and then evolved.
+ //too close to deadline to mess with now.
+ if (m.getData().getString("STATE_LOSE") != null) {
+ //mButtonRestart.setVisibility(View.VISIBLE);
+ mButtonRetry.setVisibility(View.VISIBLE);
+
+ mTimerView.setVisibility(View.INVISIBLE);
+
+ mTextView.setVisibility(View.VISIBLE);
+
+ Log.d(TAG, "the total was " + mHitTotal);
+
+ if (mHitTotal >= mSuccessThreshold) {
+ mTextView.setText(R.string.winText);
+ } else {
+ mTextView.setText("Sorry, You Lose! You got " + mHitTotal
+ + ". You need 50 to win.");
+ }
+
+ mTimerView.setText("1:12");
+ mTextView.setHeight(20);
+
}
-
- mTimerView.setText("1:12");
- mTextView.setHeight(20);
-
- }
- }//end handle msg
- });
+ }//end handle msg
+ });
+ }
setFocusable(true); // make sure we get key events