Android Open Source - NotATop Help 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  ww w . j a  v  a2 s . co  m
import com.gg.util.Constant;

import android.content.Context;
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 android.view.SurfaceView;
import android.widget.Toast;

   

public class HelpSurfaceView extends SurfaceView implements SurfaceHolder.Callback,Runnable{  
        private SurfaceHolder surfaceHolder;       
        
        private MainActivity mainActivity;
        
        private Thread thread;     //???
        private Canvas canvas;    //????
        private Paint backgroundPaint;    //????
        private Matrix backgroundMatrix;  //??????????????
        private int width;      //??????
        private int height;    //??????
        private Bitmap backgroundImage;    //??????
        private boolean endFlag = true;   //???run??????????
        private int select = 0;      //????????????
//        private boolean touchFlag = false;      //???????????????????
//        private float firstX , endX;      //?????????????????,???????????????
        private double downX;
        private double downY;
        private double upX;
        private double upY;
        
        private Toast lastToast;
        
          
        public HelpSurfaceView(Context context) {    //?????
            super(context);  
            mainActivity = (MainActivity)context;
            
            surfaceHolder=this.getHolder();  
            surfaceHolder.addCallback(this);  
            thread=new Thread(this);   
            backgroundPaint = new Paint(); 
            backgroundPaint.setColor(Color.RED);
            backgroundMatrix = new Matrix();
            backgroundImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.help1_bg);
            
            lastToast = Toast.makeText(context, "????????????", Toast.LENGTH_SHORT);
              
            this.setKeepScreenOn(true);  
        }  
        
        public void surfaceChanged(SurfaceHolder holder, int format, int width,  
                int height) {  
            // TODO Auto-generated method stub  
              
        }  
        
        public void surfaceCreated(SurfaceHolder holder) {     //????? 
          width = this.getWidth();
          height = this.getHeight();
          backgroundMatrix.setScale((float)(width) / backgroundImage.getWidth(), (float)(height) / backgroundImage.getHeight());
            thread.start();  
        }  
        
        
        public void surfaceDestroyed(SurfaceHolder holder) {  
            // TODO Auto-generated method stub  
          endFlag = false;    //run()???????
        }  
        
        //???????
        public boolean onTouchEvent(MotionEvent e) {
          switch(e.getAction()){
          case MotionEvent.ACTION_DOWN:
            //touchFlag = false;
            //firstX = e.getX();   //?????
            downX = Constant.convertX(e.getX());
            downY = Constant.convertY(e.getY());
            break;
            
          case MotionEvent.ACTION_UP:
            upX = Constant.convertX(e.getX());
            upY = Constant.convertY(e.getY());
            //endX = e.getX();   //??????
            //touchFlag = true;
            //if(touchFlag)
            //  if(firstX > endX)   //????
            //    select ++;
            //  else select --;   //????
            
            
            if(downX>1.0 && downY<0.3 && upX>1.0 && upY<0.3){
              mainActivity.getHandler().sendEmptyMessage(SurfaceViewFactory.MAIN_MENU);
            }
            
            if(downX>0.6 && downX<1.0 && downY>-0.2 && downY<0.2){
              if(upX>0.6 && upX<1.0 && upY>-0.2 && upY<0.2){
                select++;
              }
            }

            
//            if(select < 0){
//              select = 0;
//            }
            if(select > 4){
              select = 4;
              lastToast.show();
            }
            logic();    //????logic???????
            break;
          }
          return true;
          
        }
        
        
        public void run() {  
            while(endFlag){  
                draw();  
                try {  
                    Thread.sleep(1);  
                } catch (InterruptedException e) {  
                    // TODO Auto-generated catch block  
                    e.printStackTrace();  
                }  
            }  
        }  
        
        private void draw() {  
            try {  
                canvas=surfaceHolder.lockCanvas();//get a canvas example.  
                canvas.drawBitmap(backgroundImage, backgroundMatrix, backgroundPaint);  
            } catch (Exception e) {  
                // TODO: handle exception  
            }finally{  
                if (canvas!=null) {  
                    surfaceHolder.unlockCanvasAndPost(canvas);//submit a gooad canvas painting.  
                }   
            }  
              
        }
        
        private void logic() {
          switch(select) {   //?????5????
          case 0:
            backgroundImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.help1_bg);
            break;
            
          case 1:
            backgroundImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.help2_bg);
            break;
            
          case 2:
            backgroundImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.help3_bg);
            break;
            
          case 3:
            backgroundImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.help4_bg);
            break;
            
          case 4:
            backgroundImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.help5_bg);
            break;
          }
          
          backgroundMatrix.setScale((float)(width) / backgroundImage.getWidth(), (float)(height) / backgroundImage.getHeight());  //??????
        }
    }




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