mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-09 03:54:17 +08:00
Merge pull request #2237 from agnostic-apollo/extra-keys-conversion-to-agnosticism
Extra keys conversion to agnosticism and disabling hardware keyboard shortcuts and terminal margin customization support
This commit is contained in:
@@ -553,6 +553,17 @@ public class SharedProperties {
|
||||
return (object == null) ? def : object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link String} object itself if it is not {@code null} or empty, otherwise default.
|
||||
*
|
||||
* @param object The {@link String} to check.
|
||||
* @param def The default {@link String}.
|
||||
* @return Returns {@code object} if it is not {@code null}, otherwise returns {@code def}.
|
||||
*/
|
||||
public static String getDefaultIfNullOrEmpty(@androidx.annotation.Nullable String object, @androidx.annotation.Nullable String def) {
|
||||
return (object == null || object.isEmpty()) ? def : object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Covert the {@link String} value to lowercase.
|
||||
*
|
||||
|
@@ -12,7 +12,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/*
|
||||
* Version: v0.12.0
|
||||
* Version: v0.13.0
|
||||
*
|
||||
* Changelog
|
||||
*
|
||||
@@ -55,6 +55,9 @@ import java.util.Set;
|
||||
*
|
||||
* - 0.12.0 (2021-06-10)
|
||||
* - Add `*KEY_TERMINAL_CURSOR_STYLE*`.
|
||||
*
|
||||
* - 0.13.0 (2021-08-25)
|
||||
* - Add `*KEY_TERMINAL_MARGIN_HORIZONTAL*` and `*KEY_TERMINAL_MARGIN_VERTICAL*`.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -72,6 +75,10 @@ public final class TermuxPropertyConstants {
|
||||
|
||||
/* boolean */
|
||||
|
||||
/** Defines the key for whether hardware keyboard shortcuts are enabled. */
|
||||
public static final String KEY_DISABLE_HARDWARE_KEYBOARD_SHORTCUTS = "disable-hardware-keyboard-shortcuts"; // Default: "disable-hardware-keyboard-shortcuts"
|
||||
|
||||
|
||||
/** Defines the key for whether a toast will be shown when user changes the terminal session */
|
||||
public static final String KEY_DISABLE_TERMINAL_SESSION_CHANGE_TOAST = "disable-terminal-session-change-toast"; // Default: "disable-terminal-session-change-toast"
|
||||
|
||||
@@ -169,6 +176,20 @@ public final class TermuxPropertyConstants {
|
||||
|
||||
|
||||
|
||||
/** Defines the key for the terminal margin on left and right in dp units */
|
||||
public static final String KEY_TERMINAL_MARGIN_HORIZONTAL = "terminal-margin-horizontal"; // Default: "terminal-margin-horizontal"
|
||||
public static final int IVALUE_TERMINAL_MARGIN_HORIZONTAL_MIN = 0;
|
||||
public static final int IVALUE_TERMINAL_MARGIN_HORIZONTAL_MAX = 100;
|
||||
public static final int DEFAULT_IVALUE_TERMINAL_HORIZONTAL_MARGIN = 3;
|
||||
|
||||
/** Defines the key for the terminal margin on top and bottom in dp units */
|
||||
public static final String KEY_TERMINAL_MARGIN_VERTICAL = "terminal-margin-vertical"; // Default: "terminal-margin-vertical"
|
||||
public static final int IVALUE_TERMINAL_MARGIN_VERTICAL_MIN = 0;
|
||||
public static final int IVALUE_TERMINAL_MARGIN_VERTICAL_MAX = 100;
|
||||
public static final int DEFAULT_IVALUE_TERMINAL_VERTICAL_MARGIN = 0;
|
||||
|
||||
|
||||
|
||||
/** Defines the key for the terminal transcript rows */
|
||||
public static final String KEY_TERMINAL_TRANSCRIPT_ROWS = "terminal-transcript-rows"; // Default: "terminal-transcript-rows"
|
||||
public static final int IVALUE_TERMINAL_TRANSCRIPT_ROWS_MIN = TerminalEmulator.TERMINAL_TRANSCRIPT_ROWS_MIN;
|
||||
@@ -295,6 +316,7 @@ public final class TermuxPropertyConstants {
|
||||
* */
|
||||
public static final Set<String> TERMUX_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
|
||||
/* boolean */
|
||||
KEY_DISABLE_HARDWARE_KEYBOARD_SHORTCUTS,
|
||||
KEY_DISABLE_TERMINAL_SESSION_CHANGE_TOAST,
|
||||
KEY_ENFORCE_CHAR_BASED_INPUT,
|
||||
KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP,
|
||||
@@ -309,6 +331,8 @@ public final class TermuxPropertyConstants {
|
||||
KEY_BELL_BEHAVIOUR,
|
||||
KEY_TERMINAL_CURSOR_BLINK_RATE,
|
||||
KEY_TERMINAL_CURSOR_STYLE,
|
||||
KEY_TERMINAL_MARGIN_HORIZONTAL,
|
||||
KEY_TERMINAL_MARGIN_VERTICAL,
|
||||
KEY_TERMINAL_TRANSCRIPT_ROWS,
|
||||
|
||||
/* float */
|
||||
@@ -335,6 +359,7 @@ public final class TermuxPropertyConstants {
|
||||
* default: false
|
||||
* */
|
||||
public static final Set<String> TERMUX_DEFAULT_BOOLEAN_BEHAVIOUR_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
|
||||
KEY_DISABLE_HARDWARE_KEYBOARD_SHORTCUTS,
|
||||
KEY_DISABLE_TERMINAL_SESSION_CHANGE_TOAST,
|
||||
KEY_ENFORCE_CHAR_BASED_INPUT,
|
||||
KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP,
|
||||
|
@@ -219,6 +219,10 @@ public class TermuxSharedProperties {
|
||||
return (int) getTerminalCursorBlinkRateInternalPropertyValueFromValue(value);
|
||||
case TermuxPropertyConstants.KEY_TERMINAL_CURSOR_STYLE:
|
||||
return (int) getTerminalCursorStyleInternalPropertyValueFromValue(value);
|
||||
case TermuxPropertyConstants.KEY_TERMINAL_MARGIN_HORIZONTAL:
|
||||
return (int) getTerminalMarginHorizontalInternalPropertyValueFromValue(value);
|
||||
case TermuxPropertyConstants.KEY_TERMINAL_MARGIN_VERTICAL:
|
||||
return (int) getTerminalMarginVerticalInternalPropertyValueFromValue(value);
|
||||
case TermuxPropertyConstants.KEY_TERMINAL_TRANSCRIPT_ROWS:
|
||||
return (int) getTerminalTranscriptRowsInternalPropertyValueFromValue(value);
|
||||
|
||||
@@ -318,6 +322,42 @@ public class TermuxSharedProperties {
|
||||
return (int) SharedProperties.getDefaultIfNotInMap(TermuxPropertyConstants.KEY_TERMINAL_CURSOR_STYLE, TermuxPropertyConstants.MAP_TERMINAL_CURSOR_STYLE, SharedProperties.toLowerCase(value), TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_CURSOR_STYLE, true, LOG_TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the int for the value if its not null and is between
|
||||
* {@link TermuxPropertyConstants#IVALUE_TERMINAL_MARGIN_HORIZONTAL_MIN} and
|
||||
* {@link TermuxPropertyConstants#IVALUE_TERMINAL_MARGIN_HORIZONTAL_MAX},
|
||||
* otherwise returns {@link TermuxPropertyConstants#DEFAULT_IVALUE_TERMINAL_HORIZONTAL_MARGIN}.
|
||||
*
|
||||
* @param value The {@link String} value to convert.
|
||||
* @return Returns the internal value for value.
|
||||
*/
|
||||
public static int getTerminalMarginHorizontalInternalPropertyValueFromValue(String value) {
|
||||
return SharedProperties.getDefaultIfNotInRange(TermuxPropertyConstants.KEY_TERMINAL_MARGIN_HORIZONTAL,
|
||||
DataUtils.getIntFromString(value, TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_HORIZONTAL_MARGIN),
|
||||
TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_HORIZONTAL_MARGIN,
|
||||
TermuxPropertyConstants.IVALUE_TERMINAL_MARGIN_HORIZONTAL_MIN,
|
||||
TermuxPropertyConstants.IVALUE_TERMINAL_MARGIN_HORIZONTAL_MAX,
|
||||
true, true, LOG_TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the int for the value if its not null and is between
|
||||
* {@link TermuxPropertyConstants#IVALUE_TERMINAL_MARGIN_VERTICAL_MIN} and
|
||||
* {@link TermuxPropertyConstants#IVALUE_TERMINAL_MARGIN_VERTICAL_MAX},
|
||||
* otherwise returns {@link TermuxPropertyConstants#DEFAULT_IVALUE_TERMINAL_VERTICAL_MARGIN}.
|
||||
*
|
||||
* @param value The {@link String} value to convert.
|
||||
* @return Returns the internal value for value.
|
||||
*/
|
||||
public static int getTerminalMarginVerticalInternalPropertyValueFromValue(String value) {
|
||||
return SharedProperties.getDefaultIfNotInRange(TermuxPropertyConstants.KEY_TERMINAL_MARGIN_VERTICAL,
|
||||
DataUtils.getIntFromString(value, TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_VERTICAL_MARGIN),
|
||||
TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_VERTICAL_MARGIN,
|
||||
TermuxPropertyConstants.IVALUE_TERMINAL_MARGIN_VERTICAL_MIN,
|
||||
TermuxPropertyConstants.IVALUE_TERMINAL_MARGIN_VERTICAL_MAX,
|
||||
true, true, LOG_TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the int for the value if its not null and is between
|
||||
* {@link TermuxPropertyConstants#IVALUE_TERMINAL_TRANSCRIPT_ROWS_MIN} and
|
||||
@@ -423,7 +463,7 @@ public class TermuxSharedProperties {
|
||||
* @return Returns the internal value for value.
|
||||
*/
|
||||
public static String getExtraKeysInternalPropertyValueFromValue(String value) {
|
||||
return SharedProperties.getDefaultIfNull(value, TermuxPropertyConstants.DEFAULT_IVALUE_EXTRA_KEYS);
|
||||
return SharedProperties.getDefaultIfNullOrEmpty(value, TermuxPropertyConstants.DEFAULT_IVALUE_EXTRA_KEYS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -433,7 +473,7 @@ public class TermuxSharedProperties {
|
||||
* @return Returns the internal value for value.
|
||||
*/
|
||||
public static String getExtraKeysStyleInternalPropertyValueFromValue(String value) {
|
||||
return SharedProperties.getDefaultIfNull(value, TermuxPropertyConstants.DEFAULT_IVALUE_EXTRA_KEYS_STYLE);
|
||||
return SharedProperties.getDefaultIfNullOrEmpty(value, TermuxPropertyConstants.DEFAULT_IVALUE_EXTRA_KEYS_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,6 +500,10 @@ public class TermuxSharedProperties {
|
||||
|
||||
|
||||
|
||||
public boolean areHardwareKeyboardShortcutsDisabled() {
|
||||
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_DISABLE_TERMINAL_SESSION_CHANGE_TOAST, true);
|
||||
}
|
||||
|
||||
public boolean areTerminalSessionChangeToastsDisabled() {
|
||||
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_DISABLE_TERMINAL_SESSION_CHANGE_TOAST, true);
|
||||
}
|
||||
@@ -504,6 +548,14 @@ public class TermuxSharedProperties {
|
||||
return (int) getInternalPropertyValue(TermuxPropertyConstants.KEY_TERMINAL_CURSOR_STYLE, true);
|
||||
}
|
||||
|
||||
public int getTerminalMarginHorizontal() {
|
||||
return (int) getInternalPropertyValue(TermuxPropertyConstants.KEY_TERMINAL_MARGIN_HORIZONTAL, true);
|
||||
}
|
||||
|
||||
public int getTerminalMarginVertical() {
|
||||
return (int) getInternalPropertyValue(TermuxPropertyConstants.KEY_TERMINAL_MARGIN_VERTICAL, true);
|
||||
}
|
||||
|
||||
public int getTerminalTranscriptRows() {
|
||||
return (int) getInternalPropertyValue(TermuxPropertyConstants.KEY_TERMINAL_TRANSCRIPT_ROWS, true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user