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

Commit 37598210 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Move PointerTracker.DrawingProxy to MainKeyboardView (step 2)

Change-Id: If15d5ee683b8026d1871a3fe438dba498944faa7
parent 0e4f0da4
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -51,8 +51,6 @@
        <!-- Blur radius of key text shadow. -->
        <attr name="keyTextShadowRadius" format="float" />

        <!-- Layout resource for key press feedback.-->
        <attr name="keyPreviewLayout" format="reference" />
        <!-- Key preview background states -->
        <attr name="state_left_edge" format="boolean" />
        <attr name="state_right_edge" format="boolean" />
@@ -71,8 +69,6 @@
        <attr name="gestureFloatingPreviewHorizontalPadding" format="dimension" />
        <attr name="gestureFloatingPreviewVerticalPadding" format="dimension" />
        <attr name="gestureFloatingPreviewRoundRadius" format="dimension" />
        <!-- Delay after gesture input and gesture floating preview text dismissing in millisecond -->
        <attr name="gestureFloatingPreviewTextLingerTimeout" format="integer" />
        <!-- Delay after gesture trail starts fading out in millisecond. -->
        <attr name="gesturePreviewTrailFadeoutStartDelay" format="integer" />
        <!-- Duration while gesture preview trail is fading out in millisecond. -->
@@ -117,6 +113,8 @@
        <attr name="longPressShiftKeyTimeout" format="integer" />
        <!-- Ignore special key timeout while typing in millisecond. -->
        <attr name="ignoreAltCodeKeyTimeout" format="integer" />
        <!-- Layout resource for key press feedback.-->
        <attr name="keyPreviewLayout" format="reference" />
        <!-- Vertical offset of the key press feedback from the key. -->
        <attr name="keyPreviewOffset" format="dimension" />
        <!-- Height of the key press feedback popup. -->
@@ -127,6 +125,8 @@
        <attr name="moreKeysKeyboardLayout" format="reference" />
        <!-- More keys keyboard will shown at touched point. -->
        <attr name="showMoreKeysKeyboardAtTouchedPoint" format="boolean" />
        <!-- Delay after gesture input and gesture floating preview text dismissing in millisecond -->
        <attr name="gestureFloatingPreviewTextLingerTimeout" format="integer" />
        <!-- Static threshold for gesture after fast typing (msec) -->
        <attr name="gestureStaticTimeThresholdAfterFastTyping" format="integer" />
        <!-- Static threshold for starting gesture detection (keyWidth%/sec) -->
+2 −2
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@
        <item name="keyHintLetterPadding">@dimen/key_hint_letter_padding</item>
        <item name="keyPopupHintLetterPadding">@dimen/key_popup_hint_letter_padding</item>
        <item name="keyShiftedLetterHintPadding">@dimen/key_uppercase_letter_padding</item>
        <item name="keyPreviewLayout">@layout/key_preview</item>
        <item name="keyPreviewTextColor">@color/key_text_color_default</item>
        <item name="keyPreviewTextRatio">@fraction/key_preview_text_ratio</item>
        <item name="verticalCorrection">@dimen/keyboard_vertical_correction</item>
@@ -67,7 +66,6 @@
        <item name="gestureFloatingPreviewHorizontalPadding">@dimen/gesture_floating_preview_horizontal_padding</item>
        <item name="gestureFloatingPreviewVerticalPadding">@dimen/gesture_floating_preview_vertical_padding</item>
        <item name="gestureFloatingPreviewRoundRadius">@dimen/gesture_floating_preview_round_radius</item>
        <item name="gestureFloatingPreviewTextLingerTimeout">@integer/config_gesture_floating_preview_text_linger_timeout</item>
        <item name="gesturePreviewTrailFadeoutStartDelay">@integer/config_gesture_preview_trail_fadeout_start_delay</item>
        <item name="gesturePreviewTrailFadeoutDuration">@integer/config_gesture_preview_trail_fadeout_duration</item>
        <item name="gesturePreviewTrailUpdateInterval">@integer/config_gesture_preview_trail_update_interval</item>
