android 向類比發送多點觸摸事件~

來源:互聯網
上載者:User

要向android發送系統多點觸摸事件,發現網上有人問,但是沒有人有答案~我也發過文章沒有人回答~搞了好久很搞出來~google真TMD不搞個文檔,搞個例子~

貼下代碼~下面是適合2.2的~

 public boolean sendMoveDouble()
 {
  //point 1 release first
  Log.i("key", "199199 send sendMovedoubl...........e");
  
  Instrumentation inst = new Instrumentation();
  MotionEvent e;
  //nano
  e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
    SystemClock.uptimeMillis(), System.nanoTime(),
    0, 1, new int[]{0},
    new float[]{bx1, by1, 1, 1}, 0,
             0, 0, 0, 0);
  Log.i("key", "199199 send sendMovedoubl...........1");
  inst.sendPointerSync(e);
      SystemClock.sleep(200);//Ms

  e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
    SystemClock.uptimeMillis(), System.nanoTime(),
    261, 2, new int[]{0, 1},
    new float[]{bx1, by1, 1, 1, ex1, ey1, 1, 1}, 0,
             0, 0, 0, 0);
  Log.i("key", "199199 send sendMovedoubl...........2");
  inst.sendPointerSync(e);
      SystemClock.sleep(200);//Ms

  e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
    SystemClock.uptimeMillis(), System.nanoTime(),
    2, 2, new int[]{0, 1},
    new float[]{bx2, by2, 1, 1, ex2, ey2, 1, 1}, 0,
             0, 0, 0, 0);
  Log.i("key", "199199 send sendMovedoubl...........3");
  inst.sendPointerSync(e);
      SystemClock.sleep(200);//Ms

  e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
    SystemClock.uptimeMillis(), System.nanoTime(),
    6, 2, new int[]{0, 1},
    new float[]{bx2, by2, 1, 1, ex2, ey2, 1, 1}, 0,
             0, 0, 0, 0);
  inst.sendPointerSync(e);
      SystemClock.sleep(200);//Ms
  Log.i("key", "199199 send sendMovedoubl...........4");

  e=MotionEvent.obtainNano(SystemClock.uptimeMillis(),
    SystemClock.uptimeMillis(), System.nanoTime(),
    1, 1, new int[]{1},
    new float[]{bx2, by2, 1, 1}, 0,
             0, 0, 0, 0);
  Log.i("key", "199199 send sendMovedoubl...........5");

  inst.sendPointerSync(e);

  return true;
 }

 

MotionEvent.obtainNano這個函數是2.2的,在SDK中沒有,你必須有android的源碼,在源碼中編譯才能連結到!在sdk中提示沒有這個函數

利用這個代碼我在2.2中成功的實現了放大和縮小

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.