예제 #1
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();
           }
         });
   }
 }
예제 #2
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;
 }