ankushsachdeva / emojicon

Android library to show emojicon dialog box over soft keyboard
283 stars 149 forks source link

Status bar and navigation bar #23

Open mlucchini opened 9 years ago

mlucchini commented 9 years ago

It seems that for Lollipop, in EmojiconsPopup::setSizeForSoftKeyboard, we have to substract the size of "navigation_bar_height" as well as "status_bar_height" in case there's a navigation bar being displayed otherwise the emoji popup will take more space than the soft keyboard.

shailesh242121 commented 9 years ago

Ya the previous comment is right Here is the solution i have got

/**
 * Call this function to resize the emoji popup according to your soft keyboard size
 */
public void setSizeForSoftKeyboard(){
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();
            rootView.getWindowVisibleDisplayFrame(r);

            int screenHeight = rootView.getRootView()
                    .getHeight();
            int heightDifference = screenHeight
                    - (r.bottom - r.top);
            int resourceId = mContext.getResources()
                    .getIdentifier("status_bar_height",
                            "dimen", "android");

            int navigation = mContext.getResources()
                    .getIdentifier("navigation_bar_height",
                            "dimen", "android");

            if (resourceId > 0) {
                if(Build.VERSION.SDK_INT> Build.VERSION_CODES.KITKAT)
                {
                    heightDifference -= mContext.getResources()
                            .getDimensionPixelSize(resourceId);
                    heightDifference -=mContext.getResources().getDimension(navigation);
                }else
                heightDifference -= mContext.getResources()
                        .getDimensionPixelSize(resourceId);
            }

            if (heightDifference > 100) {
                keyBoardHeight = heightDifference;
                setSize(LayoutParams.MATCH_PARENT, keyBoardHeight);
                if(isOpened == false){
                    if(onSoftKeyboardOpenCloseListener!=null)
                        onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight);
                }
                isOpened = true;
                if(pendingOpen){
                    showAtBottom();
                    pendingOpen = false;
                }
            }
            else{
                isOpened = false;
                if(onSoftKeyboardOpenCloseListener!=null)
                    onSoftKeyboardOpenCloseListener.onKeyboardClose();
            }
        }
    });
}
cridus commented 9 years ago

I found that the above code makes the popup always shorter than the keyboard. I tried several devices in the emulator, and both Lollipop and L. How can I reproduce this with an emulator?

Meeks91 commented 9 years ago

Hi, I'm having the same problem now, shailesh242121's code is better than the original, but on some devices it doesn't quite cover the whole keyboard, did anyone figure out a solution ?

Thanks in advance.