Android Open Source - NotATop End Surface View






From Project

Back to project page NotATop.

License

The source code is released under:

GNU General Public License

If you think the Android project NotATop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gg.view;
//from   www. j  a  va 2 s .  c  o  m
import com.gg.util.Constant;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;


public class EndSurfaceView extends SurfaceView implements SurfaceHolder.Callback{
  MainActivity mainActivity;//mainActivity??????
  Paint paint;//????????
  DrawThread drawThread;//???????????    
  Bitmap bgBitmap;//??????  
  //Bitmap titleBitmap;//???????
  Bitmap scoreBitmap;
  //Bitmap dataBitmap;
  Bitmap[] numberBitmaps;//??????  
  //Bitmap dashBitmap;//????"-"???????
  int bmpx;//???????  
  //String queryResultStr;//???????????
  //String[] splitResultStrs;//?????????????????
  private int numberWidth;//??????????
  private int posFrom=-1;//??????????
  private int length=6;//?????????????
//  int downY=0;//????????y????
//  int upY=0;
  
  private double downX;
  private double downY;
  private double upX;
  private double upY;
  
  public EndSurfaceView(MainActivity mainActivity) {
    super(mainActivity);
    this.mainActivity=mainActivity;
    //???????????????
    this.requestFocus();
        this.setFocusableInTouchMode(true);
    getHolder().addCallback(this);//????????  
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //???????
    canvas.drawColor(Color.WHITE);
    
    //canvas.drawBitmap(bgBitmap, 0, 0, paint);
    canvas.drawBitmap(bgBitmap, new Rect(0, 0,
        (int) bgBitmap.getWidth(), (int) bgBitmap
            .getHeight()), new Rect(0, 0,
        (int) Constant.SCREEN_WIDTH, (int) Constant.SCREEN_HEIGHT), paint);
    
    //????????
    //canvas.drawBitmap(titleBitmap, bmpx, Constant.SCREEN_HEIGHT/20, paint);
//    canvas.drawBitmap(scoreBitmap, Constant.SCREEN_WIDTH*2/3, Constant.SCREEN_HEIGHT/5, paint);
    //canvas.drawBitmap(dataBitmap, Constant.SCREEN_WIDTH*1/3, titleBitmap.getHeight()+Constant.SCREEN_HEIGHT/10, paint);
//    //?????????
//    int x,y;
//    for(int i=0;i<splitResultStrs.length;i++)
//    {
//      if(i%2==0)//?????????
//      {
//        x=Constant.SCREEN_WIDTH*3/4;        
//      }
//      else//???????????
//      {
//        x=Constant.SCREEN_WIDTH/2;
//      }
//      y=Constant.SCREEN_HEIGHT/20+titleBitmap.getHeight()+scoreBitmap.getHeight()+(numberBitmaps[0].getHeight()+Constant.SCREEN_HEIGHT/45)*(i/2+1);
//      //?????????
//      drawDateBitmap(splitResultStrs[i],x,y,canvas,paint);
//    }
    drawDateBitmap(mainActivity.getCurrScore()+"",Constant.SCREEN_WIDTH*3/4,Constant.SCREEN_HEIGHT/4,canvas,paint);
  }
  //?????????????
  public void drawDateBitmap(String numberStr,float endX,float endY,Canvas canvas,Paint paint)
  {
    for(int i=0;i<numberStr.length();i++)
    {
      char c=numberStr.charAt(i);
      if(c=='-')
      {
        //canvas.drawBitmap(dashBitmap,endX-numberWidth*(numberStr.length()-i), endY, paint);
      }
      else
      {
        canvas.drawBitmap
        (
            numberBitmaps[c-'0'], 
            endX-numberWidth*(numberStr.length()-i), 
            endY, 
            paint
        );
      }      
    }
  }
  @Override
  public boolean onTouchEvent(MotionEvent e) {
//    int y = (int) event.getY();    
//      switch(event.getAction())
//      {
//      case MotionEvent.ACTION_DOWN:
//        downY=y;
//        break;
//      case MotionEvent.ACTION_UP:
//        upY=y;        
//          if(Math.abs(downY-upY)<20)//????????????????
//          {
//            return true;
//          }
//          else if(downY<upY)//?????
//          {  
//            //???????????????????
//            if(this.posFrom-this.length>=-1)
//            {
//              this.posFrom-=this.length;              
//            }
//          }
//          else//?????
//          {  
//            //???????????????????
//            if(this.posFrom+this.length<mainActivity.getRowCount()-1)
//            {
//              this.posFrom+=this.length;              
//            }
//          }
//          queryResultStr=mainActivity.query(posFrom,length);//??????????????
//      splitResultStrs=queryResultStr.split("/", 0);//??"/"????????????
//        break;      
//      }
    
    
    switch(e.getAction()){
    case MotionEvent.ACTION_DOWN:
      downX = Constant.convertX(e.getX());
      downY = Constant.convertY(e.getY());
      break;
    case MotionEvent.ACTION_MOVE:
      break;
    case MotionEvent.ACTION_UP:
      upX = Constant.convertX(e.getX());
      upY = Constant.convertY(e.getY());
      
      if(downX<-1 && downY<-0.4){
        if(upX<-1 && upY<-0.4){
          mainActivity.getHandler().sendEmptyMessage(SurfaceViewFactory.SELECT);
        }
      }else if(downX>-0.6 && downX<0.6 && downY<-0.4){
        if(upX>-0.6 && upX<0.6 && upY<-0.4){
          mainActivity.getHandler().sendEmptyMessage(SurfaceViewFactory.GAME_MODE);
        }
      }else if(downX>1 && downY<-0.4){
        if(upX>1 && upY<-0.4){
          mainActivity.getHandler().sendEmptyMessage(SurfaceViewFactory.MAIN_MENU);
        }
      }
      break;
    }
    return true;
  }  
  
  public void surfaceChanged(SurfaceHolder holder, int format, int width,
      int height) {    
  }

  public void surfaceCreated(SurfaceHolder holder){
    paint=new Paint();//????????
    paint.setAntiAlias(true);//??????  
    createAllThreads();//???????????
    initBitmap();//??????????  
    numberWidth=numberBitmaps[0].getWidth()+3*5;//????????????
    //????????????
    bmpx=(Constant.SCREEN_WIDTH-50)/2;
    posFrom=-1;//????????????-1      
    //queryResultStr=mainActivity.query(posFrom,length);//??????????????
    //splitResultStrs=queryResultStr.split("/", 0);//??"/"????????????    
    startAllThreads();//???????????
  }
  
  public void surfaceDestroyed(SurfaceHolder holder) {
      boolean retry = true;
          stopAllThreads();
          while (retry) {
              try {
                drawThread.join();
                  retry = false;
              } 
              catch (InterruptedException e) {e.printStackTrace();}//?????????????????????
          }
  }
  //????????
  public void initBitmap(){
    //titleBitmap=BitmapFactory.decodeResource(this.getResources(), R.drawable.high_score);  
    bgBitmap=BitmapFactory.decodeResource(this.getResources(), R.drawable.end_bg);
    numberBitmaps=new Bitmap[]{
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end0),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end1),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end2),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end3),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end4),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end5),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end6),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end7),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end8),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end9),
        BitmapFactory.decodeResource(this.getResources(), R.drawable.end0),
    };
    //dashBitmap=BitmapFactory.decodeResource(this.getResources(), R.drawable.gang);
    scoreBitmap=BitmapFactory.decodeResource(this.getResources(), R.drawable.score);
    //dataBitmap=BitmapFactory.decodeResource(this.getResources(), R.drawable.data);
  }
  void createAllThreads()
  {
    drawThread=new DrawThread(this);//???????????    
  }
  void startAllThreads()
  {
    drawThread.setFlag(true);     
    drawThread.start();
  }
  void stopAllThreads()
  {
    drawThread.setFlag(false);       
  }
  private class DrawThread extends Thread{
    private boolean flag = true;  
    private int sleepSpan = 100;
    EndSurfaceView fatherView;
    SurfaceHolder surfaceHolder;
    public DrawThread(EndSurfaceView fatherView){
      this.fatherView = fatherView;
      this.surfaceHolder = fatherView.getHolder();
    }
    public void run(){
      Canvas c;
          while (this.flag) {
              c = null;
              try {
                // ??????????????????????????????????????????null
                  c = this.surfaceHolder.lockCanvas(null);
                  synchronized (this.surfaceHolder) {
                    fatherView.onDraw(c);//????
                  }
              } finally {
                  if (c != null) {
                    //???????
                      this.surfaceHolder.unlockCanvasAndPost(c);
                  }
              }
              try{
                Thread.sleep(sleepSpan);//????????????
              }
              catch(Exception e){
                e.printStackTrace();//?????????
              }
          }
    }
    public void setFlag(boolean flag) {
      this.flag = flag;
    }
  }
}




Java Source Code List

com.gg.game.ClassicGame.java
com.gg.game.ClassicGame.java
com.gg.game.GameFrame.java
com.gg.game.GameFrame.java
com.gg.game.TimeGame.java
com.gg.game.TimeGame.java
com.gg.module.DrawBackground.java
com.gg.module.DrawBackground.java
com.gg.module.DrawScore.java
com.gg.module.DrawScore.java
com.gg.module.DrawTrack.java
com.gg.module.DrawTrack.java
com.gg.module.SelectControl.java
com.gg.module.SelectControl.java
com.gg.module.SoundControl.java
com.gg.module.SoundControl.java
com.gg.module.VoiceControl.java
com.gg.module.VoiceControl.java
com.gg.top.BasicTop.java
com.gg.top.BasicTop.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCone.java
com.gg.top.DrawCone.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawTop.java
com.gg.top.DrawTop.java
com.gg.util.Circle.java
com.gg.util.Circle.java
com.gg.util.Constant.java
com.gg.util.Constant.java
com.gg.util.DateUtil.java
com.gg.util.DateUtil.java
com.gg.util.Direction.java
com.gg.util.Direction.java
com.gg.util.Line.java
com.gg.util.Line.java
com.gg.util.Point.java
com.gg.util.Point.java
com.gg.util.TextureRect.java
com.gg.util.TextureRect.java
com.gg.util.TrackPoint.java
com.gg.util.TrackPoint.java
com.gg.util.Track.java
com.gg.util.Track.java
com.gg.util.Utils.java
com.gg.util.Utils.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.MainActivity.java
com.gg.view.MainActivity.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.WelcomeSurfaceView.java
com.gg.view.WelcomeSurfaceView.java