title: How to generate zoom/pinch gesture for testing for Android
body: <p>I'm trying to generate zoom/pinch gesture for testing, I have tried to use the Android API MotionEvent.obtain(), but found it is hard to implement the zoom/pinch events.</p>
  
  <p>I referenced the API from <a href="http://developer.android.com/reference/android/view/MotionEvent.html#obtain(long,%20long,%20int,%20int,%20android.view.MotionEvent.PointerProperties[],%20android.view.MotionEvent.PointerCoords[],%20int,%20int,%20float,%20float,%20int,%20int,%20int,%20int)">MotionEvent.obtain</a>. Can you tell me the correct method?</p>
  
  <p>Here is my implementation:</p>
  
  <pre><code>//for zoom, we need four points coordinations: start0, start1, end0, end1
  
  Instrumentation inst;
  
  // action down event
  MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 1, prop_start0, pointerCoords_start0, 0,  0, 0, 0, 0, 0, 0, 0 );
  inst.sendPointerSync(event);
  
  // action pointer 2 down event
  event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_2_DOWN, 2, properties_start0_1, pointerCoords_start0_1, 0, 0, 0, 0, 0, 0, 0, 0);
  inst.sendPointerSync(event);
  
  // action move events
  duration = 1000; //1000 ms
  event_interval = 10;//time interval between consecutive events 10ms 
  moveEventNum = duration / event_interval; 
  stepx0 = (end0.x - start0.x)/moveEventNum;
  stepy0 = (end0.y - start0.y)/moveEventNum;
  stepx1 = (end1.x - start1.x)/moveEventNum;
  stepy1 = (end1.y - start1.y)/moveEventNum;
  
  move_event0= start0;
  move_event1 = start1;
  for ( int i = 0; i &lt; moveEventNum; i++) {
         //  [generate middle points here ]
         mov_event0.x += stepx0;
         mov_event0.y += stepy0;
         mov_event1.x += stepx1;
         mov_event1.y += stepy1;
  
        eventTime += event_interval;
  
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 2, properties_move_event, pointerCoords_move_event0_1, 0, 0, 0, 0, 0, 0, 0, 0); 
  
       inst.sendPointerSync(event);
  }
  
  event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_2_UP, 2, properties_end0_1, pointerCoords_end0_1, 0, 0, 0, 0, 0, 0, 0, 0);
  inst.sendPointerSync(event);
  
  event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, 1, end1, pointerCoords_end1, 0, 0, 0, 0, 0, 0, 0, 0 );
  inst.sendPointerSync(event);
  </code></pre>