看到GitHub上已經不少微信跳一跳的輔助了,可是都須要依賴PC端,昨天想着能不能只利用安卓本地來寫一款輔助,先來看效果:git
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: //按下
Log.d(TAG, "開始位置: " + event.getRawX() + " " + event.getRawY());
mStartX = event.getRawX();
mStartY = event.getRawY();
break;
case MotionEvent.ACTION_UP: //鬆開
Log.d(TAG, "結束位置: " + event.getRawX() + " " + event.getRawY());
float endX = event.getRawX();
float endY = event.getRawY();
//三角形邊長1
float length1 = Math.abs(endX - mStartX);
//三角形邊長2
float length2 = Math.abs(endY - mStartY);
//經過勾股定理計算間距
int distance =
(int) Math.sqrt(Math.pow(length1, 2) + Math.pow(length2, 2));
Log.d(TAG, "距離: " + distance);
int temp = (int) (distance * 1.44); //這裏須要多嘗試幾回 找到最佳時間
exec("input swipe 600 1800 600 1800 " + (temp) + "\n");
break;
}
return true;
}複製代碼