Skip to content

Commit

Permalink
Backport IME height check to Android 10
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishiranu committed Dec 14, 2020
1 parent 0d90389 commit 87012c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/com/mishiranu/dashchan/widget/ExpandedScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ExpandedScreen implements RecyclerScrollTracker.OnScrollListener {
private final Activity activity;
private InsetsLayout.Insets windowInsets = InsetsLayout.Insets.DEFAULT;
private boolean useGesture29;
private int imeBottom30;
private int imeBottom29;

private final View rootView;
private final View toolbarView;
Expand Down Expand Up @@ -177,10 +177,10 @@ public ExpandedScreen(Init init, View rootView, View toolbarView, FrameLayout dr
windowInsets = applyData.window;
}
if (!this.windowInsets.equals(windowInsets) || useGesture29 != applyData.useGesture29 ||
imeBottom30 != applyData.imeBottom30) {
imeBottom29 != applyData.imeBottom29) {
this.windowInsets = windowInsets;
useGesture29 = applyData.useGesture29;
imeBottom30 = applyData.imeBottom30;
imeBottom29 = applyData.imeBottom29;
updatePaddings();
}
});
Expand Down Expand Up @@ -536,7 +536,7 @@ public void updatePaddings() {
int rightNavigationBarHeight = windowInsets.right;
int bottomNavigationBarHeight = windowInsets.bottom;
boolean useGesture29 = this.useGesture29;
int bottomImeHeight = imeBottom30;
int bottomImeHeight = imeBottom29;
if (rootView != null) {
ViewUtils.setNewMargin(rootView, leftNavigationBarHeight, 0,
rightNavigationBarHeight, bottomImeHeight);
Expand Down
43 changes: 26 additions & 17 deletions src/com/mishiranu/dashchan/widget/InsetsLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.RequiresApi;
import com.mishiranu.dashchan.C;
import com.mishiranu.dashchan.R;
import com.mishiranu.dashchan.util.ResourceUtils;

public class InsetsLayout extends FrameLayout {
public static final class Insets {
Expand Down Expand Up @@ -62,16 +63,16 @@ public int hashCode() {
public static class Apply {
public final Insets window;
public final boolean useGesture29;
public final int imeBottom30;
public final int imeBottom29;

private Apply(Insets window, boolean useGesture29, int imeBottom30) {
private Apply(Insets window, boolean useGesture29, int imeBottom29) {
this.window = window;
this.useGesture29 = useGesture29;
this.imeBottom30 = imeBottom30;
this.imeBottom29 = imeBottom29;
}

public Insets get() {
int bottom = Math.max(window.bottom, imeBottom30);
int bottom = Math.max(window.bottom, imeBottom29);
return bottom != window.bottom ? new Insets(window.left, window.top, window.right, window.bottom) : window;
}
}
Expand Down Expand Up @@ -117,16 +118,16 @@ public static boolean isTargetGesture29(View view) {

private Insets lastWindow = Insets.DEFAULT;
private Insets lastGesture29 = Insets.DEFAULT;
private Insets lastIme30 = Insets.DEFAULT;
private Insets lastIme29 = Insets.DEFAULT;

private void onInsetsChangedInternal(Insets window, Insets gesture29, Insets ime30) {
if (!lastWindow.equals(window) || !lastGesture29.equals(gesture29) || !lastIme30.equals(ime30)) {
private void onInsetsChangedInternal(Insets window, Insets gesture29, Insets ime29) {
if (!lastWindow.equals(window) || !lastGesture29.equals(gesture29) || !lastIme29.equals(ime29)) {
lastWindow = window;
lastGesture29 = gesture29;
lastIme30 = ime30;
lastIme29 = ime29;
if (onApplyInsetsListener != null) {
boolean useGesture29 = C.API_Q && (gesture29.left > window.left || gesture29.right > window.right);
onApplyInsetsListener.onApplyInsets(new Apply(window, useGesture29, ime30.bottom));
onApplyInsetsListener.onApplyInsets(new Apply(window, useGesture29, ime29.bottom));
}
}
}
Expand Down Expand Up @@ -157,26 +158,34 @@ public WindowInsets onApplyWindowInsets(WindowInsets insets) {
setPadding(0, 0, 0, 0);
Insets window;
Insets gesture29;
Insets ime30;
Insets ime29;
if (C.API_R) {
Insets realWindow = new Insets(insets.getInsetsIgnoringVisibility
(WindowInsets.Type.displayCutout() | WindowInsets.Type.systemBars()));
gesture29 = new Insets(insets.getInsets(WindowInsets.Type.systemGestures()));
ime30 = new Insets(insets.getInsets(WindowInsets.Type.ime()));
if (ime30.bottom > realWindow.bottom) {
ime29 = new Insets(insets.getInsets(WindowInsets.Type.ime()));
if (ime29.bottom > realWindow.bottom) {
// Assume keyboard can be at the bottom only
window = new Insets(realWindow.left, realWindow.top, realWindow.right, 0);
} else {
window = realWindow;
}
} else if (C.API_Q) {
@SuppressWarnings("deprecation")
Insets windowDeprecated = new Insets(insets.getSystemWindowInsets());
window = getWindowWithCutout(windowDeprecated, insets);
Insets realWindow = new Insets(insets.getSystemWindowInsets());
@SuppressWarnings("deprecation")
Insets gesture29Deprecated = new Insets(insets.getSystemGestureInsets());
gesture29 = gesture29Deprecated;
ime30 = Insets.DEFAULT;
float density = ResourceUtils.obtainDensity(this);
int minKeyboardHeight = (int) (200f * density);
if (realWindow.bottom >= minKeyboardHeight) {
// Sometimes SOFT_INPUT_ADJUST_RESIZE doesn't work with Android 10 gestures
window = new Insets(realWindow.left, realWindow.top, realWindow.right, 0);
ime29 = new Insets(0, 0, 0, realWindow.bottom);
} else {
window = realWindow;
ime29 = Insets.DEFAULT;
}
} else {
@SuppressWarnings("deprecation")
int left = insets.getSystemWindowInsetLeft();
Expand All @@ -188,9 +197,9 @@ public WindowInsets onApplyWindowInsets(WindowInsets insets) {
int bottom = insets.getSystemWindowInsetBottom();
window = getWindowWithCutout(new Insets(left, top, right, bottom), insets);
gesture29 = Insets.DEFAULT;
ime30 = Insets.DEFAULT;
ime29 = Insets.DEFAULT;
}
onInsetsChangedInternal(window, gesture29, ime30);
onInsetsChangedInternal(window, gesture29, ime29);
}
}
}
Expand Down

0 comments on commit 87012c4

Please sign in to comment.