0

Could someone help me understand or guide me on some reading material on how to create emoticons and how they work on android?

I need to know the whole process from a layman versus programmatical point of view.

user2230604
  • 31
  • 1
  • 1
  • 3
  • How exactly do you want to use emoticons? As far as I know there's no special procedure; you just use Imageviews or tags in Webview. A quick google search showed http://stackoverflow.com/questions/3341702/displaying-emoticons-in-android and http://androidcodeexamples.blogspot.tw/2011/08/how-to-add-smileyemojis-in-edittext.html that may be helpful to you. – Matter Cat Mar 06 '15 at 05:32
  • here it is . what you want https://github.com/rockerhieu/emojicon – Qadir Hussain Mar 06 '15 at 05:52
  • 1
    https://github.com/rockerhieu/emojicon basically customize the EditText and TextView, Just place them. in your layout and you will see your emojis in the editText and Text view. :) – Qadir Hussain Mar 06 '15 at 05:53
  • i am basically looking for making custom emoticon and binding it to custom defined keystrokes – user2230604 Mar 06 '15 at 06:02

3 Answers3

4

We cannot create our own custom emoticons for generic keyboard in android. Because these images are stored in form of codes. which may not be implemented by facebook,skype and other. We have to follow the build in emoticons See list,

If you want to use them within your app. Use this

See this and this.

See SoftKeyboard sample here

And tutorial on Creating a Custom keyboard

Community
  • 1
  • 1
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
  • forget about binding , i cant even create custom pngs n use it as emoticons? – user2230604 Mar 06 '15 at 08:01
  • suppose you have implemented it at your end. How other social sites may know what do you send like /uu1003d? . When you send emoticons using skype. These codes are stored at both ends. You can use it within your app. if on both ends your app works – Zar E Ahmer Mar 06 '15 at 08:06
2

See the article : https://www.androidhive.info/2016/11/android-integrate-emojis-keyboard-app/ to understand how emojis works and how to implement emoji feature for your application.

See the article : https://apps.timwhitlock.info/emoji/tables/unicode to determine the unicode of emojis.

you can get input emoji from keyboard. resize it according to your requirement.for rotation and flipping support you can play with the layout, holding the emoji.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
1

use custom library : https://github.com/rockerhieu/emojicon

public class EmojiKeyboard {

    private static final String TAG = "EmojiKeyboard";
    private static final String PREF_KEY_HEIGHT_KB = "EmojiKbHeight";

    private Context context;
    private int screenHeight = -1;
    private int emojiKbHeight = -1;
    private PopupWindow emojiKeyboardPopup;
    private View view;
    private SharedPreferences preferences;

    public EmojiKeyboard(Context context, View view) {
        if (context instanceof Activity) {
            this.context = context;
            this.view = view;
            preferences = context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE);

            //Restore EmojiKeyboard Height
            emojiKbHeight = preferences.getInt(PREF_KEY_HEIGHT_KB, -1);

            //TODO support less then 11 API, and not perfect resizing when switched the keyboard
            view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    /*
                    * Get root view height
                    * */
                    screenHeight = screenHeight == -1 && bottom > oldBottom
                            ? bottom
                            : screenHeight;

                    /*
                    * Calculate soft keyboard height
                    * */
                    int dHeight = oldBottom - bottom;
                    boolean validHeight = emojiKbHeight == -1 && dHeight > 80 && bottom != oldBottom;

                    /*
                    * Сheck twice because the keyboard may have been switched
                    * */
                    emojiKbHeight = validHeight
                            ? dHeight : emojiKbHeight != (dHeight) && dHeight > 0
                            ? dHeight
                            : emojiKbHeight;

                    /*
                    * Store emoji keyboard height into SharedPreferences
                    * */
                    preferences.edit().putInt(PREF_KEY_HEIGHT_KB, emojiKbHeight).commit();

                    /*
                    * If layout returned to a standard height then dismissing keyboard (OnBackPressed)
                    * */
                    if (screenHeight == bottom) {
                        dismissEmojiKeyboard();
                    }

                    /*
                    * Resize emoji on the go when a user switches between keyboards
                    * */
                    resizeEmoji();
                }
            });
        }
    }


    public void showEmoji() {
        if (emojiKeyboardPopup == null) {
            createEmojiKeyboard();
        }
        if (!isShowed()) {
            new Handler().postDelayed(new Runnable() {
                public void run() {
                    emojiKeyboardPopup.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                    resizeEmoji();
                }
            }, 10L);

        } else {
            dismissEmojiKeyboard();
        }
    }

    public void createEmojiKeyboard() {
        EmojiView emojiKeyboard = new EmojiView(context, EmojiView.EMOJI_DARK_STYLE, new EmojiView.onEmojiClickListener() {
            public void onBackspace() {
                if (((Activity) context).getWindow().getCurrentFocus() instanceof EditText) {
                    ((Activity) context).getWindow().getCurrentFocus().dispatchKeyEvent(new KeyEvent(0, 67));
                }
            }

            public void onEmojiSelected(Emojicon emojicon) {
                if (((Activity) context).getWindow().getCurrentFocus() instanceof EditText) {
                    EmojiView.input((EditText) ((Activity) context).getWindow().getCurrentFocus(), emojicon);
                }
            }
        });
        emojiKeyboardPopup = new PopupWindow(emojiKeyboard);
        emojiKeyboardPopup.setHeight(View.MeasureSpec.makeMeasureSpec(setEmojiKeyboardHeight(), View.MeasureSpec.EXACTLY));
        emojiKeyboardPopup.setWidth(View.MeasureSpec.makeMeasureSpec(getDisplayDimensions(context).x, View.MeasureSpec.EXACTLY));
        emojiKeyboardPopup.setAnimationStyle(0);
    }

    public void dismissEmojiKeyboard() {
        if (isShowed()) {
            emojiKeyboardPopup.dismiss();
        }
    }

    public boolean isShowed() {
        return emojiKeyboardPopup != null && emojiKeyboardPopup.isShowing();
    }

    /*
    * Emoji set up size
    * */
    public void resizeEmoji() {
        if (isShowed()) {
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) emojiKeyboardPopup.getContentView().getLayoutParams();
            layoutParams.height = setEmojiKeyboardHeight();
            wm.updateViewLayout(emojiKeyboardPopup.getContentView(), layoutParams);
        }
    }

    public int setEmojiKeyboardHeight() {
        return emojiKbHeight == -1 && emojiKbHeight != screenHeight && emojiKbHeight < 80
                ? (getDisplayDimensions(context).y / 2)
                : emojiKbHeight;
    }

    public Point getDisplayDimensions(Context context) {
        Point size = new Point();
        WindowManager w = ((Activity) context).getWindowManager();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
            w.getDefaultDisplay().getSize(size);
        } else {
            Display d = w.getDefaultDisplay();
            size.x = d.getWidth();
            size.y = d.getHeight();
        }
        return size;
    }
}
Sonu Kumar
  • 969
  • 1
  • 11
  • 36