Skip to content

Commit

Permalink
Preserve the termux.properties literal string values internally that …
Browse files Browse the repository at this point in the history
…were being converted to boolean on load time

The `TermuxPropertyConstants` class has been updated to `v0.8.0`. Check its Changelog sections for info on changes.
  • Loading branch information
agnostic-apollo committed May 10, 2021
1 parent e4e638b commit e6dac93
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Set;

/*
* Version: v0.7.0
* Version: v0.8.0
*
* Changelog
*
Expand All @@ -36,6 +36,11 @@
*
* - 0.7.0 (2021-05-09)
* - Add `*SOFT_KEYBOARD_TOGGLE_BEHAVIOUR*`.
*
* - 0.8.0 (2021-05-10)
* - Change the `KEY_USE_BACK_KEY_AS_ESCAPE_KEY` and `KEY_VIRTUAL_VOLUME_KEYS_DISABLED` booleans
* to `KEY_BACK_KEY_BEHAVIOUR` and `KEY_VOLUME_KEYS_BEHAVIOUR` String internal values.
* - Renamed `SOFT_KEYBOARD_TOGGLE_BEHAVIOUR` to `KEY_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR`.
*/

/**
Expand All @@ -51,13 +56,7 @@
*/
public final class TermuxPropertyConstants {

/** Defines the key for whether to use back key as the escape key */
public static final String KEY_USE_BACK_KEY_AS_ESCAPE_KEY = "back-key"; // Default: "back-key"

public static final String VALUE_BACK_KEY_BEHAVIOUR_BACK = "back";
public static final String VALUE_BACK_KEY_BEHAVIOUR_ESCAPE = "escape";


/* boolean */

/** Defines the key for whether to enforce character based input to fix the issue where for some devices like Samsung, the letters might not appear until enter is pressed */
public static final String KEY_ENFORCE_CHAR_BASED_INPUT = "enforce-char-based-input"; // Default: "enforce-char-based-input"
Expand Down Expand Up @@ -89,13 +88,9 @@ public final class TermuxPropertyConstants {



/** Defines the key for whether virtual volume keys are disabled */
public static final String KEY_VIRTUAL_VOLUME_KEYS_DISABLED = "volume-keys"; // Default: "volume-keys"

public static final String VALUE_VOLUME_KEY_BEHAVIOUR_VOLUME = "volume";
public static final String VALUE_VOLUME_KEY_BEHAVIOUR_VIRTUAL = "virtual";


/* int */

/** Defines the key for the bell behaviour */
public static final String KEY_BELL_BEHAVIOUR = "bell-character"; // Default: "bell-character"
Expand All @@ -120,14 +115,22 @@ public final class TermuxPropertyConstants {



/** Defines the key for the bell behaviour */


/* float */

/** Defines the key for the terminal toolbar height */
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;





/* Integer */

/** 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 */
Expand All @@ -153,6 +156,19 @@ public final class TermuxPropertyConstants {





/* String */

/** Defines the key for whether back key will behave as escape key or literal back key */
public static final String KEY_BACK_KEY_BEHAVIOUR = "back-key"; // Default: "back-key"

public static final String IVALUE_BACK_KEY_BEHAVIOUR_BACK = "back";
public static final String IVALUE_BACK_KEY_BEHAVIOUR_ESCAPE = "escape";
public static final String DEFAULT_IVALUE_BACK_KEY_BEHAVIOUR = IVALUE_BACK_KEY_BEHAVIOUR_BACK;



/** Defines the key for the default working directory */
public static final String KEY_DEFAULT_WORKING_DIRECTORY = "default-working-directory"; // Default: "default-working-directory"
/** Defines the default working directory */
Expand All @@ -162,57 +178,67 @@ public final class TermuxPropertyConstants {

/** Defines the key for extra keys */
public static final String KEY_EXTRA_KEYS = "extra-keys"; // Default: "extra-keys"
public static final String DEFAULT_IVALUE_EXTRA_KEYS = "[[ESC, TAB, CTRL, ALT, {key: '-', popup: '|'}, DOWN, UP]]";

/** Defines the key for extra keys style */
public static final String KEY_EXTRA_KEYS_STYLE = "extra-keys-style"; // Default: "extra-keys-style"
public static final String DEFAULT_IVALUE_EXTRA_KEYS = "[[ESC, TAB, CTRL, ALT, {key: '-', popup: '|'}, DOWN, UP]]";
public static final String DEFAULT_IVALUE_EXTRA_KEYS_STYLE = "default";



/** Defines the key for whether toggle soft keyboard request will show/hide or enable/disable keyboard */
public static final String SOFT_KEYBOARD_TOGGLE_BEHAVIOUR = "soft-keyboard-toggle-behaviour"; // Default: "soft-keyboard-toggle-behaviour"
public static final String KEY_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR = "soft-keyboard-toggle-behaviour"; // Default: "soft-keyboard-toggle-behaviour"

public static final String IVALUE_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR_SHOW_HIDE = "show/hide";
public static final String IVALUE_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR_ENABLE_DISABLE = "enable/disable";
public static final String DEFAULT_IVALUE_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR = IVALUE_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR_SHOW_HIDE;



/** Defines the key for whether volume keys will behave as virtual or literal volume keys */
public static final String KEY_VOLUME_KEYS_BEHAVIOUR = "volume-keys"; // Default: "volume-keys"

public static final String IVALUE_VOLUME_KEY_BEHAVIOUR_VIRTUAL = "virtual";
public static final String IVALUE_VOLUME_KEY_BEHAVIOUR_VOLUME = "volume";
public static final String DEFAULT_IVALUE_VOLUME_KEYS_BEHAVIOUR = IVALUE_VOLUME_KEY_BEHAVIOUR_VIRTUAL;





/** Defines the set for keys loaded by termux
* Setting this to {@code null} will make {@link SharedProperties} throw an exception.
* */
public static final Set<String> TERMUX_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
// boolean
/* boolean */
KEY_ENFORCE_CHAR_BASED_INPUT,
KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP,
KEY_USE_BACK_KEY_AS_ESCAPE_KEY,
KEY_USE_BLACK_UI,
KEY_USE_CTRL_SPACE_WORKAROUND,
KEY_USE_FULLSCREEN,
KEY_USE_FULLSCREEN_WORKAROUND,
KEY_VIRTUAL_VOLUME_KEYS_DISABLED,
TermuxConstants.PROP_ALLOW_EXTERNAL_APPS,

// int
/* int */
KEY_BELL_BEHAVIOUR,

// float
/* float */
KEY_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR,

// Integer
/* Integer */
KEY_SHORTCUT_CREATE_SESSION,
KEY_SHORTCUT_NEXT_SESSION,
KEY_SHORTCUT_PREVIOUS_SESSION,
KEY_SHORTCUT_RENAME_SESSION,

// String
/* String */
KEY_BACK_KEY_BEHAVIOUR,
KEY_DEFAULT_WORKING_DIRECTORY,
KEY_EXTRA_KEYS,
KEY_EXTRA_KEYS_STYLE,
SOFT_KEYBOARD_TOGGLE_BEHAVIOUR
));
KEY_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR,
KEY_VOLUME_KEYS_BEHAVIOUR
));

/** Defines the set for keys loaded by termux that have default boolean behaviour
* "true" -> true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,38 +181,39 @@ public static Object getInternalTermuxPropertyValueFromValue(Context context, St
- If the value is not null and does exist in MAP_*, then internal value returned by map will be used.
*/
switch (key) {
// boolean
case TermuxPropertyConstants.KEY_USE_BACK_KEY_AS_ESCAPE_KEY:
return (boolean) getUseBackKeyAsEscapeKeyInternalPropertyValueFromValue(value);
/* boolean */
case TermuxPropertyConstants.KEY_USE_BLACK_UI:
return (boolean) getUseBlackUIInternalPropertyValueFromValue(context, value);
case TermuxPropertyConstants.KEY_VIRTUAL_VOLUME_KEYS_DISABLED:
return (boolean) getVolumeKeysDisabledInternalPropertyValueFromValue(value);

// int
/* int */
case TermuxPropertyConstants.KEY_BELL_BEHAVIOUR:
return (int) getBellBehaviourInternalPropertyValueFromValue(value);

// float
/* float */
case TermuxPropertyConstants.KEY_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR:
return (float) getTerminalToolbarHeightScaleFactorInternalPropertyValueFromValue(value);

// Integer (may be null)
/* Integer (may be null) */
case TermuxPropertyConstants.KEY_SHORTCUT_CREATE_SESSION:
case TermuxPropertyConstants.KEY_SHORTCUT_NEXT_SESSION:
case TermuxPropertyConstants.KEY_SHORTCUT_PREVIOUS_SESSION:
case TermuxPropertyConstants.KEY_SHORTCUT_RENAME_SESSION:
return (Integer) getCodePointForSessionShortcuts(key, value);

// String (may be null)
/* String (may be null) */
case TermuxPropertyConstants.KEY_BACK_KEY_BEHAVIOUR:
return (String) getBackKeyBehaviourInternalPropertyValueFromValue(value);
case TermuxPropertyConstants.KEY_DEFAULT_WORKING_DIRECTORY:
return (String) getDefaultWorkingDirectoryInternalPropertyValueFromValue(value);
case TermuxPropertyConstants.KEY_EXTRA_KEYS:
return (String) getExtraKeysInternalPropertyValueFromValue(value);
case TermuxPropertyConstants.KEY_EXTRA_KEYS_STYLE:
return (String) getExtraKeysStyleInternalPropertyValueFromValue(value);
case TermuxPropertyConstants.SOFT_KEYBOARD_TOGGLE_BEHAVIOUR:
case TermuxPropertyConstants.KEY_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR:
return (String) getSoftKeyboardToggleBehaviourInternalPropertyValueFromValue(value);
case TermuxPropertyConstants.KEY_VOLUME_KEYS_BEHAVIOUR:
return (String) getVolumeKeysBehaviourInternalPropertyValueFromValue(value);

default:
// default boolean behaviour
if (TermuxPropertyConstants.TERMUX_DEFAULT_BOOLEAN_BEHAVIOUR_PROPERTIES_LIST.contains(key))
Expand All @@ -230,15 +231,7 @@ else if (TermuxPropertyConstants.TERMUX_DEFAULT_INVERETED_BOOLEAN_BEHAVIOUR_PROP



/**
* Returns {@code true} if value is not {@code null} and equals {@link TermuxPropertyConstants#VALUE_BACK_KEY_BEHAVIOUR_ESCAPE}, otherwise false.
*
* @param value The {@link String} value to convert.
* @return Returns the internal value for value.
*/
public static boolean getUseBackKeyAsEscapeKeyInternalPropertyValueFromValue(String value) {
return SharedProperties.getDefaultIfNull(value, TermuxPropertyConstants.VALUE_BACK_KEY_BEHAVIOUR_BACK).equals(TermuxPropertyConstants.VALUE_BACK_KEY_BEHAVIOUR_ESCAPE);
}


/**
* Returns {@code true} or {@code false} if value is the literal string "true" or "false" respectively regardless of case.
Expand All @@ -252,17 +245,6 @@ public static boolean getUseBlackUIInternalPropertyValueFromValue(Context contex
return SharedProperties.getBooleanValueForStringValue(value, nightMode == Configuration.UI_MODE_NIGHT_YES);
}

/**
* 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.
*/
public static boolean getVolumeKeysDisabledInternalPropertyValueFromValue(String value) {
return SharedProperties.getDefaultIfNull(value, TermuxPropertyConstants.VALUE_VOLUME_KEY_BEHAVIOUR_VIRTUAL).equals(TermuxPropertyConstants.VALUE_VOLUME_KEY_BEHAVIOUR_VOLUME);
}

/**
* Returns the internal value after mapping it based on
* {@code TermuxPropertyConstants#MAP_BELL_BEHAVIOUR} if the value is not {@code null}
Expand Down Expand Up @@ -336,6 +318,16 @@ public static Integer getCodePointForSessionShortcuts(String key, String value)
return codePoint;
}

/**
* Returns the value itself if it is not {@code null}, otherwise returns {@link TermuxPropertyConstants#DEFAULT_IVALUE_BACK_KEY_BEHAVIOUR}.
*
* @param value {@link String} value to convert.
* @return Returns the internal value for value.
*/
public static String getBackKeyBehaviourInternalPropertyValueFromValue(String value) {
return SharedProperties.getDefaultIfNull(value, TermuxPropertyConstants.DEFAULT_IVALUE_BACK_KEY_BEHAVIOUR);
}

/**
* Returns the path itself if a directory exists at it and is readable, otherwise returns
* {@link TermuxPropertyConstants#DEFAULT_IVALUE_DEFAULT_WORKING_DIRECTORY}.
Expand Down Expand Up @@ -385,6 +377,15 @@ public static String getSoftKeyboardToggleBehaviourInternalPropertyValueFromValu
return SharedProperties.getDefaultIfNull(value, TermuxPropertyConstants.DEFAULT_IVALUE_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR);
}

/**
* Returns the value itself if it is not {@code null}, otherwise returns {@link TermuxPropertyConstants#DEFAULT_IVALUE_VOLUME_KEYS_BEHAVIOUR}.
*
* @param value {@link String} value to convert.
* @return Returns the internal value for value.
*/
public static String getVolumeKeysBehaviourInternalPropertyValueFromValue(String value) {
return SharedProperties.getDefaultIfNull(value, TermuxPropertyConstants.DEFAULT_IVALUE_VOLUME_KEYS_BEHAVIOUR);
}



Expand All @@ -397,10 +398,6 @@ public boolean shouldSoftKeyboardBeHiddenOnStartup() {
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP, true);
}

public boolean isBackKeyTheEscapeKey() {
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_BACK_KEY_AS_ESCAPE_KEY, true);
}

public boolean isUsingBlackUI() {
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_BLACK_UI, true);
}
Expand All @@ -417,10 +414,6 @@ public boolean isUsingFullScreenWorkAround() {
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_FULLSCREEN_WORKAROUND, true);
}

