Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.WindowInsetsCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.viewpager.widget.ViewPager;

Expand Down Expand Up @@ -233,7 +234,8 @@ public void onCreate(Bundle savedInstanceState) {

View content = findViewById(android.R.id.content);
content.setOnApplyWindowInsetsListener((v, insets) -> {
mNavBarHeight = insets.getSystemWindowInsetBottom();
WindowInsetsCompat insetsCompat = WindowInsetsCompat.toWindowInsetsCompat(insets);
mNavBarHeight = insetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom;
return insets;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.Rect;
import android.inputmethodservice.InputMethodService;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -275,7 +276,19 @@ public void onGlobalLayout() {
public static class WindowInsetsListener implements View.OnApplyWindowInsetsListener {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
mStatusBarHeight = WindowInsetsCompat.toWindowInsetsCompat(insets).getInsets(WindowInsetsCompat.Type.statusBars()).top;
WindowInsetsCompat insetsCompat = WindowInsetsCompat.toWindowInsetsCompat(insets);
mStatusBarHeight = insetsCompat.getInsets(WindowInsetsCompat.Type.statusBars()).top;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// If decorFitsSystemWindows is false, we should apply padding to avoid overlapping with system bars and IME.
androidx.core.graphics.Insets systemBarInsets = insetsCompat.getInsets(WindowInsetsCompat.Type.systemBars());
androidx.core.graphics.Insets imeInsets = insetsCompat.getInsets(WindowInsetsCompat.Type.ime());

// Use the maximum of system bar bottom and IME bottom to avoid overlapping
int bottomPadding = Math.max(systemBarInsets.bottom, imeInsets.bottom);
v.setPadding(systemBarInsets.left, systemBarInsets.top, systemBarInsets.right, bottomPadding);
}

// Let view window handle insets however it wants
return v.onApplyWindowInsets(insets);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.termux.app.terminal.io;

import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;

import androidx.core.view.WindowInsetsCompat;

import com.termux.app.TermuxActivity;

Expand Down Expand Up @@ -31,7 +35,24 @@ private FullScreenWorkAround(TermuxActivity activity) {
mChildOfContent = content.getChildAt(0);
mViewGroupLayoutParams = mChildOfContent.getLayoutParams();
mNavBarHeight = activity.getNavBarHeight();
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(this::possiblyResizeChildOfContent);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
mChildOfContent.setOnApplyWindowInsetsListener((v, insets) -> {
WindowInsetsCompat insetsCompat = WindowInsetsCompat.toWindowInsetsCompat(insets);
int imeHeight = insetsCompat.getInsets(WindowInsetsCompat.Type.ime()).bottom;
int navBarHeight = insetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom;

if (imeHeight > 0) {
mViewGroupLayoutParams.height = v.getRootView().getHeight() - imeHeight + navBarHeight;
} else {
mViewGroupLayoutParams.height = v.getRootView().getHeight();
}
v.setLayoutParams(mViewGroupLayoutParams);
return insets;
});
} else {
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(this::possiblyResizeChildOfContent);
}
}

private void possiblyResizeChildOfContent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,19 @@ public static void setSoftKeyboardAlwaysHiddenFlags(final Activity activity) {
}

public static void setSoftInputModeAdjustResize(final Activity activity) {
// TODO: The flag is deprecated for API 30 and WindowInset API should be used
// https://developer.android.com/reference/android/view/WindowManager.LayoutParams#SOFT_INPUT_ADJUST_RESIZE
// https://medium.com/androiddevelopers/animating-your-keyboard-fb776a8fb66d
// https://stackoverflow.com/a/65194077/14686958
if (activity != null && activity.getWindow() != null)
if (activity == null || activity.getWindow() == null) return;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// SOFT_INPUT_ADJUST_RESIZE is deprecated in API 30.
// The modern way to handle this is to set decorFitsSystemWindows to false
// and then handle WindowInsets manually using View.OnApplyWindowInsetsListener.
// https://developer.android.com/reference/android/view/WindowManager.LayoutParams#SOFT_INPUT_ADJUST_RESIZE
// https://medium.com/androiddevelopers/animating-your-keyboard-fb776a8fb66d
// https://stackoverflow.com/a/65194077/14686958
activity.getWindow().setDecorFitsSystemWindows(false);
} else {
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
}

/**
Expand Down