Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d60f4942 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Make DrawingProxy and TimerProxy as a top-level interface"

parents 933920fe 34a9e2ae
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ import android.view.ViewGroup;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.MainKeyboardAccessibilityDelegate;
import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.internal.DrawingPreviewPlacerView;
import com.android.inputmethod.keyboard.internal.DrawingProxy;
import com.android.inputmethod.keyboard.internal.GestureFloatingTextDrawingPreview;
import com.android.inputmethod.keyboard.internal.GestureTrailsDrawingPreview;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
@@ -110,7 +110,7 @@ import javax.annotation.Nullable;
 * @attr ref R.styleable#MainKeyboardView_gestureRecognitionSpeedThreshold
 * @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration
 */
public final class MainKeyboardView extends KeyboardView implements PointerTracker.DrawingProxy,
public final class MainKeyboardView extends KeyboardView implements DrawingProxy,
        MoreKeysPanel.Controller {
    private static final String TAG = MainKeyboardView.class.getSimpleName();

+5 −63
Original line number Diff line number Diff line
@@ -25,11 +25,13 @@ import android.view.MotionEvent;
import com.android.inputmethod.keyboard.internal.BatchInputArbiter;
import com.android.inputmethod.keyboard.internal.BatchInputArbiter.BatchInputArbiterListener;
import com.android.inputmethod.keyboard.internal.BogusMoveEventDetector;
import com.android.inputmethod.keyboard.internal.DrawingProxy;
import com.android.inputmethod.keyboard.internal.GestureEnabler;
import com.android.inputmethod.keyboard.internal.GestureStrokeDrawingParams;
import com.android.inputmethod.keyboard.internal.GestureStrokeDrawingPoints;
import com.android.inputmethod.keyboard.internal.GestureStrokeRecognitionParams;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.keyboard.internal.TimerProxy;
import com.android.inputmethod.keyboard.internal.TypingTimeRecorder;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.common.Constants;
@@ -52,66 +54,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
    private static final boolean DEBUG_LISTENER = false;
    private static boolean DEBUG_MODE = DebugFlags.DEBUG_ENABLED || DEBUG_EVENT;

    public interface DrawingProxy {
        public void invalidateKey(@Nullable Key key);
        public void showKeyPreview(@Nonnull Key key);
        public void dismissKeyPreview(@Nonnull Key key);
        public void dismissKeyPreviewWithoutDelay(@Nonnull Key key);
        public void onLongPress(@Nonnull PointerTracker tracker);
        public static final int FADE_IN = 0;
        public static final int FADE_OUT = 1;
        public void startWhileTypingAnimation(final int fadeInOrOut);
        public void showSlidingKeyInputPreview(@Nullable PointerTracker tracker);
        public void showGestureTrail(@Nonnull PointerTracker tracker,
                boolean showsFloatingPreviewText);
        public void dismissGestureFloatingPreviewTextWithoutDelay();
    }

    public interface TimerProxy {
        public void startTypingStateTimer(Key typedKey);
        public boolean isTypingState();
        public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay);
        public void startLongPressTimerOf(PointerTracker tracker, int delay);
        public void cancelLongPressTimerOf(PointerTracker tracker);
        public void cancelLongPressShiftKeyTimers();
        public void cancelKeyTimersOf(PointerTracker tracker);
        public void startDoubleTapShiftKeyTimer();
        public void cancelDoubleTapShiftKeyTimer();
        public boolean isInDoubleTapShiftKeyTimeout();
        public void startUpdateBatchInputTimer(PointerTracker tracker);
        public void cancelUpdateBatchInputTimer(PointerTracker tracker);
        public void cancelAllUpdateBatchInputTimers();

        public static class Adapter implements TimerProxy {
            @Override
            public void startTypingStateTimer(Key typedKey) {}
            @Override
            public boolean isTypingState() { return false; }
            @Override
            public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay) {}
            @Override
            public void startLongPressTimerOf(PointerTracker tracker, int delay) {}
            @Override
            public void cancelLongPressTimerOf(PointerTracker tracker) {}
            @Override
            public void cancelLongPressShiftKeyTimers() {}
            @Override
            public void cancelKeyTimersOf(PointerTracker tracker) {}
            @Override
            public void startDoubleTapShiftKeyTimer() {}
            @Override
            public void cancelDoubleTapShiftKeyTimer() {}
            @Override
            public boolean isInDoubleTapShiftKeyTimeout() { return false; }
            @Override
            public void startUpdateBatchInputTimer(PointerTracker tracker) {}
            @Override
            public void cancelUpdateBatchInputTimer(PointerTracker tracker) {}
            @Override
            public void cancelAllUpdateBatchInputTimers() {}
        }
    }

    static final class PointerTrackerParams {
        public final boolean mKeySelectionByDraggingFinger;
        public final int mTouchNoiseThresholdTime;
@@ -586,7 +528,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
        }
        sListener.onStartBatchInput();
        dismissAllMoreKeysPanels();
        sTimerProxy.cancelLongPressTimerOf(this);
        sTimerProxy.cancelLongPressTimersOf(this);
    }

    private void showGestureTrail() {
@@ -1094,7 +1036,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
    }

    public void cancelLongPressTimer() {
        sTimerProxy.cancelLongPressTimerOf(this);
        sTimerProxy.cancelLongPressTimersOf(this);
    }

    public void onLongPressed() {
@@ -1163,7 +1105,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
    private void startLongPressTimer(final Key key) {
        // Note that we need to cancel all active long press shift key timers if any whenever we
        // start a new long press timer for both non-shift and shift keys.
        sTimerProxy.cancelLongPressShiftKeyTimers();
        sTimerProxy.cancelLongPressShiftKeyTimer();
        if (sInGesture) return;
        if (key == null) return;
        if (!key.isLongPressEnabled()) return;
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.keyboard.internal;

import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.PointerTracker;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public interface DrawingProxy {
    // TODO: Remove this method.
    public void invalidateKey(@Nullable Key key);

    // TODO: Rename this method to onKeyPressed.
    public void showKeyPreview(@Nonnull Key key);

    // TODO: Rename this method to onKeyReleased.
    public void dismissKeyPreview(@Nonnull Key key);

    /**
     * Dismiss a key preview visual without delay.
     * @param key the key whose preview visual should be dismissed.
     */
    public void dismissKeyPreviewWithoutDelay(@Nonnull Key key);

    // TODO: Rename this method to onKeyLongPressed.
    public void onLongPress(@Nonnull PointerTracker tracker);

    /**
     * Start a while-typing-animation.
     * @param fadeInOrOut {@link #FADE_IN} starts while-typing-fade-in animation.
     * {@link #FADE_OUT} starts while-typing-fade-out animation.
     */
    public void startWhileTypingAnimation(int fadeInOrOut);
    public static final int FADE_IN = 0;
    public static final int FADE_OUT = 1;

    /**
     * Show sliding-key input preview.
     * @param tracker the {@link PointerTracker} that is currently doing the sliding-key input.
     * null to dismiss the sliding-key input preview.
     */
    public void showSlidingKeyInputPreview(@Nullable PointerTracker tracker);

    /**
     * Show gesture trails.
     * @param tracker the {@link PointerTracker} whose gesture trail will be shown.
     * @param showsFloatingPreviewText when true, a gesture floating preview text will be shown
     * with this <code>tracker</code>'s trail.
     */
    public void showGestureTrail(@Nonnull PointerTracker tracker, boolean showsFloatingPreviewText);

    /**
     * Dismiss a gesture floating preview text without delay.
     */
    public void dismissGestureFloatingPreviewTextWithoutDelay();
}
+9 −11
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ import android.view.ViewConfiguration;

import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;

@@ -86,7 +84,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
    }

    @Override
    public void startKeyRepeatTimerOf(final PointerTracker tracker, final int repeatCount,
    public void startKeyRepeatTimerOf(@Nonnull final PointerTracker tracker, final int repeatCount,
            final int delay) {
        final Key key = tracker.getKey();
        if (key == null || delay == 0) {
@@ -110,7 +108,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
    }

    @Override
    public void startLongPressTimerOf(final PointerTracker tracker, final int delay) {
    public void startLongPressTimerOf(@Nonnull final PointerTracker tracker, final int delay) {
        final Key key = tracker.getKey();
        if (key == null) {
            return;
@@ -123,13 +121,13 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
    }

    @Override
    public void cancelLongPressTimerOf(final PointerTracker tracker) {
    public void cancelLongPressTimersOf(@Nonnull final PointerTracker tracker) {
        removeMessages(MSG_LONGPRESS_KEY, tracker);
        removeMessages(MSG_LONGPRESS_SHIFT_KEY, tracker);
    }

    @Override
    public void cancelLongPressShiftKeyTimers() {
    public void cancelLongPressShiftKeyTimer() {
        removeMessages(MSG_LONGPRESS_SHIFT_KEY);
    }

@@ -139,7 +137,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
    }

    @Override
    public void startTypingStateTimer(final Key typedKey) {
    public void startTypingStateTimer(@Nonnull final Key typedKey) {
        if (typedKey.isModifier() || typedKey.altCodeWhileTyping()) {
            return;
        }
@@ -190,9 +188,9 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
    }

    @Override
    public void cancelKeyTimersOf(final PointerTracker tracker) {
    public void cancelKeyTimersOf(@Nonnull final PointerTracker tracker) {
        cancelKeyRepeatTimerOf(tracker);
        cancelLongPressTimerOf(tracker);
        cancelLongPressTimersOf(tracker);
    }

    public void cancelAllKeyTimers() {
@@ -201,7 +199,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
    }

    @Override
    public void startUpdateBatchInputTimer(final PointerTracker tracker) {
    public void startUpdateBatchInputTimer(@Nonnull final PointerTracker tracker) {
        if (mGestureRecognitionUpdateTime <= 0) {
            return;
        }
@@ -211,7 +209,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
    }

    @Override
    public void cancelUpdateBatchInputTimer(final PointerTracker tracker) {
    public void cancelUpdateBatchInputTimer(@Nonnull final PointerTracker tracker) {
        removeMessages(MSG_UPDATE_BATCH_INPUT, tracker);
    }

+133 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.keyboard.internal;

import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.PointerTracker;

import javax.annotation.Nonnull;

public interface TimerProxy {
    /**
     * Start a timer to detect if a user is typing keys.
     * @param typedKey the key that is typed.
     */
    public void startTypingStateTimer(@Nonnull Key typedKey);

    /**
     * Check if a user is key typing.
     * @return true if a user is in typing.
     */
    public boolean isTypingState();

    /**
     * Start a timer to simulate repeated key presses while a user keep pressing a key.
     * @param tracker the {@link PointerTracker} that points the key to be repeated.
     * @param repeatCount the number of times that the key is repeating. Starting from 1.
     * @param delay the interval delay to the next key repeat, in millisecond.
     */
    public void startKeyRepeatTimerOf(@Nonnull PointerTracker tracker, int repeatCount, int delay);

    /**
     * Start a timer to detect a long pressed key.
     * If a key pointed by <code>tracker</code> is a shift key, start another timer to detect
     * long pressed shift key.
     * @param tracker the {@link PointerTracker} that starts long pressing.
     * @param delay the delay to fire the long press timer, in millisecond.
     */
    public void startLongPressTimerOf(@Nonnull PointerTracker tracker, int delay);

    /**
     * Cancel timers for detecting a long pressed key and a long press shift key.
     * @param tracker cancel long press timers of this {@link PointerTracker}.
     */
    public void cancelLongPressTimersOf(@Nonnull PointerTracker tracker);

    /**
     * Cancel a timer for detecting a long pressed shift key.
     */
    public void cancelLongPressShiftKeyTimer();

    /**
     * Cancel timers for detecting repeated key press, long pressed key, and long pressed shift key.
     * @param tracker the {@link PointerTracker} that starts timers to be canceled.
     */
    public void cancelKeyTimersOf(@Nonnull PointerTracker tracker);

    /**
     * Start a timer to detect double tapped shift key.
     */
    public void startDoubleTapShiftKeyTimer();

    /**
     * Cancel a timer of detecting double tapped shift key.
     */
    public void cancelDoubleTapShiftKeyTimer();

    /**
     * Check if a timer of detecting double tapped shift key is running.
     * @return true if detecting double tapped shift key is on going.
     */
    public boolean isInDoubleTapShiftKeyTimeout();

    /**
     * Start a timer to fire updating batch input while <code>tracker</code> is on hold.
     * @param tracker the {@link PointerTracker} that stops moving.
     */
    public void startUpdateBatchInputTimer(@Nonnull PointerTracker tracker);

    /**
     * Cancel a timer of firing updating batch input.
     * @param tracker the {@link PointerTracker} that resumes moving or ends gesture input.
     */
    public void cancelUpdateBatchInputTimer(@Nonnull PointerTracker tracker);

    /**
     * Cancel all timers of firing updating batch input.
     */
    public void cancelAllUpdateBatchInputTimers();

    public static class Adapter implements TimerProxy {
        @Override
        public void startTypingStateTimer(@Nonnull Key typedKey) {}
        @Override
        public boolean isTypingState() { return false; }
        @Override
        public void startKeyRepeatTimerOf(@Nonnull PointerTracker tracker, int repeatCount,
                int delay) {}
        @Override
        public void startLongPressTimerOf(@Nonnull PointerTracker tracker, int delay) {}
        @Override
        public void cancelLongPressTimersOf(@Nonnull PointerTracker tracker) {}
        @Override
        public void cancelLongPressShiftKeyTimer() {}
        @Override
        public void cancelKeyTimersOf(@Nonnull PointerTracker tracker) {}
        @Override
        public void startDoubleTapShiftKeyTimer() {}
        @Override
        public void cancelDoubleTapShiftKeyTimer() {}
        @Override
        public boolean isInDoubleTapShiftKeyTimeout() { return false; }
        @Override
        public void startUpdateBatchInputTimer(@Nonnull PointerTracker tracker) {}
        @Override
        public void cancelUpdateBatchInputTimer(@Nonnull PointerTracker tracker) {}
        @Override
        public void cancelAllUpdateBatchInputTimers() {}
    }
}