@@ -85,6 +83,7 @@
        <item name="longPressKeyTimeout">@integer/config_long_press_key_timeout</item>
        <item name="longPressShiftKeyTimeout">@integer/config_long_press_shift_key_timeout</item>
        <item name="ignoreAltCodeKeyTimeout">@integer/config_ignore_alt_code_key_timeout</item>
        <item name="keyPreviewLayout">@layout/key_preview</item>
        <item name="keyPreviewOffset">@dimen/key_preview_offset</item>
        <item name="keyPreviewHeight">@dimen/key_preview_height</item>
        <item name="keyPreviewLingerTimeout">@integer/config_key_preview_linger_timeout</item>
@@ -95,6 +94,7 @@
        <item name="altCodeKeyWhileTypingFadeoutAnimator">@anim/alt_code_key_while_typing_fadeout</item>
        <item name="altCodeKeyWhileTypingFadeinAnimator">@anim/alt_code_key_while_typing_fadein</item>
        <!-- Common attributes of MainKeyboardView for gesture typing detection and recognition -->
        <item name="gestureFloatingPreviewTextLingerTimeout">@integer/config_gesture_floating_preview_text_linger_timeout</item>
        <item name="gestureStaticTimeThresholdAfterFastTyping">@integer/config_gesture_static_time_threshold_after_fast_typing</item>
        <item name="gestureDetectFastMoveSpeedThreshold">@fraction/config_gesture_detect_fast_move_speed_threshold</item>
        <item name="gestureDynamicThresholdDecayDuration">@integer/config_gesture_dynamic_threshold_decay_duration</item>
+0 −193
Original line number Diff line number Diff line
@@ -28,26 +28,16 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Message;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyVisualAttributes;
import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.CoordinateUtils;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.ResearchLogger;

@@ -57,26 +47,12 @@ import java.util.HashSet;
 * A view that renders a virtual {@link Keyboard}.
 *
 * @attr ref R.styleable#KeyboardView_keyBackground
 * @attr ref R.styleable#KeyboardView_keyPreviewLayout
 * @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding
 * @attr ref R.styleable#KeyboardView_keyHintLetterPadding
 * @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding
 * @attr ref R.styleable#KeyboardView_keyShiftedLetterHintPadding
 * @attr ref R.styleable#KeyboardView_keyTextShadowRadius
 * @attr ref R.styleable#KeyboardView_backgroundDimAlpha
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextSize
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextColor
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextOffset
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewColor
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewHorizontalPadding
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewVerticalPadding
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewRoundRadius
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextLingerTimeout
 * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutStartDelay
 * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutDuration
 * @attr ref R.styleable#KeyboardView_gesturePreviewTrailUpdateInterval
 * @attr ref R.styleable#KeyboardView_gesturePreviewTrailColor
 * @attr ref R.styleable#KeyboardView_gesturePreviewTrailWidth
 * @attr ref R.styleable#KeyboardView_verticalCorrection
 * @attr ref R.styleable#Keyboard_Key_keyTypeface
 * @attr ref R.styleable#Keyboard_Key_keyLetterSize
@@ -97,8 +73,6 @@ import java.util.HashSet;
 * @attr ref R.styleable#Keyboard_Key_keyPreviewTextColor
 */
public class KeyboardView extends View {
    private static final String TAG = KeyboardView.class.getSimpleName();

