Skip to content

Most visited

Recently visited

navigation

EmojiEditTextHelper

public final class EmojiEditTextHelper
extends Object

java.lang.Object
   ↳ android.support.text.emoji.widget.EmojiEditTextHelper


Utility class to enhance custom EditText widgets with EmojiCompat.

 public class MyEmojiEditText extends EditText {
      public MyEmojiEditText(Context context) {
          super(context);
          init();
      }
      // ...
      private void init() {
          super.setKeyListener(getEmojiEditTextHelper().getKeyListener(getKeyListener()));
      }

      @Override
      public void setKeyListener(android.text.method.KeyListener keyListener) {
          super.setKeyListener(getEmojiEditTextHelper().getKeyListener(keyListener));
      }

      @Override
      public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
          InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
          return getEmojiEditTextHelper().onCreateInputConnection(inputConnection, outAttrs);
      }

      private EmojiEditTextHelper getEmojiEditTextHelper() {
          if (mEmojiEditTextHelper == null) {
              mEmojiEditTextHelper = new EmojiEditTextHelper(this);
          }
          return mEmojiEditTextHelper;
      }
 }
 

Summary

Public constructors

EmojiEditTextHelper(EditText editText)

Default constructor.

Public methods

KeyListener getKeyListener(KeyListener keyListener)

Attaches EmojiCompat KeyListener to the widget.

int getMaxEmojiCount()

Returns the maximum number of EmojiSpans to be added to a CharSequence.

InputConnection onCreateInputConnection(InputConnection inputConnection, EditorInfo outAttrs)

Updates the InputConnection with emoji support.

void setMaxEmojiCount(int maxEmojiCount)

Set the maximum number of EmojiSpans to be added to a CharSequence.

Inherited methods

From class java.lang.Object

Public constructors

EmojiEditTextHelper

EmojiEditTextHelper (EditText editText)

Default constructor.

Parameters
editText EditText: EditText instance

Public methods

getKeyListener

KeyListener getKeyListener (KeyListener keyListener)

Attaches EmojiCompat KeyListener to the widget. Should be called from setKeyListener(KeyListener). Existing keyListener is wrapped into EmojiCompat KeyListener. When used on devices running API 18 or below, this method returns keyListener that is given as a parameter.

Parameters
keyListener KeyListener: KeyListener passed into setKeyListener(KeyListener)

Returns
KeyListener a new KeyListener instance that wraps keyListener.

getMaxEmojiCount

int getMaxEmojiCount ()

Returns the maximum number of EmojiSpans to be added to a CharSequence.

Returns
int

See also:

onCreateInputConnection

InputConnection onCreateInputConnection (InputConnection inputConnection, 
                EditorInfo outAttrs)

Updates the InputConnection with emoji support. Should be called from onCreateInputConnection(EditorInfo). When used on devices running API 18 or below, this method returns inputConnection that is given as a parameter.

Parameters
inputConnection InputConnection: InputConnection instance created by TextView

outAttrs EditorInfo: EditorInfo passed into onCreateInputConnection(EditorInfo)

Returns
InputConnection a new InputConnection instance that wraps inputConnection

setMaxEmojiCount

void setMaxEmojiCount (int maxEmojiCount)

Set the maximum number of EmojiSpans to be added to a CharSequence. The number of spans in a CharSequence affects the performance of the EditText insert/delete operations. Insert/delete operations slow down as the number of spans increases.

Parameters
maxEmojiCount int: maximum number of EmojiSpans to be added to a single CharSequence, should be equal or greater than 0

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.