예제 #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);
  }
예제 #2
0
 public void surfaceCreated(SurfaceHolder holder) {
   if (!running) {
     running = true;
     thread.setMode(Mode.RUNNING);
     thread.start();
   } else {
     thread.resume();
   }
 }
예제 #3
0
  public void surfaceDestroyed(SurfaceHolder holder) {
    thread.setMode(Mode.STOPPED);

    boolean retry = true;
    while (retry) {
      try {
        thread.join();
        retry = false;
      } catch (InterruptedException e) {
      }
    }
  }
예제 #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) {
     }
   }
 }
예제 #6
0
    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
      stop();
      _thread.setRunning(false);
      while (true) {
        try {
          _thread.join();
          break;
        } catch (InterruptedException e) {

        }
      }
    }
예제 #7
0
 public void startAnimation() {
   if (dt == null) {
     Log.d(LOG_TAG, "startAnimation");
     dt = new DrawThread(this, getHolder());
     dt.start();
   }
 }
예제 #8
0
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   if (mDrawThread == null) {
     mDrawThread = new DrawThread(mHolder, getContext());
     mDrawThread.start();
   }
 }
예제 #9
0
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) {
   if (mDrawThread != null) {
     mDrawThread.setRunFlag(false);
     mDrawThread = null;
   }
 }
예제 #10
0
파일: WidgetView.java 프로젝트: fesch/CanZE
 // 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();
           }
         });
   }
 }
예제 #11
0
파일: WidgetView.java 프로젝트: fesch/CanZE
 @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;
 }
예제 #12
0
 private void startAnimation() {
   isLoopDraw = true;
   isLoopCount = true;
   drawThread = new DrawThread();
   countThread = new CountThread();
   drawThread.start();
   countThread.start();
   Log.i(TAG, "satrtAnimation=" + anim);
 }
예제 #13
0
 public void stopAnimation() {
   Log.d(LOG_TAG, "stopAnimation");
   if (dt != null) {
     dt.flag = false;
     Thread t = dt;
     dt = null;
     t.interrupt();
   }
 }
예제 #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(); // 启动绘制线程
 }
예제 #16
0
 public void surfaceDestroyed(SurfaceHolder holder) {
   if (dt != null) {
     dt.flag = false;
     dt = null;
   }
 }
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) { // 界面销毁时调用的方法
   drawThread.setFlag(false); // 停止绘制线程
 }
예제 #18
0
 public void onWindowFocusChanged(boolean hasWindowFocus) {
   if (!hasWindowFocus) thread.onPause();
 }
예제 #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();
 }
예제 #21
0
 public void surfaceCreated(SurfaceHolder holder) {
   if (!_run) {
     thread.setRunning(true);
     thread.start();
   }
 }