Skip to content

Commit

Permalink
Fix #328
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Danic <[email protected]>
  • Loading branch information
mario committed Jan 24, 2019
1 parent 748c208 commit fad8606
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateHidden|adjustResize">
android:windowSoftInputMode="stateVisible|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
27 changes: 21 additions & 6 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

import static com.vanniktech.emoji.Utils.backspace;
import static com.vanniktech.emoji.Utils.checkNotNull;
import static com.vanniktech.emoji.Utils.shouldOverrideRegularCondition;

public final class EmojiPopup {
static final int MIN_KEYBOARD_HEIGHT = 100;
static final float HEIGHT_DIFFERENCE_FACTOR = 1.4f;

final View rootView;
final Activity context;
Expand Down Expand Up @@ -69,7 +69,7 @@ public final class EmojiPopup {
int height = 0;

if (shouldOverrideRegularCondition) {
height = (int) (Utils.getScreenHeight(context) / 2f - heightDifference * HEIGHT_DIFFERENCE_FACTOR);
height = Utils.getScreenHeight(context) - editText.getHeight() - correctionFactor ;
popupWindow.setHeight(height);
} else {
height = heightDifference + correctionFactor;
Expand Down Expand Up @@ -162,6 +162,8 @@ public final class EmojiPopup {
}
}
});

popupWindow.setFocusable(true);
}

public void toggle() {
Expand All @@ -172,18 +174,22 @@ public void toggle() {

if (isKeyboardOpen) {
// If the keyboard is visible, simply show the emoji popup.
showAtBottom();
editText.postDelayed(new Runnable() {
@Override public void run() {
showAtBottom();
}
}, 50);
} else if (editText != null) {
final View view = editText;

// Open the text keyboard first and immediately after that show the emoji popup.
view.setFocusableInTouchMode(true);
view.setFocusable(true);
view.requestFocus();

showAtBottomPending();

final InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
showAtBottomPending();
} else {
throw new IllegalArgumentException("The provided EditText is null.");
}
Expand All @@ -195,6 +201,7 @@ public void toggle() {
context.getWindow().getDecorView().getViewTreeObserver().dispatchOnGlobalLayout();
}


public boolean isShowing() {
return popupWindow.isShowing();
}
Expand All @@ -212,13 +219,21 @@ void showAtBottom() {
popupWindow.showAtLocation(rootView, Gravity.NO_GRAVITY, desiredLocation.x, desiredLocation.y);

if (onEmojiPopupShownListener != null) {
if (shouldOverrideRegularCondition(context, editText)) {
final InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(editText, 0);
}
onEmojiPopupShownListener.onEmojiPopupShown();
}
}

private void showAtBottomPending() {
if (isKeyboardOpen) {
showAtBottom();
editText.postDelayed(new Runnable() {
@Override public void run() {
showAtBottom();
}
}, 50);
} else {
isPendingOpen = true;
}
Expand Down

0 comments on commit fad8606

Please sign in to comment.