From aa7e2294bebe9d83399c297f9bc1d0be837f002d Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Thu, 5 Oct 2017 18:19:48 -0700 Subject: [PATCH] Added new ViewNode properties for Autofill (minEms, maxEms, maxLength). Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases -t android.autofillservice.cts.LoginActivityTest#testNewTextAttributes Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases Fixes: 38323227 Change-Id: I6d8606f2d0668644ae1bd33e982edef0ec1e8e63 --- api/current.txt | 6 ++ api/system-current.txt | 6 ++ api/test-current.txt | 6 ++ .../android/app/assist/AssistStructure.java | 57 +++++++++++++++++++ core/java/android/view/ViewStructure.java | 24 ++++++++ core/java/android/widget/TextView.java | 11 ++++ 6 files changed, 110 insertions(+) diff --git a/api/current.txt b/api/current.txt index 25cac5c2a16e8..31dafc36d2765 100644 --- a/api/current.txt +++ b/api/current.txt @@ -6668,6 +6668,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(); @@ -46969,6 +46972,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 82cdbaf541f76..8e74b49a16222 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6918,6 +6918,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(); @@ -50661,6 +50664,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 34b663be5db6b..9a5f0b81a538d 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -6739,6 +6739,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(); @@ -47518,6 +47521,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 c208f1dbba8a3..eac76119a9d3c 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. @@ -712,6 +715,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(); @@ -874,6 +880,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); @@ -1428,6 +1437,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; + } } /** @@ -1759,6 +1801,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 0ecd20da21c50..4f9124466539b 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 791a8fae418f9..ac7d3be40b4b4 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());