导入android content context象棋答案helpview java.pdf
packagecom.realaction.chessapp;
importandroid.content.Context;
importandroid.graphics.Bitmap;
importandroid.graphics.BitmapFactory;
importandroid.graphics.Canvas;
importandroid.graphics.Paint;
importandroid.view.MotionEvent;
importandroid.view.SurfaceHolder;
importandroid.view.SurfaceView;
/**
*
*
*
*/
publicclassHelpViewextendsSurfaceViewimplementsSurfaceHolder.Callback{
MainActivityactivity;//Activity
privateTutorialThreadthread;//
Bitmapback;//
BitmaphelpBackground;//
publicHelpView(Contextcontext,MainActivityactivity){//
super(context);
this.activity=activity;//õactivity
getHolder().addCallback(this);
this.thread=newTutorialThread(getHolder(),this);//
initBitmap();//
}
publicvoidinitBitmap(){//õ
back=BitmapFactory.decodeResource(getResources(),R.drawable.back);//
helpBackground=BitmapFactory.decodeResource(getResources(),
R.drawable.helpbackground);//
}
publicvoidonDraw(Canvascanvas){//д
canvas.drawBitmap(helpBackground,0,90,neint());//
canvas.drawBitmap(back,200,370,neint());//
}
publicvoidsurfaceChanged(SurfaceHolderholder,intformat,intwidth,
intheight){
}
publicvoidsurfaceCreated(SurfaceHolderholder){//
this.thread.setFlag(true);//λ
this.thread.start();//
}
publicvoidsurfaceDestroyed(SurfaceHolderholder){//
booleanretry=true;//λ
thread.setFlag(false);//λ
while(retry){
try{
thread.join();//
retry=false;//
}catch(InterruptedExceptione){
}//
}
}
publicbooleanonTouchEvent(MotionEventevent){//
if(event.getAction()MotionEvent.ACTION_DOWN){
if(event.getX()200event.getX()200+back.getWidth()