Esempio n. 1
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int action = event.getAction();

    if (mDrawThread == null) {
      return false;
    }

    if (action == MotionEvent.ACTION_DOWN) {
      synchronized (touchLock) {
        mDrawThread.isDirty = true;
      }
      return true;
    } else if (action == MotionEvent.ACTION_MOVE) {
      synchronized (touchLock) {
        mDrawThread.isDirty = true;
      }
      return true;
    } else if (action == MotionEvent.ACTION_UP) {
      synchronized (touchLock) {
        mDrawThread.isDirty = true;
      }
      return true;
    }

    return super.onTouchEvent(event);
  }
 public void surfaceCreated(SurfaceHolder holder) {
   if (!running) {
     running = true;
     thread.setMode(Mode.RUNNING);
     thread.start();
   } else {
     thread.resume();
   }
 }
  public void surfaceDestroyed(SurfaceHolder holder) {
    thread.setMode(Mode.STOPPED);

    boolean retry = true;
    while (retry) {
      try {
        thread.join();
        retry = false;
      } catch (InterruptedException e) {
      }
    }
  }
Esempio n. 4
0
 public void surfaceDestroyed(SurfaceHolder holder) {
   boolean retry = true;
   thread.setRunning(false);
   while (retry) {
     try {
       thread.join();
       retry = false;
     } catch (InterruptedException e) {
       // we will try it again and again...
     }
   }
 }
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) {
   boolean retry = true;
   drawThread.setRunning(false);
   while (retry) {
     try {
       drawThread.join();
       retry = false;
     } catch (InterruptedException e) {
     }
   }
 }
Esempio n. 6
0
    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
      stop();
      _thread.setRunning(false);
      while (true) {
        try {
          _thread.join();
          break;
        } catch (InterruptedException e) {

        }
      }
    }
Esempio n. 7
0
 public void startAnimation() {
   if (dt == null) {
     Log.d(LOG_TAG, "startAnimation");
     dt = new DrawThread(this, getHolder());
     dt.start();
   }
 }
Esempio n. 8
0
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   if (mDrawThread == null) {
     mDrawThread = new DrawThread(mHolder, getContext());
     mDrawThread.start();
   }
 }
Esempio n. 9
0
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) {
   if (mDrawThread != null) {
     mDrawThread.setRunFlag(false);
     mDrawThread = null;
   }
 }
Esempio n. 10
0
 // INDIRECT repaint method (using a separate thread
 public void repaint() {
   if (drawThread == null || !drawThread.isRunning()) {
     // gargabe collect
     System.gc();
     // post a task to the UI thread
     this.post(
         new Runnable() {
           @Override
           public void run() {
             // create a new drawThread
             drawThread =
                 new DrawThread(
                     getHolder(),
                     getContext(),
                     new Handler() {
                       @Override
                       public void handleMessage(Message m) {}
                     });
             // call the setter for the pointer to the model
             if (drawable != null) {
               drawable.setWidth(getWidth());
               drawable.setHeight(getHeight());
               // draw the widget
               drawThread.setDrawable(drawable);
             }
             // start the thread
             drawThread.start();
           }
         });
   }
 }
Esempio n. 11
0
 @Override
 public void surfaceDestroyed(SurfaceHolder arg0) {
   // stop the drawThread properly
   boolean retry = true;
   while (retry) {
     try {
       // wait for it to finish
       if (drawThread != null && drawThread.isRunning()) drawThread.join();
       retry = false;
     } catch (InterruptedException e) {
       // ignore any error
       e.printStackTrace();
     }
   }
   // set it to null, so that a new one can be created in case of a resume
   drawThread = null;
 }
Esempio n. 12
0
 private void startAnimation() {
   isLoopDraw = true;
   isLoopCount = true;
   drawThread = new DrawThread();
   countThread = new CountThread();
   drawThread.start();
   countThread.start();
   Log.i(TAG, "satrtAnimation=" + anim);
 }