    // XML attributes
    protected final KeyVisualAttributes mKeyVisualAttributes;
    private final int mKeyLabelHorizontalPadding;
@@ -126,20 +100,6 @@ public class KeyboardView extends View {
    private Keyboard mKeyboard;
    protected final KeyDrawParams mKeyDrawParams = new KeyDrawParams();

    // Preview placer view
    // TODO: Move PreviewPlacerView to MainKeyboardView
    protected final PreviewPlacerView mPreviewPlacerView;
    private final int[] mOriginCoords = CoordinateUtils.newInstance();

    // Key preview
    // TODO: Move these variable to MainKeyboardView
    protected final int mKeyPreviewLayoutId;
    protected final SparseArray<TextView> mKeyPreviewTexts = CollectionUtils.newSparseArray();

    // Gesture floating preview text
    // TODO: Make this parameter customizable by user via settings.
    private int mGestureFloatingPreviewTextLingerTimeout;

    // Drawing
    /** True if the entire keyboard needs to be dimmed. */
    private boolean mNeedsToDimEntireKeyboard;
@@ -164,56 +124,6 @@ public class KeyboardView extends View {
    private static final char[] KEY_LABEL_REFERENCE_CHAR = { 'M' };
    private static final char[] KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR = { '8' };

    // TODO: Move this to MainKeyboardView
    protected final DrawingHandler mDrawingHandler = new DrawingHandler(this);

    public static class DrawingHandler extends StaticInnerHandlerWrapper<KeyboardView> {
        private static final int MSG_DISMISS_KEY_PREVIEW = 0;
        private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;

        public DrawingHandler(final KeyboardView outerInstance) {
            super(outerInstance);
        }

        @Override
        public void handleMessage(final Message msg) {
            final KeyboardView keyboardView = getOuterInstance();
            if (keyboardView == null) return;
            final PointerTracker tracker = (PointerTracker) msg.obj;
            switch (msg.what) {
            case MSG_DISMISS_KEY_PREVIEW:
                final TextView previewText = keyboardView.mKeyPreviewTexts.get(tracker.mPointerId);
                if (previewText != null) {
                    previewText.setVisibility(INVISIBLE);
                }
                break;
            case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
                keyboardView.mPreviewPlacerView.setGestureFloatingPreviewText(SuggestedWords.EMPTY);
                break;
            }
        }

        public void dismissKeyPreview(final long delay, final PointerTracker tracker) {
            sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay);
        }

        public void cancelDismissKeyPreview(final PointerTracker tracker) {
            removeMessages(MSG_DISMISS_KEY_PREVIEW, tracker);
        }

        private void cancelAllDismissKeyPreviews() {
            removeMessages(MSG_DISMISS_KEY_PREVIEW);
        }

        public void dismissGestureFloatingPreviewText(final long delay) {
            sendMessageDelayed(obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT), delay);
        }

        public void cancelAllMessages() {
            cancelAllDismissKeyPreviews();
        }
    }

    public KeyboardView(final Context context, final AttributeSet attrs) {
        this(context, attrs, R.attr.keyboardViewStyle);
    }
@@ -235,14 +145,10 @@ public class KeyboardView extends View {
                R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0);
        mKeyTextShadowRadius = keyboardViewAttr.getFloat(
                R.styleable.KeyboardView_keyTextShadowRadius, 0.0f);
        mKeyPreviewLayoutId = keyboardViewAttr.getResourceId(
                R.styleable.KeyboardView_keyPreviewLayout, 0);
        mVerticalCorrection = keyboardViewAttr.getDimension(
                R.styleable.KeyboardView_verticalCorrection, 0);
        mBackgroundDimAlpha = keyboardViewAttr.getInt(
                R.styleable.KeyboardView_backgroundDimAlpha, 0);
        mGestureFloatingPreviewTextLingerTimeout = keyboardViewAttr.getInt(
                R.styleable.KeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);
        keyboardViewAttr.recycle();

        final TypedArray keyAttr = context.obtainStyledAttributes(attrs,
@@ -250,7 +156,6 @@ public class KeyboardView extends View {
        mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
        keyAttr.recycle();

        mPreviewPlacerView = new PreviewPlacerView(context, attrs);
        mPaint.setAntiAlias(true);
    }

@@ -286,13 +191,6 @@ public class KeyboardView extends View {
        return mKeyboard;
    }

    // TODO: Move this method to MainKeyboardView
    public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail,
            final boolean drawsGestureFloatingPreviewText) {
        mPreviewPlacerView.setGesturePreviewMode(
                drawsGesturePreviewTrail, drawsGestureFloatingPreviewText);
    }

    @Override
    protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
        if (mKeyboard != null) {
@@ -733,94 +631,6 @@ public class KeyboardView extends View {
        return paint;
    }

    public void cancelAllMessages() {
        mDrawingHandler.cancelAllMessages();
    }

    // TODO: Move this method to MainKeyboardView.
    protected TextView getKeyPreviewText(final int pointerId) {
        TextView previewText = mKeyPreviewTexts.get(pointerId);
        if (previewText != null) {
            return previewText;
        }
        final Context context = getContext();
        if (mKeyPreviewLayoutId != 0) {
            previewText = (TextView)LayoutInflater.from(context).inflate(mKeyPreviewLayoutId, null);
        } else {
            previewText = new TextView(context);
        }
        mKeyPreviewTexts.put(pointerId, previewText);
        return previewText;
    }

    // TODO: Move this method to MainKeyboardView.
    private void dismissAllKeyPreviews() {
        final int pointerCount = mKeyPreviewTexts.size();
        for (int id = 0; id < pointerCount; id++) {
            final TextView previewText = mKeyPreviewTexts.get(id);
            if (previewText != null) {
                previewText.setVisibility(INVISIBLE);
            }
        }
        PointerTracker.setReleasedKeyGraphicsToAllKeys();
    }

    // TODO: Move this to MainKeyboardView
    protected void addKeyPreview(final TextView keyPreview) {
        locatePreviewPlacerView();
        mPreviewPlacerView.addView(
                keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacerView, 0, 0));
    }

