summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2011-07-11 14:58:27 -0700
committerGilles Debunne <debunne@google.com>2011-07-12 13:05:10 -0700
commit4a7199ae2b25ad57ae9c3a634aacd1315afe4041 (patch)
tree20379123f7e16891aeb0059397b2d3db82c034a7
parent2d6bb33800e35b452a42a8ee0e35043d790b0b22 (diff)
downloadframeworks_base-4a7199ae2b25ad57ae9c3a634aacd1315afe4041.zip
frameworks_base-4a7199ae2b25ad57ae9c3a634aacd1315afe4041.tar.gz
frameworks_base-4a7199ae2b25ad57ae9c3a634aacd1315afe4041.tar.bz2
Suggestions are dismissed by back key
Also changed back when in text selection mode: selection mode / suggestion are hidden first, before the IME is dismissed. Bug 4541805. Change-Id: I71ee7fe2fdf9e882d059482aa29dd45ade3e5dbe
-rw-r--r--core/java/android/widget/TextView.java61
1 files changed, 53 insertions, 8 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index e350ec4..e0f84b7 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -16,11 +16,6 @@
package android.widget;
-import com.android.internal.util.FastMath;
-import com.android.internal.widget.EditableInputConnection;
-
-import org.xmlpull.v1.XmlPullParserException;
-
import android.R;
import android.content.ClipData;
import android.content.ClipData.Item;
@@ -132,6 +127,11 @@ import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.RemoteViews.RemoteView;
+import com.android.internal.util.FastMath;
+import com.android.internal.widget.EditableInputConnection;
+
+import org.xmlpull.v1.XmlPullParserException;
+
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.text.BreakIterator;
@@ -4724,6 +4724,40 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
@Override
+ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ boolean areSuggestionsShown = areSuggestionsShown();
+ boolean isInSelectionMode = mSelectionActionMode != null;
+
+ if (areSuggestionsShown || isInSelectionMode) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
+ KeyEvent.DispatcherState state = getKeyDispatcherState();
+ if (state != null) {
+ state.startTracking(event, this);
+ }
+ return true;
+ } else if (event.getAction() == KeyEvent.ACTION_UP) {
+ KeyEvent.DispatcherState state = getKeyDispatcherState();
+ if (state != null) {
+ state.handleUpEvent(event);
+ }
+ if (event.isTracking() && !event.isCanceled()) {
+ if (areSuggestionsShown) {
+ hideSuggestions();
+ return true;
+ }
+ if (isInSelectionMode) {
+ stopSelectionActionMode();
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return super.onKeyPreIme(keyCode, event);
+ }
+
+ @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
int which = doKeyDown(keyCode, event, null);
if (which == 0) {
@@ -4875,6 +4909,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Has to be done on key down (and not on key up) to correctly be intercepted.
case KeyEvent.KEYCODE_BACK:
+ if (areSuggestionsShown()) {
+ hideSuggestions();
+ return -1;
+ }
if (mSelectionActionMode != null) {
stopSelectionActionMode();
return -1;
@@ -7245,7 +7283,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Because of View recycling in ListView, there is no easy way to know when a TextView with
// selection becomes visible again. Until a better solution is found, stop text selection
// mode (if any) as soon as this TextView is recycled.
- stopSelectionActionMode();
+ hideControllers();
}
@Override
@@ -7520,8 +7558,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (!selectAllGotFocus && hasSelection()) {
startSelectionActionMode();
} else {
- stopSelectionActionMode();
- hideSuggestions();
+ hideControllers();
if (hasInsertionController() && !selectAllGotFocus && mText.length() > 0) {
getInsertionController().show();
}
@@ -8668,6 +8705,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mContainer.dismiss();
}
+ public boolean isShowing() {
+ return mContainer.isShowing();
+ }
+
@Override
public void onClick(View view) {
if (view instanceof TextView) {
@@ -8794,6 +8835,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
+ boolean areSuggestionsShown() {
+ return mSuggestionsPopupWindow != null && mSuggestionsPopupWindow.isShowing();
+ }
+
/**
* Some parts of the text can have alternate suggestion text attached. This is typically done by
* the IME by adding {@link SuggestionSpan}s to the text.