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

JetBoyView

public class JetBoyView extends android.view.SurfaceView implements SurfaceHolder.Callback

Fields Summary
public static final int
mSuccessThreshold
public int
mHitStreak
public int
mHitTotal
public int
mCurrentBed
private android.graphics.Bitmap
mTitleBG
private android.graphics.Bitmap
mTitleBG2
public static final String
TAG
private JetBoyThread
thread
The thread that actually draws the animation
private android.widget.TextView
mTimerView
private android.widget.Button
mButtonRetry
private android.widget.TextView
mTextView
Constructors Summary
public JetBoyView(android.content.Context context, android.util.AttributeSet attrs)
The constructor called from the main JetBoy activity

param
context
param
attrs


                        
         
        super(context, attrs);

        // register our interest in hearing about changes to our surface
        SurfaceHolder holder = getHolder();
        holder.addCallback(this);
        
        // create thread only; it's started in surfaceCreated()
        // 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"));
    
                    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);
    
                    }
                }//end handle msg
            });
        }

        setFocusable(true); // make sure we get key events

        Log.d(TAG, "@@@ done creating view!");
    
Methods Summary
public voidSetButtonView(android.widget.Button _buttonRetry)
A reference to the button to start game over.

param
_buttonRetry

        mButtonRetry = _buttonRetry;
        //  mButtonRestart = _buttonRestart;
    
public voidSetTextView(android.widget.TextView textView)

        mTextView = textView;

    
public com.example.android.jetboy.JetBoyView$JetBoyThreadgetThread()
Fetches the animation thread corresponding to this LunarView.

return
the animation thread

        return thread;
    
public voidonWindowFocusChanged(boolean hasWindowFocus)
Standard window-focus override. Notice focus lost so we can pause on focus lost. e.g. user switches to take a call.

        if (!hasWindowFocus) {
            if (thread != null)
                thread.pause();

        }
    
public voidsetTimerView(android.widget.TextView tv)
Pass in a reference to the timer view widget so we can update it from here.

param
tv

        mTimerView = tv;
    
public voidsurfaceChanged(android.view.SurfaceHolder holder, int format, int width, int height)

        thread.setSurfaceSize(width, height);
    
public voidsurfaceCreated(android.view.SurfaceHolder arg0)

        // start the thread here so that we don't busy-wait in run()
        // waiting for the surface to be created
        thread.setRunning(true);
        thread.start();
    
public voidsurfaceDestroyed(android.view.SurfaceHolder arg0)

        boolean retry = true;
        thread.setRunning(false);
        while (retry) {
            try {
                thread.join();
                retry = false;

            } catch (InterruptedException e) {
            }
        }