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
This commit is contained in:
Xavier Ducrohet
2009-04-03 17:49:02 -07:00
committed by The Android Open Source Project
parent 46132107e6
commit 382b479bbd
4 changed files with 94 additions and 161 deletions

View File

@@ -1,38 +1,37 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project <!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!-- This file describes the code in the JetBoy package, which is <!-- This file describes the code in the JetBoy package, which is
used by the system to determine how to start the application and used by the system to determine how to start the application and
integrate it with the rest of the system. --> integrate it with the rest of the system. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.jetboy" package="com.example.android.jetboy" android:versionCode="1"
android:versionCode="1" android:versionName="1.0.0">
android:versionName="1.0.0"> <application android:icon="@drawable/icon"
<application android:icon="@drawable/icon" android:label="@string/app_name"> android:label="@string/app_name"
<activity android:name=".JetBoy" android:theme="@android:style/Theme.NoTitleBar">
android:label="@string/app_name" <activity android:name=".JetBoy"
android:screenOrientation="landscape"> android:label="@string/app_name"
<intent-filter> android:screenOrientation="landscape">
<action android:name="android.intent.action.MAIN" /> <intent-filter>
<category android:name="android.intent.category.LAUNCHER" /> <action android:name="android.intent.action.MAIN" />
</intent-filter> <category
</activity> android:name="android.intent.category.LAUNCHER" />
</application> </intent-filter>
<uses-sdk android:minSdkVersion="3"></uses-sdk> </activity>
</manifest> </application>
<uses-sdk android:minSdkVersion="3"></uses-sdk>
</manifest>

View File

@@ -1,93 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<com.example.android.jetboy.JetBoyView
android:id="@+id/JetBoyView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="top" android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/text"
android:text="@string/helpText"
style="@style/helpText"
android:visibility="invisible"
android:layout_width="300px"
android:layout_height="300px"
android:layout_centerInParent="true"
android:gravity="left"
android:background="#88ffffff"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:gravity="center_horizontal"
android:orientation="horizontal">
<Button android:id="@+id/Button01"
android:text="@string/start"
style="@style/ButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:cursorVisible="true">
</Button>
</LinearLayout> <com.example.android.jetboy.JetBoyView android:id="@+id/JetBoyView"
android:layout_width="fill_parent"
<LinearLayout android:layout_height="fill_parent" />
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:gravity="center_horizontal" <TextView android:id="@+id/text" android:text="@string/helpText"
android:orientation="horizontal"> style="@style/helpText" android:visibility="invisible"
<Button android:id="@+id/Button02" android:layout_width="300px" android:layout_height="300px"
android:text="@string/retry" android:background="#7Fffffff" android:layout_gravity="center" />
style="@style/ButtonText"
android:visibility="invisible" <Button android:id="@+id/Button01" android:text="@string/start"
android:layout_width="wrap_content" style="@style/ButtonText" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clickable="true" android:layout_gravity="center_horizontal|bottom" />
android:cursorVisible="true">
</Button> <Button android:id="@+id/Button02" android:text="@string/retry"
style="@style/ButtonText" android:visibility="invisible"
<!--Button android:id="@+id/Button03" android:layout_width="wrap_content"
android:text="@string/restart" android:layout_height="wrap_content"
style="@style/ButtonText" android:layout_gravity="center_horizontal|bottom" />
android:visibility="invisible"
android:layout_width="wrap_content" <TextView android:id="@+id/timer" android:text="@string/timer"
android:layout_height="wrap_content" style="@style/timerText" android:visibility="invisible"
android:clickable="true" android:layout_width="wrap_content"
android:cursorVisible="true"> android:layout_height="wrap_content"
</Button--> android:layout_gravity="top|right" android:background="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="top" android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="@+id/timer"
android:text="@string/timer"
style="@style/timerText"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:background="#000000"
android:textSize="24sp"/>
</LinearLayout>
</FrameLayout> </FrameLayout>

View File

@@ -25,7 +25,6 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.Window;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
@@ -55,12 +54,8 @@ public class JetBoy extends Activity implements View.OnClickListener {
* @param savedInstanceState - The previous instance of this app * @param savedInstanceState - The previous instance of this app
*/ */
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// turn off the window's title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main); setContentView(R.layout.main);
// get handles to the JetView from XML and the JET thread. // 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 * @param v The object which has been clicked
*/ */
public void onClick(View v) { public void onClick(View v) {
// this is the first screen // this is the first screen
if (mJetBoyThread.getGameState() == mJetBoyThread.STATE_START) { if (mJetBoyThread.getGameState() == JetBoyThread.STATE_START) {
mButton.setText("PLAY!"); mButton.setText("PLAY!");
mTextView.setVisibility(View.VISIBLE); 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 // 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); mButton.setVisibility(View.INVISIBLE);
mTextView.setVisibility(View.INVISIBLE); mTextView.setVisibility(View.INVISIBLE);
mTimerView.setVisibility(View.VISIBLE); mTimerView.setVisibility(View.VISIBLE);

View File

@@ -174,7 +174,6 @@ public class JetBoyView extends SurfaceView implements SurfaceHolder.Callback {
// in this game 80 is used for sending asteroid // in this game 80 is used for sending asteroid
// 82 is used as game time for 1/4 note beat. // 82 is used as game time for 1/4 note beat.
private final String mSendEvent = "80"; private final String mSendEvent = "80";
private final String mTimerEvent = "82"; private final String mTimerEvent = "82";
// used to track beat for synch of mute/unmute actions // 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); holder.addCallback(this);
// create thread only; it's started in surfaceCreated() // create thread only; it's started in surfaceCreated()
thread = new JetBoyThread(holder, context, new Handler() { // except if used in the layout editor.
if (isInEditMode() == false) {
public void handleMessage(Message m) { thread = new JetBoyThread(holder, context, new Handler() {
mTimerView.setText(m.getData().getString("text")); public void handleMessage(Message m) {
//ok so maybe it isn't really a "lose" mTimerView.setText(m.getData().getString("text"));
//this bit was borrowed from lunar lander and then evolved.
//too close to deadline to mess with now. //ok so maybe it isn't really a "lose"
if (m.getData().getString("STATE_LOSE") != null) { //this bit was borrowed from lunar lander and then evolved.
//mButtonRestart.setVisibility(View.VISIBLE); //too close to deadline to mess with now.
mButtonRetry.setVisibility(View.VISIBLE); if (m.getData().getString("STATE_LOSE") != null) {
//mButtonRestart.setVisibility(View.VISIBLE);
mTimerView.setVisibility(View.INVISIBLE); mButtonRetry.setVisibility(View.VISIBLE);
mTextView.setVisibility(View.VISIBLE); mTimerView.setVisibility(View.INVISIBLE);
Log.d(TAG, "the total was " + mHitTotal); mTextView.setVisibility(View.VISIBLE);
if (mHitTotal >= mSuccessThreshold) { Log.d(TAG, "the total was " + mHitTotal);
mTextView.setText(R.string.winText);
} else { if (mHitTotal >= mSuccessThreshold) {
mTextView.setText("Sorry, You Lose! You got " + mHitTotal mTextView.setText(R.string.winText);
+ ". You need 50 to win."); } else {
mTextView.setText("Sorry, You Lose! You got " + mHitTotal
+ ". You need 50 to win.");
}
mTimerView.setText("1:12");
mTextView.setHeight(20);
} }
}//end handle msg
mTimerView.setText("1:12"); });
mTextView.setHeight(20); }
}
}//end handle msg
});
setFocusable(true); // make sure we get key events setFocusable(true); // make sure we get key events