Skip to content

Commit

Permalink
Allow users to disable terminal margin adjustment from termux settings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agnostic-apollo committed Jul 8, 2021
1 parent 7aefd94 commit e0ad9ff
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ public void onStart() {
if (mTermuxTerminalViewClient != null)
mTermuxTerminalViewClient.onStart();

addTermuxActivityRootViewGlobalLayoutListener();
if (mPreferences.isTerminalMarginAdjustmentEnabled())
addTermuxActivityRootViewGlobalLayoutListener();

registerTermuxActivityBroadcastReceiver();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.termux.app.fragments.settings.termux;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.Keep;
import androidx.preference.PreferenceDataStore;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;

import com.termux.R;
import com.termux.shared.settings.preferences.TermuxAppSharedPreferences;

@Keep
public class TerminalViewPreferencesFragment extends PreferenceFragmentCompat {

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Context context = getContext();
if (context == null) return;

PreferenceManager preferenceManager = getPreferenceManager();
preferenceManager.setPreferenceDataStore(TerminalViewPreferencesDataStore.getInstance(context));

setPreferencesFromResource(R.xml.termux_terminal_view_preferences, rootKey);
}

}

class TerminalViewPreferencesDataStore extends PreferenceDataStore {

private final Context mContext;
private final TermuxAppSharedPreferences mPreferences;

private static TerminalViewPreferencesDataStore mInstance;

private TerminalViewPreferencesDataStore(Context context) {
mContext = context;
mPreferences = TermuxAppSharedPreferences.build(context, true);
}

public static synchronized TerminalViewPreferencesDataStore getInstance(Context context) {
if (mInstance == null) {
mInstance = new TerminalViewPreferencesDataStore(context);
}
return mInstance;
}



@Override
public void putBoolean(String key, boolean value) {
if (mPreferences == null) return;
if (key == null) return;

switch (key) {
case "terminal_margin_adjustment":
mPreferences.setTerminalMarginAdjustment(value);
break;
default:
break;
}
}

@Override
public boolean getBoolean(String key, boolean defValue) {
if (mPreferences == null) return false;

switch (key) {
case "terminal_margin_adjustment":
return mPreferences.isTerminalMarginAdjustmentEnabled();
default:
return false;
}
}

}
14 changes: 14 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@
<string name="termux_soft_keyboard_enabled_only_if_no_hardware_on">Soft keyboard will be enabled only if no hardware keyboard is connected.</string>


<!-- Terminal View Preferences -->
<string name="termux_terminal_view_preferences_title">Terminal View</string>
<string name="termux_terminal_view_preferences_summary">Preferences for terminal view</string>

<!-- View Category -->
<string name="termux_terminal_view_view_header">View</string>

<!-- Terminal View Margin Adjustment -->
<string name="termux_terminal_view_terminal_margin_adjustment_title">Terminal Margin Adjustment</string>
<string name="termux_terminal_view_terminal_margin_adjustment_off">Terminal margin adjustment will be disabled.</string>
<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>



<!-- Termux Tasker App Preferences -->
<string name="termux_tasker_preferences_title">&TERMUX_TASKER_APP_NAME;</string>
<string name="termux_tasker_preferences_summary">Preferences for &TERMUX_TASKER_APP_NAME; app</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/termux_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
app:summary="@string/termux_terminal_io_preferences_summary"
app:fragment="com.termux.app.fragments.settings.termux.TerminalIOPreferencesFragment"/>

<Preference
app:title="@string/termux_terminal_view_preferences_title"
app:summary="@string/termux_terminal_view_preferences_summary"
app:fragment="com.termux.app.fragments.settings.termux.TerminalViewPreferencesFragment"/>

</PreferenceScreen>
15 changes: 15 additions & 0 deletions app/src/main/res/xml/termux_terminal_view_preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<PreferenceScreen xmlns:app="http:https://schemas.android.com/apk/res-auto">

<PreferenceCategory
app:key="view"
app:title="@string/termux_terminal_view_view_header">

<SwitchPreferenceCompat
app:key="terminal_margin_adjustment"
app:summaryOff="@string/termux_terminal_view_terminal_margin_adjustment_off"
app:summaryOn="@string/termux_terminal_view_terminal_margin_adjustment_on"
app:title="@string/termux_terminal_view_terminal_margin_adjustment_title" />

</PreferenceCategory>

</PreferenceScreen>
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public boolean toogleShowTerminalToolbar() {



public boolean isTerminalMarginAdjustmentEnabled() {
return SharedPreferenceUtils.getBoolean(mSharedPreferences, TERMUX_APP.KEY_TERMINAL_MARGIN_ADJUSTMENT, TERMUX_APP.DEFAULT_TERMINAL_MARGIN_ADJUSTMENT);
}

public void setTerminalMarginAdjustment(boolean value) {
SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_TERMINAL_MARGIN_ADJUSTMENT, value, false);
}



public boolean isSoftKeyboardEnabled() {
return SharedPreferenceUtils.getBoolean(mSharedPreferences, TERMUX_APP.KEY_SOFT_KEYBOARD_ENABLED, TERMUX_APP.DEFAULT_VALUE_KEY_SOFT_KEYBOARD_ENABLED);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.termux.shared.settings.preferences;

/*
* Version: v0.10.0
* Version: v0.11.0
*
* Changelog
*
Expand Down Expand Up @@ -44,6 +44,10 @@
* - 0.10.0 (2021-05-12)
* - Added following to `TERMUX_APP`:
* `KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE` and `DEFAULT_VALUE_KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE`.
*
* - 0.11.0 (2021-07-08)
* - Added following to `TERMUX_APP`:
* `KEY_DISABLE_TERMINAL_MARGIN_ADJUSTMENT`.
*/

/**
Expand All @@ -60,6 +64,15 @@ public final class TermuxPreferenceConstants {
*/
public static final class TERMUX_APP {

/**
* Defines the key for whether terminal view margin adjustment that is done to prevent soft
* keyboard from covering bottom part of terminal view on some devices is enabled or not.
* Margin adjustment may cause screen flickering on some devices and so should be disabled.
*/
public static final String KEY_TERMINAL_MARGIN_ADJUSTMENT = "terminal_margin_adjustment";
public static final boolean DEFAULT_TERMINAL_MARGIN_ADJUSTMENT = true;


/**
* Defines the key for whether to show terminal toolbar containing extra keys and text input field.
*/
Expand Down

0 comments on commit e0ad9ff

Please sign in to comment.