Guest User

Untitled

a guest
Aug 14th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. private float lastX;
  2. private float lastY;
  3.  
  4. public boolean onTouch(View v, MotionEvent ev) {
  5.  
  6. final float y = ev.getX();
  7. final float x = ev.getY();
  8.  
  9. final int hs = ev.getHistorySize();
  10.  
  11. final int ac = ev.getAction();
  12. switch(ac)
  13. {
  14. case MotionEvent.ACTION_DOWN:
  15. {
  16. this.lastX = x;
  17. this.lastY = y;
  18. Log.i("TEST", "Down at " + x + "/" + y + " (History size="+hs+")");
  19. return true;
  20. }
  21. case MotionEvent.ACTION_MOVE:
  22. {
  23. Log.i("TEST", "Move at " + x + "/" + y + ": Delta="+(lastX-x)+"/"+(lastY-y) + " (History size="+hs+")");
  24. this.lastX = x;
  25. this.lastY = y;
  26. return true;
  27. }
  28. case MotionEvent.ACTION_UP:
  29. {
  30. Log.i("TEST", "Up at " + x + "/" + y + " (History size="+hs+")");
  31. return true;
  32. }
  33. }
  34. }
  35.  
  36. Down at 376.0/259.0 (History size=0)
  37. Move at 392.0/268.0: Delta=-16.0/-9.0 (History size=0)
  38. Move at 394.0/268.0: Delta=-2.0/0.0 (History size=0)
  39. Move at 395.0/269.0: Delta=-1.0/-1.0 (History size=0)
  40. Move at 394.0/268.0: Delta=1.0/1.0 (History size=0)
  41. Move at 396.0/269.0: Delta=-2.0/-1.0 (History size=0)
  42. Move at 399.0/271.0: Delta=-3.0/-2.0 (History size=1)
  43. Move at 401.0/272.0: Delta=-2.0/-1.0 (History size=0)
  44. Move at 403.0/273.0: Delta=-2.0/-1.0 (History size=0)
  45. Move at 404.0/273.0: Delta=-1.0/0.0 (History size=0)
  46. Move at 405.0/274.0: Delta=-1.0/-1.0 (History size=0)
  47. Move at 406.0/275.0: Delta=-1.0/-1.0 (History size=0)
  48. Up at 406.0/275.0 (History size=0)
  49.  
  50. private static PointF touchScreenStartPtArr[] = new PointF[10];
  51. private static PointF touchScreenStopPtArr[] = new PointF[10];
  52. private static PointF touchScreenCurrPtArr[] = new PointF[10];
  53.  
  54. OnTouchListener onTouchListenerMulti = new OnTouchListener() {
  55.  
  56. @Override
  57. public boolean onTouch(View v, MotionEvent event) {
  58.  
  59. int action = event.getAction() & MotionEvent.ACTION_MASK;
  60. int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
  61. int fingerId = event.getPointerId(pointerIndex);
  62.  
  63. switch (action) {
  64. case MotionEvent.ACTION_DOWN:
  65. case MotionEvent.ACTION_POINTER_DOWN:
  66. touchScreenStartPtArr[fingerId].x = event.getX(pointerIndex);
  67. touchScreenStartPtArr[fingerId].y = event.getY(pointerIndex);
  68. break;
  69. case MotionEvent.ACTION_UP:
  70. case MotionEvent.ACTION_POINTER_UP:
  71. case MotionEvent.ACTION_CANCEL:
  72. touchScreenStopPtArr[fingerId].x = event.getX(pointerIndex);
  73. touchScreenStopPtArr[fingerId].y = event.getX(pointerIndex);
  74. break;
  75. case MotionEvent.ACTION_MOVE:
  76. int pointerCount = event.getPointerCount();
  77. for (int i = 0; i < pointerCount; i++) {
  78. touchScreenCurrPtArr[fingerId].x = event.getX(i);
  79. touchScreenCurrPtArr[fingerId].y = event.getY(i);
  80. }
  81. break;
  82. }
  83. return true;
  84. }
  85. };
  86.  
  87. Down at 387.29388/247.27272 (History size=0)
  88. Move at 387.29388/247.27272: Delta=0.0/0.0 (History size=0)
  89. Move at 387.29388/247.27272: Delta=0.0/0.0 (History size=0)
  90. Move at 387.29388/245.39589: Delta=0.0/1.876831 (History size=0)
  91. Move at 387.29388/244.92668: Delta=0.0/0.46920776 (History size=0)
  92. Move at 387.29388/244.45747: Delta=0.0/0.46920776 (History size=0)
  93. Move at 387.29388/243.98827: Delta=0.0/0.46920776 (History size=0)
  94. Move at 387.29388/243.51906: Delta=0.0/0.46920776 (History size=0)
  95. Move at 389.01614/243.51906: Delta=-1.7222595/0.0 (History size=0)
  96. Move at 389.8773/243.51906: Delta=-0.861145/0.0 (History size=0)
  97. Move at 389.8773/243.04985: Delta=0.0/0.46920776 (History size=0)
  98. Move at 390.73843/243.04985: Delta=-0.861145/0.0 (History size=0)
  99. Move at 390.73843/242.58064: Delta=0.0/0.46920776 (History size=0)
  100. Move at 391.59958/242.58064: Delta=-0.861145/0.0 (History size=0)
  101. Move at 391.59958/242.11143: Delta=0.0/0.46920776 (History size=0)
  102. Move at 392.46072/242.11143: Delta=-0.861145/0.0 (History size=0)
  103. Move at 392.46072/241.64223: Delta=0.0/0.46920776 (History size=0)
  104. Move at 393.32187/241.64223: Delta=-0.861145/0.0 (History size=0)
  105. Move at 394.183/241.64223: Delta=-0.861145/0.0 (History size=0)
  106. Move at 394.183/241.17302: Delta=0.0/0.46920776 (History size=0)
  107. Move at 395.04413/241.17302: Delta=-0.8611145/0.0 (History size=0)
  108. Move at 395.04413/242.11143: Delta=0.0/-0.9384155 (History size=0)
  109. Move at 395.04413/242.58064: Delta=0.0/-0.46920776 (History size=0)
  110. Up at 395.04413/242.58064 (History size=0)
Add Comment
Please, Sign In to add comment