需要能够捏缩放,但不能在我的触摸监听器中双击

Need to be able to pinch to zoom, but not to do a double Tap in my touch listener

所以我的视图下有一个视图,我需要通过捏合来缩放。但是,如果用户双击,我不想将双击传递给我的第二个视图。因为我需要忽略双击时设置的功能。 唯一的问题是该功能设置为在从触摸侦听器接收到 2 ACTION_DOWN 事件时调用。 现在我试图制定一个逻辑来防止双击工作,但让捏缩放工作,但它仍然不完美。如果我用 2 根手指轻敲屏幕的 1 个位置,然后用另一个手指轻敲另一个位置,再往前一点,它就会变成双击,而不是像我需要的那样消耗 Touch。 这是我的 touchEventListener 的代码:

viewTop.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.i("","double touch event action: ===========================");
            Log.i("","double touch event test action:" + event.getPointerId(0));
            if(event.getPointerId(0) == 0) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if (secondPressed) {
                        Log.i("", "double touch test : FIRST FINGER: CONSUMED TRUE");
                        timeLastTouch = System.currentTimeMillis();
                        return true;
                    }else {
                        Log.i("", "double touch DOWN : " + timeLastTouch + "... time passed: " + (System.currentTimeMillis() - timeLastTouch) + "..... location diff: " + (event.getX() - xLastTouch));
                        Log.i("", "double touch test XLAST : " + xLastTouch + "/" + yLastTouch + "   ... XLAST 2 : " + xLastTouch2 + "/" + yLastTouch2);
                        if (System.currentTimeMillis() - timeLastTouch < 1000 && Math.abs(event.getX() - xLastTouch) < 150 && Math.abs(event.getY() - yLastTouch) < 150) {
                            Log.i("", "double touch test TRUE DOWN");
                            secondPressed = true;
                            timeLastTouch = System.currentTimeMillis();
                            xLastTouch = event.getX();
                            yLastTouch = event.getY();
                            return true;
                        } else if (System.currentTimeMillis() - timeLastTouch < 1000 && Math.abs(event.getX() - xLastTouch2) < 150 && Math.abs(event.getY() - yLastTouch2) < 150) {
                            Log.i("", "double touch test TRUE DOWN");
                            secondPressed = true;
                            timeLastTouch = System.currentTimeMillis();
                            return true;
                        } else {
                            timeLastTouch = System.currentTimeMillis();
                            if(xLastTouch2 == -1) {
                                xLastTouch2 = event.getX();
                                yLastTouch2 = event.getY();
                            }else {
                                xLastTouch = event.getX();
                                yLastTouch = event.getY();
                            }
                            Log.i("", "double touch test FALSE DOWN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! X : " + event.getX() + "/" + event.getY() + ".... TIME: " + (System.currentTimeMillis() - timeLastTouch));
                            Log.i("", "double touch test FALSE DOWN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DIFF LAST TOUCH: " + Math.abs(event.getX() - xLastTouch) + "/" + Math.abs(event.getY() - yLastTouch));
                            Log.i("", "double touch test FALSE DOWN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DIFF LAST TOUCH2: " + Math.abs(event.getX() - xLastTouch2) + "/" + Math.abs(event.getY() - yLastTouch2));
                            return false;
                        }
                    }
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    handlerTouch.removeCallbacksAndMessages(null);
                    Log.i("", "double touch test FALSE UP");
                    timeLastTouch = System.currentTimeMillis();
                    handlerTouch.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            resetTouches();
                            Log.i("", "double touch test : SECOND PRESSED BECOMES FALSE");
                        }
                    }, 300);
                    return true;
                } else {
                    timeLastTouch = System.currentTimeMillis();
                    xLastTouch = event.getX();
                    yLastTouch = event.getY();
                    Log.i("", "double touch ELSE FALSE");
                    return false;
                }
            }else if(event.getPointerId(0) == 1){
                timeLastTouch = System.currentTimeMillis();
                if(event.getAction() == MotionEvent.ACTION_DOWN) {
                    xLastTouch2 = event.getX();
                    yLastTouch2 = event.getY();
                    secondPressed = true;
                    return false;
                }else if(event.getAction() == MotionEvent.ACTION_UP){
                    Log.i("","double touch test : SECONDARY FINGER: SECOND PRESSED BECOMES FALSE");
                    handlerTouch.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            resetTouches();
                            Log.i("", "double touch test : SECOND PRESSED BECOMES FALSE");
                        }
                    }, 300);
                }else {
                    Log.i("","double touch test : SECONDARY FINGER: SECOND PRESSED BECOMES TRUE");
                    secondPressed = true;
                }
                return false;
            }else {
                timeLastTouch = System.currentTimeMillis();
                secondPressed = true;
                return false;
            }
        }
    });

resetTouches 在哪里:

    private void resetTouches() {
    xLastTouch = -1f;
    yLastTouch = -1f;
    xLastTouch2 = -1f;
    yLastTouch2 = -1f;
    secondPressed = false;
}

现在我有点卡住了,不知道要更改什么或如何更改以防止双击工作。是否有任何更改可能更容易实现此功能?我可以改变什么来改进这个?

这是为我做的:

final ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(InCallActivity.this, new ScaleGestureDetector.OnScaleGestureListener() {
        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            Log.i("", "double touch test2 onScaleEnd: " + detector.getScaleFactor());
            app.TouchEvent(0, 1, (int) xFinger1, (int) yFinger1);
            if (xFinger2 != 0) {
                app.TouchEvent(1, 1, (int) xFinger2, (int) yFinger2);
            } else scale(1, (int) (yFinger1));
        }
        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            Log.i("", "double touch test2 onScaleBegin: " + detector.getScaleFactor());
            app.TouchEvent(0, 0, (int) xFinger1, (int) yFinger1);
            if (xFinger2 != 0) {
                app.TouchEvent(1, 0, (int) xFinger2, (int) yFinger2);
            } else app.TouchEvent(1, 0, (int) xFinger1, (int) yFinger1);
            return true;
        }
        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            Log.i("", "double touch test2 zoom ongoing, scale: " + detector.getScaleFactor());
            app.TouchEvent(0, 2, (int) xFinger1, (int) yFinger1);
            if (xFinger2 != 0) {
                app.TouchEvent(1, 2, (int) xFinger2, (int) yFinger2);
            } else {
                scaleValue = detector.getScaleFactor();
                scale(2, (int) (yFinger1));
            }
            return false;
        }
    });
    viewTop.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.i("", "double touch test2 ON TOUCH: " + event.getPointerId(0) + "x/y: " + event.getX() + "/" + event.getY());
            xFinger1 = event.getX(0);
            yFinger1 = event.getY(0);
            try {
                xFinger2 = event.getX(1);
                yFinger2 = event.getY(1);
                mScaleDetector.onTouchEvent(event);
            } catch (Exception e) {
                return logicFor1Finger(event, e);
            }
            return true;
        }
    });