package com.bn.st.d2; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.view.MotionEvent; import android.view.SurfaceHolder; import static com.bn.st.xc.Constant.*; import com.bn.R; public class HelpSurfaceView extends MySFView { MyActivity activity;//Activity的引用 Canvas c;//画笔的引用 Paint paint;//画笔的引用 SurfaceHolder holder;//锁的引用 Bitmap[] bg_bitmap; //背景图 Bitmap pre_page; //上一页按钮图片 Bitmap next_page; //下一页按钮图片 Bitmap back; Bitmap pre_page_press; //上一页按钮图片 Bitmap next_page_press; //下一页按钮图片 Bitmap back_press; //帮助界面中的闪烁提示 Bitmap[] mark_bitmap; //每张闪烁提示图片的xy坐标 private final float[][] mark_xy= { {246,308}, {44,170}, {15,115}, {50,160}, {184,242} }; int fullTime=0;//记录从开始到当前的时间 long startTime;//开始时间 private float button_pre_x=20f*ratio_width;//back图片按钮的左上角的点的坐标 private float button_pre_y=415f*ratio_height; private float button_next_x=710f*ratio_width;//next图片按钮的左上角点的坐标 private float button_next_y=415f*ratio_height; private int next_flag=0;//0表示不移动,-1表示左移,1表示右移 private float bg_bitmap_curr_x=0;//当前背景图片的左上角点的X坐标 private float bg_bitmap_curr_y=0;//当前背景图片的左上角点的Y坐标 private float bg_bitmap_next_x;//下一幅背景图片的左上角点的X坐标 private float bg_bitmap_next_y=0;//下一幅背景图片的左上角点的Y坐标 private float move_span=80;//图片移动的速度 int page_index=0;//当前帮助页面的索引值 public boolean flag_go=true; boolean back_flag=false; boolean pre_page_flag=false; boolean next_page_flag=false; boolean isHaveNextFlag=true; boolean isHavePreFlag=false; public HelpSurfaceView(MyActivity activity) { this.activity = activity; paint = new Paint(); //创建画笔 bg_bitmap=new Bitmap[5];//创建帮助界面背景图片数组对象 mark_bitmap=new Bitmap[5];//创建帮助界面中标注提醒图片数组对象 paint.setAntiAlias(true);//打开抗锯齿 initBitmap(); //初始化用到的图片资源 startTime=System.currentTimeMillis(); } public void initThread() { next_flag=0;//0表示不移动,-1表示左移,1表示右移 bg_bitmap_curr_x=0;//当前背景图片的左上角点的X坐标 bg_bitmap_curr_y=0;//当前背景图片的左上角点的Y坐标 bg_bitmap_next_x=0;//下一幅背景图片的左上角点的X坐标 bg_bitmap_next_y=0;//下一幅背景图片的左上角点的Y坐标 move_span=80;//图片移动的速度 page_index=0;//当前帮助页面的索引值 flag_go=true; back_flag=false; pre_page_flag=false; next_page_flag=false; isHaveNextFlag=true; isHavePreFlag=false; new Thread()//创建一个线程调用doDraw方法 { @Override public void run() { while(flag_go) { //判断是左移还是右移 if(next_flag==-1)//左移 { bg_bitmap_curr_x=bg_bitmap_curr_x-move_span; bg_bitmap_next_x=bg_bitmap_next_x-move_span; if(bg_bitmap_curr_x<=-SCREEN_WIDTH) { bg_bitmap_curr_x=-SCREEN_WIDTH; next_flag=0; page_index++; bg_bitmap_curr_x=0; bg_bitmap_next_x=SCREEN_WIDTH; if(page_index==bg_bitmap.length-1) { isHaveNextFlag=false; } } } if(next_flag==1)//右移 { bg_bitmap_curr_x=bg_bitmap_curr_x+move_span; bg_bitmap_next_x=bg_bitmap_next_x+move_span; if(bg_bitmap_curr_x>=SCREEN_WIDTH) { bg_bitmap_curr_x=SCREEN_WIDTH; page_index--; bg_bitmap_curr_x=0; bg_bitmap_next_x=-SCREEN_WIDTH; if(page_index==0) { isHavePreFlag=false; } next_flag=0; } } try { Thread.sleep(10);//线程休眠100毫秒 } catch (InterruptedException e) { e.printStackTrace(); } } } }.start(); } //重写onDraw方法 @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.argb(255, 0, 0, 0));//清屏为黑色 canvas.drawBitmap(bg_bitmap[page_index],bg_bitmap_curr_x,bg_bitmap_curr_y, null);//画当前背景 //当界面没有在移动的时候,绘制当前帮助界面的闪烁图标提示 if(next_flag==0) { //绘制帮助界面闪动的图标 long currentTime=System.currentTimeMillis();//记录当前时间 fullTime=(int) ((currentTime-startTime));//记录总时间 //将1秒分成两份,在0.7秒内绘制,0.3秒内不绘制 if((fullTime/100)%10 < 7) { //绘制翻页指示图标 System.out.println(ratio_width+" "+ratio_height); canvas.drawBitmap(mark_bitmap[page_index], mark_xy[page_index][0]*ratio_width, mark_xy[page_index][1]*ratio_height, paint); } } if(next_flag==-1) { canvas.drawBitmap(bg_bitmap[page_index+1],bg_bitmap_next_x,bg_bitmap_next_y, null);//画下一幅背景 } if(next_flag==1) { canvas.drawBitmap(bg_bitmap[page_index-1],bg_bitmap_next_x,bg_bitmap_next_y, null);//画下一幅背景 } if(isHaveNextFlag==false) { if(!back_flag) { canvas.drawBitmap(back, button_next_x, button_next_y, null);//绘制back按钮 } else { canvas.drawBitmap(back_press, button_next_x, button_next_y, null);//绘制back按钮 } } if(page_index>0)//当前的页面索引大于0 { if(!pre_page_flag) { canvas.drawBitmap(pre_page, button_pre_x, button_pre_y, paint);//绘制上一页按钮 }else { canvas.drawBitmap(pre_page_press, button_pre_x, button_pre_y, paint);//绘制上一页按钮 } } if(!isHavePreFlag) { if(!back_flag) { canvas.drawBitmap(back, button_pre_x, button_pre_y, null);//绘制back按钮 } else { canvas.drawBitmap(back_press, button_pre_x, button_pre_y, null);//绘制back按钮 } } if(page_indexbutton_pre_x&&xbutton_pre_y&&ybutton_next_x&&xbutton_next_y&&ybutton_next_x&&xbutton_next_y&&ybutton_pre_x&&xbutton_pre_y&&ybutton_pre_x&&xbutton_pre_y&&ybutton_next_x&&xbutton_next_y&&y