mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
Allow users to adjust termux toolbar height with termux.properties
This `terminal-toolbar-height` key can be used to adjust the toolbar height. The user can set a float value between `0.4` and `3.0` which will be used as the scaling factor for the default height. The default scaling factor is `1`. So adding an entry like `terminal-toolbar-height=2.0` to `termux.properties` file will make the toolbar height twice its original height. Running `termux-reload-settings` command will also update the height instantaneously if changed. Fixes #1857
This commit is contained in:
@@ -124,9 +124,11 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
||||
* If between onResume() and onStop(). Note that only one session is in the foreground of the terminal view at the
|
||||
* time, so if the session causing a change is not in the foreground it should probably be treated as background.
|
||||
*/
|
||||
boolean mIsVisible;
|
||||
private boolean mIsVisible;
|
||||
|
||||
int mNavBarHeight;
|
||||
private int mNavBarHeight;
|
||||
|
||||
private int mTerminalToolbarDefaultHeight;
|
||||
|
||||
private static final int CONTEXT_MENU_SELECT_URL_ID = 0;
|
||||
private static final int CONTEXT_MENU_SHARE_TRANSCRIPT_ID = 1;
|
||||
@@ -341,8 +343,9 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
||||
if (mPreferences.getShowTerminalToolbar()) terminalToolbarViewPager.setVisibility(View.VISIBLE);
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = terminalToolbarViewPager.getLayoutParams();
|
||||
layoutParams.height = layoutParams.height * (mProperties.getExtraKeysInfo() == null ? 0 : mProperties.getExtraKeysInfo().getMatrix().length);
|
||||
terminalToolbarViewPager.setLayoutParams(layoutParams);
|
||||
mTerminalToolbarDefaultHeight = layoutParams.height;
|
||||
|
||||
setTerminalToolbarHeight();
|
||||
|
||||
String savedTextInput = null;
|
||||
if(savedInstanceState != null)
|
||||
@@ -352,8 +355,20 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
||||
terminalToolbarViewPager.addOnPageChangeListener(new TerminalToolbarViewPager.OnPageChangeListener(this, terminalToolbarViewPager));
|
||||
}
|
||||
|
||||
private void setTerminalToolbarHeight() {
|
||||
final ViewPager terminalToolbarViewPager = findViewById(R.id.terminal_toolbar_view_pager);
|
||||
if(terminalToolbarViewPager == null) return;
|
||||
ViewGroup.LayoutParams layoutParams = terminalToolbarViewPager.getLayoutParams();
|
||||
layoutParams.height = (int) Math.round(mTerminalToolbarDefaultHeight *
|
||||
(mProperties.getExtraKeysInfo() == null ? 0 : mProperties.getExtraKeysInfo().getMatrix().length) *
|
||||
mProperties.getTerminalToolbarHeightScaleFactor());
|
||||
terminalToolbarViewPager.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
public void toggleTerminalToolbar() {
|
||||
final ViewPager terminalToolbarViewPager = findViewById(R.id.terminal_toolbar_view_pager);
|
||||
if(terminalToolbarViewPager == null) return;
|
||||
|
||||
final boolean showNow = mPreferences.toogleShowTerminalToolbar();
|
||||
terminalToolbarViewPager.setVisibility(showNow ? View.VISIBLE : View.GONE);
|
||||
if (showNow && terminalToolbarViewPager.getCurrentItem() == 1) {
|
||||
@@ -690,6 +705,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
||||
}
|
||||
}
|
||||
|
||||
setTerminalToolbarHeight();
|
||||
|
||||
// To change the activity and drawer theme, activity needs to be recreated.
|
||||
// But this will destroy the activity, and will call the onCreate() again.
|
||||
// We need to investigate if enabling this is wise, since all stored variables and
|
||||
|
@@ -7,6 +7,7 @@ import android.util.TypedValue;
|
||||
import com.termux.app.TermuxConstants;
|
||||
import com.termux.app.utils.Logger;
|
||||
import com.termux.app.utils.TermuxUtils;
|
||||
import com.termux.app.utils.TextDataUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -89,7 +90,7 @@ public class TermuxSharedPreferences {
|
||||
} catch (NumberFormatException | ClassCastException e) {
|
||||
fontSize = DEFAULT_FONTSIZE;
|
||||
}
|
||||
fontSize = clamp(fontSize, MIN_FONTSIZE, MAX_FONTSIZE);
|
||||
fontSize = TextDataUtils.clamp(fontSize, MIN_FONTSIZE, MAX_FONTSIZE);
|
||||
|
||||
return fontSize;
|
||||
}
|
||||
@@ -147,11 +148,6 @@ public class TermuxSharedPreferences {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* If value is not in the range [min, max], set it to either min or max.
|
||||
*/
|
||||
static int clamp(int value, int min, int max) {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/*
|
||||
* Version: v0.2.0
|
||||
* Version: v0.3.0
|
||||
*
|
||||
* Changelog
|
||||
*
|
||||
@@ -20,6 +20,8 @@ import java.util.Set;
|
||||
* - Renamed `HOME_PATH` to `TERMUX_HOME_DIR_PATH`
|
||||
* - Renamed `TERMUX_PROPERTIES_PRIMARY_PATH` to `TERMUX_PROPERTIES_PRIMARY_FILE_PATH`
|
||||
* - Renamed `TERMUX_PROPERTIES_SECONDARY_FILE_PATH` to `TERMUX_PROPERTIES_SECONDARY_FILE_PATH`
|
||||
* - 0.3.0 (2021-03-16)
|
||||
* - Add `*TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR*`
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -116,6 +118,14 @@ public final class TermuxPropertyConstants {
|
||||
|
||||
|
||||
|
||||
/** Defines the key for the bell behaviour */
|
||||
public static final String KEY_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR = "terminal-toolbar-height"; // Default: "terminal-toolbar-height"
|
||||
public static final float IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MIN = 0.4f;
|
||||
public static final float IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MAX = 3;
|
||||
public static final float DEFAULT_IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR = 1;
|
||||
|
||||
|
||||
|
||||
/** Defines the key for create session shortcut */
|
||||
public static final String KEY_SHORTCUT_CREATE_SESSION = "shortcut.create-session"; // Default: "shortcut.create-session"
|
||||
/** Defines the key for next session shortcut */
|
||||
@@ -176,6 +186,9 @@ public final class TermuxPropertyConstants {
|
||||
// int
|
||||
KEY_BELL_BEHAVIOUR,
|
||||
|
||||
// float
|
||||
KEY_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR,
|
||||
|
||||
// Integer
|
||||
KEY_SHORTCUT_CREATE_SESSION,
|
||||
KEY_SHORTCUT_NEXT_SESSION,
|
||||
|
@@ -8,6 +8,7 @@ import androidx.annotation.Nullable;
|
||||
import com.termux.app.terminal.io.extrakeys.ExtraKeysInfo;
|
||||
import com.termux.app.terminal.io.KeyboardShortcut;
|
||||
import com.termux.app.utils.Logger;
|
||||
import com.termux.app.utils.TextDataUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
@@ -313,6 +314,10 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
|
||||
case TermuxPropertyConstants.KEY_BELL_BEHAVIOUR:
|
||||
return (int) getBellBehaviourInternalPropertyValueFromValue(value);
|
||||
|
||||
// float
|
||||
case TermuxPropertyConstants.KEY_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR:
|
||||
return (float) getTerminalToolbarHeightScaleFactorInternalPropertyValueFromValue(value);
|
||||
|
||||
// Integer (may be null)
|
||||
case TermuxPropertyConstants.KEY_SHORTCUT_CREATE_SESSION:
|
||||
case TermuxPropertyConstants.KEY_SHORTCUT_NEXT_SESSION:
|
||||
@@ -391,7 +396,8 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if value is not {@code null} and equals {@link TermuxPropertyConstants#VALUE_VOLUME_KEY_BEHAVIOUR_VOLUME}, otherwise {@code false}.
|
||||
* Returns {@code true} if value is not {@code null} and equals
|
||||
* {@link TermuxPropertyConstants#VALUE_VOLUME_KEY_BEHAVIOUR_VOLUME}, otherwise {@code false}.
|
||||
*
|
||||
* @param value The {@link String} value to convert.
|
||||
* @return Returns the internal value for value.
|
||||
@@ -401,7 +407,9 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if value is not {@code null} and equals {@link TermuxPropertyConstants#VALUE_BACK_KEY_BEHAVIOUR_ESCAPE}, otherwise {@code false}.
|
||||
* Returns the internal value after mapping it based on
|
||||
* {@code TermuxPropertyConstants#MAP_BELL_BEHAVIOUR} if the value is not {@code null}
|
||||
* and is valid, otherwise returns {@code TermuxPropertyConstants#DEFAULT_IVALUE_BELL_BEHAVIOUR}.
|
||||
*
|
||||
* @param value The {@link String} value to convert.
|
||||
* @return Returns the internal value for value.
|
||||
@@ -410,6 +418,35 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
|
||||
return getDefaultIfNull(TermuxPropertyConstants.MAP_BELL_BEHAVIOUR.get(toLowerCase(value)), TermuxPropertyConstants.DEFAULT_IVALUE_BELL_BEHAVIOUR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the int for the value if its not null and is between
|
||||
* {@code TermuxPropertyConstants#IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MIN} and
|
||||
* {@code TermuxPropertyConstants#IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MAX},
|
||||
* otherwise returns {@code TermuxPropertyConstants#DEFAULT_IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR}.
|
||||
*
|
||||
* @param value The {@link String} value to convert.
|
||||
* @return Returns the internal value for value.
|
||||
*/
|
||||
public static float getTerminalToolbarHeightScaleFactorInternalPropertyValueFromValue(String value) {
|
||||
return rangeTerminalToolbarHeightScaleFactorValue(TextDataUtils.getFloatFromString(value, TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value itself if it is between
|
||||
* {@code TermuxPropertyConstants#IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MIN} and
|
||||
* {@code TermuxPropertyConstants#IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MAX},
|
||||
* otherwise returns {@code TermuxPropertyConstants#DEFAULT_IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR}.
|
||||
*
|
||||
* @param value The value to clamp.
|
||||
* @return Returns the clamped value.
|
||||
*/
|
||||
public static float rangeTerminalToolbarHeightScaleFactorValue(float value) {
|
||||
return TextDataUtils.rangedOrDefault(value,
|
||||
TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR,
|
||||
TermuxPropertyConstants.IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MIN,
|
||||
TermuxPropertyConstants.IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code point for the value if key is not {@code null} and value is not {@code null} and is valid,
|
||||
* otherwise returns {@code null}.
|
||||
@@ -517,6 +554,10 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
|
||||
return (int) getInternalPropertyValue(TermuxPropertyConstants.KEY_BELL_BEHAVIOUR, true);
|
||||
}
|
||||
|
||||
public float getTerminalToolbarHeightScaleFactor() {
|
||||
return rangeTerminalToolbarHeightScaleFactorValue((float) getInternalPropertyValue(TermuxPropertyConstants.KEY_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR, true));
|
||||
}
|
||||
|
||||
public List<KeyboardShortcut> getSessionShortcuts() {
|
||||
return mSessionShortcuts;
|
||||
}
|
||||
|
@@ -21,6 +21,47 @@ public class TextDataUtils {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static float getFloatFromString(String value, float def) {
|
||||
if(value == null) return def;
|
||||
|
||||
try {
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getIntFromString(String value, int def) {
|
||||
if(value == null) return def;
|
||||
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If value is not in the range [min, max], set it to either min or max.
|
||||
*/
|
||||
public static int clamp(int value, int min, int max) {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
/**
|
||||
* If value is not in the range [min, max], set it to default.
|
||||
*/
|
||||
public static float rangedOrDefault(float value, float def, float min, float max) {
|
||||
if (value < min || value > max)
|
||||
return def;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static LinkedHashSet<CharSequence> extractUrls(String text) {
|
||||
|
||||
StringBuilder regex_sb = new StringBuilder();
|
||||
|
Reference in New Issue
Block a user