summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2011-08-12 13:24:16 -0700
committerGilles Debunne <debunne@google.com>2011-08-12 13:57:45 -0700
commit248b112ddaea42eb7c9330407aee1c9d836db7fd (patch)
tree3a13dc885b7ce0f8ec50cd50c8c078868d7860b3
parent27dca78ec1bd7b789226524dcda4fa5a5a2a8544 (diff)
downloadframeworks_base-248b112ddaea42eb7c9330407aee1c9d836db7fd.zip
frameworks_base-248b112ddaea42eb7c9330407aee1c9d836db7fd.tar.gz
frameworks_base-248b112ddaea42eb7c9330407aee1c9d836db7fd.tar.bz2
Text suggestions are enabled for a subset of input types
Change-Id: I0e521eec2784af99ff741a1132a3bc3f7b7aa071
-rw-r--r--core/java/android/widget/TextView.java46
1 files changed, 36 insertions, 10 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index b95fa1b..dd8fa1b 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;
@@ -139,6 +134,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;
@@ -220,6 +220,7 @@ import java.util.HashMap;
* @attr ref android.R.styleable#TextView_imeActionLabel
* @attr ref android.R.styleable#TextView_imeActionId
* @attr ref android.R.styleable#TextView_editorExtras
+ * @attr ref android.R.styleable#TextView_suggestionsEnabled
*/
@RemoteView
public class TextView extends View implements ViewTreeObserver.OnPreDrawListener {
@@ -9382,7 +9383,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
void showSuggestions() {
- if (!mSuggestionsEnabled || !isTextEditable()) return;
+ if (!isSuggestionsEnabled() || !isTextEditable()) return;
if (mSuggestionsPopupWindow == null) {
mSuggestionsPopupWindow = new SuggestionsPopupWindow();
@@ -9409,18 +9410,41 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* user double taps on these parts of the text. No suggestions are displayed when this value is
* false. Use {@link #setSuggestionsEnabled(boolean)} to change this value.
*
+ * Note that suggestions are only enabled for a subset of input types. In addition to setting
+ * this flag to <code>true</code> using {@link #setSuggestionsEnabled(boolean)} or the
+ * <code>android:suggestionsEnabled</code> xml attribute, this method will return
+ * <code>true</code> only if the class of your input type is {@link InputType#TYPE_CLASS_TEXT}.
+ * In addition, the type variation must also be one of
+ * {@link InputType#TYPE_TEXT_VARIATION_NORMAL},
+ * {@link InputType#TYPE_TEXT_VARIATION_EMAIL_SUBJECT},
+ * {@link InputType#TYPE_TEXT_VARIATION_LONG_MESSAGE},
+ * {@link InputType#TYPE_TEXT_VARIATION_SHORT_MESSAGE} or
+ * {@link InputType#TYPE_TEXT_VARIATION_WEB_EDIT_TEXT}.
+ *
* @return true if the suggestions popup window is enabled.
*
* @attr ref android.R.styleable#TextView_suggestionsEnabled
*/
public boolean isSuggestionsEnabled() {
- return mSuggestionsEnabled;
+ if (!mSuggestionsEnabled) return false;
+ if ((mInputType & InputType.TYPE_MASK_CLASS) != InputType.TYPE_CLASS_TEXT) return false;
+ final int variation =
+ mInputType & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_MASK_VARIATION);
+ if (variation == EditorInfo.TYPE_TEXT_VARIATION_NORMAL ||
+ variation == EditorInfo.TYPE_TEXT_VARIATION_EMAIL_SUBJECT ||
+ variation == EditorInfo.TYPE_TEXT_VARIATION_LONG_MESSAGE ||
+ variation == EditorInfo.TYPE_TEXT_VARIATION_SHORT_MESSAGE ||
+ variation == EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT) return true;
+
+ return false;
}
/**
* Enables or disables the suggestion popup. See {@link #isSuggestionsEnabled()}.
*
* @param enabled Whether or not suggestions are enabled.
+ *
+ * @attr ref android.R.styleable#TextView_suggestionsEnabled
*/
public void setSuggestionsEnabled(boolean enabled) {
mSuggestionsEnabled = enabled;
@@ -9692,10 +9716,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
@Override
public void show() {
- mPasteTextView.setVisibility(canPaste() ? View.VISIBLE : View.GONE);
- mReplaceTextView.setVisibility(mSuggestionsEnabled ? View.VISIBLE : View.GONE);
+ boolean canPaste = canPaste();
+ boolean suggestionsEnabled = isSuggestionsEnabled();
+ mPasteTextView.setVisibility(canPaste ? View.VISIBLE : View.GONE);
+ mReplaceTextView.setVisibility(suggestionsEnabled ? View.VISIBLE : View.GONE);
- if (!canPaste() && !mSuggestionsEnabled) return;
+ if (!canPaste && !suggestionsEnabled) return;
super.show();
}