Skip to content

Commit

Permalink
Add Multi editText support
Browse files Browse the repository at this point in the history
  • Loading branch information
hani-momanii committed Apr 5, 2017
1 parent 3849ee1 commit cb1af98
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class MainActivity extends AppCompatActivity {

CheckBox mCheckBox;
EmojiconEditText emojiconEditText;
EmojiconEditText emojiconEditText, emojiconEditText2;
EmojiconTextView textView;
ImageView emojiButton;
ImageView submitButton;
Expand All @@ -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");
}
});

Expand All @@ -54,7 +55,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
textView.setUseSystemDefault(b);
}
});

emojIcon.addEmojiconEditTextList(emojiconEditText2);

submitButton.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -66,9 +67,4 @@ public void onClick(View v) {
}







}
10 changes: 10 additions & 0 deletions example/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
emojicon:emojiconSize="28sp"/>


<hani.momanii.supernova_emoji_library.Helper.EmojiconEditText
android:id="@+id/emojicon_edit_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/emojicon_edit_text"
android:imeOptions="actionSend"
android:inputType="text"
emojicon:emojiconSize="28sp"/>


<CheckBox
android:id="@+id/use_system_default"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import android.widget.ImageView;
import android.widget.PopupWindow;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import hani.momanii.supernova_emoji_library.Helper.EmojiconEditText;
import hani.momanii.supernova_emoji_library.Helper.EmojiconGridView;
import hani.momanii.supernova_emoji_library.Helper.EmojiconsPopup;
Expand All @@ -32,78 +36,92 @@
/**
* @author Hani Al Momani (hani.momanii@gmail.com)
*/
public class EmojIconActions {
public class EmojIconActions implements View.OnFocusChangeListener {

boolean useSystemEmoji=false;
EmojiconsPopup popup;
Context context;
View rootView;
ImageView emojiButton;
EmojiconEditText emojiconEditText;
int KeyBoardIcon= R.drawable.ic_action_keyboard;
int SmileyIcons= R.drawable.smiley;
KeyboardListener keyboardListener;
private boolean useSystemEmoji = false;
private EmojiconsPopup popup;
private Context context;
private View rootView;
private ImageView emojiButton;
private int KeyBoardIcon = R.drawable.ic_action_keyboard;
private int SmileyIcons = R.drawable.smiley;
private KeyboardListener keyboardListener;
private List<EmojiconEditText> 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();

Expand All @@ -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) {
Expand All @@ -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();
}
});
Expand All @@ -139,7 +158,7 @@ public void onKeyboardClose() {

@Override
public void onEmojiconClicked(Emojicon emojicon) {
if (emojiconEditText == null || emojicon == null) {
if (emojicon == null) {
return;
}

Expand All @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit cb1af98

Please sign in to comment.