    // TODO: Move this to MainKeyboardView
    protected void locatePreviewPlacerView() {
        if (mPreviewPlacerView.getParent() != null) {
            return;
        }
        final int width = getWidth();
        final int height = getHeight();
        if (width == 0 || height == 0) {
            // In transient state.
            return;
        }
        getLocationInWindow(mOriginCoords);
        final DisplayMetrics dm = getResources().getDisplayMetrics();
        if (CoordinateUtils.y(mOriginCoords) < dm.heightPixels / 4) {
            // In transient state.
            return;
        }
        final View rootView = getRootView();
        if (rootView == null) {
            Log.w(TAG, "Cannot find root view");
            return;
        }
        final ViewGroup windowContentView = (ViewGroup)rootView.findViewById(android.R.id.content);
        // Note: It'd be very weird if we get null by android.R.id.content.
        if (windowContentView == null) {
            Log.w(TAG, "Cannot find android.R.id.content view to add PreviewPlacerView");
        } else {
            windowContentView.addView(mPreviewPlacerView);
            mPreviewPlacerView.setKeyboardViewGeometry(mOriginCoords, width, height);
        }
    }

    public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
        locatePreviewPlacerView();
        mPreviewPlacerView.setGestureFloatingPreviewText(suggestedWords);
    }

    public void dismissGestureFloatingPreviewText() {
        locatePreviewPlacerView();
        mDrawingHandler.dismissGestureFloatingPreviewText(mGestureFloatingPreviewTextLingerTimeout);
    }

    // TODO: Move This to MainKeyboardView
    public void showGesturePreviewTrail(final PointerTracker tracker,
            final boolean isOldestTracker) {
        locatePreviewPlacerView();
        mPreviewPlacerView.invalidatePointer(tracker, isOldestTracker);
    }

    /**
     * Requests a redraw of the entire keyboard. Calling {@link #invalidate} is not sufficient
     * because the keyboard renders the keys to an off-screen buffer and an invalidate() only
@@ -850,8 +660,6 @@ public class KeyboardView extends View {
    }

    public void closing() {
        dismissAllKeyPreviews();
        cancelAllMessages();
        mInvalidateAllKeys = true;
        mKeyboard = null;
        requestLayout();
@@ -861,7 +669,6 @@ public class KeyboardView extends View {
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        closing();
        mPreviewPlacerView.removeAllViews();
        freeOffscreenBuffer();
    }
}
+169 −7

File changed.

Preview size limit exceeded, changes collapsed.

+9 −0
Original line number Diff line number Diff line
@@ -34,6 +34,14 @@ import com.android.inputmethod.latin.SuggestedWords;
/**
 * The class for single gesture preview text. The class for multiple gesture preview text will be
 * derived from it.
 *
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextSize
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextColor
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextOffset
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewColor
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewHorizontalPadding
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewVerticalPadding
 * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewRoundRadius
 */
public class GestureFloatingPreviewText extends AbstractDrawingPreview {
    private static final class GesturePreviewTextParams {
@@ -50,6 +58,7 @@ public class GestureFloatingPreviewText extends AbstractDrawingPreview {
        private static final char[] TEXT_HEIGHT_REFERENCE_CHAR = { 'M' };

        public GesturePreviewTextParams(final TypedArray keyboardViewAttr) {
            // TODO: Move these XML attributes to MainKeyboardView
            mGesturePreviewTextSize = keyboardViewAttr.getDimensionPixelSize(
                    R.styleable.KeyboardView_gestureFloatingPreviewTextSize, 0);
            mGesturePreviewTextColor = keyboardViewAttr.getColor(
Loading