Skip to content

Commit e0ad9ff

Browse files
Allow users to disable terminal margin adjustment from termux settings
Previously in (3213502) support was added with `disable-terminal-margin-adjustment` `termux.properties` property to disable terminal margin adjustment in case in causes screen flickering or other issues on some devices. It has now been removed in (7aefd94) and moved to Termux Settings since if it causes issues at startup and users can't access `termux.properties` file from the terminal, they will have to use SAF or root to access it, which will require an external app. Users can set the value from the `Termux Settings` -> `Termux` -> `Terminal View` -> `Terminal Margin Adjustment` toggle. The `Termux Settings` can be accessed from left drawer in termux and from the android launcher shortcut for Termux Settings, usually accessible by long holding on Termux icon.
1 parent 7aefd94 commit e0ad9ff

File tree

7 files changed

+137
-2
lines changed

7 files changed

+137
-2
lines changed

app/src/main/java/com/termux/app/TermuxActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ public void onStart() {
259259
if (mTermuxTerminalViewClient != null)
260260
mTermuxTerminalViewClient.onStart();
261261

262-
addTermuxActivityRootViewGlobalLayoutListener();
262+
if (mPreferences.isTerminalMarginAdjustmentEnabled())
263+
addTermuxActivityRootViewGlobalLayoutListener();
263264

264265
registerTermuxActivityBroadcastReceiver();
265266
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.termux.app.fragments.settings.termux;
2+
3+
import android.content.Context;
4+
import android.os.Bundle;
5+
6+
import androidx.annotation.Keep;
7+
import androidx.preference.PreferenceDataStore;
8+
import androidx.preference.PreferenceFragmentCompat;
9+
import androidx.preference.PreferenceManager;
10+
11+
import com.termux.R;
12+
import com.termux.shared.settings.preferences.TermuxAppSharedPreferences;
13+
14+
@Keep
15+
public class TerminalViewPreferencesFragment extends PreferenceFragmentCompat {
16+
17+
@Override
18+
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
19+
Context context = getContext();
20+
if (context == null) return;
21+
22+
PreferenceManager preferenceManager = getPreferenceManager();
23+
preferenceManager.setPreferenceDataStore(TerminalViewPreferencesDataStore.getInstance(context));
24+
25+
setPreferencesFromResource(R.xml.termux_terminal_view_preferences, rootKey);
26+
}
27+
28+
}
29+
30+
class TerminalViewPreferencesDataStore extends PreferenceDataStore {
31+
32+
private final Context mContext;
33+
private final TermuxAppSharedPreferences mPreferences;
34+
35+
private static TerminalViewPreferencesDataStore mInstance;
36+
37+
private TerminalViewPreferencesDataStore(Context context) {
38+
mContext = context;
39+
mPreferences = TermuxAppSharedPreferences.build(context, true);
40+
}
41+
42+
public static synchronized TerminalViewPreferencesDataStore getInstance(Context context) {
43+
if (mInstance == null) {
44+
mInstance = new TerminalViewPreferencesDataStore(context);
45+
}
46+
return mInstance;
47+
}
48+
49+
50+
51+
@Override
52+
public void putBoolean(String key, boolean value) {
53+
if (mPreferences == null) return;
54+
if (key == null) return;
55+
56+
switch (key) {
57+
case "terminal_margin_adjustment":
58+
mPreferences.setTerminalMarginAdjustment(value);
59+
break;
60+
default:
61+
break;
62+
}
63+
}
64+
65+
@Override
66+
public boolean getBoolean(String key, boolean defValue) {
67+
if (mPreferences == null) return false;
68+
69+
switch (key) {
70+
case "terminal_margin_adjustment":
71+
return mPreferences.isTerminalMarginAdjustmentEnabled();
72+
default:
73+
return false;
74+
}
75+
}
76+
77+
}

app/src/main/res/values/strings.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,20 @@
168168
<string name="termux_soft_keyboard_enabled_only_if_no_hardware_on">Soft keyboard will be enabled only if no hardware keyboard is connected.</string>
169169

170170

