Skip to content

Commit 1ef8eb9

Browse files
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
1 parent d3ddb21 commit 1ef8eb9

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

app/src/main/java/com/termux/app/TermuxActivity.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,20 @@ private void setNewSessionButtonView() {
405405

406406
private void setToggleKeyboardView() {
407407
findViewById(R.id.toggle_keyboard_button).setOnClickListener(v -> {
408-
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
409-
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
408+
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
409+
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
410410
getDrawer().closeDrawers();
411411
});
412412

413413
findViewById(R.id.toggle_keyboard_button).setOnLongClickListener(v -> {
414414
toggleTerminalToolbar();
415415
return true;
416416
});
417+
418+
// If soft keyboard is to be hidden on startup
419+
if(mProperties.shouldSoftKeyboardBeHiddenOnStartup()) {
420+
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
421+
}
417422
}
418423

419424

app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,26 @@
1010
import java.util.Set;
1111

1212
/*
13-
* Version: v0.4.0
13+
* Version: v0.5.0
1414
*
1515
* Changelog
1616
*
1717
* - 0.1.0 (2021-03-11)
1818
* - Initial Release.
1919
*
2020
* - 0.2.0 (2021-03-11)
21-
* - Renamed `HOME_PATH` to `TERMUX_HOME_DIR_PATH`
22-
* - Renamed `TERMUX_PROPERTIES_PRIMARY_PATH` to `TERMUX_PROPERTIES_PRIMARY_FILE_PATH`
23-
* - Renamed `TERMUX_PROPERTIES_SECONDARY_FILE_PATH` to `TERMUX_PROPERTIES_SECONDARY_FILE_PATH`
21+
* - Renamed `HOME_PATH` to `TERMUX_HOME_DIR_PATH`.
22+
* - Renamed `TERMUX_PROPERTIES_PRIMARY_PATH` to `TERMUX_PROPERTIES_PRIMARY_FILE_PATH`.
23+
* - Renamed `TERMUX_PROPERTIES_SECONDARY_FILE_PATH` to `TERMUX_PROPERTIES_SECONDARY_FILE_PATH`.
2424
*
2525
* - 0.3.0 (2021-03-16)
26-
* - Add `*TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR*`
26+
* - Add `*TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR*`.
2727
*
2828
* - 0.4.0 (2021-03-16)
2929
* - Removed `MAP_GENERIC_BOOLEAN` and `MAP_GENERIC_INVERTED_BOOLEAN`.
30+
*
31+
* - 0.5.0 (2021-03-25)
32+
* - Add `KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP`.
3033
*/
3134

3235
/**
@@ -55,6 +58,11 @@ public final class TermuxPropertyConstants {
5558

5659

5760

61+
/** Defines the key for whether to hide soft keyboard when termux app is started */
62+
public static final String KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP = "hide-soft-keyboard-on-startup"; // Default: "hide-soft-keyboard-on-startup"
63+
64+
65+
5866
/** Defines the key for whether to use black UI */
5967
public static final String KEY_USE_BLACK_UI = "use-black-ui"; // Default: "use-black-ui"
6068

@@ -163,6 +171,7 @@ public final class TermuxPropertyConstants {
163171
public static final Set<String> TERMUX_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
164172
// boolean
165173
KEY_ENFORCE_CHAR_BASED_INPUT,
174+
KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP,
166175
KEY_USE_BACK_KEY_AS_ESCAPE_KEY,
167176
KEY_USE_BLACK_UI,
168177
KEY_USE_CTRL_SPACE_WORKAROUND,
@@ -196,6 +205,7 @@ public final class TermuxPropertyConstants {
196205
* */
197206
public static final Set<String> TERMUX_DEFAULT_BOOLEAN_BEHAVIOUR_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
198207
KEY_ENFORCE_CHAR_BASED_INPUT,
208+
KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP,
199209
KEY_USE_CTRL_SPACE_WORKAROUND,
200210
KEY_USE_FULLSCREEN,
201211
KEY_USE_FULLSCREEN_WORKAROUND,

app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java

+4
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ public boolean isEnforcingCharBasedInput() {
437437
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_ENFORCE_CHAR_BASED_INPUT, true);
438438
}
439439

440+
public boolean shouldSoftKeyboardBeHiddenOnStartup() {
441+
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP, true);
442+
}
443+
440444
public boolean isBackKeyTheEscapeKey() {
441445
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_BACK_KEY_AS_ESCAPE_KEY, true);
442446
}

0 commit comments

Comments
 (0)