-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3849ee1
commit cb1af98
Showing
3 changed files
with
122 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -32,78 +36,92 @@ | |
/** | ||
* @author Hani Al Momani ([email protected]) | ||
*/ | ||
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(); | ||
|
||
|
@@ -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; | ||
} | ||
|
||
|