Google is committed to advancing racial equity for Black communities. See how.

TextViewRichContentReceiverCompat

public abstract class TextViewRichContentReceiverCompat
extends RichContentReceiverCompat<TextView>

java.lang.Object
   ↳ 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

TextViewRichContentReceiverCompat()

Public methods

Set<String> getSupportedMimeTypes()

Returns the MIME types that can be handled by this callback.

boolean onReceive(TextView textView, ClipData clip, int source, int flags)

Insert the given clip.

Inherited methods

Public constructors

TextViewRichContentReceiverCompat

public TextViewRichContentReceiverCompat ()

Public methods

getSupportedMimeTypes

public Set<String> getSupportedMimeTypes ()

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".

Returns
Set<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

public boolean onReceive (TextView textView, 
                ClipData clip, 
                int source, 
                int flags)

Insert the given clip.

For a UI component where this callback is set, this function will be invoked in the following scenarios:

  1. Paste from the clipboard (e.g. "Paste" or "Paste as plain text" action in the insertion/selection menu)
  2. Content insertion from the keyboard (InputConnection.commitContent(InputContentInfo, int, Bundle))

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
textView TextView: 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.

Returns
boolean Returns true if the clip was inserted.