Fix back button behavior on OnePlus phones.
Couple things happened: - Core issue: The device always thought the keyboard was open, so it was always trying to dismiss the keyboard when you pressed back (instead of actually going back) - Big fix: Increase the tolerance of our view height differentialt that detects if the keyboard is open - Other fix: the getViewInset() method is always missing on Q, so as a temp fix we fall back to the status bar height. Gets the calculation to be closer, even if not truly correct.
This commit is contained in:
parent
f1d98f6c7b
commit
1363f55f77
3 changed files with 20 additions and 12 deletions
|
@ -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 androidx.appcompat.widget.LinearLayoutCompat;
|
import androidx.appcompat.widget.LinearLayoutCompat;
|
||||||
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
@ -31,6 +32,7 @@ import android.view.View;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -69,17 +71,17 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
||||||
|
|
||||||
public KeyboardAwareLinearLayout(Context context, AttributeSet attrs, int defStyle) {
|
public KeyboardAwareLinearLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
final int statusBarRes = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
|
||||||
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);
|
||||||
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);
|
||||||
statusBarHeight = statusBarRes > 0 ? getResources().getDimensionPixelSize(statusBarRes) : 0;
|
statusBarHeight = ViewUtil.getStatusBarHeight(this);
|
||||||
viewInset = getViewInset();
|
viewInset = getViewInset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
updateRotation();
|
updateRotation();
|
||||||
updateKeyboardState();
|
updateKeyboardState();
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
@ -100,7 +102,7 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
||||||
getWindowVisibleDisplayFrame(rect);
|
getWindowVisibleDisplayFrame(rect);
|
||||||
|
|
||||||
final int availableHeight = getAvailableHeight();
|
final int availableHeight = getAvailableHeight();
|
||||||
final int keyboardHeight = availableHeight - (rect.bottom - rect.top);
|
final int keyboardHeight = availableHeight - rect.bottom;
|
||||||
|
|
||||||
if (keyboardHeight > minKeyboardSize) {
|
if (keyboardHeight > minKeyboardSize) {
|
||||||
if (getKeyboardHeight() != keyboardHeight) {
|
if (getKeyboardHeight() != keyboardHeight) {
|
||||||
|
@ -128,17 +130,19 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
||||||
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);
|
||||||
return insets.bottom;
|
if (insets != null) {
|
||||||
|
return insets.bottom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
return 0;
|
return statusBarHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAvailableHeight() {
|
private int getAvailableHeight() {
|
||||||
final int availableHeight = this.getRootView().getHeight() - viewInset - (!isFullscreen ? statusBarHeight : 0);
|
final int availableHeight = this.getRootView().getHeight() - viewInset;
|
||||||
final int availableWidth = this.getRootView().getWidth() - (!isFullscreen ? statusBarHeight : 0);
|
final int availableWidth = this.getRootView().getWidth();
|
||||||
|
|
||||||
if (isLandscape() && availableHeight > availableWidth) {
|
if (isLandscape() && availableHeight > availableWidth) {
|
||||||
//noinspection SuspiciousNameCombination
|
//noinspection SuspiciousNameCombination
|
||||||
|
|
|
@ -979,9 +979,13 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
Log.d(TAG, "onBackPressed()");
|
Log.d(TAG, "onBackPressed()");
|
||||||
if (reactionOverlay.isShowing()) reactionOverlay.hide();
|
if (reactionOverlay.isShowing()) {
|
||||||
else if (container.isInputOpen()) container.hideCurrentInput(composeText);
|
reactionOverlay.hide();
|
||||||
else super.onBackPressed();
|
} else if (container.isInputOpen()) {
|
||||||
|
container.hideCurrentInput(composeText);
|
||||||
|
} else {
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="emoji_drawer_size">32sp</dimen>
|
<dimen name="emoji_drawer_size">32sp</dimen>
|
||||||
<dimen name="min_keyboard_size">50dp</dimen>
|
<dimen name="min_keyboard_size">60dp</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_portrait">170dp</dimen>
|
<dimen name="min_custom_keyboard_top_margin_portrait">170dp</dimen>
|
||||||
|
|
Loading…
Add table
Reference in a new issue