Esempio n. 13
0
 public void stopAnimation() {
   Log.d(LOG_TAG, "stopAnimation");
   if (dt != null) {
     dt.flag = false;
     Thread t = dt;
     dt = null;
     t.interrupt();
   }
 }
Esempio n. 14
0
 @Override
 public void surfaceCreated(SurfaceHolder arg0) {
   setKeepScreenOn(true);
   _thread.setRunning(true);
   _thread.start();
   // Start setting paints with anti alias and color
   whiteTextPaint.setColor(Color.WHITE);
   whiteTextPaint.setAntiAlias(true);
   whiteTextPaint.setTextSize(14);
   blackTextPaint.setColor(Color.BLACK);
   blackTextPaint.setAntiAlias(true);
   blackTextPaint.setTextSize(14);
   largeTextPaint.setColor(Color.WHITE);
   largeTextPaint.setAntiAlias(true);
   largeTextPaint.setTextSize(32);
   redTextPaint.setColor(Color.RED);
   redTextPaint.setAntiAlias(true);
   redTextPaint.setTextSize(18);
   ColorMatrix cm = new ColorMatrix(mx);
   invert.setColorFilter(new ColorMatrixColorFilter(cm));
   invert.setAntiAlias(true);
   // End settings paint
   // Set bitmap dimensions
   bulletW = bulletBitmap.getWidth();
   bulletH = bulletBitmap.getHeight();
   squareW = squareBitmap.getWidth();
   squareH = squareBitmap.getHeight();
   parabolicW = parabolicBitmap.getWidth();
   parabolicH = parabolicBitmap.getHeight();
   turningW = turningBitmap.getWidth();
   turningH = turningBitmap.getHeight();
   homingW = homingBitmap.getWidth();
   homingH = homingBitmap.getHeight();
   berzerkW = berzerkBitmap.getWidth();
   berzerkH = berzerkBitmap.getHeight();
   mcW = mcBitmap.getWidth();
   mcH = mcBitmap.getHeight();
   // End setting bitmap dimensions
 }
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   paint = new Paint(); // 创建画笔
   paint.setAntiAlias(true); // 打开抗锯齿
   // 加载图片资源
   bulletBmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.bullet);
   bgBmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.bg);
   explodeBmps =
       new Bitmap[] {
         BitmapFactory.decodeResource(this.getResources(), R.drawable.explode0),
         BitmapFactory.decodeResource(this.getResources(), R.drawable.explode1),
         BitmapFactory.decodeResource(this.getResources(), R.drawable.explode2),
         BitmapFactory.decodeResource(this.getResources(), R.drawable.explode3),
         BitmapFactory.decodeResource(this.getResources(), R.drawable.explode4),
         BitmapFactory.decodeResource(this.getResources(), R.drawable.explode5),
       };
   bullet = new Bullet(this, bulletBmp, explodeBmps, 0, 290, 1.3f, -5.9f); // 创建子弹对象
   drawThread = new DrawThread(this); // 创建绘制线程
   drawThread.start(); // 启动绘制线程
 }
Esempio n. 16
0
 public void surfaceDestroyed(SurfaceHolder holder) {
   if (dt != null) {
     dt.flag = false;
     dt = null;
   }
 }
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) { // 界面销毁时调用的方法
   drawThread.setFlag(false); // 停止绘制线程
 }
Esempio n. 18
0
 public void onWindowFocusChanged(boolean hasWindowFocus) {
   if (!hasWindowFocus) thread.onPause();
 }
Esempio n. 19
0
 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
   thread.setSurfaceSize(width, height);
 }
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   drawThread = new DrawThread(getHolder());
   drawThread.setRunning(true);
   drawThread.start();
 }
Esempio n. 21
0
 public void surfaceCreated(SurfaceHolder holder) {
   if (!_run) {
     thread.setRunning(true);
     thread.start();
   }
 }