public boolean areVirtualVolumeKeysDisabled() {
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_VIRTUAL_VOLUME_KEYS_DISABLED, true);
}

public int getBellBehaviour() {
return (int) getInternalPropertyValue(TermuxPropertyConstants.KEY_BELL_BEHAVIOUR, true);
}
Expand All @@ -429,14 +422,21 @@ public float getTerminalToolbarHeightScaleFactor() {
return rangeTerminalToolbarHeightScaleFactorValue((float) getInternalPropertyValue(TermuxPropertyConstants.KEY_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR, true));
}

public boolean isBackKeyTheEscapeKey() {
return (boolean) TermuxPropertyConstants.IVALUE_BACK_KEY_BEHAVIOUR_ESCAPE.equals(getInternalPropertyValue(TermuxPropertyConstants.KEY_BACK_KEY_BEHAVIOUR, true));
}

public String getDefaultWorkingDirectory() {
return (String) getInternalPropertyValue(TermuxPropertyConstants.KEY_DEFAULT_WORKING_DIRECTORY, true);
}

public boolean shouldEnableDisableSoftKeyboardOnToggle() {
return (boolean) TermuxPropertyConstants.IVALUE_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR_ENABLE_DISABLE.equals(getInternalPropertyValue(TermuxPropertyConstants.SOFT_KEYBOARD_TOGGLE_BEHAVIOUR, true));
return (boolean) TermuxPropertyConstants.IVALUE_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR_ENABLE_DISABLE.equals(getInternalPropertyValue(TermuxPropertyConstants.KEY_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR, true));
}

public boolean areVirtualVolumeKeysDisabled() {
return (boolean) TermuxPropertyConstants.IVALUE_VOLUME_KEY_BEHAVIOUR_VOLUME.equals(getInternalPropertyValue(TermuxPropertyConstants.KEY_VOLUME_KEYS_BEHAVIOUR, true));
}



Expand Down

0 comments on commit e6dac93

Please sign in to comment.