summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.txt3
-rw-r--r--core/java/android/text/InputFilter.java14
-rw-r--r--core/java/android/view/accessibility/AccessibilityNodeInfo.java38
-rw-r--r--core/java/android/widget/TextView.java9
4 files changed, 58 insertions, 6 deletions
diff --git a/api/current.txt b/api/current.txt
index eb991ad..c5ef565 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -30809,6 +30809,7 @@ package android.text {
public static class InputFilter.LengthFilter implements android.text.InputFilter {
ctor public InputFilter.LengthFilter(int);
method public java.lang.CharSequence filter(java.lang.CharSequence, int, int, android.text.Spanned, int, int);
+ method public int getMax();
}
public abstract interface InputType {
@@ -36042,6 +36043,7 @@ package android.view.accessibility {
method public android.view.accessibility.AccessibilityNodeInfo getLabelFor();
method public android.view.accessibility.AccessibilityNodeInfo getLabeledBy();
method public int getLiveRegion();
+ method public int getMaxTextLength();
method public int getMovementGranularities();
method public java.lang.CharSequence getPackageName();
method public android.view.accessibility.AccessibilityNodeInfo getParent();
@@ -36105,6 +36107,7 @@ package android.view.accessibility {
method public void setLabeledBy(android.view.View, int);
method public void setLiveRegion(int);
method public void setLongClickable(boolean);
+ method public void setMaxTextLength(int);
method public void setMovementGranularities(int);
method public void setMultiLine(boolean);
method public void setPackageName(java.lang.CharSequence);
diff --git a/core/java/android/text/InputFilter.java b/core/java/android/text/InputFilter.java
index 8d4b08e..bff09a2 100644
--- a/core/java/android/text/InputFilter.java
+++ b/core/java/android/text/InputFilter.java
@@ -75,14 +75,15 @@ public interface InputFilter
* greater than the specified length.
*/
public static class LengthFilter implements InputFilter {
+ private final int mMax;
+
public LengthFilter(int max) {
mMax = max;
}
- public CharSequence filter(CharSequence source, int start, int end,
- Spanned dest, int dstart, int dend) {
+ public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
+ int dstart, int dend) {
int keep = mMax - (dest.length() - (dend - dstart));
-
if (keep <= 0) {
return "";
} else if (keep >= end - start) {
@@ -99,6 +100,11 @@ public interface InputFilter
}
}
- private int mMax;
+ /**
+ * @return the maximum length enforced by this input filter
+ */
+ public int getMax() {
+ return mMax;
+ }
}
}
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<AccessibilityAction> 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.
+ * <p>
+ * Typically used to indicate that an editable text field has a limit on
+ * the number of characters entered.
+ * <p>
+ * <strong>Note:</strong> 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.
* <p>
* <strong>Note:</strong> 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);
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index b162e54..a536b2d 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -8392,6 +8392,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
+ // Check for known input filter types.
+ final int numFilters = mFilters.length;
+ for (int i = 0; i < numFilters; i++) {
+ final InputFilter filter = mFilters[i];
+ if (filter instanceof InputFilter.LengthFilter) {
+ info.setMaxTextLength(((InputFilter.LengthFilter) filter).getMax());
+ }
+ }
+
if (!isSingleLine()) {
info.setMultiLine(true);
}