Fix some keyboard issues in landscape.

This commit is contained in:
Greyson Parrelli 2019-05-01 11:56:16 -07:00
parent 05345b8582
commit 934a2a67bc
2 changed files with 43 additions and 13 deletions

View File

@ -4,7 +4,8 @@
<dimen name="min_keyboard_size">50dp</dimen> <dimen name="min_keyboard_size">50dp</dimen>
<dimen name="default_custom_keyboard_size">220dp</dimen> <dimen name="default_custom_keyboard_size">220dp</dimen>
<dimen name="min_custom_keyboard_size">110dp</dimen> <dimen name="min_custom_keyboard_size">110dp</dimen>
<dimen name="min_custom_keyboard_top_margin">170dp</dimen> <dimen name="min_custom_keyboard_top_margin_portrait">170dp</dimen>
<dimen name="min_custom_keyboard_top_margin_landscape">50dp</dimen>
<dimen name="emoji_drawer_item_padding">5dp</dimen> <dimen name="emoji_drawer_item_padding">5dp</dimen>
<dimen name="emoji_drawer_indicator_height">1.5dp</dimen> <dimen name="emoji_drawer_indicator_height">1.5dp</dimen>
<dimen name="emoji_drawer_left_right_padding">5dp</dimen> <dimen name="emoji_drawer_left_right_padding">5dp</dimen>

View File

@ -49,7 +49,8 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
private final int minKeyboardSize; private final int minKeyboardSize;
private final int minCustomKeyboardSize; private final int minCustomKeyboardSize;
private final int defaultCustomKeyboardSize; private final int defaultCustomKeyboardSize;
private final int minCustomKeyboardTopMargin; private final int minCustomKeyboardTopMarginPortrait;
private final int minCustomKeyboardTopMarginLandscape;
private final int statusBarHeight; private final int statusBarHeight;
private int viewInset; private int viewInset;
@ -72,7 +73,8 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
minKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_keyboard_size); minKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_keyboard_size);
minCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_size); minCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_size);
defaultCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.default_custom_keyboard_size); defaultCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.default_custom_keyboard_size);
minCustomKeyboardTopMargin = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin); minCustomKeyboardTopMarginPortrait = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin_portrait);
minCustomKeyboardTopMarginLandscape = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin_portrait);
statusBarHeight = statusBarRes > 0 ? getResources().getDimensionPixelSize(statusBarRes) : 0; statusBarHeight = statusBarRes > 0 ? getResources().getDimensionPixelSize(statusBarRes) : 0;
viewInset = getViewInset(); viewInset = getViewInset();
} }
@ -97,12 +99,20 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
getWindowVisibleDisplayFrame(rect); getWindowVisibleDisplayFrame(rect);
final int availableHeight = this.getRootView().getHeight() - viewInset - (!isFullscreen ? statusBarHeight : 0); final int availableHeight = getAvailableHeight();
final int keyboardHeight = availableHeight - (rect.bottom - rect.top); final int keyboardHeight = availableHeight - (rect.bottom - rect.top);
if (keyboardHeight > minKeyboardSize) { if (keyboardHeight > minKeyboardSize) {
if (getKeyboardHeight() != keyboardHeight) setKeyboardPortraitHeight(keyboardHeight); if (getKeyboardHeight() != keyboardHeight) {
if (!keyboardOpen) onKeyboardOpen(keyboardHeight); if (isLandscape()) {
setKeyboardLandscapeHeight(keyboardHeight);
} else {
setKeyboardPortraitHeight(keyboardHeight);
}
}
if (!keyboardOpen) {
onKeyboardOpen(keyboardHeight);
}
} else if (keyboardOpen) { } else if (keyboardOpen) {
onKeyboardClose(); onKeyboardClose();
} }
@ -128,6 +138,18 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
return 0; return 0;
} }
private int getAvailableHeight() {
final int availableHeight = this.getRootView().getHeight() - viewInset - (!isFullscreen ? statusBarHeight : 0);
final int availableWidth = this.getRootView().getWidth() - (!isFullscreen ? statusBarHeight : 0);
if (isLandscape() && availableHeight > availableWidth) {
//noinspection SuspiciousNameCombination
return availableWidth;
}
return availableHeight;
}
protected void onKeyboardOpen(int keyboardHeight) { protected void onKeyboardOpen(int keyboardHeight) {
Log.i(TAG, "onKeyboardOpen(" + keyboardHeight + ")"); Log.i(TAG, "onKeyboardOpen(" + keyboardHeight + ")");
keyboardOpen = true; keyboardOpen = true;
@ -158,13 +180,15 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
} }
private int getKeyboardLandscapeHeight() { private int getKeyboardLandscapeHeight() {
return Math.max(getHeight(), getRootView().getHeight()) / 2; int keyboardHeight = PreferenceManager.getDefaultSharedPreferences(getContext())
.getInt("keyboard_height_landscape", defaultCustomKeyboardSize);
return Util.clamp(keyboardHeight, minCustomKeyboardSize, getRootView().getHeight() - minCustomKeyboardTopMarginLandscape);
} }
private int getKeyboardPortraitHeight() { private int getKeyboardPortraitHeight() {
int keyboardHeight = PreferenceManager.getDefaultSharedPreferences(getContext()) int keyboardHeight = PreferenceManager.getDefaultSharedPreferences(getContext())
.getInt("keyboard_height_portrait", defaultCustomKeyboardSize); .getInt("keyboard_height_portrait", defaultCustomKeyboardSize);
return Util.clamp(keyboardHeight, minCustomKeyboardSize, getRootView().getHeight() - minCustomKeyboardTopMargin); return Util.clamp(keyboardHeight, minCustomKeyboardSize, getRootView().getHeight() - minCustomKeyboardTopMarginPortrait);
} }
private void setKeyboardPortraitHeight(int height) { private void setKeyboardPortraitHeight(int height) {
@ -172,6 +196,11 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
.edit().putInt("keyboard_height_portrait", height).apply(); .edit().putInt("keyboard_height_portrait", height).apply();
} }
private void setKeyboardLandscapeHeight(int height) {
PreferenceManager.getDefaultSharedPreferences(getContext())
.edit().putInt("keyboard_height_landscape", height).apply();
}
public void postOnKeyboardClose(final Runnable runnable) { public void postOnKeyboardClose(final Runnable runnable) {
if (keyboardOpen) { if (keyboardOpen) {
addOnKeyboardHiddenListener(new OnKeyboardHiddenListener() { addOnKeyboardHiddenListener(new OnKeyboardHiddenListener() {