Advertisement
KIKIJIKI

Untitled

Feb 15th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1.         @Override
  2.         public void onTouchEvent(MotionEvent event)
  3.         {
  4.             int index = event.getActionIndex();
  5.             int id = event.getPointerId(index);
  6.             int count = event.getPointerCount();
  7.  
  8.             if(_ss.isActive() == false)
  9.                 return;
  10.  
  11.             switch(event.getActionMasked())
  12.             {
  13.             case MotionEvent.ACTION_DOWN:
  14.             case MotionEvent.ACTION_POINTER_DOWN:
  15.             {
  16.                 if(_nextOnTouch)
  17.                 {
  18.                     if(_ss.stopWaiting())
  19.                     {
  20.                         return;
  21.                     }
  22.                 }
  23.                
  24.                 if(id >= count)
  25.                     break;
  26.  
  27.                 Touch t = new Touch();
  28.                 t.position = new vec(event.getX(id), event.getY(id));
  29.                 t.timer.scheduleAtFixedRate(new TimeredTouchTask(t.position, id), 0, SHOOTING_INTERVAL);
  30.  
  31.                 Touch old = _touch.put(id, t);
  32.                
  33.                 if(old != null)
  34.                 {
  35.                     old.timer.cancel();
  36.                     old.timer = null;
  37.                     old = null;
  38.                 }
  39.             }
  40.             break;
  41.                
  42.             case MotionEvent.ACTION_UP:
  43.             case MotionEvent.ACTION_POINTER_UP:
  44.             {
  45.                 removeTouch(id);
  46.             }
  47.             break;
  48.  
  49.             case MotionEvent.ACTION_MOVE:
  50.             {
  51.                 Iterator<Integer> it = _touch.keySet().iterator();
  52.                
  53.                 while(it.hasNext())
  54.                 {
  55.                     int i = it.next();
  56.                                                                            
  57.                     if(i < count)
  58.                     {
  59.                         vec t = _touch.get(i).position;
  60.                        
  61.                         t.x = event.getX(i);
  62.                         t.y = event.getY(i);
  63.                     }
  64.                     else
  65.                     {
  66.                         it.remove();
  67.                         removeTouch(i);
  68.                     }
  69.                 }
  70.             }
  71.             break;
  72.             }
  73.         }
  74.        
  75.         private void removeTouch(int id)
  76.         {
  77.             Touch t = _touch.get(id);
  78.            
  79.             if(t != null)
  80.             {
  81.                 if(t.timer != null)
  82.                 {
  83.                     t.timer.cancel();
  84.                     t.timer = null;
  85.                 }
  86.                
  87.                 t = null;
  88.                 _touch.remove(id);
  89.             }
  90.         }
  91.        
  92.         private class TimeredTouchTask extends TimerTask
  93.         {
  94.             private vec _t;
  95.             private int _id;
  96.  
  97.             public TimeredTouchTask(vec t, int id)
  98.             {
  99.                 _t = t;
  100.                 _id = id;
  101.             }
  102.  
  103.             @Override
  104.             public void run()
  105.             {
  106.                 if(_ss != null && _ss.isActive())
  107.                 {
  108.                     _ss.getActiveSequence().pushLine(_t, _e.getScreenOffset());
  109.                 }
  110.                 else
  111.                 {
  112.                     Touch t = _touch.get(_id);
  113.                    
  114.                     if(t != null)
  115.                         _touch.remove(_id);
  116.                    
  117.                     cancel();
  118.                 }
  119.             }
  120.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement