TextViewRichContentReceiverCompat
abstract class TextViewRichContentReceiverCompat : RichContentReceiverCompat<TextView!>
kotlin.Any | ||
↳ | androidx.core.widget.RichContentReceiverCompat<android.widget.TextView> | |
↳ | androidx.core.widget.TextViewRichContentReceiverCompat |
Base implementation of RichContentReceiverCompat
for editable TextView
components.
This class handles insertion of text (plain text, styled text, HTML, etc) but not images or other rich content. It should be used as a base class when implementing a custom RichContentReceiverCompat
, to provide consistent behavior for insertion of text while implementing custom behavior for insertion of other content (images, etc).
See RichContentReceiverCompat
for an example of how to implement a custom receiver.
Summary
Inherited constants | |
---|---|
Public constructors | |
---|---|
<init>() Base implementation of |
Public methods | |
---|---|
open MutableSet<String!> |
Returns the MIME types that can be handled by this callback. |
open Boolean |
Insert the given clip. |
Public constructors
<init>
TextViewRichContentReceiverCompat()
Base implementation of RichContentReceiverCompat
for editable TextView
components.
This class handles insertion of text (plain text, styled text, HTML, etc) but not images or other rich content. It should be used as a base class when implementing a custom RichContentReceiverCompat
, to provide consistent behavior for insertion of text while implementing custom behavior for insertion of other content (images, etc).
See RichContentReceiverCompat
for an example of how to implement a custom receiver.
Public methods
getSupportedMimeTypes
@NonNull open fun getSupportedMimeTypes(): MutableSet<String!>
Returns the MIME types that can be handled by this callback.
Different platform features (e.g. pasting from the clipboard, inserting stickers from the keyboard, etc) may use this function to conditionally alter their behavior. For example, the keyboard may choose to hide its UI for inserting GIFs if the input field that has focus has a RichContentReceiverCompat
set and the MIME types returned from this function don't include "image/gif".
Return | |
---|---|
MutableSet<String!> |
An immutable set with the MIME types supported by this callback. The returned MIME types may contain wildcards such as "text/*", "image/*", etc. |
onReceive
open fun onReceive(
@NonNull textView: TextView,
@NonNull clip: ClipData,
source: Int,
flags: Int
): Boolean
Insert the given clip.
For a UI component where this callback is set, this function will be invoked in the following scenarios:
- Paste from the clipboard (e.g. "Paste" or "Paste as plain text" action in the insertion/selection menu)
- Content insertion from the keyboard (
InputConnection#commitContent
)
For text, if the view has a selection, the selection should be overwritten by the clip; if there's no selection, this method should insert the content at the current cursor position.
For rich content (e.g. an image), this function may insert the content inline, or it may add the content as an attachment (could potentially go into a completely separate view).
This function may be invoked with a clip whose MIME type is not in the list of supported types returned by getSupportedMimeTypes()
. This provides the opportunity to implement custom fallback logic if desired.
Parameters | |
---|---|
view |
The view where the content insertion was requested. |
clip |
ClipData: The clip to insert. |
source |
Int: The trigger of the operation. |
flags |
Int: Optional flags to configure the insertion behavior. Use 0 for default behavior. See FLAG_ constants on this class for other options. |
Return | |
---|---|
Boolean |
Returns true if the clip was inserted. |