Added a new flag in TextView to disable Suggestions.

This is needed for specific TextEdit (such as AutoCompleteTextField)
which do not want to display the "No suggestions available" message.

Bug 4443830

Change-Id: Ic228b56bacfdf2765e70eb24952ab087556c1f93
This commit is contained in:
Gilles Debunne
2011-05-23 16:28:47 -07:00
parent 37cd57772b
commit f3a135bfba
4 changed files with 47 additions and 5 deletions

View File

@@ -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;
@@ -129,6 +124,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;
@@ -320,6 +320,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
private int mTextEditSuggestionItemLayout;
private SuggestionsPopupWindow mSuggestionsPopupWindow;
private SuggestionRangeSpan mSuggestionRangeSpan;
private boolean mSuggestionsEnabled = true;
private int mCursorDrawableRes;
private final Drawable[] mCursorDrawable = new Drawable[2];
@@ -806,6 +807,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
case com.android.internal.R.styleable.TextView_textIsSelectable:
mTextIsSelectable = a.getBoolean(attr, false);
break;
case com.android.internal.R.styleable.TextView_suggestionsEnabled:
mSuggestionsEnabled = a.getBoolean(attr, true);
break;
}
}
a.recycle();
@@ -8601,6 +8606,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
void showSuggestions() {
if (!mSuggestionsEnabled || !isTextEditable()) return;
if (mSuggestionsPopupWindow == null) {
mSuggestionsPopupWindow = new SuggestionsPopupWindow();
}
@@ -8614,6 +8621,31 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
/**
* 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.
*
* When suggestions are enabled (default), this list of suggestions will be displayed when the
* 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.
*
* @return true if the suggestions popup window is enabled.
*
* @attr ref android.R.styleable#TextView_suggestionsEnabled
*/
public boolean isSuggestionsEnabled() {
return mSuggestionsEnabled;
}
/**
* Enables or disables the suggestion popup. See {@link #isSuggestionsEnabled()}.
*
* @param enabled Whether or not suggestions are enabled.
*/
public void setSuggestionsEnabled(boolean enabled) {
mSuggestionsEnabled = enabled;
}
/**
* If provided, this ActionMode.Callback will be used to create the ActionMode when text
* selection is initiated in this View.