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

Commit aab49b40 authored by Gilles Debunne's avatar Gilles Debunne Committed by Android (Google) Code Review
Browse files

Merge "Text selection on phone"

parents 680e0a47 ed674181
Loading
Loading
Loading
Loading
+24 −8
Original line number Diff line number Diff line
@@ -8738,11 +8738,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            return false;
        }

        if (!hasSelection()) {
            // There may already be a selection on device rotation
            boolean currentWordSelected = selectCurrentWord();
            if (!currentWordSelected) {
                // No word found under cursor or text selection not permitted.
                return false;
            }
        }

        ActionMode.Callback actionModeCallback = new SelectionActionModeCallback();
        mSelectionActionMode = startActionMode(actionModeCallback);
@@ -9057,6 +9060,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        private int mContainerPositionX, mContainerPositionY;
        // Visible or not (scrolled off screen), whether or not this handle should be visible
        private boolean mIsActive = false;
        // Used to detect that setFrame was called
        private boolean mNeedsUpdate = true;

        public HandleView() {
            super(TextView.this.mContext);
@@ -9074,6 +9079,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            mIdealVerticalOffset = 0.7f * handleHeight;
        }

        @Override
        protected boolean setFrame(int left, int top, int right, int bottom) {
            boolean changed = super.setFrame(left, top, right, bottom);
            // onPreDraw is called for PhoneWindow before the layout of this view is
            // performed. Make sure to update position, even if container didn't move.
            if (changed) mNeedsUpdate  = true;
            return changed;
        }

        protected abstract void initDrawable();

        // Touch-up filter: number of previous positions remembered
@@ -9222,7 +9236,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            mPositionY += viewportToContentVerticalOffset();
        }

        protected boolean updateContainerPosition() {
        private void checkForContainerPositionChange() {
            positionAtCursorOffset(getCurrentCursorOffset());

            final int previousContainerPositionX = mContainerPositionX;
@@ -9232,12 +9246,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            mContainerPositionX = mTempCoords[0] + mPositionX;
            mContainerPositionY = mTempCoords[1] + mPositionY;

            return (previousContainerPositionX != mContainerPositionX ||
                    previousContainerPositionY != mContainerPositionY);
            mNeedsUpdate |= previousContainerPositionX != mContainerPositionX;
            mNeedsUpdate |= previousContainerPositionY != mContainerPositionY;
        }

        public boolean onPreDraw() {
            if (updateContainerPosition()) {
            checkForContainerPositionChange();
            if (mNeedsUpdate) {
                if (mIsDragging) {
                    if (mTempCoords[0] != mLastParentX || mTempCoords[1] != mLastParentY) {
                        mTouchToWindowOffsetX += mTempCoords[0] - mLastParentX;
@@ -9261,6 +9276,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                        dismiss();
                    }
                }
                mNeedsUpdate = false;
            }
            return true;
        }