diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index addd0ac4ea..7d5c352d50 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -228,6 +228,13 @@ public void onStart() { mTerminalView.onScreenUpdated(); } + @Override + public void onResume() { + super.onResume(); + + setSoftKeyboardState(); + } + /** * Part of the {@link ServiceConnection} interface. The service is bound with * {@link #bindService(Intent, ServiceConnection, int)} in {@link #onCreate(Bundle)} which will cause a call to this @@ -414,6 +421,15 @@ private void setToggleKeyboardView() { toggleTerminalToolbar(); return true; }); + } + + private void setSoftKeyboardState() { + // If soft keyboard is to disabled + if(!mPreferences.getSoftKeyboardEnabled()) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); + } else { + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); + } // If soft keyboard is to be hidden on startup if(mProperties.shouldSoftKeyboardBeHiddenOnStartup()) { @@ -723,6 +739,8 @@ public void onReceive(Context context, Intent intent) { setTerminalToolbarHeight(); + setSoftKeyboardState(); + // To change the activity and drawer theme, activity needs to be recreated. // But this will destroy the activity, and will call the onCreate() again. // We need to investigate if enabling this is wise, since all stored variables and diff --git a/app/src/main/java/com/termux/app/fragments/settings/DebuggingPreferencesFragment.java b/app/src/main/java/com/termux/app/fragments/settings/DebuggingPreferencesFragment.java index d7a3aa600c..d8841eb477 100644 --- a/app/src/main/java/com/termux/app/fragments/settings/DebuggingPreferencesFragment.java +++ b/app/src/main/java/com/termux/app/fragments/settings/DebuggingPreferencesFragment.java @@ -15,6 +15,7 @@ import com.termux.app.utils.Logger; public class DebuggingPreferencesFragment extends PreferenceFragmentCompat { + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { PreferenceManager preferenceManager = getPreferenceManager(); @@ -126,4 +127,5 @@ public boolean getBoolean(String key, boolean defValue) { return false; } } + } diff --git a/app/src/main/java/com/termux/app/fragments/settings/TerminalIOPreferencesFragment.java b/app/src/main/java/com/termux/app/fragments/settings/TerminalIOPreferencesFragment.java new file mode 100644 index 0000000000..874a87b4b0 --- /dev/null +++ b/app/src/main/java/com/termux/app/fragments/settings/TerminalIOPreferencesFragment.java @@ -0,0 +1,71 @@ +package com.termux.app.fragments.settings; + +import android.content.Context; +import android.os.Bundle; + +import androidx.annotation.Nullable; + +import androidx.preference.PreferenceDataStore; +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceManager; + +import com.termux.R; +import com.termux.app.settings.preferences.TermuxAppSharedPreferences; + +public class TerminalIOPreferencesFragment extends PreferenceFragmentCompat { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + PreferenceManager preferenceManager = getPreferenceManager(); + preferenceManager.setPreferenceDataStore(TerminalIOPreferencesDataStore.getInstance(getContext())); + + setPreferencesFromResource(R.xml.terminal_io_preferences, rootKey); + } + +} + +class TerminalIOPreferencesDataStore extends PreferenceDataStore { + + private final Context mContext; + private final TermuxAppSharedPreferences mPreferences; + + private static TerminalIOPreferencesDataStore mInstance; + + private TerminalIOPreferencesDataStore(Context context) { + mContext = context; + mPreferences = new TermuxAppSharedPreferences(context); + } + + public static synchronized TerminalIOPreferencesDataStore getInstance(Context context) { + if (mInstance == null) { + mInstance = new TerminalIOPreferencesDataStore(context.getApplicationContext()); + } + return mInstance; + } + + + + @Override + public void putBoolean(String key, boolean value) { + if(key == null) return; + + switch (key) { + case "soft_keyboard_enabled": + mPreferences.setSoftKeyboardEnabled(value); + break; + default: + break; + } + } + + @Override + public boolean getBoolean(String key, boolean defValue) { + switch (key) { + case "soft_keyboard_enabled": + return mPreferences.getSoftKeyboardEnabled(); + default: + return false; + } + } + +} diff --git a/app/src/main/java/com/termux/app/settings/preferences/TermuxAppSharedPreferences.java b/app/src/main/java/com/termux/app/settings/preferences/TermuxAppSharedPreferences.java index a1e663d7bc..de469143a6 100644 --- a/app/src/main/java/com/termux/app/settings/preferences/TermuxAppSharedPreferences.java +++ b/app/src/main/java/com/termux/app/settings/preferences/TermuxAppSharedPreferences.java @@ -53,6 +53,16 @@ public boolean toogleShowTerminalToolbar() { + public boolean getSoftKeyboardEnabled() { + return SharedPreferenceUtils.getBoolean(mSharedPreferences, TERMUX_APP.KEY_SOFT_KEYBOARD_ENABLED, TERMUX_APP.DEFAULT_VALUE_KEY_SOFT_KEYBOARD_ENABLED); + } + + public void setSoftKeyboardEnabled(boolean value) { + SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_SOFT_KEYBOARD_ENABLED, value, false); + } + + + public boolean getKeepScreenOn() { return SharedPreferenceUtils.getBoolean(mSharedPreferences, TERMUX_APP.KEY_KEEP_SCREEN_ON, TERMUX_APP.DEFAULT_VALUE_KEEP_SCREEN_ON); } diff --git a/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java b/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java index 3fed9967bd..fd4aef0722 100644 --- a/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java +++ b/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java @@ -1,7 +1,7 @@ package com.termux.app.settings.preferences; /* - * Version: v0.6.0 + * Version: v0.7.0 * * Changelog * @@ -29,6 +29,10 @@ * * - 0.6.0 (2021-03-24) * - Change `DEFAULT_VALUE_KEEP_SCREEN_ON` value to `false` in `TERMUX_APP`. + * + * - 0.7.0 (2021-03-27) + * - Added following to `TERMUX_APP`: + * `KEY_SOFT_KEYBOARD_ENABLED` and `DEFAULT_VALUE_KEY_SOFT_KEYBOARD_ENABLED`. */ /** @@ -46,39 +50,47 @@ public final class TermuxPreferenceConstants { public static final class TERMUX_APP { /** - * Defines the key for whether to show terminal toolbar containing extra keys and text input field + * Defines the key for whether to show terminal toolbar containing extra keys and text input field. */ public static final String KEY_SHOW_TERMINAL_TOOLBAR = "show_extra_keys"; public static final boolean DEFAULT_VALUE_SHOW_TERMINAL_TOOLBAR = true; /** - * Defines the key for whether to always keep screen on + * Defines the key for whether the soft keyboard will be enabled, for cases where users want + * to use a hardware keyboard instead. + */ + public static final String KEY_SOFT_KEYBOARD_ENABLED = "soft_keyboard_enabled"; + public static final boolean DEFAULT_VALUE_KEY_SOFT_KEYBOARD_ENABLED = true; + + + /** + * Defines the key for whether to always keep screen on. */ public static final String KEY_KEEP_SCREEN_ON = "screen_always_on"; public static final boolean DEFAULT_VALUE_KEEP_SCREEN_ON = false; /** - * Defines the key for font size of termux terminal view + * Defines the key for font size of termux terminal view. */ public static final String KEY_FONTSIZE = "fontsize"; /** - * Defines the key for current termux terminal session + * Defines the key for current termux terminal session. */ public static final String KEY_CURRENT_SESSION = "current_session"; /** - * Defines the key for current termux log level + * Defines the key for current termux log level. */ public static final String KEY_LOG_LEVEL = "log_level"; /** - * Defines the key for last used notification id + * Defines the key for last used notification id. */ public static final String KEY_LAST_NOTIFICATION_ID = "last_notification_id"; public static final int DEFAULT_VALUE_KEY_LAST_NOTIFICATION_ID = 0; @@ -91,7 +103,7 @@ public static final class TERMUX_APP { public static final boolean DEFAULT_VALUE_TERMINAL_VIEW_KEY_LOGGING_ENABLED = false; /** - * Defines the key for whether flashes and notifications for plugin errors are enabled or not + * Defines the key for whether flashes and notifications for plugin errors are enabled or not. */ public static final String KEY_PLUGIN_ERROR_NOTIFICATIONS_ENABLED = "plugin_error_notifications_enabled"; public static final boolean DEFAULT_VALUE_PLUGIN_ERROR_NOTIFICATIONS_ENABLED = true; @@ -104,7 +116,7 @@ public static final class TERMUX_APP { public static final class TERMUX_TASKER_APP { /** - * Defines the key for current termux log level + * Defines the key for current termux log level. */ public static final String KEY_LOG_LEVEL = "log_level"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52a43ae78d..211fa379c8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -172,4 +172,17 @@ Disable flashes and notifications for plugin errors. Show flashes and notifications for plugin errors. (Default) + + + Terminal I/O + + + Keyboard + + + Soft Keyboard + Soft keyboard will be disabled. + Soft keyboard will be enabled. (Default) + + diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 39c731ebf8..75dd8826ac 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -5,4 +5,9 @@ app:summary="Preferences for debugging" app:fragment="com.termux.app.fragments.settings.DebuggingPreferencesFragment"/> + + diff --git a/app/src/main/res/xml/terminal_io_preferences.xml b/app/src/main/res/xml/terminal_io_preferences.xml new file mode 100644 index 0000000000..d20e7c58bf --- /dev/null +++ b/app/src/main/res/xml/terminal_io_preferences.xml @@ -0,0 +1,15 @@ + + + + + + + + +