171+
<!-- Terminal View Preferences -->
172+
<string name="termux_terminal_view_preferences_title">Terminal View</string>
173+
<string name="termux_terminal_view_preferences_summary">Preferences for terminal view</string>
174+
175+
<!-- View Category -->
176+
<string name="termux_terminal_view_view_header">View</string>
177+
178+
<!-- Terminal View Margin Adjustment -->
179+
<string name="termux_terminal_view_terminal_margin_adjustment_title">Terminal Margin Adjustment</string>
180+
<string name="termux_terminal_view_terminal_margin_adjustment_off">Terminal margin adjustment will be disabled.</string>
181+
<string name="termux_terminal_view_terminal_margin_adjustment_on">Terminal margin adjustment will be enabled. It should be enabled to try to fix the issue where soft keyboard covers part of extra keys/terminal view. If it causes screen flickering on your devices, then disable it. (Default)</string>
182+
183+
184+
171185
<!-- Termux Tasker App Preferences -->
172186
<string name="termux_tasker_preferences_title">&TERMUX_TASKER_APP_NAME;</string>
173187
<string name="termux_tasker_preferences_summary">Preferences for &TERMUX_TASKER_APP_NAME; app</string>

app/src/main/res/xml/termux_preferences.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@
1010
app:summary="@string/termux_terminal_io_preferences_summary"
1111
app:fragment="com.termux.app.fragments.settings.termux.TerminalIOPreferencesFragment"/>
1212

13+
<Preference
14+
app:title="@string/termux_terminal_view_preferences_title"
15+
app:summary="@string/termux_terminal_view_preferences_summary"
16+
app:fragment="com.termux.app.fragments.settings.termux.TerminalViewPreferencesFragment"/>
17+
1318
</PreferenceScreen>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
2+
3+
<PreferenceCategory
4+
app:key="view"
5+
app:title="@string/termux_terminal_view_view_header">
6+
7+
<SwitchPreferenceCompat
8+
app:key="terminal_margin_adjustment"
9+
app:summaryOff="@string/termux_terminal_view_terminal_margin_adjustment_off"
10+
app:summaryOn="@string/termux_terminal_view_terminal_margin_adjustment_on"
11+
app:title="@string/termux_terminal_view_terminal_margin_adjustment_title" />
12+
13+
</PreferenceCategory>
14+
15+
</PreferenceScreen>

termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxAppSharedPreferences.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ public boolean toogleShowTerminalToolbar() {
9191

9292

9393

94+
public boolean isTerminalMarginAdjustmentEnabled() {
95+
return SharedPreferenceUtils.getBoolean(mSharedPreferences, TERMUX_APP.KEY_TERMINAL_MARGIN_ADJUSTMENT, TERMUX_APP.DEFAULT_TERMINAL_MARGIN_ADJUSTMENT);
96+
}
97+
98+
public void setTerminalMarginAdjustment(boolean value) {
99+
SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_TERMINAL_MARGIN_ADJUSTMENT, value, false);
100+
}
101+
102+
103+
94104
public boolean isSoftKeyboardEnabled() {
95105
return SharedPreferenceUtils.getBoolean(mSharedPreferences, TERMUX_APP.KEY_SOFT_KEYBOARD_ENABLED, TERMUX_APP.DEFAULT_VALUE_KEY_SOFT_KEYBOARD_ENABLED);
96106
}

termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxPreferenceConstants.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.termux.shared.settings.preferences;
22

33
/*
4-
* Version: v0.10.0
4+
* Version: v0.11.0
55
*
66
* Changelog
77
*
@@ -44,6 +44,10 @@
4444
* - 0.10.0 (2021-05-12)
4545
* - Added following to `TERMUX_APP`:
4646
* `KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE` and `DEFAULT_VALUE_KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE`.
47+
*
48+
* - 0.11.0 (2021-07-08)
49+
* - Added following to `TERMUX_APP`:
50+
* `KEY_DISABLE_TERMINAL_MARGIN_ADJUSTMENT`.
4751
*/
4852

4953
/**
@@ -60,6 +64,15 @@ public final class TermuxPreferenceConstants {
6064
*/
6165
public static final class TERMUX_APP {
6266

67+
/**
68+
* Defines the key for whether terminal view margin adjustment that is done to prevent soft
69+
* keyboard from covering bottom part of terminal view on some devices is enabled or not.
70+
* Margin adjustment may cause screen flickering on some devices and so should be disabled.
71+
*/
72+
public static final String KEY_TERMINAL_MARGIN_ADJUSTMENT = "terminal_margin_adjustment";
73+
public static final boolean DEFAULT_TERMINAL_MARGIN_ADJUSTMENT = true;
74+
75+
6376
/**
6477
* Defines the key for whether to show terminal toolbar containing extra keys and text input field.
6578
*/

0 commit comments

Comments
 (0)