1

我有一个输入服务和视图。我需要为 ExplorationByTouch 覆盖一些手势:例如:我想关闭双击。这是代码的一部分,我想在其中执行此操作。知道怎么做吗?

@Override
    public boolean onTouchEvent(MotionEvent e) {
        final int action = e.getAction();

        switch (getActionMasked(action)) {

        case MotionEvent.ACTION_DOWN: { // Processing the first touch
            // Index of the first pointer always equals to 0
            final int firstIndex = 0;
            final int identifier = e.getPointerId(firstIndex);

            setPressed(true);
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
            Log.d("Pressed", "Press first finger");

            final Stroke firstStroke = Stroke.newInstance("first");
            strokes.put(identifier, firstStroke);
            firstStroke.append(Point.valueOf(e.getX(), e.getY()));

            anotherHandScheme.onFingerTouch();
            mainHandScheme.onFingerTouch();
            break;
        }

        case MotionEvent.ACTION_POINTER_DOWN: { // Processing of the second touch
            final int index = getActionIndex(action);
            final int identifier = e.getPointerId(index);

            // We ignore the third and the following touches
            if (identifier > 1)
                break;

            setPressed(true);
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);

            final Stroke secondStroke = Stroke.newInstance("second");
            strokes.put(identifier, secondStroke);
            secondStroke.append(Point.valueOf(e.getX(index), e.getY(index)));

            anotherHandScheme.onFingerTouch();
            mainHandScheme.onFingerTouch();
            break;
        }

        case MotionEvent.ACTION_MOVE: {
            final Set<Integer> identifiers = strokes.keySet();
            for (Integer id : identifiers) {
                final int index = e.findPointerIndex(id);
                final Point newPoint = Point.valueOf(e.getX(index), e.getY(index));

                if (!newPoint.equals(strokes.get(id).lastPoint()))
                    strokes.get(id).append(newPoint);
            }

            anotherHandScheme.onFingerMove();
            mainHandScheme.onFingerMove();
            break;
        }

        case MotionEvent.ACTION_POINTER_UP: { // Processing of the second touch
            final int index = getActionIndex(action);
            strokes.remove(e.getPointerId(index));

            anotherHandScheme.onFingerGone();
            mainHandScheme.onFingerGone();
            setPressed(false);
            break;
        }

        case MotionEvent.ACTION_UP:
            // All fingers leave the screen surface
            strokes.clear();
            anotherHandScheme.onFingerGone();
            mainHandScheme.onFingerGone();
            setPressed(false);
            break;
        }

        return true;
    }
4

0 回答 0