这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
66 changes: 66 additions & 0 deletions app/src/main/java/com/termux/app/FullScreenWorkAround.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.termux.app;

import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;

/**
* Work around for fullscreen mode in Termux to fix ExtraKeysView not being visible.
* This class is derived from:
* https://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible
* and has some additional tweaks
* ---
* For more information, see https://issuetracker.google.com/issues/36911528
*/
public class FullScreenWorkAround {
private View mChildOfContent;
private int mUsableHeightPrevious;
private ViewGroup.LayoutParams mViewGroupLayoutParams;

private int mNavBarHeight;


public static void apply(TermuxActivity activity) {
new FullScreenWorkAround(activity);
}

private FullScreenWorkAround(TermuxActivity activity) {
ViewGroup content = activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mViewGroupLayoutParams = mChildOfContent.getLayoutParams();
mNavBarHeight = activity.getNavBarHeight();
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(this::possiblyResizeChildOfContent);
}

private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != mUsableHeightPrevious) {
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
if (heightDifference > (usableHeightSansKeyboard / 4)) {
// keyboard probably just became visible

// ensures that usable layout space does not extend behind the
// soft keyboard, causing the extra keys to not be visible
mViewGroupLayoutParams.height = (usableHeightSansKeyboard - heightDifference) + getNavBarHeight();
} else {
// keyboard probably just became hidden
mViewGroupLayoutParams.height = usableHeightSansKeyboard;
}
mChildOfContent.requestLayout();
mUsableHeightPrevious = usableHeightNow;
}
}

private int getNavBarHeight() {
return mNavBarHeight;
}

private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);
}

}

23 changes: 23 additions & 0 deletions app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection

boolean mIsUsingBlackUI;

int mNavBarHeight;

final SoundPool mBellSoundPool = new SoundPool.Builder().setMaxStreams(1).setAudioAttributes(
new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION).build()).build();
Expand Down Expand Up @@ -214,8 +216,19 @@ public void onCreate(Bundle bundle) {

super.onCreate(bundle);


setContentView(R.layout.drawer_layout);

View content = findViewById(android.R.id.content);
content.setOnApplyWindowInsetsListener((v, insets) -> {
mNavBarHeight = insets.getSystemWindowInsetBottom();
return insets;
});

if (mSettings.isUsingFullScreen()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

if (mIsUsingBlackUI) {
findViewById(R.id.left_drawer).setBackgroundColor(
getResources().getColor(android.R.color.background_dark)
Expand Down Expand Up @@ -256,6 +269,12 @@ public Object instantiateItem(@NonNull ViewGroup collection, int position) {
if (position == 0) {
layout = mExtraKeysView = (ExtraKeysView) inflater.inflate(R.layout.extra_keys_main, collection, false);
mExtraKeysView.reload(mSettings.mExtraKeys);

// apply extra keys fix if enabled in prefs
if (mSettings.isUsingFullScreen() && mSettings.isUsingFullScreenWorkAround()) {
FullScreenWorkAround.apply(TermuxActivity.this);
}

} else {
layout = inflater.inflate(R.layout.extra_keys_right, collection, false);
final EditText editText = layout.findViewById(R.id.text_input);
Expand Down Expand Up @@ -331,6 +350,10 @@ public void onPageSelected(int position) {
sendOpenedBroadcast();
}

public int getNavBarHeight() {
return mNavBarHeight;
}

/**
* Send a broadcast notifying Termux app has been opened
*/
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/com/termux/app/TermuxPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import androidx.annotation.IntDef;

import static com.termux.terminal.EmulatorDebug.LOG_TAG;

final class TermuxPreferences {

@IntDef({BELL_VIBRATE, BELL_BEEP, BELL_IGNORE})
Expand Down Expand Up @@ -67,6 +69,9 @@ final static class KeyboardShortcut {
private boolean mScreenAlwaysOn;
private int mFontSize;

private boolean mUseFullScreen;
private boolean mUseFullScreenWorkAround;

@AsciiBellBehaviour
int mBellBehaviour = BELL_VIBRATE;

Expand Down Expand Up @@ -137,6 +142,14 @@ boolean isUsingBlackUI() {
return mUseDarkUI;
}

boolean isUsingFullScreen() {
return mUseFullScreen;
}

boolean isUsingFullScreenWorkAround() {
return mUseFullScreenWorkAround;
}

void setScreenAlwaysOn(Context context, boolean newValue) {
mScreenAlwaysOn = newValue;
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(SCREEN_ALWAYS_ON_KEY, newValue).apply();
Expand Down Expand Up @@ -196,6 +209,24 @@ void reloadFromProperties(Context context) {
mUseDarkUI = nightMode == Configuration.UI_MODE_NIGHT_YES;
}

switch (props.getProperty("fullscreen", "").toLowerCase()) {
case "true":
mUseFullScreen = true;
break;
case "false":
default:
mUseFullScreen = false;
}

switch (props.getProperty("use-fullscreen-workaround", "").toLowerCase()) {
case "true":
mUseFullScreenWorkAround = true;
break;
case "false":
default:
mUseFullScreenWorkAround = false;
}

String defaultExtraKeys = "[[ESC, TAB, CTRL, ALT, {key: '-', popup: '|'}, DOWN, UP]]";

try {
Expand Down