private float downX[] = new float[5];
private float downY[] = new float[5];
private float upX[] = new float[5];
private float upY[] = new float[5];
private float mathDownX[] = new float[4];
private float mathDownY[] = new float[4];
private float mathUpX[] = new float[4];
private float mathUpY[] = new float[4];
private int mPointCount;
@Override
public boolean onTouchEvent(MotionEvent event) {
mPointCount = event.getPointerCount();
int action = event.getAction() & MotionEvent.ACTION_MASK;
switch (action) {
case MotionEvent.ACTION_POINTER_DOWN:
if (mPointCount == 3) {
for (int i = 0; i < mPointCount; i++) {
int pointerIndex = event.getPointerId(i);
if (pointerIndex < 0) {
pointerIndex = 0;
} else if (pointerIndex >= mPointCount) {
pointerIndex = mPointCount - 1;
}
downX[i] = event.getX(pointerIndex);
downY[i] = event.getY(pointerIndex);
}
}
if (mPointCount == 5) {
for (int i = 0; i < mPointCount; i++) {
int pointerIndex = event.getPointerId(i);
if (pointerIndex < 0) {
pointerIndex = 0;
} else if (pointerIndex >= mPointCount) {
pointerIndex = mPointCount - 1;
}
downX[i] = event.getX(pointerIndex);
downY[i] = event.getY(pointerIndex);
}
}
break;
case MotionEvent.ACTION_POINTER_UP:
if (mPointCount == 3) {
for (int i = 0; i < mPointCount; i++) {
int pointerIndex = event.getPointerId(i);
if (pointerIndex < 0) {
pointerIndex = 0;
} else if (pointerIndex >= mPointCount) {
pointerIndex = mPointCount - 1;
}
upX[i] = event.getX(pointerIndex);
upY[i] = event.getY(pointerIndex);
}
}
if (mPointCount == 5) {
for (int i = 0; i < mPointCount; i++) {
int pointerIndex = event.getPointerId(i);
if (pointerIndex < 0) {
pointerIndex = 0;
} else if (pointerIndex >= mPointCount) {
pointerIndex = mPointCount - 1;
}
upX[i] = event.getX(pointerIndex);
upY[i] = event.getY(pointerIndex);
}
}
Log.i(TAG, "onTouchEvent up mPointCount " + mPointCount);
int result = 0;
if (mPointCount == 3) {
for (int i = 0; i < mPointCount; i++) {
float offsetY = upY[i] - downY[i];
if (offsetY > 0) {
result += 1;
}
}
Log.i(TAG, "onTouchEvent 三指下滑 " + result);
if (result >= 3) {
playLauncherVideo();
}
} else if (mPointCount == 5) {
for (int i = 0; i < mPointCount - 1; i++) {
mathDownX[i] = Math.abs(downX[i + 1] - downX[i]);
mathDownY[i] = Math.abs(downY[i + 1] - downY[i]);
mathUpX[i] = Math.abs(upX[i + 1] - upX[i]);
mathUpY[i] = Math.abs(upY[i + 1] - upY[i]);
if (mathUpX[i] - mathDownX[i] < 0 || mathUpY[i] - mathDownY[i] < 0) {
result += 1;
}
}
Log.i(TAG, "onTouchEvent 五指捏 " + result);
if (result >= 4) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.tinnove.facerecognition", "com.tinnove.facerecognition.BlackScreenActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
break;
}
return super.onTouchEvent(event);
}