Merge "Add API for obtaining max text length for accessibility" into lmp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f2546bf423
@@ -30813,6 +30813,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 {
|
||||
@@ -36046,6 +36047,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();
|
||||
@@ -36109,6 +36111,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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -1044,6 +1045,36 @@ public class AccessibilityNodeInfo implements Parcelable {
|
||||
return mActions.remove(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user