diff --git a/res/values/dimens.xml b/res/values/dimens.xml index b17e25e061..f1b494bd82 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -4,7 +4,8 @@ 50dp 220dp 110dp - 170dp + 170dp + 50dp 5dp 1.5dp 5dp diff --git a/src/org/thoughtcrime/securesms/components/KeyboardAwareLinearLayout.java b/src/org/thoughtcrime/securesms/components/KeyboardAwareLinearLayout.java index d885619b30..673e9dbb79 100644 --- a/src/org/thoughtcrime/securesms/components/KeyboardAwareLinearLayout.java +++ b/src/org/thoughtcrime/securesms/components/KeyboardAwareLinearLayout.java @@ -49,7 +49,8 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat { private final int minKeyboardSize; private final int minCustomKeyboardSize; private final int defaultCustomKeyboardSize; - private final int minCustomKeyboardTopMargin; + private final int minCustomKeyboardTopMarginPortrait; + private final int minCustomKeyboardTopMarginLandscape; private final int statusBarHeight; private int viewInset; @@ -69,12 +70,13 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat { public KeyboardAwareLinearLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final int statusBarRes = getResources().getIdentifier("status_bar_height", "dimen", "android"); - minKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_keyboard_size); - minCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_size); - defaultCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.default_custom_keyboard_size); - minCustomKeyboardTopMargin = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin); - statusBarHeight = statusBarRes > 0 ? getResources().getDimensionPixelSize(statusBarRes) : 0; - viewInset = getViewInset(); + minKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_keyboard_size); + minCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_size); + defaultCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.default_custom_keyboard_size); + 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; + viewInset = getViewInset(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @@ -97,12 +99,20 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat { getWindowVisibleDisplayFrame(rect); - final int availableHeight = this.getRootView().getHeight() - viewInset - (!isFullscreen ? statusBarHeight : 0); + final int availableHeight = getAvailableHeight(); final int keyboardHeight = availableHeight - (rect.bottom - rect.top); if (keyboardHeight > minKeyboardSize) { - if (getKeyboardHeight() != keyboardHeight) setKeyboardPortraitHeight(keyboardHeight); - if (!keyboardOpen) onKeyboardOpen(keyboardHeight); + if (getKeyboardHeight() != keyboardHeight) { + if (isLandscape()) { + setKeyboardLandscapeHeight(keyboardHeight); + } else { + setKeyboardPortraitHeight(keyboardHeight); + } + } + if (!keyboardOpen) { + onKeyboardOpen(keyboardHeight); + } } else if (keyboardOpen) { onKeyboardClose(); } @@ -128,6 +138,18 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat { 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) { Log.i(TAG, "onKeyboardOpen(" + keyboardHeight + ")"); keyboardOpen = true; @@ -158,13 +180,15 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat { } 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() { int keyboardHeight = PreferenceManager.getDefaultSharedPreferences(getContext()) .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) { @@ -172,6 +196,11 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat { .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) { if (keyboardOpen) { addOnKeyboardHiddenListener(new OnKeyboardHiddenListener() {