summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Gilles Debunne <debunne@google.com> 2011-02-04 15:49:56 -0800
committer Android Git Automerger <android-git-automerger@android.com> 2011-02-04 15:49:56 -0800
commit2f7e9d403a8ef6660d3acf8c41f57ce339c9f7cc (patch)
treef2eb59cd8ff26cf07fe11b388f19fdb1b2cb4088
parentcc8f87e9410dd4de9a2fda4738429e6c6087c789 (diff)
parent53841df2a49bffa53ba3d1e4b0580f4f23a64dc3 (diff)
am 53841df2: Merge "SelectAllOnFocus shows a higlighted text. DO NOT MERGE." into gingerbread
* commit '53841df2a49bffa53ba3d1e4b0580f4f23a64dc3': SelectAllOnFocus shows a higlighted text. DO NOT MERGE.
-rw-r--r--core/java/android/widget/TextView.java94
-rw-r--r--core/res/res/layout/search_bar.xml1
2 files changed, 37 insertions, 58 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index bdc5014eeb92..6b57f8701e23 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -297,6 +297,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
Drawable mSelectHandleRight;
Drawable mSelectHandleCenter;
+ // Set when this TextView gained focus with some text selected. Will start selection mode.
+ private boolean mCreatedWithASelection = false;
+
/*
* Kick-start the font cache for the zygote process (to pay the cost of
* initializing freetype for our default font only once).
@@ -3774,8 +3777,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// - ExtractEditText does not call onFocus when it is displayed. Fixing this issue would
// allow to test for hasSelection in onFocusChanged, which would trigger a
// startTextSelectionMode here. TODO
- if (this instanceof ExtractEditText && selectionController != null && hasSelection()) {
+ if (mCreatedWithASelection ||
+ (this instanceof ExtractEditText && selectionController != null && hasSelection())) {
startTextSelectionMode();
+ mCreatedWithASelection = false;
}
mPreDrawState = PREDRAW_DONE;
@@ -4191,6 +4196,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mInsertionPointCursorController.isShowing()) {
mInsertionPointCursorController.updatePosition();
}
+
if (mSelectionModifierCursorController != null &&
mSelectionModifierCursorController.isShowing()) {
mSelectionModifierCursorController.updatePosition();
@@ -6601,6 +6607,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
int selStart = getSelectionStart();
int selEnd = getSelectionEnd();
+ // SelectAllOnFocus fields are highlighted and not selected. Do not start text selection
+ // mode for these, unless there was a specific selection already started.
+ final boolean isFocusHighlighted = mSelectAllOnFocus && selStart == 0 &&
+ selEnd == mText.length();
+ mCreatedWithASelection = mFrozenWithFocus && hasSelection() && !isFocusHighlighted;
+
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.
@@ -6613,10 +6625,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mMovement.onTakeFocus(this, (Spannable) mText, direction);
}
- if (mSelectAllOnFocus) {
- Selection.setSelection((Spannable) mText, 0, mText.length());
- }
-
// The DecorView does not have focus when the 'Done' ExtractEditText button is
// pressed. Since it is the ViewRoot's mView, it requests focus before
// ExtractEditText clears focus, which gives focus to the ExtractEditText.
@@ -6635,6 +6643,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
*/
Selection.setSelection((Spannable) mText, selStart, selEnd);
}
+
+ if (mSelectAllOnFocus) {
+ Selection.setSelection((Spannable) mText, 0, mText.length());
+ }
+
mTouchFocusSelected = true;
}
@@ -6664,7 +6677,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// ExtractEditText goes out of focus.
mIsInTextSelectionMode = false;
} else {
- terminateTextSelectionMode();
+ stopTextSelectionMode();
}
if (mSelectionModifierCursorController != null) {
@@ -6766,29 +6779,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
final int end = getSelectionEnd();
if (start == end) {
- if (start >= prevStart && start < prevEnd) {
+ boolean tapInsideSelectAllOnFocus = mSelectAllOnFocus && prevStart == 0 &&
+ prevEnd == mText.length();
+ if (start >= prevStart && start < prevEnd && !tapInsideSelectAllOnFocus) {
// Restore previous selection
Selection.setSelection((Spannable)mText, prevStart, prevEnd);
- if (hasSelectionController() && !getSelectionController().isShowing()) {
- // If the anchors aren't showing, revive them.
- getSelectionController().show();
- } else {
- // Tapping inside the selection displays the cut/copy/paste context menu
- // as long as the anchors are already showing.
- showContextMenu();
- }
- return;
+ // Tapping inside the selection displays the cut/copy/paste context menu
+ showContextMenu();
} else {
// Tapping outside stops selection mode, if any
stopTextSelectionMode();
- if (hasInsertionController() && mText.length() > 0) {
+ boolean selectAllGotFocus = mSelectAllOnFocus && mTouchFocusSelected;
+ if (hasInsertionController() && !selectAllGotFocus) {
getInsertionController().show();
}
}
- } else if (hasSelection() && hasSelectionController()) {
- getSelectionController().show();
}
}
@@ -6811,7 +6818,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
int end = Math.min(len, mPrevEnd);
Selection.setSelection((Spannable)mText, start, end);
- if (hasSelection()) {
+ boolean selectAllGotFocus = mSelectAllOnFocus && mTouchFocusSelected;
+ if (hasSelection() && !selectAllGotFocus) {
startTextSelectionMode();
}
}
@@ -7169,7 +7177,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
private boolean canSelectText() {
- return textCanBeSelected() && mText.length() != 0;
+ return hasSelectionController() && mText.length() != 0;
}
private boolean textCanBeSelected() {
@@ -7339,7 +7347,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
int selectionStart, selectionEnd;
-
+
long wordLimits = getWordLimitsAt(minOffset);
if (wordLimits >= 0) {
selectionStart = extractRangeStartFromLong(wordLimits);
@@ -7498,6 +7506,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
if (added) {
+ hideControllers();
menu.setHeaderTitle(com.android.internal.R.string.editTextMenuTitle);
}
}
@@ -7674,29 +7683,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
return;
}
- if (!requestFocus()) {
+ if (!canSelectText() || !requestFocus()) {
return;
}
selectCurrentWord();
+ getSelectionController().show();
+ final InputMethodManager imm = (InputMethodManager)
+ getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.showSoftInput(this, 0, null);
mIsInTextSelectionMode = true;
}
}
-
- /**
- * Same as {@link #stopTextSelectionMode()}, except that there is no cursor controller
- * fade out animation. Needed since the drawable and their alpha values are shared by all
- * TextViews. Switching from one TextView to another would fade the cursor controllers in the
- * new one otherwise.
- */
- private void terminateTextSelectionMode() {
- stopTextSelectionMode();
- if (mSelectionModifierCursorController != null) {
- SelectionModifierCursorController selectionModifierCursorController =
- (SelectionModifierCursorController) mSelectionModifierCursorController;
- selectionModifierCursorController.cancelFadeOutAnimation();
- }
- }
private void stopTextSelectionMode() {
if (mIsInTextSelectionMode) {
@@ -8074,14 +8072,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Whether selection anchors are active
private boolean mIsShowing;
- private static final int DELAY_BEFORE_FADE_OUT = 4100;
-
- private final Runnable mHider = new Runnable() {
- public void run() {
- hide();
- }
- };
-
SelectionModifierCursorController() {
mStartHandle = new HandleView(this, HandleView.LEFT);
mEndHandle = new HandleView(this, HandleView.RIGHT);
@@ -8098,29 +8088,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mStartHandle.show();
mEndHandle.show();
hideInsertionPointCursorController();
- hideDelayed(DELAY_BEFORE_FADE_OUT);
}
public void hide() {
mStartHandle.hide();
mEndHandle.hide();
mIsShowing = false;
- removeCallbacks(mHider);
- }
-
- private void hideDelayed(int delay) {
- removeCallbacks(mHider);
- postDelayed(mHider, delay);
}
public boolean isShowing() {
return mIsShowing;
}
- public void cancelFadeOutAnimation() {
- hide();
- }
-
public void updatePosition(HandleView handle, int x, int y) {
int selectionStart = getSelectionStart();
int selectionEnd = getSelectionEnd();
@@ -8172,7 +8151,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mStartHandle.positionAtCursor(selectionStart, true);
mEndHandle.positionAtCursor(selectionEnd, true);
- hideDelayed(DELAY_BEFORE_FADE_OUT);
}
public boolean onTouchEvent(MotionEvent event) {
diff --git a/core/res/res/layout/search_bar.xml b/core/res/res/layout/search_bar.xml
index 7935e2a3fd53..c7c073c4438c 100644
--- a/core/res/res/layout/search_bar.xml
+++ b/core/res/res/layout/search_bar.xml
@@ -75,6 +75,7 @@
android:drawablePadding="2dip"
android:singleLine="true"
android:ellipsize="end"
+ android:selectAllOnFocus="true"
android:inputType="text|textAutoComplete"
android:dropDownWidth="match_parent"
android:dropDownHeight="match_parent"