From 029942f77d05ed3d20256403652b220c83dad6e1 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Tue, 12 Aug 2014 14:55:56 -0700 Subject: Add API for obtaining max text length for accessibility BUG: 16736956 Change-Id: I15ffb9bf68e074adf3e0dbcd230367e115c03e3c --- .../view/accessibility/AccessibilityNodeInfo.java | 38 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'core/java/android/view/accessibility') diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.java b/core/java/android/view/accessibility/AccessibilityNodeInfo.java index 1bf4639..3987fbc 100644 --- a/core/java/android/view/accessibility/AccessibilityNodeInfo.java +++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.java @@ -562,6 +562,7 @@ public class AccessibilityNodeInfo implements Parcelable { private LongArray mChildNodeIds; private ArrayList mActions; + private int mMaxTextLength = -1; private int mMovementGranularities; private int mTextSelectionStart = UNDEFINED_SELECTION_INDEX; @@ -1045,6 +1046,36 @@ public class AccessibilityNodeInfo implements Parcelable { } /** + * Sets the maximum text length, or -1 for no limit. + *

+ * Typically used to indicate that an editable text field has a limit on + * the number of characters entered. + *

+ * Note: Cannot be called from an + * {@link android.accessibilityservice.AccessibilityService}. + * This class is made immutable before being delivered to an AccessibilityService. + * + * @param max The maximum text length. + * @see #getMaxTextLength() + * + * @throws IllegalStateException If called from an AccessibilityService. + */ + public void setMaxTextLength(int max) { + enforceNotSealed(); + mMaxTextLength = max; + } + + /** + * Returns the maximum text length for this node. + * + * @return The maximum text length, or -1 for no limit. + * @see #setMaxTextLength(int) + */ + public int getMaxTextLength() { + return mMaxTextLength; + } + + /** * Sets the movement granularities for traversing the text of this node. *

* Note: Cannot be called from an @@ -2469,8 +2500,8 @@ public class AccessibilityNodeInfo implements Parcelable { parcel.writeInt(0); } + parcel.writeInt(mMaxTextLength); parcel.writeInt(mMovementGranularities); - parcel.writeInt(mBooleanProperties); parcel.writeCharSequence(mPackageName); @@ -2562,6 +2593,7 @@ public class AccessibilityNodeInfo implements Parcelable { } mBooleanProperties = other.mBooleanProperties; + mMaxTextLength = other.mMaxTextLength; mMovementGranularities = other.mMovementGranularities; final LongArray otherChildNodeIds = other.mChildNodeIds; @@ -2636,8 +2668,8 @@ public class AccessibilityNodeInfo implements Parcelable { } } + mMaxTextLength = parcel.readInt(); mMovementGranularities = parcel.readInt(); - mBooleanProperties = parcel.readInt(); mPackageName = parcel.readCharSequence(); @@ -2695,6 +2727,7 @@ public class AccessibilityNodeInfo implements Parcelable { mLabeledById = ROOT_NODE_ID; mWindowId = UNDEFINED_ITEM_ID; mConnectionId = UNDEFINED_CONNECTION_ID; + mMaxTextLength = -1; mMovementGranularities = 0; if (mChildNodeIds != null) { mChildNodeIds.clear(); @@ -2911,6 +2944,7 @@ public class AccessibilityNodeInfo implements Parcelable { builder.append("; className: ").append(mClassName); builder.append("; text: ").append(mText); builder.append("; error: ").append(mError); + builder.append("; maxTextLength: ").append(mMaxTextLength); builder.append("; contentDescription: ").append(mContentDescription); builder.append("; viewIdResName: ").append(mViewIdResourceName); -- cgit v1.1