summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2010-10-08 17:21:42 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-10-08 17:21:42 -0700
commit42dd7ec9f03f169d373c3753d52eb5632ab5b142 (patch)
tree355e30c3ecf19515528c7ce6f39c0f8db91ab5b2
parent37c8ad779fb171470af2757b5750c1b5f2d1f368 (diff)
parenta827d7bc347ce6f1a0074dd9fe515919a35a38a9 (diff)
downloadframeworks_base-42dd7ec9f03f169d373c3753d52eb5632ab5b142.zip
frameworks_base-42dd7ec9f03f169d373c3753d52eb5632ab5b142.tar.gz
frameworks_base-42dd7ec9f03f169d373c3753d52eb5632ab5b142.tar.bz2
am a827d7bc: Merge "Other improvements to text cursor movement." into gingerbread
Merge commit 'a827d7bc347ce6f1a0074dd9fe515919a35a38a9' into gingerbread-plus-aosp * commit 'a827d7bc347ce6f1a0074dd9fe515919a35a38a9': Other improvements to text cursor movement.
-rw-r--r--core/java/android/widget/TextView.java37
1 files changed, 24 insertions, 13 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 8bf8aa4..790f35f 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -6556,7 +6556,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) {
// If a tap was used to give focus to that view, move cursor at tap position.
// Has to be done before onTakeFocus, which can be overloaded.
- moveCursorToLastTapPosition();
+ final int lastTapPosition = getLastTapPosition();
+ if (lastTapPosition >= 0) {
+ Selection.setSelection((Spannable) mText, lastTapPosition);
+ }
if (mMovement != null) {
mMovement.onTakeFocus(this, (Spannable) mText, direction);
@@ -6615,6 +6618,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} else {
terminateTextSelectionMode();
}
+
+ if (mSelectionModifierCursorController != null) {
+ ((SelectionModifierCursorController) mSelectionModifierCursorController).resetTouchOffsets();
+ }
}
startStopMarquee(focused);
@@ -6626,20 +6633,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
- private void moveCursorToLastTapPosition() {
+ private int getLastTapPosition() {
if (mSelectionModifierCursorController != null) {
- int mTapToFocusPosition = ((SelectionModifierCursorController)
+ int lastTapPosition = ((SelectionModifierCursorController)
mSelectionModifierCursorController).getMinTouchOffset();
- if (mTapToFocusPosition >= 0) {
+ if (lastTapPosition >= 0) {
// Safety check, should not be possible.
- if (mTapToFocusPosition > mText.length()) {
- Log.e(LOG_TAG, "Invalid tap focus position (" + mTapToFocusPosition + " vs "
+ if (lastTapPosition > mText.length()) {
+ Log.e(LOG_TAG, "Invalid tap focus position (" + lastTapPosition + " vs "
+ mText.length() + ")");
- mTapToFocusPosition = mText.length();
+ lastTapPosition = mText.length();
}
- Selection.setSelection((Spannable) mText, mTapToFocusPosition);
+ return lastTapPosition;
}
}
+
+ return -1;
}
@Override
@@ -7302,10 +7311,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
private String getWordForDictionary() {
- if (!mContextMenuTriggeredByKey) {
- moveCursorToLastTapPosition();
- }
- long wordLimits = getWordLimitsAt(getSelectionStart());
+ int seedPosition = mContextMenuTriggeredByKey ? getSelectionStart() : getLastTapPosition();
+ long wordLimits = getWordLimitsAt(seedPosition);
if (wordLimits >= 0) {
int start = extractRangeStartFromLong(wordLimits);
int end = extractRangeEndFromLong(wordLimits);
@@ -8024,7 +8031,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
SelectionModifierCursorController() {
mStartHandle = new HandleView(this, HandleView.LEFT);
mEndHandle = new HandleView(this, HandleView.RIGHT);
- mMinTouchOffset = mMaxTouchOffset = -1;
+ resetTouchOffsets();
}
public void show() {
@@ -8156,6 +8163,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
return mMaxTouchOffset;
}
+ public void resetTouchOffsets() {
+ mMinTouchOffset = mMaxTouchOffset = -1;
+ }
+
/**
* @return true iff this controller is currently used to move the selection start.
*/