diff options
| author | Clara Bayarri <clarabayarri@google.com> | 2015-03-31 13:41:56 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-31 13:41:58 +0000 |
| commit | 3af4330c5371f20ac5a378e6abe6bf1c356b0a06 (patch) | |
| tree | 30beb30d6aeeb20be228d6e9915312df25d25887 | |
| parent | f6967e686b8eba2719cff21485194b0156e4415b (diff) | |
| parent | ea4f150c38853c8b03e7e459a1b39bce13eee4be (diff) | |
| download | frameworks_base-3af4330c5371f20ac5a378e6abe6bf1c356b0a06.zip frameworks_base-3af4330c5371f20ac5a378e6abe6bf1c356b0a06.tar.gz frameworks_base-3af4330c5371f20ac5a378e6abe6bf1c356b0a06.tar.bz2 | |
Merge "Editor: Provide the selection content rect to ActionMode.Callback2"
| -rw-r--r-- | core/java/android/widget/Editor.java | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index f753b51..82e36c3 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -2939,7 +2939,24 @@ public class Editor { * The default callback provides a subset of Select All, Cut, Copy and Paste actions, depending * on which of these this TextView supports. */ - private class SelectionActionModeCallback implements ActionMode.Callback { + private class SelectionActionModeCallback extends ActionMode.Callback2 { + private final Path mSelectionPath = new Path(); + private final RectF mSelectionBounds = new RectF(); + + private int mSelectionHandleHeight; + private int mInsertionHandleHeight; + + public SelectionActionModeCallback() { + SelectionModifierCursorController selectionController = getSelectionController(); + if (selectionController.mStartHandle == null) { + selectionController.initDrawables(); + selectionController.initHandles(); + } + mSelectionHandleHeight = Math.max( + mSelectHandleLeft.getMinimumHeight(), mSelectHandleRight.getMinimumHeight()); + getInsertionController().getHandle(); + mInsertionHandleHeight = mSelectHandleCenter.getMinimumHeight(); + } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { @@ -3057,6 +3074,40 @@ public class Editor { mSelectionActionMode = null; } + + @Override + public void onGetContentRect(ActionMode mode, View view, Rect outRect) { + if (!view.equals(mTextView) || mTextView.getLayout() == null) { + super.onGetContentRect(mode, view, outRect); + return; + } + if (mTextView.getSelectionStart() != mTextView.getSelectionEnd()) { + // We have a selection. + mSelectionPath.reset(); + mTextView.getLayout().getSelectionPath( + mTextView.getSelectionStart(), mTextView.getSelectionEnd(), mSelectionPath); + mSelectionPath.computeBounds(mSelectionBounds, true); + mSelectionBounds.bottom += mSelectionHandleHeight; + } else { + // We have a single cursor. + int line = mTextView.getLayout().getLineForOffset(mTextView.getSelectionStart()); + float primaryHorizontal = + mTextView.getLayout().getPrimaryHorizontal(mTextView.getSelectionStart()); + mSelectionBounds.set( + primaryHorizontal, + mTextView.getLayout().getLineTop(line), + primaryHorizontal + 1, + mTextView.getLayout().getLineTop(line + 1) + mInsertionHandleHeight); + } + // Take TextView's padding and scroll into account. + int textHorizontalOffset = mTextView.viewportToContentHorizontalOffset(); + int textVerticalOffset = mTextView.viewportToContentVerticalOffset(); + outRect.set( + (int) Math.floor(mSelectionBounds.left + textHorizontalOffset), + (int) Math.floor(mSelectionBounds.top + textVerticalOffset), + (int) Math.ceil(mSelectionBounds.right + textHorizontalOffset), + (int) Math.ceil(mSelectionBounds.bottom + textVerticalOffset)); + } } private void onReplace() { |
