Improve keyboard sizing in bubbled conversations.

fork-5.53.8
Cody Henthorne 2021-06-09 16:18:55 -04:00 zatwierdzone przez GitHub
rodzic a3e3667dc2
commit 412ee220ce
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 55 dodań i 21 usunięć

Wyświetl plik

@ -1,16 +1,16 @@
/** /**
* Copyright (C) 2014 Open Whisper Systems * Copyright (C) 2014 Open Whisper Systems
* * <p>
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -23,6 +23,7 @@ import android.os.Build;
import android.os.Build.VERSION_CODES; import android.os.Build.VERSION_CODES;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Surface; import android.view.Surface;
import android.view.View; import android.view.View;
import android.view.WindowInsets; import android.view.WindowInsets;
@ -49,11 +50,14 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
private final Rect rect = new Rect(); private final Rect rect = new Rect();
private final Set<OnKeyboardHiddenListener> hiddenListeners = new HashSet<>(); private final Set<OnKeyboardHiddenListener> hiddenListeners = new HashSet<>();
private final Set<OnKeyboardShownListener> shownListeners = new HashSet<>(); private final Set<OnKeyboardShownListener> shownListeners = new HashSet<>();
private final DisplayMetrics displayMetrics = new DisplayMetrics();
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 minCustomKeyboardTopMarginPortrait; private final int minCustomKeyboardTopMarginPortrait;
private final int minCustomKeyboardTopMarginLandscape; private final int minCustomKeyboardTopMarginLandscape;
private final int minCustomKeyboardTopMarginLandscapeBubble;
private final int statusBarHeight; private final int statusBarHeight;
private int viewInset; private int viewInset;
@ -61,6 +65,7 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
private boolean keyboardOpen = false; private boolean keyboardOpen = false;
private int rotation = -1; private int rotation = -1;
private boolean isFullscreen = false; private boolean isFullscreen = false;
private boolean isBubble = false;
public KeyboardAwareLinearLayout(Context context) { public KeyboardAwareLinearLayout(Context context) {
this(context, null); this(context, null);
@ -77,6 +82,7 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
defaultCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.default_custom_keyboard_size); defaultCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.default_custom_keyboard_size);
minCustomKeyboardTopMarginPortrait = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin_portrait); minCustomKeyboardTopMarginPortrait = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin_portrait);
minCustomKeyboardTopMarginLandscape = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin_portrait); minCustomKeyboardTopMarginLandscape = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin_portrait);
minCustomKeyboardTopMarginLandscapeBubble = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin_landscape_bubble);
statusBarHeight = ViewUtil.getStatusBarHeight(this); statusBarHeight = ViewUtil.getStatusBarHeight(this);
viewInset = getViewInset(); viewInset = getViewInset();
} }
@ -88,6 +94,10 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} }
public void setIsBubble(boolean isBubble) {
this.isBubble = isBubble;
}
private void updateRotation() { private void updateRotation() {
int oldRotation = rotation; int oldRotation = rotation;
rotation = getDeviceRotation(); rotation = getDeviceRotation();
@ -149,7 +159,7 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
if (attachInfo != null) { if (attachInfo != null) {
Field stableInsetsField = attachInfo.getClass().getDeclaredField("mStableInsets"); Field stableInsetsField = attachInfo.getClass().getDeclaredField("mStableInsets");
stableInsetsField.setAccessible(true); stableInsetsField.setAccessible(true);
Rect insets = (Rect)stableInsetsField.get(attachInfo); Rect insets = (Rect) stableInsetsField.get(attachInfo);
if (insets != null) { if (insets != null) {
return insets.bottom; return insets.bottom;
} }
@ -197,28 +207,50 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
int rotation = getDeviceRotation(); int rotation = getDeviceRotation();
return rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270; return rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270;
} }
private int getDeviceRotation() { private int getDeviceRotation() {
return ServiceUtil.getWindowManager(getContext()).getDefaultDisplay().getRotation(); if (Build.VERSION.SDK_INT >= 30) {
getContext().getDisplay().getRealMetrics(displayMetrics);
} else {
ServiceUtil.getWindowManager(getContext()).getDefaultDisplay().getRealMetrics(displayMetrics);
}
return displayMetrics.widthPixels > displayMetrics.heightPixels ? Surface.ROTATION_90 : Surface.ROTATION_0;
} }
private int getKeyboardLandscapeHeight() { private int getKeyboardLandscapeHeight() {
if (isBubble) {
return getRootView().getHeight() - minCustomKeyboardTopMarginLandscapeBubble;
}
int keyboardHeight = PreferenceManager.getDefaultSharedPreferences(getContext()) int keyboardHeight = PreferenceManager.getDefaultSharedPreferences(getContext())
.getInt("keyboard_height_landscape", defaultCustomKeyboardSize); .getInt("keyboard_height_landscape", defaultCustomKeyboardSize);
return Util.clamp(keyboardHeight, minCustomKeyboardSize, getRootView().getHeight() - minCustomKeyboardTopMarginLandscape); return Util.clamp(keyboardHeight, minCustomKeyboardSize, getRootView().getHeight() - minCustomKeyboardTopMarginLandscape);
} }
private int getKeyboardPortraitHeight() { private int getKeyboardPortraitHeight() {
if (isBubble) {
return getRootView().getHeight() - minCustomKeyboardTopMarginPortrait;
}
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() - minCustomKeyboardTopMarginPortrait); return Util.clamp(keyboardHeight, minCustomKeyboardSize, getRootView().getHeight() - minCustomKeyboardTopMarginPortrait);
} }
private void setKeyboardPortraitHeight(int height) { private void setKeyboardPortraitHeight(int height) {
if (isBubble) {
return;
}
PreferenceManager.getDefaultSharedPreferences(getContext()) PreferenceManager.getDefaultSharedPreferences(getContext())
.edit().putInt("keyboard_height_portrait", height).apply(); .edit().putInt("keyboard_height_portrait", height).apply();
} }
private void setKeyboardLandscapeHeight(int height) { private void setKeyboardLandscapeHeight(int height) {
if (isBubble) {
return;
}
PreferenceManager.getDefaultSharedPreferences(getContext()) PreferenceManager.getDefaultSharedPreferences(getContext())
.edit().putInt("keyboard_height_landscape", height).apply(); .edit().putInt("keyboard_height_landscape", height).apply();
} }

Wyświetl plik

@ -1974,6 +1974,7 @@ public class ConversationActivity extends PassphraseRequiredActivity
cancelJoinRequest = findViewById(R.id.conversation_cancel_request); cancelJoinRequest = findViewById(R.id.conversation_cancel_request);
joinGroupCallButton = findViewById(R.id.conversation_group_call_join); joinGroupCallButton = findViewById(R.id.conversation_group_call_join);
container.setIsBubble(isInBubble());
container.addOnKeyboardShownListener(this); container.addOnKeyboardShownListener(this);
inputPanel.setListener(this); inputPanel.setListener(this);
inputPanel.setMediaListener(this); inputPanel.setMediaListener(this);

Wyświetl plik

@ -5,6 +5,7 @@
<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_portrait">170dp</dimen> <dimen name="min_custom_keyboard_top_margin_portrait">170dp</dimen>
<dimen name="min_custom_keyboard_top_margin_landscape_bubble">56dp</dimen>
<dimen name="emoji_drawer_item_width">48dp</dimen> <dimen name="emoji_drawer_item_width">48dp</dimen>
<dimen name="conversation_item_body_text_size">16sp</dimen> <dimen name="conversation_item_body_text_size">16sp</dimen>
<dimen name="conversation_item_date_text_size">12sp</dimen> <dimen name="conversation_item_date_text_size">12sp</dimen>