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

Commit 70e96375 authored by Haoyu Zhang's avatar Haoyu Zhang Committed by Android (Google) Code Review
Browse files

Merge "Scribe: Introduce HandwritingSlop"

parents 6a2cd766 3d462b00
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -50529,6 +50529,7 @@ package android.view {
    method public int getScaledDoubleTapSlop();
    method public int getScaledEdgeSlop();
    method public int getScaledFadingEdgeLength();
    method public int getScaledHandwritingSlop();
    method public float getScaledHorizontalScrollFactor();
    method public int getScaledHoverSlop();
    method public int getScaledMaximumDrawingCacheSize();
+14 −13
Original line number Diff line number Diff line
@@ -50,10 +50,10 @@ import java.util.List;
 */
public class HandwritingInitiator {
    /**
     * The touchSlop from {@link ViewConfiguration} used to decide whether a pointer is considered
     * moving or stationary.
     * The maximum amount of distance a stylus touch can wander before it is considered
     * handwriting.
     */
    private final int mTouchSlop;
    private final int mHandwritingSlop;
    /**
     * The timeout used to distinguish tap or long click from handwriting. If the stylus doesn't
     * move before this timeout, it's not considered as handwriting.
@@ -79,7 +79,7 @@ public class HandwritingInitiator {
    @VisibleForTesting
    public HandwritingInitiator(@NonNull ViewConfiguration viewConfiguration,
            @NonNull InputMethodManager inputMethodManager) {
        mTouchSlop = viewConfiguration.getScaledTouchSlop();
        mHandwritingSlop = viewConfiguration.getScaledHandwritingSlop();
        mHandwritingTimeoutInMillis = ViewConfiguration.getLongPressTimeout();
        mImm = inputMethodManager;
    }
@@ -113,7 +113,7 @@ public class HandwritingInitiator {
                mState.mStylusDownCandidateView = new WeakReference<>(
                        findBestCandidateView(mState.mStylusDownX, mState.mStylusDownY));
                mState.mShouldInitHandwriting = true;
                mState.mExceedTouchSlop = false;
                mState.mExceedHandwritingSlop = false;
                break;
            case MotionEvent.ACTION_POINTER_UP:
                final int pointerId = motionEvent.getPointerId(motionEvent.getActionIndex());
@@ -131,7 +131,7 @@ public class HandwritingInitiator {
            case MotionEvent.ACTION_MOVE:
                // Either we've already tried to initiate handwriting, or the ongoing MotionEvent
                // sequence is considered to be tap, long-click or other gestures.
                if (!mState.mShouldInitHandwriting || mState.mExceedTouchSlop) {
                if (!mState.mShouldInitHandwriting || mState.mExceedHandwritingSlop) {
                    return;
                }

@@ -146,7 +146,7 @@ public class HandwritingInitiator {
                final float x = motionEvent.getX(pointerIndex);
                final float y = motionEvent.getY(pointerIndex);
                if (largerThanTouchSlop(x, y, mState.mStylusDownX, mState.mStylusDownY)) {
                    mState.mExceedTouchSlop = true;
                    mState.mExceedHandwritingSlop = true;
                    View candidateView = mState.mStylusDownCandidateView.get();
                    if (candidateView == null || !candidateView.isAttachedToWindow()) {
                        // If there was no candidate view found in the stylus down event, or if that
@@ -233,7 +233,7 @@ public class HandwritingInitiator {
     * next ACTION_DOWN.
     */
    private void tryStartHandwriting() {
        if (!mState.mExceedTouchSlop) {
        if (!mState.mExceedHandwritingSlop) {
            return;
        }
        final View connectedView = getConnectedView();
@@ -421,7 +421,7 @@ public class HandwritingInitiator {
    private boolean largerThanTouchSlop(float x1, float y1, float x2, float y2) {
        float dx = x1 - x2;
        float dy = y1 - y2;
        return dx * dx + dy * dy > mTouchSlop * mTouchSlop;
        return dx * dx + dy * dy > mHandwritingSlop * mHandwritingSlop;
    }

    /** Object that keeps the MotionEvent related states for HandwritingInitiator. */
@@ -440,11 +440,12 @@ public class HandwritingInitiator {
         */
        private boolean mShouldInitHandwriting = false;
        /**
         * Whether the current ongoing stylus MotionEvent sequence already exceeds the touchSlop.
         * It's used for the case where the stylus exceeds touchSlop before the target View built
         * InputConnection.
         * Whether the current ongoing stylus MotionEvent sequence already exceeds the
         * handwriting slop.
         * It's used for the case where the stylus exceeds handwriting slop before the target View
         * built InputConnection.
         */
        private boolean mExceedTouchSlop = false;
        private boolean mExceedHandwritingSlop = false;

        /** The pointer id of the stylus pointer that is being tracked. */
        private int mStylusPointerId = -1;
+15 −0
Original line number Diff line number Diff line
@@ -179,6 +179,9 @@ public class ViewConfiguration {
     */
    private static final int TOUCH_SLOP = 8;

    /** Distance a stylus touch can wander before we think the user is handwriting in dips. */
    private static final int HANDWRITING_SLOP = 4;

    /**
     * Defines the minimum size of the touch target for a scrollbar in dips
     */
@@ -328,6 +331,7 @@ public class ViewConfiguration {
    private final int mMaximumFlingVelocity;
    private final int mScrollbarSize;
    private final int mTouchSlop;
    private final int mHandwritingSlop;
    private final int mMinScalingSpan;
    private final int mHoverSlop;
    private final int mMinScrollbarTouchTarget;
@@ -372,6 +376,7 @@ public class ViewConfiguration {
        mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
        mScrollbarSize = SCROLL_BAR_SIZE;
        mTouchSlop = TOUCH_SLOP;
        mHandwritingSlop = HANDWRITING_SLOP;
        mHoverSlop = TOUCH_SLOP / 2;
        mMinScrollbarTouchTarget = MIN_SCROLLBAR_TOUCH_TARGET;
        mDoubleTapTouchSlop = DOUBLE_TAP_TOUCH_SLOP;
@@ -478,6 +483,8 @@ public class ViewConfiguration {
                com.android.internal.R.bool.config_ui_enableFadingMarquee);
        mTouchSlop = res.getDimensionPixelSize(
                com.android.internal.R.dimen.config_viewConfigurationTouchSlop);
        mHandwritingSlop = res.getDimensionPixelSize(
                com.android.internal.R.dimen.config_viewConfigurationHandwritingSlop);
        mHoverSlop = res.getDimensionPixelSize(
                com.android.internal.R.dimen.config_viewConfigurationHoverSlop);
        mMinScrollbarTouchTarget = res.getDimensionPixelSize(
@@ -746,6 +753,14 @@ public class ViewConfiguration {
        return mTouchSlop;
    }

    /**
     * @return Distance in pixels a stylus touch can wander before we think the user is
     * handwriting.
     */
    public int getScaledHandwritingSlop() {
        return mHandwritingSlop;
    }

    /**
     * @return Distance in pixels a hover can wander while it is still considered "stationary".
     *
+4 −0
Original line number Diff line number Diff line
@@ -2572,6 +2572,10 @@
         movement threshold where scrolling should begin. -->
    <dimen name="config_viewConfigurationTouchSlop">8dp</dimen>

    <!-- Base "handwriting slop" value used by ViewConfiguration as a
     movement threshold where stylus handwriting should begin. -->
    <dimen name="config_viewConfigurationHandwritingSlop">4dp</dimen>

    <!-- Base "hover slop" value used by ViewConfiguration as a
         movement threshold under which hover is considered "stationary". -->
    <dimen name="config_viewConfigurationHoverSlop">4dp</dimen>
+1 −0
Original line number Diff line number Diff line
@@ -491,6 +491,7 @@
  <java-symbol type="dimen" name="config_minScrollbarTouchTarget" />
  <java-symbol type="dimen" name="config_prefDialogWidth" />
  <java-symbol type="dimen" name="config_viewConfigurationTouchSlop" />
  <java-symbol type="dimen" name="config_viewConfigurationHandwritingSlop" />
  <java-symbol type="dimen" name="config_viewConfigurationHoverSlop" />
  <java-symbol type="dimen" name="config_ambiguousGestureMultiplier" />
  <java-symbol type="dimen" name="config_viewMinFlingVelocity" />
Loading