removed unnecessary background; Added new funciton showAtBottomPending()
This commit is contained in:
parent
2fc6baf9e8
commit
0f5fefe35b
3 changed files with 113 additions and 82 deletions
|
@ -69,6 +69,7 @@ popup.setOnSoftKeyboardOpenCloseListener(new OnSoftKeyboardOpenCloseListener() {
|
|||
});
|
||||
|
||||
//To show popup manually you can call popup.showAtBottom();
|
||||
//To show popup when the soft keyboard is not already visible, use popup.showAtBottomPending()
|
||||
```
|
||||
|
||||
Note: You can change the size of emojis in XML layout through attribute `emojiconSize`.
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
<!-- No backgrounds, titles or window float -->
|
||||
<item name="android:windowFrame">@null</item>
|
||||
<item name="android:windowBackground">@drawable/popup_bg</item>
|
||||
<item name="android:windowBackground">@null</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowIsFloating">false</item>
|
||||
</style>
|
||||
|
|
|
@ -35,7 +35,6 @@ import android.os.SystemClock;
|
|||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
@ -43,7 +42,6 @@ import android.view.View.OnClickListener;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import android.widget.EditText;
|
||||
import android.widget.PopupWindow;
|
||||
|
||||
|
||||
|
@ -57,6 +55,7 @@ public class EmojiconsPopup extends PopupWindow implements ViewPager.OnPageChang
|
|||
private PagerAdapter mEmojisAdapter;
|
||||
private EmojiconRecentsManager mRecentsManager;
|
||||
private int keyBoardHeight = 0;
|
||||
private Boolean pendingOpen = false;
|
||||
private Boolean isOpened = false;
|
||||
OnEmojiconClickedListener onEmojiconClickedListener;
|
||||
OnEmojiconBackspaceClickedListener onEmojiconBackspaceClickedListener;
|
||||
|
@ -64,40 +63,77 @@ public class EmojiconsPopup extends PopupWindow implements ViewPager.OnPageChang
|
|||
View rootView;
|
||||
Context mContext;
|
||||
|
||||
public ViewPager emojisPager;
|
||||
|
||||
private ViewPager emojisPager;
|
||||
/**
|
||||
* Constructor
|
||||
* @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 mContext The context of current activity.
|
||||
*/
|
||||
public EmojiconsPopup(View rootView, Context mContext){
|
||||
super(mContext);
|
||||
this.mContext = mContext;
|
||||
this.rootView = rootView;
|
||||
View customView = createCustomView();
|
||||
setContentView(customView);
|
||||
|
||||
setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
//default size
|
||||
setSize((int) mContext.getResources().getDimension(R.dimen.keyboard_height), LayoutParams.MATCH_PARENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the listener for the event of keyboard opening or closing.
|
||||
*/
|
||||
public void setOnSoftKeyboardOpenCloseListener(OnSoftKeyboardOpenCloseListener listener){
|
||||
this.onSoftKeyboardOpenCloseListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the listener for the event when any of the emojicon is clicked
|
||||
*/
|
||||
public void setOnEmojiconClickedListener(OnEmojiconClickedListener listener){
|
||||
this.onEmojiconClickedListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the listener for the event when backspace on emojicon popup is clicked
|
||||
*/
|
||||
public void setOnEmojiconBackspaceClickedListener(OnEmojiconBackspaceClickedListener listener){
|
||||
this.onEmojiconBackspaceClickedListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function to show the emoji popup.
|
||||
* NOTE: Since, the soft keyboard sizes are variable on different android devices, the
|
||||
* library needs you to open the soft keyboard atleast once before calling this function.
|
||||
* If that is not possible see showAtBottomPending() function.
|
||||
*
|
||||
*/
|
||||
public void showAtBottom(){
|
||||
showAtLocation(rootView, Gravity.BOTTOM, 0, 0);
|
||||
}
|
||||
/**
|
||||
* Use this function when the soft keyboard has not been opened yet. This
|
||||
* will show the emoji popup after the keyboard is up next time.
|
||||
* Generally, you will be calling InputMethodManager.showSoftInput function after
|
||||
* calling this function.
|
||||
*/
|
||||
public void showAtBottomPending(){
|
||||
if(isKeyBoardOpen())
|
||||
showAtBottom();
|
||||
else
|
||||
pendingOpen = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Returns true if the soft keyboard is open, false otherwise.
|
||||
*/
|
||||
public Boolean isKeyBoardOpen(){
|
||||
return isOpened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss the popup
|
||||
*/
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
|
@ -105,6 +141,9 @@ public class EmojiconsPopup extends PopupWindow implements ViewPager.OnPageChang
|
|||
.getInstance(mContext).saveRecents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this function to resize the emoji popup according to your soft keyboard size
|
||||
*/
|
||||
public void setSizeForSoftKeyboard(){
|
||||
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
|
||||
@Override
|
||||
|
@ -131,6 +170,10 @@ public class EmojiconsPopup extends PopupWindow implements ViewPager.OnPageChang
|
|||
onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight);
|
||||
}
|
||||
isOpened = true;
|
||||
if(pendingOpen){
|
||||
showAtBottom();
|
||||
pendingOpen = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
isOpened = false;
|
||||
|
@ -141,12 +184,17 @@ public class EmojiconsPopup extends PopupWindow implements ViewPager.OnPageChang
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually set the popup window size
|
||||
* @param width Width of the popup
|
||||
* @param height Height of the popup
|
||||
*/
|
||||
public void setSize(int width, int height){
|
||||
setWidth(width);
|
||||
setHeight(height);
|
||||
}
|
||||
|
||||
public View createCustomView() {
|
||||
private View createCustomView() {
|
||||
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
||||
View view = inflater.inflate(R.layout.emojicons, null, false);
|
||||
emojisPager = (ViewPager) view.findViewById(R.id.emojis_pager);
|
||||
|
@ -206,30 +254,12 @@ public class EmojiconsPopup extends PopupWindow implements ViewPager.OnPageChang
|
|||
return view;
|
||||
}
|
||||
|
||||
public static void input(EditText editText, Emojicon emojicon) {
|
||||
if (editText == null || emojicon == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int start = editText.getSelectionStart();
|
||||
int end = editText.getSelectionEnd();
|
||||
if (start < 0) {
|
||||
editText.append(emojicon.getEmoji());
|
||||
} else {
|
||||
editText.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecentEmoji(Context context, Emojicon emojicon) {
|
||||
EmojiconRecentsGridView fragment = ((EmojisPagerAdapter)emojisPager.getAdapter()).getRecentFragment();
|
||||
fragment.addRecentEmoji(context, emojicon);
|
||||
}
|
||||
|
||||
public static void backspace(EditText editText) {
|
||||
KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
|
||||
editText.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int i, float v, int i2) {
|
||||
|
|
Loading…
Reference in a new issue