diff --git a/api/current.txt b/api/current.txt index 6504271cbd0cb..79816ac17b67e 100644 --- a/api/current.txt +++ b/api/current.txt @@ -6674,6 +6674,9 @@ package android.app.assist { method public int getInputType(); method public int getLeft(); method public android.os.LocaleList getLocaleList(); + method public int getMaxTextEms(); + method public int getMaxTextLength(); + method public int getMinTextEms(); method public int getScrollX(); method public int getScrollY(); method public java.lang.CharSequence getText(); @@ -47015,6 +47018,9 @@ package android.view { method public abstract void setInputType(int); method public abstract void setLocaleList(android.os.LocaleList); method public abstract void setLongClickable(boolean); + method public abstract void setMaxTextEms(int); + method public abstract void setMaxTextLength(int); + method public abstract void setMinTextEms(int); method public abstract void setOpaque(boolean); method public abstract void setSelected(boolean); method public abstract void setText(java.lang.CharSequence); diff --git a/api/system-current.txt b/api/system-current.txt index 0d1e8f05bc013..40683d359eaac 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6925,6 +6925,9 @@ package android.app.assist { method public int getInputType(); method public int getLeft(); method public android.os.LocaleList getLocaleList(); + method public int getMaxTextEms(); + method public int getMaxTextLength(); + method public int getMinTextEms(); method public int getScrollX(); method public int getScrollY(); method public java.lang.CharSequence getText(); @@ -50740,6 +50743,9 @@ package android.view { method public abstract void setInputType(int); method public abstract void setLocaleList(android.os.LocaleList); method public abstract void setLongClickable(boolean); + method public abstract void setMaxTextEms(int); + method public abstract void setMaxTextLength(int); + method public abstract void setMinTextEms(int); method public abstract void setOpaque(boolean); method public abstract void setSelected(boolean); method public abstract void setText(java.lang.CharSequence); diff --git a/api/test-current.txt b/api/test-current.txt index f55d9db6c35dd..445871014a5e7 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -6743,6 +6743,9 @@ package android.app.assist { method public int getInputType(); method public int getLeft(); method public android.os.LocaleList getLocaleList(); + method public int getMaxTextEms(); + method public int getMaxTextLength(); + method public int getMinTextEms(); method public int getScrollX(); method public int getScrollY(); method public java.lang.CharSequence getText(); @@ -47596,6 +47599,9 @@ package android.view { method public abstract void setInputType(int); method public abstract void setLocaleList(android.os.LocaleList); method public abstract void setLongClickable(boolean); + method public abstract void setMaxTextEms(int); + method public abstract void setMaxTextLength(int); + method public abstract void setMinTextEms(int); method public abstract void setOpaque(boolean); method public abstract void setSelected(boolean); method public abstract void setText(java.lang.CharSequence); diff --git a/core/java/android/app/assist/AssistStructure.java b/core/java/android/app/assist/AssistStructure.java index d9b7cd7e9e457..e491a4f901e88 100644 --- a/core/java/android/app/assist/AssistStructure.java +++ b/core/java/android/app/assist/AssistStructure.java @@ -616,6 +616,9 @@ public class AssistStructure implements Parcelable { CharSequence[] mAutofillOptions; boolean mSanitized; HtmlInfo mHtmlInfo; + int mMinEms = -1; + int mMaxEms = -1; + int mMaxLength = -1; // POJO used to override some autofill-related values when the node is parcelized. // Not written to parcel. @@ -713,6 +716,9 @@ public class AssistStructure implements Parcelable { if (p instanceof HtmlInfo) { mHtmlInfo = (HtmlInfo) p; } + mMinEms = in.readInt(); + mMaxEms = in.readInt(); + mMaxLength = in.readInt(); } if ((flags&FLAGS_HAS_LARGE_COORDS) != 0) { mX = in.readInt(); @@ -876,6 +882,9 @@ public class AssistStructure implements Parcelable { } else { out.writeParcelable(null, 0); } + out.writeInt(mMinEms); + out.writeInt(mMaxEms); + out.writeInt(mMaxLength); } if ((flags&FLAGS_HAS_LARGE_COORDS) != 0) { out.writeInt(mX); @@ -1444,6 +1453,39 @@ public class AssistStructure implements Parcelable { public ViewNode getChildAt(int index) { return mChildren[index]; } + + /** + * Returns the minimum width in ems of the text associated with this node, or {@code -1} + * if not supported by the node. + * + *
It's only relevant when the {@link AssistStructure} is used for autofill purposes, + * not for assist purposes. + */ + public int getMinTextEms() { + return mMinEms; + } + + /** + * Returns the maximum width in ems of the text associated with this node, or {@code -1} + * if not supported by the node. + * + *
It's only relevant when the {@link AssistStructure} is used for autofill purposes, + * not for assist purposes. + */ + public int getMaxTextEms() { + return mMaxEms; + } + + /** + * Returns the maximum length of the text associated with this node node, or {@code -1} + * if not supported by the node or not set. + * + *
It's only relevant when the {@link AssistStructure} is used for autofill purposes, + * not for assist purposes. + */ + public int getMaxTextLength() { + return mMaxLength; + } } /** @@ -1775,6 +1817,21 @@ public class AssistStructure implements Parcelable { mNode.mInputType = inputType; } + @Override + public void setMinTextEms(int minEms) { + mNode.mMinEms = minEms; + } + + @Override + public void setMaxTextEms(int maxEms) { + mNode.mMaxEms = maxEms; + } + + @Override + public void setMaxTextLength(int maxLength) { + mNode.mMaxLength = maxLength; + } + @Override public void setDataIsSensitive(boolean sensitive) { mNode.mSanitized = !sensitive; diff --git a/core/java/android/view/ViewStructure.java b/core/java/android/view/ViewStructure.java index f671c34997d20..309366c61656a 100644 --- a/core/java/android/view/ViewStructure.java +++ b/core/java/android/view/ViewStructure.java @@ -364,6 +364,30 @@ public abstract class ViewStructure { */ public abstract void setDataIsSensitive(boolean sensitive); + /** + * Sets the minimum width in ems of the text associated with this view, when supported. + * + *
Should only be set when the node is used for autofill purposes - it will be ignored + * when used for Assist. + */ + public abstract void setMinTextEms(int minEms); + + /** + * Sets the maximum width in ems of the text associated with this view, when supported. + * + *
Should only be set when the node is used for autofill purposes - it will be ignored + * when used for Assist. + */ + public abstract void setMaxTextEms(int maxEms); + + /** + * Sets the maximum length of the text associated with this view, when supported. + * + *
Should only be set when the node is used for autofill purposes - it will be ignored + * when used for Assist. + */ + public abstract void setMaxTextLength(int maxLength); + /** * Call when done populating a {@link ViewStructure} returned by * {@link #asyncNewChild}. diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 24ae03c37b116..d9bc51fffd6ac 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -10338,6 +10338,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener // of the View (and can be any drawable) or a BackgroundColorSpan inside the text. structure.setTextStyle(getTextSize(), getCurrentTextColor(), AssistStructure.ViewNode.TEXT_COLOR_UNDEFINED /* bgColor */, style); + } else { + structure.setMinTextEms(getMinEms()); + structure.setMaxTextEms(getMaxEms()); + int maxLength = -1; + for (InputFilter filter: getFilters()) { + if (filter instanceof InputFilter.LengthFilter) { + maxLength = ((InputFilter.LengthFilter) filter).getMax(); + break; + } + } + structure.setMaxTextLength(maxLength); } } structure.setHint(getHint());