mirror of
				https://github.com/fankes/termux-app.git
				synced 2025-10-25 13:19:21 +08:00 
			
		
		
		
	Preserve the termux.properties literal string values internally that 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.
This commit is contained in:
		| @@ -10,7 +10,7 @@ import java.util.HashSet; | ||||
| import java.util.Set; | ||||
|  | ||||
| /* | ||||
|  * Version: v0.7.0 | ||||
|  * Version: v0.8.0 | ||||
|  * | ||||
|  * Changelog | ||||
|  * | ||||
| @@ -36,6 +36,11 @@ import java.util.Set; | ||||
|  * | ||||
|  * - 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`. | ||||
|  */ | ||||
|  | ||||
| /** | ||||
| @@ -51,13 +56,7 @@ import java.util.Set; | ||||
|  */ | ||||
| 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" | ||||
| @@ -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" | ||||
| @@ -120,7 +115,11 @@ 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; | ||||
| @@ -128,6 +127,10 @@ public final class TermuxPropertyConstants { | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     /* 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 */ | ||||
| @@ -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 */ | ||||
| @@ -162,15 +178,16 @@ 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"; | ||||
| @@ -178,41 +195,50 @@ public final class TermuxPropertyConstants { | ||||
|  | ||||
|  | ||||
|  | ||||
|     /** 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 | ||||
|   | ||||
| @@ -181,38 +181,39 @@ public class TermuxSharedProperties implements SharedPropertiesParser { | ||||
|           - 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)) | ||||
| @@ -230,15 +231,7 @@ public class TermuxSharedProperties implements SharedPropertiesParser { | ||||
|  | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * 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. | ||||
| @@ -252,17 +245,6 @@ public class TermuxSharedProperties implements SharedPropertiesParser { | ||||
|         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} | ||||
| @@ -336,6 +318,16 @@ public class TermuxSharedProperties implements SharedPropertiesParser { | ||||
|         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}. | ||||
| @@ -385,6 +377,15 @@ public class TermuxSharedProperties implements SharedPropertiesParser { | ||||
|         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); | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
| @@ -397,10 +398,6 @@ public class TermuxSharedProperties implements SharedPropertiesParser { | ||||
|         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); | ||||
|     } | ||||
| @@ -417,10 +414,6 @@ public class TermuxSharedProperties implements SharedPropertiesParser { | ||||
|         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); | ||||
|     } | ||||
| @@ -429,14 +422,21 @@ public class TermuxSharedProperties implements SharedPropertiesParser { | ||||
|         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)); | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user