Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ public Keyboard(AppCompatActivity activity, boolean resizeOnFullScreen) {
FrameLayout content = activity.getWindow().getDecorView().findViewById(android.R.id.content);
rootView = content.getRootView();

ViewCompat.setOnApplyWindowInsetsListener(
rootView,
(v, insets) -> {
boolean showingKeyboard = ViewCompat.getRootWindowInsets(rootView).isVisible(WindowInsetsCompat.Type.ime());

if (showingKeyboard && resizeOnFullScreen) {
possiblyResizeChildOfContent(true);
}

return insets;
}
);

ViewCompat.setWindowInsetsAnimationCallback(
rootView,
new WindowInsetsAnimationCompat.Callback(WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP) {
Expand Down Expand Up @@ -142,38 +155,9 @@ private void possiblyResizeChildOfContent(boolean keyboardShown) {
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
if (shouldApplyEdgeToEdgeAdjustments()) {
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(rootView);
if (insets != null) {
int systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom;
if (systemBars > 0) {
return r.bottom + systemBars;
}
}
}

return isOverlays() ? r.bottom : r.height();
}

private boolean shouldApplyEdgeToEdgeAdjustments() {
var adjustMarginsForEdgeToEdge = this.bridge == null ? "auto" : this.bridge.getConfig().adjustMarginsForEdgeToEdge();
if (adjustMarginsForEdgeToEdge.equals("force")) { // Force edge-to-edge adjustments regardless of app settings
return true;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && adjustMarginsForEdgeToEdge.equals("auto")) { // Auto means that we need to check the app's edge-to-edge preference
TypedValue value = new TypedValue();
boolean optOutAttributeExists = activity
.getTheme()
.resolveAttribute(android.R.attr.windowOptOutEdgeToEdgeEnforcement, value, true);

if (!optOutAttributeExists) { // Default is to apply edge to edge
return true;
} else {
return value.data == 0;
}
}
return false;
}

@SuppressWarnings("deprecation")
private boolean isOverlays() {
final Window window = activity.getWindow();
Expand Down