FileDocCategorySizeDatePackage
JetBoy.javaAPI DocAndroid 1.5 API4646Wed May 06 22:41:08 BST 2009com.example.android.jetboy

JetBoy

public class JetBoy extends android.app.Activity implements View.OnClickListener

Fields Summary
private com.example.android.jetboy.JetBoyView.JetBoyThread
mJetBoyThread
A handle to the thread that's actually running the animation.
private JetBoyView
mJetBoyView
A handle to the View in which the game is running.
private android.widget.Button
mButton
private android.widget.Button
mButtonRetry
private android.widget.TextView
mTextView
private android.widget.TextView
mTimerView
Constructors Summary
Methods Summary
public voidonClick(android.view.View v)
Handles component interaction

param
v The object which has been clicked

        // this is the first screen
        if (mJetBoyThread.getGameState() == JetBoyThread.STATE_START) {
            mButton.setText("PLAY!");
            mTextView.setVisibility(View.VISIBLE);

            mTextView.setText(R.string.helpText);
            mJetBoyThread.setGameState(JetBoyThread.STATE_PLAY);

        }
        // we have entered game play, now we about to start running
        else if (mJetBoyThread.getGameState() == JetBoyThread.STATE_PLAY) {
            mButton.setVisibility(View.INVISIBLE);
            mTextView.setVisibility(View.INVISIBLE);
            mTimerView.setVisibility(View.VISIBLE);
            mJetBoyThread.setGameState(JetBoyThread.STATE_RUNNING);

        }
        // this is a retry button
        else if (mButtonRetry.equals(v)) {

            mTextView.setText(R.string.helpText);

            mButton.setText("PLAY!");
            mButtonRetry.setVisibility(View.INVISIBLE);
            // mButtonRestart.setVisibility(View.INVISIBLE);

            mTextView.setVisibility(View.VISIBLE);
            mButton.setText("PLAY!");
            mButton.setVisibility(View.VISIBLE);

            mJetBoyThread.setGameState(JetBoyThread.STATE_PLAY);

        } else {
            Log.d("JB VIEW", "unknown click " + v.getId());

            Log.d("JB VIEW", "state is  " + mJetBoyThread.mState);

        }
    
public voidonCreate(android.os.Bundle savedInstanceState)
Required method from parent class

param
savedInstanceState - The previous instance of this app

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        // get handles to the JetView from XML and the JET thread.
        mJetBoyView = (JetBoyView)findViewById(R.id.JetBoyView);
        mJetBoyThread = mJetBoyView.getThread();

        // look up the happy shiny button
        mButton = (Button)findViewById(R.id.Button01);
        mButton.setOnClickListener(this);

        mButtonRetry = (Button)findViewById(R.id.Button02);
        mButtonRetry.setOnClickListener(this);

        // set up handles for instruction text and game timer text
        mTextView = (TextView)findViewById(R.id.text);
        mTimerView = (TextView)findViewById(R.id.timer);

        mJetBoyView.setTimerView(mTimerView);

        mJetBoyView.SetButtonView(mButtonRetry);

        mJetBoyView.SetTextView(mTextView);
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent msg)
Standard override to get key-press events.


        if (keyCode == 4)
            super.onKeyDown(keyCode, msg);

        return mJetBoyThread.doKeyDown(keyCode, msg);
    
public booleanonKeyUp(int keyCode, android.view.KeyEvent msg)
Standard override for key-up. We actually care about these, so we can turn off the engine or stop rotating.

        return mJetBoyThread.doKeyUp(keyCode, msg);