Allow users to enable/disable keyboard instead of just show/hide with keyboard toggle buttons

This `soft-keyboard-toggle-behaviour` key can be used to change the behaviour. The default behaviour is `show/hide`. The user can set the value to `enable/disable` in `termux.properties` file to change default behaviour of keyboard toggle buttons to enable/disable. In this mode, tapping the keyboard toggle button will disable (and hide) the keyboard and tapping on the terminal view will not open the keybaord automatically, until the keyboard toggle button is pressed again manually. This applies to split screen and floating keyboard as well. The keyboard can also be enabled from Settings -> Keyboard I/O -> Soft Keyboard toggle. Running `termux-reload-settings` command will also update the behaviour instantaneously if changed.

Fixed issue where "hide-soft-keyboard-on-startup" property wouldn't work if Termux app was switched back from another app. Fixes #1098

Fixed issue where soft keyboard may not show on startup on some devices but it still may fail sometimes.

The `TermuxPropertyConstants` class has been updated to `v0.7.0`. Check its Changelog sections for info on changes.
This commit is contained in:
agnostic-apollo
2021-05-10 06:03:29 +05:00
parent fe8c3ba216
commit e4e638bd31
5 changed files with 80 additions and 22 deletions

View File

@@ -10,7 +10,7 @@ import java.util.HashSet;
import java.util.Set;
/*
* Version: v0.6.0
* Version: v0.7.0
*
* Changelog
*
@@ -33,6 +33,9 @@ import java.util.Set;
*
* - 0.6.0 (2021-04-07)
* - Updated javadocs.
*
* - 0.7.0 (2021-05-09)
* - Add `*SOFT_KEYBOARD_TOGGLE_BEHAVIOUR*`.
*/
/**
@@ -166,6 +169,15 @@ public final class TermuxPropertyConstants {
/** 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 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 set for keys loaded by termux
@@ -198,7 +210,8 @@ public final class TermuxPropertyConstants {
// String
KEY_DEFAULT_WORKING_DIRECTORY,
KEY_EXTRA_KEYS,
KEY_EXTRA_KEYS_STYLE
KEY_EXTRA_KEYS_STYLE,
SOFT_KEYBOARD_TOGGLE_BEHAVIOUR
));
/** Defines the set for keys loaded by termux that have default boolean behaviour

View File

@@ -211,6 +211,8 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
return (String) getExtraKeysInternalPropertyValueFromValue(value);
case TermuxPropertyConstants.KEY_EXTRA_KEYS_STYLE:
return (String) getExtraKeysStyleInternalPropertyValueFromValue(value);
case TermuxPropertyConstants.SOFT_KEYBOARD_TOGGLE_BEHAVIOUR:
return (String) getSoftKeyboardToggleBehaviourInternalPropertyValueFromValue(value);
default:
// default boolean behaviour
if (TermuxPropertyConstants.TERMUX_DEFAULT_BOOLEAN_BEHAVIOUR_PROPERTIES_LIST.contains(key))
@@ -373,6 +375,16 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
return SharedProperties.getDefaultIfNull(value, TermuxPropertyConstants.DEFAULT_IVALUE_EXTRA_KEYS_STYLE);
}
/**
* Returns the value itself if it is not {@code null}, otherwise returns {@link TermuxPropertyConstants#DEFAULT_IVALUE_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR}.
*
* @param value {@link String} value to convert.
* @return Returns the internal value for value.
*/
public static String getSoftKeyboardToggleBehaviourInternalPropertyValueFromValue(String value) {
return SharedProperties.getDefaultIfNull(value, TermuxPropertyConstants.DEFAULT_IVALUE_SOFT_KEYBOARD_TOGGLE_BEHAVIOUR);
}
@@ -421,6 +433,10 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
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));
}

View File

@@ -19,7 +19,9 @@ public class KeyboardUtils {
public static void setSoftKeyboardVisibility(@NonNull final Runnable showSoftKeyboardRunnable, final Activity activity, final View view, final boolean visible) {
if (visible) {
view.postDelayed(showSoftKeyboardRunnable, 1000);
// A Runnable with a delay is used, otherwise soft keyboard may not automatically open
// on some devices, but still may fail
view.postDelayed(showSoftKeyboardRunnable, 500);
} else {
view.removeCallbacks(showSoftKeyboardRunnable);
hideSoftKeyboard(activity, view);