From 6cac4639b09bbc2cd6436859a9edbf0d8d9584c0 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Thu, 25 Mar 2021 12:30:59 +0500 Subject: [PATCH] Add hide-soft-keyboard-on-startup property If its set to `true` in termux.properties file, then soft keyboard will automatically be hidden on Termux App start to solve issues for when users use hardware keyboard and soft keyboard is automatically opened and wastes terminal screen space. The `TermuxPropertyConstants` classes has been updated to `v0.5.0`. Check its Changelog sections for info on changes. Fixes #1978 --- .../java/com/termux/app/TermuxActivity.java | 9 +++++++-- .../properties/TermuxPropertyConstants.java | 20 ++++++++++++++----- .../properties/TermuxSharedProperties.java | 4 ++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index 0b311e8c7e..8684506147 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -405,8 +405,8 @@ private void setNewSessionButtonView() { private void setToggleKeyboardView() { findViewById(R.id.toggle_keyboard_button).setOnClickListener(v -> { - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); + InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); getDrawer().closeDrawers(); }); @@ -414,6 +414,11 @@ private void setToggleKeyboardView() { toggleTerminalToolbar(); return true; }); + + // If soft keyboard is to be hidden on startup + if(mProperties.shouldSoftKeyboardBeHiddenOnStartup()) { + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + } } diff --git a/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java b/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java index b3acbb3973..fefe4246cf 100644 --- a/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java +++ b/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java @@ -10,7 +10,7 @@ import java.util.Set; /* - * Version: v0.4.0 + * Version: v0.5.0 * * Changelog * @@ -18,15 +18,18 @@ * - Initial Release. * * - 0.2.0 (2021-03-11) - * - 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` + * - 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*` + * - Add `*TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR*`. * * - 0.4.0 (2021-03-16) * - Removed `MAP_GENERIC_BOOLEAN` and `MAP_GENERIC_INVERTED_BOOLEAN`. + * + * - 0.5.0 (2021-03-25) + * - Add `KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP`. */ /** @@ -55,6 +58,11 @@ public final class TermuxPropertyConstants { + /** Defines the key for whether to hide soft keyboard when termux app is started */ + public static final String KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP = "hide-soft-keyboard-on-startup"; // Default: "hide-soft-keyboard-on-startup" + + + /** Defines the key for whether to use black UI */ public static final String KEY_USE_BLACK_UI = "use-black-ui"; // Default: "use-black-ui" @@ -163,6 +171,7 @@ public final class TermuxPropertyConstants { public static final Set TERMUX_PROPERTIES_LIST = new HashSet<>(Arrays.asList( // 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, @@ -196,6 +205,7 @@ public final class TermuxPropertyConstants { * */ public static final Set TERMUX_DEFAULT_BOOLEAN_BEHAVIOUR_PROPERTIES_LIST = new HashSet<>(Arrays.asList( KEY_ENFORCE_CHAR_BASED_INPUT, + KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP, KEY_USE_CTRL_SPACE_WORKAROUND, KEY_USE_FULLSCREEN, KEY_USE_FULLSCREEN_WORKAROUND, diff --git a/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java b/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java index a39c273b4a..0943a2f80a 100644 --- a/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java +++ b/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java @@ -437,6 +437,10 @@ public boolean isEnforcingCharBasedInput() { return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_ENFORCE_CHAR_BASED_INPUT, true); } + 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); }