Search in sources :

Example 1 with PointerTracker

use of com.android.inputmethod.keyboard.PointerTracker in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class NonDistinctMultitouchHelper method processMotionEvent.

public void processMotionEvent(final MotionEvent me, final KeyDetector keyDetector) {
    final int pointerCount = me.getPointerCount();
    final int oldPointerCount = mOldPointerCount;
    mOldPointerCount = pointerCount;
    // in multi-touch events.
    if (pointerCount > 1 && oldPointerCount > 1) {
        return;
    }
    // Use only main pointer tracker.
    final PointerTracker mainTracker = PointerTracker.getPointerTracker(MAIN_POINTER_TRACKER_ID);
    final int action = me.getActionMasked();
    final int index = me.getActionIndex();
    final long eventTime = me.getEventTime();
    final long downTime = me.getDownTime();
    // In single-touch.
    if (oldPointerCount == 1 && pointerCount == 1) {
        if (me.getPointerId(index) == mainTracker.mPointerId) {
            mainTracker.processMotionEvent(me, keyDetector);
            return;
        }
        // Inject a copied event.
        injectMotionEvent(action, me.getX(index), me.getY(index), downTime, eventTime, mainTracker, keyDetector);
        return;
    }
    // Single-touch to multi-touch transition.
    if (oldPointerCount == 1 && pointerCount == 2) {
        // Send an up event for the last pointer, be cause we can't trust the coordinates of
        // this multi-touch event.
        mainTracker.getLastCoordinates(mLastCoords);
        final int x = CoordinateUtils.x(mLastCoords);
        final int y = CoordinateUtils.y(mLastCoords);
        mOldKey = mainTracker.getKeyOn(x, y);
        // Inject an artifact up event for the old key.
        injectMotionEvent(MotionEvent.ACTION_UP, x, y, downTime, eventTime, mainTracker, keyDetector);
        return;
    }
    // Multi-touch to single-touch transition.
    if (oldPointerCount == 2 && pointerCount == 1) {
        // Send a down event for the latest pointer if the key is different from the previous
        // key.
        final int x = (int) me.getX(index);
        final int y = (int) me.getY(index);
        final Key newKey = mainTracker.getKeyOn(x, y);
        if (mOldKey != newKey) {
            // Inject an artifact down event for the new key.
            // An artifact up event for the new key will usually be injected as a single-touch.
            injectMotionEvent(MotionEvent.ACTION_DOWN, x, y, downTime, eventTime, mainTracker, keyDetector);
            if (action == MotionEvent.ACTION_UP) {
                // Inject an artifact up event for the new key also.
                injectMotionEvent(MotionEvent.ACTION_UP, x, y, downTime, eventTime, mainTracker, keyDetector);
            }
        }
        return;
    }
    Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount + " (previously " + oldPointerCount + ")");
}
Also used : PointerTracker(com.android.inputmethod.keyboard.PointerTracker) Key(com.android.inputmethod.keyboard.Key)

Example 2 with PointerTracker

use of com.android.inputmethod.keyboard.PointerTracker in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class TimerHandler method handleMessage.

@Override
public void handleMessage(final Message msg) {
    final DrawingProxy drawingProxy = getOwnerInstance();
    if (drawingProxy == null) {
        return;
    }
    switch(msg.what) {
        case MSG_TYPING_STATE_EXPIRED:
            drawingProxy.startWhileTypingAnimation(DrawingProxy.FADE_IN);
            break;
        case MSG_REPEAT_KEY:
            final PointerTracker tracker1 = (PointerTracker) msg.obj;
            tracker1.onKeyRepeat(msg.arg1, /* code */
            msg.arg2);
            break;
        case MSG_LONGPRESS_KEY:
        case MSG_LONGPRESS_SHIFT_KEY:
            cancelLongPressTimers();
            final PointerTracker tracker2 = (PointerTracker) msg.obj;
            tracker2.onLongPressed();
            break;
        case MSG_UPDATE_BATCH_INPUT:
            final PointerTracker tracker3 = (PointerTracker) msg.obj;
            tracker3.updateBatchInputByTimer(SystemClock.uptimeMillis());
            startUpdateBatchInputTimer(tracker3);
            break;
        case MSG_DISMISS_KEY_PREVIEW:
            drawingProxy.onKeyReleased((Key) msg.obj, false);
            break;
        case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
            drawingProxy.dismissGestureFloatingPreviewTextWithoutDelay();
            break;
    }
}
Also used : PointerTracker(com.android.inputmethod.keyboard.PointerTracker)

Example 3 with PointerTracker

use of com.android.inputmethod.keyboard.PointerTracker in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class MainKeyboardAccessibilityDelegate method performLongClickOn.

@Override
public void performLongClickOn(final Key key) {
    if (DEBUG_HOVER) {
        Log.d(TAG, "performLongClickOn: key=" + key);
    }
    final PointerTracker tracker = PointerTracker.getPointerTracker(HOVER_EVENT_POINTER_ID);
    final long eventTime = SystemClock.uptimeMillis();
    final int x = key.getHitBox().centerX();
    final int y = key.getHitBox().centerY();
    final MotionEvent downEvent = MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0);
    // Inject a fake down event to {@link PointerTracker} to handle a long press correctly.
    tracker.processMotionEvent(downEvent, mKeyDetector);
    downEvent.recycle();
    // Invoke {@link PointerTracker#onLongPressed()} as if a long press timeout has passed.
    tracker.onLongPressed();
    // {@link PointerTracker} is in operation or not.
    if (tracker.isInOperation()) {
        // This long press shows a more keys keyboard and further hover events should be
        // handled.
        mBoundsToIgnoreHoverEvent.setEmpty();
        return;
    }
    // This long press has handled at {@link MainKeyboardView#onLongPress(PointerTracker)}.
    // We should ignore further hover events on this key.
    mBoundsToIgnoreHoverEvent.set(key.getHitBox());
    if (key.hasNoPanelAutoMoreKey()) {
        // This long press has registered a code point without showing a more keys keyboard.
        // We should talk back the code point if possible.
        final int codePointOfNoPanelAutoMoreKey = key.getMoreKeys()[0].mCode;
        final String text = KeyCodeDescriptionMapper.getInstance().getDescriptionForCodePoint(mKeyboardView.getContext(), codePointOfNoPanelAutoMoreKey);
        if (text != null) {
            sendWindowStateChanged(text);
        }
    }
}
Also used : PointerTracker(com.android.inputmethod.keyboard.PointerTracker) MotionEvent(android.view.MotionEvent)

Aggregations

PointerTracker (com.android.inputmethod.keyboard.PointerTracker)3 MotionEvent (android.view.MotionEvent)1 Key (com.android.inputmethod.keyboard.Key)1