diff options
| author | Joanne Chung <joannechung@google.com> | 2021-05-22 07:41:18 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-05-22 07:41:18 +0000 |
| commit | cee152ee43219e5be4cd00c5c54e7c9733610f3e (patch) | |
| tree | 92d841668b3d48ec3e6882f0c0f36f4630c626cd /core/java/android/view/View.java | |
| parent | 9345d1d5dce88abb3d563102ce0fb22fc63eb821 (diff) | |
| parent | 18b1d3bde4b2437cdeeacd3544274a8f8e80ed81 (diff) | |
Merge "Refine the ViewTranslationCallback usage." into sc-dev
Diffstat (limited to 'core/java/android/view/View.java')
| -rw-r--r-- | core/java/android/view/View.java | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 1f58fdcbf6d1..0acacb60da3f 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -3514,6 +3514,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * 11 PFLAG4_SCROLL_CAPTURE_HINT_MASK * 1 PFLAG4_ALLOW_CLICK_WHEN_DISABLED * 1 PFLAG4_DETACHED + * 1 PFLAG4_HAS_TRANSLATION_TRANSIENT_STATE * |-------|-------|-------|-------| */ @@ -3580,6 +3581,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ private static final int PFLAG4_DETACHED = 0x000002000; + /** + * Indicates that the view has transient state because the system is translating it. + */ + private static final int PFLAG4_HAS_TRANSLATION_TRANSIENT_STATE = 0x000004000; + /* End of masks for mPrivateFlags4 */ /** @hide */ @@ -12271,6 +12277,30 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * Set the view is tracking translation transient state. This flag is used to check if the view + * need to call setHasTransientState(false) to reset transient state that set when starting + * translation. + * + * @param hasTranslationTransientState true if this view has translation transient state + * @hide + */ + public void setHasTranslationTransientState(boolean hasTranslationTransientState) { + if (hasTranslationTransientState) { + mPrivateFlags4 |= PFLAG4_HAS_TRANSLATION_TRANSIENT_STATE; + } else { + mPrivateFlags4 &= ~PFLAG4_HAS_TRANSLATION_TRANSIENT_STATE; + } + } + + /** + * @hide + */ + public boolean hasTranslationTransientState() { + return (mPrivateFlags4 & PFLAG4_HAS_TRANSLATION_TRANSIENT_STATE) + == PFLAG4_HAS_TRANSLATION_TRANSIENT_STATE; + } + + /** * Returns true if this view is currently attached to a window. */ public boolean isAttachedToWindow() { @@ -30839,6 +30869,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * Returns a {@link ViewTranslationCallback} that is used to display the translated information + * or {@code null} if this View doesn't support translation. + * * @hide */ @Nullable @@ -30925,7 +30958,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * view or calls {@link View#onVirtualViewTranslationResponses} for view contains virtual * children 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> + * recycling of views doesn't prevent the system from attaching the response to it. Therefore, + * if overriding this method, you should set or reset the transient state. </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 @@ -30975,10 +31009,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Log.v(CONTENT_CAPTURE_LOG_TAG, "Calling setHasTransientState(true) for " + getAutofillId()); } - // TODO: Add a default ViewTranslationCallback for View that resets this in - // onClearTranslation(). Also update the javadoc for this method to mention - // that. setHasTransientState(true); + setHasTranslationTransientState(true); } } } |
