private int getNextCursorOffset(int offset, boolean findAfterGivenOffset) {
final Layout layout = mTextView.getLayout();
if (layout == null) return offset;
- final CharSequence text = mTextView.getText();
- final int nextOffset = layout.getPaint().getTextRunCursor(text, 0, text.length(),
- layout.isRtlCharAt(offset) ? Paint.DIRECTION_RTL : Paint.DIRECTION_LTR,
- offset, findAfterGivenOffset ? Paint.CURSOR_AFTER : Paint.CURSOR_BEFORE);
- return nextOffset == -1 ? offset : nextOffset;
+ return findAfterGivenOffset == layout.isRtlCharAt(offset) ?
+ layout.getOffsetToLeftOf(offset) : layout.getOffsetToRightOf(offset);
}
private long getCharClusterRange(int offset) {
final int textLength = mTextView.getText().length();
if (offset < textLength) {
- return TextUtils.packRangeInLong(offset, getNextCursorOffset(offset, true));
+ final int clusterEndOffset = getNextCursorOffset(offset, true);
+ return TextUtils.packRangeInLong(
+ getNextCursorOffset(clusterEndOffset, false), clusterEndOffset);
}
if (offset - 1 >= 0) {
- return TextUtils.packRangeInLong(getNextCursorOffset(offset, false), offset);
+ final int clusterStartOffset = getNextCursorOffset(offset, false);
+ return TextUtils.packRangeInLong(clusterStartOffset,
+ getNextCursorOffset(clusterStartOffset, true));
}
return TextUtils.packRangeInLong(offset, offset);
}
CharSequence selectedText = mTextView.getTransformedText(start, end);
ClipData data = ClipData.newPlainText(null, selectedText);
DragLocalState localState = new DragLocalState(mTextView, start, end);
- mTextView.startDragAndDrop(data, getTextThumbnailBuilder(selectedText), localState,
+ mTextView.startDragAndDrop(data, getTextThumbnailBuilder(start, end), localState,
View.DRAG_FLAG_GLOBAL);
stopTextActionMode();
if (hasSelectionController()) {
}
}
- private DragShadowBuilder getTextThumbnailBuilder(CharSequence text) {
+ private DragShadowBuilder getTextThumbnailBuilder(int start, int end) {
TextView shadowView = (TextView) View.inflate(mTextView.getContext(),
com.android.internal.R.layout.text_drag_thumbnail, null);
throw new IllegalArgumentException("Unable to inflate text drag thumbnail");
}
- if (text.length() > DRAG_SHADOW_MAX_TEXT_LENGTH) {
- text = text.subSequence(0, DRAG_SHADOW_MAX_TEXT_LENGTH);
+ if (end - start > DRAG_SHADOW_MAX_TEXT_LENGTH) {
+ final long range = getCharClusterRange(start + DRAG_SHADOW_MAX_TEXT_LENGTH);
+ end = TextUtils.unpackRangeEndFromLong(range);
}
+ final CharSequence text = mTextView.getTransformedText(start, end);
shadowView.setText(text);
shadowView.setTextColor(mTextView.getTextColors());
mTextView.getContext(), mTextView.mTextEditSuggestionHighlightStyle);
private TextView mAddToDictionaryButton;
private TextView mDeleteButton;
+ private ListView mSuggestionListView;
private SuggestionSpan mMisspelledSpan;
private int mContainerMarginWidth;
private int mContainerMarginTop;
mClippingLimitLeft = lp.leftMargin;
mClippingLimitRight = lp.rightMargin;
- final ListView suggestionListView = (ListView) relativeLayout.findViewById(
+ mSuggestionListView = (ListView) relativeLayout.findViewById(
com.android.internal.R.id.suggestionContainer);
mSuggestionsAdapter = new SuggestionAdapter();
- suggestionListView.setAdapter(mSuggestionsAdapter);
- suggestionListView.setOnItemClickListener(this);
+ mSuggestionListView.setAdapter(mSuggestionsAdapter);
+ mSuggestionListView.setOnItemClickListener(this);
// Inflate the suggestion items once and for all.
mSuggestionInfos = new SuggestionInfo[MAX_NUMBER_SUGGESTIONS];
popupBackground.getPadding(mTempRect);
width += mTempRect.left + mTempRect.right;
}
+ mSuggestionListView.getLayoutParams().width = width;
mPopupWindow.setWidth(width);
}
}
if (isVisible()) {
- final int positionX = parentPositionX + mPositionX;
- final int positionY = parentPositionY + mPositionY;
+ // Transform to the window coordinates to follow the view tranformation.
+ final int[] pts = { mPositionX + mHotspotX + getHorizontalOffset(), mPositionY};
+ mTextView.transformFromViewToWindowSpace(pts);
+ pts[0] -= mHotspotX + getHorizontalOffset();
+
if (isShowing()) {
- mContainer.update(positionX, positionY, -1, -1);
+ mContainer.update(pts[0], pts[1], -1, -1);
} else {
- mContainer.showAtLocation(mTextView, Gravity.NO_GRAVITY,
- positionX, positionY);
+ mContainer.showAtLocation(mTextView, Gravity.NO_GRAVITY, pts[0], pts[1]);
}
} else {
if (isShowing()) {