diff --git a/example/src/main/java/momanii/hani/supernova_emoji/MainActivity.java b/example/src/main/java/momanii/hani/supernova_emoji/MainActivity.java
index ce20038..d9a5fdb 100644
--- a/example/src/main/java/momanii/hani/supernova_emoji/MainActivity.java
+++ b/example/src/main/java/momanii/hani/supernova_emoji/MainActivity.java
@@ -15,7 +15,7 @@
public class MainActivity extends AppCompatActivity {
CheckBox mCheckBox;
- EmojiconEditText emojiconEditText;
+ EmojiconEditText emojiconEditText, emojiconEditText2;
EmojiconTextView textView;
ImageView emojiButton;
ImageView submitButton;
@@ -32,18 +32,19 @@ protected void onCreate(Bundle savedInstanceState) {
submitButton = (ImageView) findViewById(R.id.submit_btn);
mCheckBox = (CheckBox) findViewById(R.id.use_system_default);
emojiconEditText = (EmojiconEditText) findViewById(R.id.emojicon_edit_text);
+ emojiconEditText2 = (EmojiconEditText) findViewById(R.id.emojicon_edit_text2);
textView = (EmojiconTextView) findViewById(R.id.textView);
- emojIcon=new EmojIconActions(this,rootView,emojiconEditText,emojiButton);
+ emojIcon = new EmojIconActions(this, rootView, emojiconEditText, emojiButton);
emojIcon.ShowEmojIcon();
emojIcon.setKeyboardListener(new EmojIconActions.KeyboardListener() {
@Override
public void onKeyboardOpen() {
- Log.e("Keyboard","open");
+ Log.e("Keyboard", "open");
}
@Override
public void onKeyboardClose() {
- Log.e("Keyboard","close");
+ Log.e("Keyboard", "close");
}
});
@@ -54,7 +55,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
textView.setUseSystemDefault(b);
}
});
-
+ emojIcon.addEmojiconEditTextList(emojiconEditText2);
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -66,9 +67,4 @@ public void onClick(View v) {
}
-
-
-
-
-
}
diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml
index be786e7..ed956de 100644
--- a/example/src/main/res/layout/activity_main.xml
+++ b/example/src/main/res/layout/activity_main.xml
@@ -41,6 +41,16 @@
emojicon:emojiconSize="28sp"/>
+
+
+
emojiconEditTextList = new ArrayList<>();
+ private EmojiconEditText emojiconEditText;
/**
* Constructor
- * @param ctx The context of current activity.
- * @param rootView The top most layout in your view hierarchy. The difference of this view and the screen height will be used to calculate the keyboard height.
+ *
+ * @param ctx The context of current activity.
+ * @param rootView The top most layout in your view hierarchy. The difference of this
+ * view and the screen height will be used to calculate the keyboard
+ * height.
* @param emojiconEditText The Id of EditText.
- * @param emojiButton The Id of ImageButton used to open Emoji
+ * @param emojiButton The Id of ImageButton used to open Emoji
*/
- public EmojIconActions(Context ctx,View rootView,EmojiconEditText emojiconEditText,ImageView emojiButton)
- {
- this.emojiconEditText=emojiconEditText;
- this.emojiButton=emojiButton;
- this.context=ctx;
- this.rootView=rootView;
- this.popup = new EmojiconsPopup(rootView, ctx,useSystemEmoji);
+ public EmojIconActions(Context ctx, View rootView, EmojiconEditText emojiconEditText,
+ ImageView emojiButton) {
+ this.emojiButton = emojiButton;
+ this.context = ctx;
+ this.rootView = rootView;
+ addEmojiconEditTextList(emojiconEditText);
+ this.popup = new EmojiconsPopup(rootView, ctx, useSystemEmoji);
+ }
+
+ public void addEmojiconEditTextList(EmojiconEditText... emojiconEditText) {
+ Collections.addAll(emojiconEditTextList, emojiconEditText);
+ for (EmojiconEditText editText : emojiconEditText) {
+ editText.setOnFocusChangeListener(this);
+ }
}
/**
* Constructor
- * @param ctx The context of current activity.
- * @param rootView The top most layout in your view hierarchy. The difference of this view and the screen height will be used to calculate the keyboard height.
+ *
+ * @param ctx The context of current activity.
+ * @param rootView The top most layout in your view hierarchy. The difference of this
+ * view and the screen height will be used to calculate the keyboard
+ * height.
* @param emojiconEditText The Id of EditText.
- * @param emojiButton The Id of ImageButton used to open Emoji
+ * @param emojiButton The Id of ImageButton used to open Emoji
* @param iconPressedColor The color of icons on tab
- * @param tabsColor The color of tabs background
- * @param backgroundColor The color of emoji background
+ * @param tabsColor The color of tabs background
+ * @param backgroundColor The color of emoji background
*/
- public EmojIconActions(Context ctx,View rootView,EmojiconEditText emojiconEditText,ImageView emojiButton,String iconPressedColor,String tabsColor,String backgroundColor)
- {
- this.emojiconEditText=emojiconEditText;
- this.emojiButton=emojiButton;
- this.context=ctx;
- this.rootView=rootView;
- this.popup = new EmojiconsPopup(rootView, ctx,useSystemEmoji,iconPressedColor,tabsColor,backgroundColor);
+ public EmojIconActions(Context ctx, View rootView, EmojiconEditText emojiconEditText,
+ ImageView emojiButton, String iconPressedColor, String tabsColor,
+ String backgroundColor) {
+ addEmojiconEditTextList(emojiconEditText);
+ this.emojiButton = emojiButton;
+ this.context = ctx;
+ this.rootView = rootView;
+ this.popup = new EmojiconsPopup(rootView, ctx, useSystemEmoji, iconPressedColor,
+ tabsColor, backgroundColor);
}
- public void setIconsIds(int keyboardIcon,int smileyIcon)
- {
- this.KeyBoardIcon=keyboardIcon;
- this.SmileyIcons=smileyIcon;
+ public void setIconsIds(int keyboardIcon, int smileyIcon) {
+ this.KeyBoardIcon = keyboardIcon;
+ this.SmileyIcons = smileyIcon;
}
- public void setUseSystemEmoji(boolean useSystemEmoji)
- {
- this.useSystemEmoji=useSystemEmoji;
- this.emojiconEditText.setUseSystemDefault(useSystemEmoji);
+ public void setUseSystemEmoji(boolean useSystemEmoji) {
+ this.useSystemEmoji = useSystemEmoji;
+ for (EmojiconEditText editText : emojiconEditTextList) {
+ editText.setUseSystemDefault(useSystemEmoji);
+ }
refresh();
}
- private void refresh()
- {
- popup.updateUseSystemDefault(useSystemEmoji);
+ private void refresh() {
+ popup.updateUseSystemDefault(useSystemEmoji);
}
-
- public void ShowEmojIcon( )
- {
-
+ public void ShowEmojIcon() {
+ if (emojiconEditText == null)
+ emojiconEditText = emojiconEditTextList.get(0);
//Will automatically set size according to the soft keyboard size
popup.setSizeForSoftKeyboard();
@@ -112,12 +130,13 @@ public void ShowEmojIcon( )
@Override
public void onDismiss() {
- changeEmojiKeyboardIcon(emojiButton,SmileyIcons);
+ changeEmojiKeyboardIcon(emojiButton, SmileyIcons);
}
});
//If the text keyboard closes, also dismiss the emoji popup
- popup.setOnSoftKeyboardOpenCloseListener(new EmojiconsPopup.OnSoftKeyboardOpenCloseListener() {
+ popup.setOnSoftKeyboardOpenCloseListener(new EmojiconsPopup
+ .OnSoftKeyboardOpenCloseListener() {
@Override
public void onKeyboardOpen(int keyBoardHeight) {
@@ -129,7 +148,7 @@ public void onKeyboardOpen(int keyBoardHeight) {
public void onKeyboardClose() {
if (keyboardListener != null)
keyboardListener.onKeyboardClose();
- if(popup.isShowing())
+ if (popup.isShowing())
popup.dismiss();
}
});
@@ -139,7 +158,7 @@ public void onKeyboardClose() {
@Override
public void onEmojiconClicked(Emojicon emojicon) {
- if (emojiconEditText == null || emojicon == null) {
+ if (emojicon == null) {
return;
}
@@ -156,7 +175,8 @@ public void onEmojiconClicked(Emojicon emojicon) {
});
//On backspace clicked, emulate the KEYCODE_DEL key event
- popup.setOnEmojiconBackspaceClickedListener(new EmojiconsPopup.OnEmojiconBackspaceClickedListener() {
+ popup.setOnEmojiconBackspaceClickedListener(new EmojiconsPopup
+ .OnEmojiconBackspaceClickedListener() {
@Override
public void onEmojiconBackspaceClicked(View v) {
@@ -167,62 +187,78 @@ public void onEmojiconBackspaceClicked(View v) {
});
// To toggle between text keyboard and emoji keyboard keyboard(Popup)
+ showForEditText();
+ }
+
+ private void showForEditText() {
+
emojiButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
-
+ if (emojiconEditText == null)
+ emojiconEditText = emojiconEditTextList.get(0);
//If popup is not showing => emoji keyboard is not visible, we need to show it
- if(!popup.isShowing()){
+ if (!popup.isShowing()) {
//If keyboard is visible, simply show the emoji popup
- if(popup.isKeyBoardOpen()){
+ if (popup.isKeyBoardOpen()) {
popup.showAtBottom();
- changeEmojiKeyboardIcon(emojiButton,KeyBoardIcon);
+ changeEmojiKeyboardIcon(emojiButton, KeyBoardIcon);
}
- //else, open the text keyboard first and immediately after that show the emoji popup
- else{
+ //else, open the text keyboard first and immediately after that show the
+ // emoji popup
+ else {
emojiconEditText.setFocusableInTouchMode(true);
emojiconEditText.requestFocus();
- final InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
- inputMethodManager.showSoftInput(emojiconEditText, InputMethodManager.SHOW_IMPLICIT);
+ final InputMethodManager inputMethodManager = (InputMethodManager)
+ context.getSystemService(Context.INPUT_METHOD_SERVICE);
+ inputMethodManager.showSoftInput(emojiconEditText, InputMethodManager
+ .SHOW_IMPLICIT);
popup.showAtBottomPending();
- changeEmojiKeyboardIcon(emojiButton,KeyBoardIcon);
+ changeEmojiKeyboardIcon(emojiButton, KeyBoardIcon);
}
}
//If popup is showing, simply dismiss it to show the undelying text keyboard
- else{
+ else {
popup.dismiss();
}
}
});
-
}
- public void closeEmojIcon()
- {
- if(popup!=null &&popup.isShowing())
- popup.dismiss();
+ public void closeEmojIcon() {
+ if (popup != null && popup.isShowing())
+ popup.dismiss();
}
- private void changeEmojiKeyboardIcon(ImageView iconToBeChanged, int drawableResourceId){
+ private void changeEmojiKeyboardIcon(ImageView iconToBeChanged, int drawableResourceId) {
iconToBeChanged.setImageResource(drawableResourceId);
}
+ @Override
+ public void onFocusChange(View view, boolean hasFocus) {
+ if (hasFocus) {
+ if (view instanceof EmojiconEditText) {
+ emojiconEditText = (EmojiconEditText) view;
+ }
+ }
+ }
- public interface KeyboardListener{
+ public interface KeyboardListener {
void onKeyboardOpen();
+
void onKeyboardClose();
}
- public void setKeyboardListener(KeyboardListener listener){
+ public void setKeyboardListener(KeyboardListener listener) {
this.keyboardListener = listener;
}