diff options
author | Nikita Dubrovsky <dubrovsky@google.com> | 2020-10-28 16:46:07 -0700 |
---|---|---|
committer | Nikita Dubrovsky <dubrovsky@google.com> | 2020-11-12 14:19:57 -0800 |
commit | a25346bf0cec67f9a1e8644bd0dff718adb73d36 (patch) | |
tree | 0e70e24e79ac62bf238bf5e5d5e77f41b956da55 /api | |
parent | 8902c223aa675fe12b91084af9c0a8966377d30f (diff) |
Update onReceiveContent() logic for app vs platform processing
Previously onReceiveContent() would only invoke the app-configured
callback if the MIME type of the content matched one of the declared
MIME types for the callback. This change updates onReceiveContent()
to always invoke the listener if one is set (regardless of the MIME
type of the content). To delegate processing to the platform, the
app's listener can return some or all of the passed-in content. To
make this easy for apps to implement, the Payload class and its
Builder now provide some convenience methods to conditionally
partition the content.
Reasons for this change:
* Checking the MIME types could be an expensive operation. On SDKs prior
to S, ClipData does not keep track of the MIME types of individual
items, so for a ClipData that contains multiple items, checking the MIME
types requires making at least one RPC call per item.
* Allowing the listener to delegate processing to the platform via its
return value enables us to limit the API surface (we don't need to
expose TextViewOnReceiveContentListener as a public API, nor equivalent
classes for other types of views such as WebView).
* An app that wants to customize the platform behavior for coercing
content to text would previously need to declare "*/*" as the MIME type
for the callback (in order to be invoked for all content). But this
would make it impossible for features to know whether the app would
actually accept a particular type of content or just coerce it to text
(e.g. should the soft keyboard show GIF suggestions when the declared
MIME type is "*/*"). With the new logic the app's listener is always
invoked and can decide which content to process vs delegate to the
platform vs reject completely.
Bug: 170191676
Bug: 152068298
Test: atest CtsViewTestCases:ViewOnReceiveContentTest
Test: atest CtsWidgetTestCases:TextViewOnReceiveContentTest
Test: atest FrameworksCoreTests:TextViewOnReceiveContentTest
Change-Id: Ie48b6fe0b2ae4b014c371b5dc40248221947c6bf
Diffstat (limited to 'api')
-rw-r--r-- | api/current.txt | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/api/current.txt b/api/current.txt index 6459eb4c548a..1cc8d785328f 100644 --- a/api/current.txt +++ b/api/current.txt @@ -53789,16 +53789,17 @@ package android.view { field public int toolType; } - public interface OnReceiveContentCallback<T extends android.view.View> { - method public boolean onReceiveContent(@NonNull T, @NonNull android.view.OnReceiveContentCallback.Payload); + public interface OnReceiveContentListener { + method @Nullable public android.view.OnReceiveContentListener.Payload onReceiveContent(@NonNull android.view.View, @NonNull android.view.OnReceiveContentListener.Payload); } - public static final class OnReceiveContentCallback.Payload { + public static final class OnReceiveContentListener.Payload { method @NonNull public android.content.ClipData getClip(); method @Nullable public android.os.Bundle getExtras(); method public int getFlags(); method @Nullable public android.net.Uri getLinkUri(); method public int getSource(); + method @NonNull public java.util.Map<java.lang.Boolean,android.view.OnReceiveContentListener.Payload> partition(@NonNull java.util.function.Predicate<android.content.ClipData.Item>); field public static final int FLAG_CONVERT_TO_PLAIN_TEXT = 1; // 0x1 field public static final int SOURCE_APP = 0; // 0x0 field public static final int SOURCE_AUTOFILL = 4; // 0x4 @@ -53808,12 +53809,15 @@ package android.view { field public static final int SOURCE_PROCESS_TEXT = 5; // 0x5 } - public static final class OnReceiveContentCallback.Payload.Builder { - ctor public OnReceiveContentCallback.Payload.Builder(@NonNull android.content.ClipData, int); - method @NonNull public android.view.OnReceiveContentCallback.Payload build(); - method @NonNull public android.view.OnReceiveContentCallback.Payload.Builder setExtras(@Nullable android.os.Bundle); - method @NonNull public android.view.OnReceiveContentCallback.Payload.Builder setFlags(int); - method @NonNull public android.view.OnReceiveContentCallback.Payload.Builder setLinkUri(@Nullable android.net.Uri); + public static final class OnReceiveContentListener.Payload.Builder { + ctor public OnReceiveContentListener.Payload.Builder(@NonNull android.view.OnReceiveContentListener.Payload); + ctor public OnReceiveContentListener.Payload.Builder(@NonNull android.content.ClipData, int); + method @NonNull public android.view.OnReceiveContentListener.Payload build(); + method @NonNull public android.view.OnReceiveContentListener.Payload.Builder setClip(@NonNull android.content.ClipData); + method @NonNull public android.view.OnReceiveContentListener.Payload.Builder setExtras(@Nullable android.os.Bundle); + method @NonNull public android.view.OnReceiveContentListener.Payload.Builder setFlags(int); + method @NonNull public android.view.OnReceiveContentListener.Payload.Builder setLinkUri(@Nullable android.net.Uri); + method @NonNull public android.view.OnReceiveContentListener.Payload.Builder setSource(int); } public abstract class OrientationEventListener { @@ -54562,7 +54566,7 @@ package android.view { method public void onProvideContentCaptureStructure(@NonNull android.view.ViewStructure, int); method public void onProvideStructure(android.view.ViewStructure); method public void onProvideVirtualStructure(android.view.ViewStructure); - method public boolean onReceiveContent(@NonNull android.view.OnReceiveContentCallback.Payload); + method @Nullable public android.view.OnReceiveContentListener.Payload onReceiveContent(@NonNull android.view.OnReceiveContentListener.Payload); method public android.view.PointerIcon onResolvePointerIcon(android.view.MotionEvent, int); method @CallSuper protected void onRestoreInstanceState(android.os.Parcelable); method public void onRtlPropertiesChanged(int); @@ -54720,7 +54724,7 @@ package android.view { method public void setOnHoverListener(android.view.View.OnHoverListener); method public void setOnKeyListener(android.view.View.OnKeyListener); method public void setOnLongClickListener(@Nullable android.view.View.OnLongClickListener); - method public void setOnReceiveContentCallback(@Nullable String[], @Nullable android.view.OnReceiveContentCallback); + method public void setOnReceiveContentListener(@Nullable String[], @Nullable android.view.OnReceiveContentListener); method public void setOnScrollChangeListener(android.view.View.OnScrollChangeListener); method @Deprecated public void setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener); method public void setOnTouchListener(android.view.View.OnTouchListener); @@ -61736,11 +61740,6 @@ package android.widget { field @NonNull public static final android.os.Parcelable.Creator<android.widget.TextView.SavedState> CREATOR; } - public class TextViewOnReceiveContentCallback implements android.view.OnReceiveContentCallback<android.widget.TextView> { - ctor public TextViewOnReceiveContentCallback(); - method public boolean onReceiveContent(@NonNull android.widget.TextView, @NonNull android.view.OnReceiveContentCallback.Payload); - } - public interface ThemedSpinnerAdapter extends android.widget.SpinnerAdapter { method @Nullable public android.content.res.Resources.Theme getDropDownViewTheme(); method public void setDropDownViewTheme(@Nullable android.content.res.Resources.Theme); |