summaryrefslogtreecommitdiff
path: root/core/java/android/widget/TextViewOnReceiveContentCallback.java
Commit message (Collapse)AuthorAgeFilesLines
* Update onReceiveContent() logic for app vs platform processingNikita Dubrovsky2020-11-121-438/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add View.onReceiveContent() and View.getOnReceiveContentMimeTypes()Nikita Dubrovsky2020-10-261-15/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | Added View.onReceiveContent() which will invoke the callback if one is set. Added View.getOnReceiveContentMimeTypes() to return the MIME types that the view can receive, removing the getSupportedMimeTypes() method from the callback interface. Changed the code to pass MIME types as a String[] instead of a Set<String> in order to: * Avoid repeated conversion from Set to array in onCreateInputConnection. * Avoid misleading users of the API into using contains() to compare MIME types (ClipDescription.compareMimeTypes should be used in order to correctly handle wilcards such as "image/*"). Bug: 170191676 Bug: 152068298 Test: atest CtsViewTestCases:ViewTest Test: atest CtsViewTestCases:ViewOnReceiveContentTest Test: atest CtsWidgetTestCases:TextViewOnReceiveContentCallbackTest Test: atest FrameworksCoreTests:TextViewOnReceiveContentCallbackTest Test: atest FrameworksCoreTests:AutofillValueTest Change-Id: Id0c7f8f5fd3c7c44827a62dba1b2b205433e7540
* Use IME image API impl as fallback in TextViewOnReceiveContentCallbackNikita Dubrovsky2020-10-161-8/+290
| | | | | | | | | | | | | | | | | | | | | | A bunch of apps implement the keyboard image API (see https://developer.android.com/guide/topics/text/image-keyboard). When image support in augmented autofill is released, we'd like it to work immediately in apps that have previously implemented the keyboard image API, without having to wait for these apps to move to the new unified content insertion API. To make this possible, this change adds logic to call the keyboard image API (InputConnection.commitContent) if the app implements it and if the app target SDK is <= S. This gives apps a full Android release to upgrade to the new content insertion API while augemented autofill will immediately be able to insert images without any changes in apps that have implemented the keyboard image API. Bug: 163400105 Bug: 152068298 Test: Manual and unit tests atest FrameworksCoreTests:TextViewOnReceiveContentCallbackTest atest CtsWidgetTestCases:TextViewOnReceiveContentCallbackTest Change-Id: I9280604e7ec7e8d08c1179e6bbf0068647a41040
* Shorten logcat tag in TextViewOnReceiveContentCallbackNikita Dubrovsky2020-09-281-1/+1
| | | | | | Bug: 152068298 Test: Manual Change-Id: Ic191f5fe1f4f713f9c01a1934754e068b9daf96e
* Update RichContentReceiver API (now OnReceiveContentCallback)Nikita Dubrovsky2020-09-251-0/+149
Bug: 163718378 Bug: 165632620 Bug: 152068298 Test: Unit tests atest CtsWidgetTestCases:TextViewOnReceiveContentCallbackTest atest CtsViewTestCases:ViewTest atest FrameworksCoreTests:TextViewProcessTextTest Change-Id: I3fa65b47c920a9d1ddad88a79e60864dc8109753