com.vanniktech.emoji.emoji.Emoji Java Examples
The following examples show how to use
com.vanniktech.emoji.emoji.Emoji.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestEmojiProvider.java From Emoji with Apache License 2.0 | 6 votes |
@Override @NonNull public EmojiCategory[] getCategories() { return new EmojiCategory[] { new EmojiCategory() { @Override @NonNull public Emoji[] getEmojis() { return emojis; // NOPMD } @Override public int getIcon() { return R.drawable.emoji_recent; } @Override public int getCategoryName() { return R.string.emoji_category_recent; } } }; }
Example #2
Source File: RecentEmojiManagerTest.java From Emoji with Apache License 2.0 | 6 votes |
@Test public void inOrder() { recentEmojiManager.addEmoji(new Emoji(0x1f55a, R.drawable.emoji_recent, false)); recentEmojiManager.addEmoji(new Emoji(0x1f561, R.drawable.emoji_recent, false)); recentEmojiManager.addEmoji(new Emoji(0x1f4e2, R.drawable.emoji_recent, false)); recentEmojiManager.addEmoji(new Emoji(0x1f562, R.drawable.emoji_recent, false)); recentEmojiManager.addEmoji(new Emoji(0xe535, R.drawable.emoji_recent, false)); recentEmojiManager.addEmoji(new Emoji(0x1f563, R.drawable.emoji_recent, false)); recentEmojiManager.persist(); final Collection<Emoji> recentEmojis = recentEmojiManager.getRecentEmojis(); assertThat(recentEmojis).containsExactly( new Emoji(0x1f563, R.drawable.emoji_recent, false), new Emoji(0xe535, R.drawable.emoji_recent, false), new Emoji(0x1f562, R.drawable.emoji_recent, false), new Emoji(0x1f4e2, R.drawable.emoji_recent, false), new Emoji(0x1f561, R.drawable.emoji_recent, false), new Emoji(0x1f55a, R.drawable.emoji_recent, false)); }
Example #3
Source File: RecentEmojiManager.java From Emoji with Apache License 2.0 | 6 votes |
void add(final Emoji emoji, final long timestamp) { final Iterator<Data> iterator = emojis.iterator(); final Emoji emojiBase = emoji.getBase(); while (iterator.hasNext()) { final Data data = iterator.next(); if (data.emoji.getBase().equals(emojiBase)) { // Do the comparison by base so that skin tones are only saved once. iterator.remove(); } } emojis.add(0, new Data(emoji, timestamp)); if (emojis.size() > MAX_RECENTS) { emojis.remove(MAX_RECENTS); } }
Example #4
Source File: TestEmojiProvider.java From Emoji with Apache License 2.0 | 6 votes |
static EmojiProvider emptyEmojis() { return new EmojiProvider() { @Override @NonNull public EmojiCategory[] getCategories() { return new EmojiCategory[] { new EmojiCategory() { @Override @NonNull public Emoji[] getEmojis() { return new Emoji[0]; } @Override public int getIcon() { return 0; } @Override public int getCategoryName() { return 0; } } }; } }; }
Example #5
Source File: VariantEmojiManager.java From Emoji with Apache License 2.0 | 6 votes |
private void initFromSharedPreferences() { final String savedRecentVariants = getPreferences().getString(VARIANT_EMOJIS, ""); if (savedRecentVariants.length() > 0) { final StringTokenizer stringTokenizer = new StringTokenizer(savedRecentVariants, EMOJI_DELIMITER); variantsList = new ArrayList<>(stringTokenizer.countTokens()); while (stringTokenizer.hasMoreTokens()) { final String token = stringTokenizer.nextToken(); final Emoji emoji = EmojiManager.getInstance().findEmoji(token); if (emoji != null && emoji.getLength() == token.length()) { variantsList.add(emoji); } } } }
Example #6
Source File: VariantEmojiManager.java From Emoji with Apache License 2.0 | 6 votes |
@Override public void addVariant(@NonNull final Emoji newVariant) { final Emoji newVariantBase = newVariant.getBase(); for (int i = 0; i < variantsList.size(); i++) { final Emoji variant = variantsList.get(i); if (variant.getBase().equals(newVariantBase)) { if (variant.equals(newVariant)) { return; // Same skin-tone was used. } else { variantsList.remove(i); variantsList.add(newVariant); return; } } } variantsList.add(newVariant); }
Example #7
Source File: VariantEmojiManager.java From Emoji with Apache License 2.0 | 6 votes |
@Override @NonNull public Emoji getVariant(final Emoji desiredEmoji) { if (variantsList.isEmpty()) { initFromSharedPreferences(); } final Emoji baseEmoji = desiredEmoji.getBase(); for (int i = 0; i < variantsList.size(); i++) { final Emoji emoji = variantsList.get(i); if (baseEmoji.equals(emoji.getBase())) { return emoji; } } return desiredEmoji; }
Example #8
Source File: EmojiArrayAdapter.java From Emoji with Apache License 2.0 | 6 votes |
@Override @NonNull public View getView(final int position, final View convertView, @NonNull final ViewGroup parent) { EmojiImageView image = (EmojiImageView) convertView; final Context context = getContext(); if (image == null) { image = (EmojiImageView) LayoutInflater.from(context).inflate(R.layout.emoji_adapter_item, parent, false); image.setOnEmojiClickListener(listener); image.setOnEmojiLongClickListener(longListener); } final Emoji emoji = checkNotNull(getItem(position), "emoji == null"); final Emoji variantToUse = variantManager == null ? emoji : variantManager.getVariant(emoji); image.setContentDescription(emoji.getUnicode()); image.setEmoji(variantToUse); return image; }
Example #9
Source File: RecentEmojiManager.java From hipda with GNU General Public License v2.0 | 6 votes |
void add(final Emoji emoji, final long timestamp) { final Iterator<Data> iterator = emojis.iterator(); while (iterator.hasNext()) { final Data data = iterator.next(); if (data.emoji.equals(emoji)) { iterator.remove(); } } emojis.add(0, new Data(emoji, timestamp)); if (emojis.size() > MAX_RECENTS) { emojis.remove(MAX_RECENTS); } }
Example #10
Source File: EmojiManager.java From Emoji with Apache License 2.0 | 6 votes |
@NonNull List<EmojiRange> findAllEmojis(@Nullable final CharSequence text) { verifyInstalled(); final List<EmojiRange> result = new ArrayList<>(); if (!TextUtils.isEmpty(text)) { final Matcher matcher = emojiPattern.matcher(text); while (matcher.find()) { final Emoji found = findEmoji(text.subSequence(matcher.start(), matcher.end())); if (found != null) { result.add(new EmojiRange(matcher.start(), matcher.end(), found)); } } } return result; }
Example #11
Source File: ProductDetailActivity.java From FaceT with Mozilla Public License 2.0 | 5 votes |
private void setUpEmojiPopup() { emojiPopup = EmojiPopup.Builder.fromRootView(activity_product_detail_layout) .setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() { @Override public void onEmojiBackspaceClick(final View v) { Log.d(TAG, "Clicked on Backspace"); } }) .setOnEmojiClickListener(new OnEmojiClickListener() { @Override public void onEmojiClick(@NonNull final EmojiImageView imageView, @NonNull final Emoji emoji) { Log.d(TAG, "Clicked on emoji"); } }) .setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() { @Override public void onEmojiPopupShown() { emojiButton.setBackground(ContextCompat.getDrawable(ProductDetailActivity.this, R.drawable.ic_keyboard)); } }) .setOnSoftKeyboardOpenListener(new OnSoftKeyboardOpenListener() { @Override public void onKeyboardOpen(final int keyBoardHeight) { Log.d(TAG, "Opened soft keyboard"); } }) .setOnEmojiPopupDismissListener(new OnEmojiPopupDismissListener() { @Override public void onEmojiPopupDismiss() { emojiButton.setBackground(ContextCompat.getDrawable(ProductDetailActivity.this, R.drawable.emoji_one_category_people)); } }) .setOnSoftKeyboardCloseListener(new OnSoftKeyboardCloseListener() { @Override public void onKeyboardClose() { emojiPopup.dismiss(); Log.d(TAG, "Closed soft keyboard"); } }) .build(commentEmojiconEditText); }
Example #12
Source File: RecentEmojiManager.java From hipda with GNU General Public License v2.0 | 5 votes |
@NonNull @Override public Collection<Emoji> getRecentEmojis() { if (emojiList.size() == 0) { final String savedRecentEmojis = getPreferences().getString(RECENT_EMOJIS, ""); if (savedRecentEmojis.length() > 0) { final StringTokenizer stringTokenizer = new StringTokenizer(savedRecentEmojis, EMOJI_DELIMITER); emojiList = new EmojiList(stringTokenizer.countTokens()); while (stringTokenizer.hasMoreTokens()) { final String token = stringTokenizer.nextToken(); final String[] parts = token.split(TIME_DELIMITER); if (parts.length == 2) { final Emoji emoji = new Emoji(parts[0]); final long timestamp = Long.parseLong(parts[1]); emojiList.add(emoji, timestamp); } } } else { emojiList = new EmojiList(0); } } return emojiList.getEmojis(); }
Example #13
Source File: VariantEmojiManagerTest.java From Emoji with Apache License 2.0 | 5 votes |
@Before public void setUp() { variantEmojiManager = new VariantEmojiManager(RuntimeEnvironment.application); emoji = new Emoji(0x1f437, R.drawable.emoji_recent, false); variant1 = new Emoji(0x1f55b, R.drawable.emoji_recent, false); variant2 = new Emoji(0x1f55c, R.drawable.emoji_recent, false); variant3 = new Emoji(0x1f55d, R.drawable.emoji_recent, false); base = new Emoji(0x1f55a, R.drawable.emoji_recent, false, variant1, variant2, variant3); }
Example #14
Source File: ProfileEditActivity.java From FaceT with Mozilla Public License 2.0 | 5 votes |
private void setUpEmojiPopup() { emojiPopup = EmojiPopup.Builder.fromRootView(rootView) .setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() { @Override public void onEmojiBackspaceClick(final View v) { Log.d(TAG, "Clicked on Backspace"); } }) .setOnEmojiClickListener(new OnEmojiClickListener() { @Override public void onEmojiClick(@NonNull final EmojiImageView imageView, @NonNull final Emoji emoji) { Log.d(TAG, "Clicked on emoji"); } }) .setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() { @Override public void onEmojiPopupShown() { emojiButton.setImageResource(R.drawable.ic_keyboard); } }) .setOnSoftKeyboardOpenListener(new OnSoftKeyboardOpenListener() { @Override public void onKeyboardOpen(final int keyBoardHeight) { Log.d(TAG, "Opened soft keyboard"); } }) .setOnEmojiPopupDismissListener(new OnEmojiPopupDismissListener() { @Override public void onEmojiPopupDismiss() { emojiPopup.dismiss(); emojiButton.setImageResource(R.drawable.emoji_one_category_people); } }) .setOnSoftKeyboardCloseListener(new OnSoftKeyboardCloseListener() { @Override public void onKeyboardClose() { emojiPopup.dismiss(); Log.d(TAG, "Closed soft keyboard"); } }) .build(aboutMeEdittext); }
Example #15
Source File: EmojiEditText.java From hipda with GNU General Public License v2.0 | 5 votes |
public void input(final Emoji emoji) { if (emoji != null) { final int start = getSelectionStart(); final int end = getSelectionEnd(); if (start < 0) { append(emoji.getEmoji()); } else { getText().replace(Math.min(start, end), Math.max(start, end), emoji.getEmoji(), 0, emoji.getEmoji().length()); } } }
Example #16
Source File: EmojiGridView.java From hipda with GNU General Public License v2.0 | 5 votes |
public EmojiGridView init(final Emoji[] emojis, @Nullable final OnEmojiClickedListener onEmojiClickedListener) { final GridView gridView = (GridView) findViewById(R.id.emoji_grid_view); final EmojiArrayAdapter emojiArrayAdapter = new EmojiArrayAdapter(getContext(), emojis); emojiArrayAdapter.setOnEmojiClickedListener(onEmojiClickedListener); gridView.setAdapter(emojiArrayAdapter); return this; }
Example #17
Source File: RecentEmojiManager.java From hipda with GNU General Public License v2.0 | 5 votes |
Collection<Emoji> getEmojis() { Collections.sort(emojis, COMPARATOR); final Collection<Emoji> sortedEmojis = new ArrayList<>(emojis.size()); for (final Data data : emojis) { sortedEmojis.add(data.emoji); } return sortedEmojis; }
Example #18
Source File: RecentEmojiGridView.java From hipda with GNU General Public License v2.0 | 5 votes |
public RecentEmojiGridView init(@Nullable final OnEmojiClickedListener onEmojiClickedListener) { final Collection<Emoji> emojis = recentEmojis.getRecentEmojis(); final GridView gridView = (GridView) findViewById(R.id.emoji_grid_view); emojiArrayAdapter = new EmojiArrayAdapter(getContext(), emojis.toArray(new Emoji[emojis.size()])); emojiArrayAdapter.setOnEmojiClickedListener(onEmojiClickedListener); gridView.setAdapter(emojiArrayAdapter); return this; }
Example #19
Source File: TwitterEmoji.java From Emoji with Apache License 2.0 | 5 votes |
public TwitterEmoji(@NonNull final int[] codePoints, final int x, final int y, final boolean isDuplicate, final Emoji... variants) { super(codePoints, -1, isDuplicate, variants); this.x = x; this.y = y; }
Example #20
Source File: IosEmoji.java From Emoji with Apache License 2.0 | 5 votes |
public IosEmoji(final int codePoint, final int x, final int y, final boolean isDuplicate, final Emoji... variants) { super(codePoint, -1, isDuplicate, variants); this.x = x; this.y = y; }
Example #21
Source File: RecentEmojiManagerTest.java From Emoji with Apache License 2.0 | 5 votes |
@Test public void duplicateEmojis() { final Emoji emoji = new Emoji(0x1f437, R.drawable.emoji_recent, false); recentEmojiManager.addEmoji(emoji); recentEmojiManager.addEmoji(emoji); recentEmojiManager.persist(); final Collection<Emoji> recentEmojis = recentEmojiManager.getRecentEmojis(); assertThat(recentEmojis).hasSize(1).containsExactly(emoji); }
Example #22
Source File: RecentEmojiManagerTest.java From Emoji with Apache License 2.0 | 5 votes |
@Test public void persist() { final Emoji firstEmoji = new Emoji(0x1f437, R.drawable.emoji_recent, false); recentEmojiManager.addEmoji(firstEmoji); final Emoji secondEmoji = new Emoji(0x1f43d, R.drawable.emoji_recent, false); recentEmojiManager.addEmoji(secondEmoji); recentEmojiManager.persist(); final Collection<Emoji> recentEmojis = recentEmojiManager.getRecentEmojis(); assertThat(recentEmojis).hasSize(2).containsExactly(secondEmoji, firstEmoji); }
Example #23
Source File: RecentEmojiManagerTest.java From Emoji with Apache License 2.0 | 5 votes |
@Test public void addEmoji() { recentEmojiManager.addEmoji(new Emoji(0x1f437, R.drawable.emoji_recent, false)); recentEmojiManager.addEmoji(new Emoji(0x1f43d, R.drawable.emoji_recent, false)); assertThat(recentEmojiManager.getRecentEmojis()).hasSize(2) .containsExactly( new Emoji(0x1f43d, R.drawable.emoji_recent, false), new Emoji(0x1f437, R.drawable.emoji_recent, false)); }
Example #24
Source File: RecentEmojiManagerTest.java From Emoji with Apache License 2.0 | 5 votes |
@Test public void maxRecents() { for (int i = 0; i < 500; i++) { recentEmojiManager.addEmoji(new Emoji(i, R.drawable.emoji_recent, false)); } assertThat(recentEmojiManager.getRecentEmojis()).hasSize(40); }
Example #25
Source File: EmojiManagerTest.java From Emoji with Apache License 2.0 | 5 votes |
@Test public void findAllEmojisNormal() { EmojiManager.install(provider); final String text = "te" + new String(new int[]{0x5678}, 0, 1) + "st" + new String(new int[]{0x1234}, 0, 1); final EmojiRange firstExpectedRange = new EmojiRange(2, 3, new Emoji(new int[]{0x5678}, R.drawable.emoji_backspace, false)); final EmojiRange secondExpectedRange = new EmojiRange(5, 6, new Emoji(new int[]{0x1234}, R.drawable.emoji_recent, false)); assertThat(EmojiManager.getInstance().findAllEmojis(text)) .containsExactly(firstExpectedRange, secondExpectedRange); }
Example #26
Source File: EmojiArrayAdapter.java From Emoji with Apache License 2.0 | 5 votes |
EmojiArrayAdapter(@NonNull final Context context, @NonNull final Emoji[] emojis, @Nullable final VariantEmoji variantManager, @Nullable final OnEmojiClickListener listener, @Nullable final OnEmojiLongClickListener longListener) { super(context, 0, asListWithoutDuplicates(emojis)); this.variantManager = variantManager; this.listener = listener; this.longListener = longListener; }
Example #27
Source File: Utils.java From Emoji with Apache License 2.0 | 5 votes |
static void input(@NonNull final EditText editText, @Nullable final Emoji emoji) { if (emoji != null) { final int start = editText.getSelectionStart(); final int end = editText.getSelectionEnd(); if (start < 0) { editText.append(emoji.getUnicode()); } else { editText.getText().replace(Math.min(start, end), Math.max(start, end), emoji.getUnicode(), 0, emoji.getUnicode().length()); } } }
Example #28
Source File: Utils.java From Emoji with Apache License 2.0 | 5 votes |
static List<Emoji> asListWithoutDuplicates(final Emoji[] emojis) { final List<Emoji> result = new ArrayList<>(emojis.length); for (final Emoji emoji : emojis) { if (!emoji.isDuplicate()) { result.add(emoji); } } return result; }
Example #29
Source File: EmojiPopup.java From Emoji with Apache License 2.0 | 5 votes |
@Override public void onEmojiClick(@NonNull final EmojiImageView imageView, @NonNull final Emoji emoji) { Utils.input(editText, emoji); recentEmoji.addEmoji(emoji); variantEmoji.addVariant(emoji); imageView.updateEmoji(emoji); if (onEmojiClickListener != null) { onEmojiClickListener.onEmojiClick(imageView, emoji); } variantPopup.dismiss(); }
Example #30
Source File: EmojiVariantPopup.java From Emoji with Apache License 2.0 | 5 votes |
private View initView(@NonNull final Context context, @NonNull final Emoji emoji, final int width) { final View result = View.inflate(context, R.layout.emoji_popup_window_skin, null); final LinearLayout imageContainer = result.findViewById(R.id.emojiPopupWindowSkinPopupContainer); final List<Emoji> variants = emoji.getBase().getVariants(); variants.add(0, emoji.getBase()); final LayoutInflater inflater = LayoutInflater.from(context); for (final Emoji variant : variants) { final ImageView emojiImage = (ImageView) inflater.inflate(R.layout.emoji_adapter_item, imageContainer, false); final ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) emojiImage.getLayoutParams(); final int margin = Utils.dpToPx(context, MARGIN); // Use the same size for Emojis as in the picker. layoutParams.width = width; layoutParams.setMargins(margin, margin, margin, margin); emojiImage.setImageDrawable(variant.getDrawable(context)); emojiImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { if (listener != null && rootImageView != null) { listener.onEmojiClick(rootImageView, variant); } } }); imageContainer.addView(emojiImage); } return result; }