覆盖TalkBack手势

时间:2015-01-13 23:34:42

标签: android view accessibility gestures talkback

我有一个输入服务和视图。我需要覆盖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;
    }

0 个答案:

没有答案