summaryrefslogtreecommitdiff
path: root/core/java/android/view/View.java
diff options
context:
space:
mode:
authorAhaan Ugale <augale@google.com>2021-04-13 02:11:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-04-13 02:11:07 +0000
commit44dccdbe1a8cf51c157f708f0f336e7a28d4f9fd (patch)
treeafbf2abe0042a6f21ab533ae9d5e94883618df4c /core/java/android/view/View.java
parent036d189a8d923e87b90330dab2e2154740ccad52 (diff)
parentd3ef7757378ccf92cee364bc862920af34f7f438 (diff)
Merge "Fix UiTranslation for ListView." into sc-dev
Diffstat (limited to 'core/java/android/view/View.java')
-rw-r--r--core/java/android/view/View.java43
1 files changed, 41 insertions, 2 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index dd5c95404510..d6b5a2c299e9 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -9285,6 +9285,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* parentView.addView(reusableView);
* </pre>
*
+ * <p>NOTE: If this view is a descendant of an {@link android.widget.AdapterView}, the system
+ * may reset its autofill id when this view is recycled. If the autofill ids need to be stable,
+ * they should be set again in
+ * {@link android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)}.
+ *
* @param id an autofill ID that is unique in the {@link android.app.Activity} hosting the view,
* or {@code null} to reset it. Usually it's an id previously allocated to another view (and
* obtained through {@link #getAutofillId()}), or a new value obtained through
@@ -9321,6 +9326,30 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
+ * Forces a reset of the autofill ids of the subtree rooted at this view. Like calling
+ * {@link #setAutofillId(AutofillId) setAutofillId(null)} for each view, but works even if the
+ * views are attached to a window.
+ *
+ * <p>This is useful if the views are being recycled, since an autofill id should uniquely
+ * identify a particular piece of content.
+ *
+ * @hide
+ */
+ public void resetSubtreeAutofillIds() {
+ if (mAutofillViewId == NO_ID) {
+ return;
+ }
+ if (Log.isLoggable(CONTENT_CAPTURE_LOG_TAG, Log.VERBOSE)) {
+ Log.v(CONTENT_CAPTURE_LOG_TAG, "resetAutofillId() for " + mAutofillViewId);
+ } else if (Log.isLoggable(AUTOFILL_LOG_TAG, Log.VERBOSE)) {
+ Log.v(AUTOFILL_LOG_TAG, "resetAutofillId() for " + mAutofillViewId);
+ }
+ mAutofillId = null;
+ mAutofillViewId = NO_ID;
+ mPrivateFlags3 &= ~PFLAG3_AUTOFILLID_EXPLICITLY_SET;
+ }
+
+ /**
* Describes the autofill type of this view, so an
* {@link android.service.autofill.AutofillService} can create the proper {@link AutofillValue}
* when autofilling the view.
@@ -30843,8 +30872,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* {@link android.view.translation.Translator} to translate the requests. All the
* {@link ViewTranslationRequest}s must be added when the traversal is done.
*
- * <p> The default implementation will call {@link View#onCreateTranslationRequest} to build
- * {@link ViewTranslationRequest} if the view should be translated. </p>
+ * <p> The default implementation calls {@link View#onCreateTranslationRequest} to build
+ * {@link ViewTranslationRequest} if the view should be translated. The view is marked as having
+ * {@link #setHasTransientState(boolean) transient state} so that recycling of views doesn't
+ * prevent the system from attaching the response to it.</p>
*
* @param viewIds a map for the view's {@link AutofillId} and its virtual child ids or
* {@code null} if the view doesn't have virtual child that should be translated. The virtual
@@ -30865,6 +30896,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
ViewTranslationRequest request = onCreateTranslationRequest(supportedFormats);
if (request != null && request.getKeys().size() > 0) {
requests.add(request);
+ if (Log.isLoggable(CONTENT_CAPTURE_LOG_TAG, Log.VERBOSE)) {
+ Log.v(CONTENT_CAPTURE_LOG_TAG, "Calling setHasTransientState(true) for "
+ + autofillId);
+ }
+ // TODO: Add a default ViewTranslationCallback for View that resets this in
+ // onClearTranslation(). Also update the javadoc for this method to mention
+ // that.
+ setHasTransientState(true);
}
} else {
onCreateTranslationRequests(viewIds.get(autofillId), supportedFormats, request -> {