Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Configuration;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
Expand Down Expand Up @@ -53,6 +54,7 @@
import com.termux.shared.termux.settings.properties.TermuxAppSharedProperties;
import com.termux.shared.termux.theme.TermuxThemeUtils;
import com.termux.shared.theme.NightMode;
import com.termux.shared.view.KeyboardUtils;
import com.termux.shared.view.ViewUtils;
import com.termux.terminal.TerminalSession;
import com.termux.terminal.TerminalSessionClient;
Expand Down Expand Up @@ -322,6 +324,12 @@ public void onResume() {
mIsOnResumeAfterOnCreate = false;
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateExtraKeysVisibility();
}

@Override
protected void onStop() {
super.onStop();
Expand Down Expand Up @@ -512,7 +520,7 @@ private void setTerminalToolbarView(Bundle savedInstanceState) {
mTermuxTerminalViewClient, mTermuxTerminalSessionActivityClient);

final ViewPager terminalToolbarViewPager = getTerminalToolbarViewPager();
if (mPreferences.shouldShowTerminalToolbar()) terminalToolbarViewPager.setVisibility(View.VISIBLE);
if (shouldExtraKeysBeVisible()) terminalToolbarViewPager.setVisibility(View.VISIBLE);

ViewGroup.LayoutParams layoutParams = terminalToolbarViewPager.getLayoutParams();
mTerminalToolbarDefaultHeight = layoutParams.height;
Expand Down Expand Up @@ -544,13 +552,32 @@ public void toggleTerminalToolbar() {

final boolean showNow = mPreferences.toogleShowTerminalToolbar();
Logger.showToast(this, (showNow ? getString(R.string.msg_enabling_terminal_toolbar) : getString(R.string.msg_disabling_terminal_toolbar)), true);
terminalToolbarViewPager.setVisibility(showNow ? View.VISIBLE : View.GONE);
if (showNow && isTerminalToolbarTextInputViewSelected()) {
boolean visible = showNow && !(mPreferences.isExtraKeysOnlyIfNoHardware() && KeyboardUtils.isHardKeyboardConnected(this));
terminalToolbarViewPager.setVisibility(visible ? View.VISIBLE : View.GONE);
if (visible && isTerminalToolbarTextInputViewSelected()) {
// Focus the text input view if just revealed.
findViewById(R.id.terminal_toolbar_text_input).requestFocus();
}
}

/**
* Whether the extra keys toolbar should be visible, considering both the user toolbar toggle
* and the "extra keys only if no hardware" setting.
*/
public boolean shouldExtraKeysBeVisible() {
return mPreferences.shouldShowTerminalToolbar()
&& !(mPreferences.isExtraKeysOnlyIfNoHardware() && KeyboardUtils.isHardKeyboardConnected(this));
}

/**
* Update extra keys toolbar visibility based on current hardware keyboard state and preferences.
*/
public void updateExtraKeysVisibility() {
final ViewPager terminalToolbarViewPager = getTerminalToolbarViewPager();
if (terminalToolbarViewPager == null) return;
terminalToolbarViewPager.setVisibility(shouldExtraKeysBeVisible() ? View.VISIBLE : View.GONE);
}

private void saveTerminalToolbarTextInput(Bundle savedInstanceState) {
if (savedInstanceState == null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public void putBoolean(String key, boolean value) {
case "soft_keyboard_enabled_only_if_no_hardware":
mPreferences.setSoftKeyboardEnabledOnlyIfNoHardware(value);
break;
case "extra_keys_only_if_no_hardware":
mPreferences.setExtraKeysOnlyIfNoHardware(value);
break;
default:
break;
}
Expand All @@ -74,6 +77,8 @@ public boolean getBoolean(String key, boolean defValue) {
return mPreferences.isSoftKeyboardEnabled();
case "soft_keyboard_enabled_only_if_no_hardware":
return mPreferences.isSoftKeyboardEnabledOnlyIfNoHardware();
case "extra_keys_only_if_no_hardware":
return mPreferences.isExtraKeysOnlyIfNoHardware();
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public void onResume() {
// Show the soft keyboard if required
setSoftKeyboardState(true, mActivity.isActivityRecreated());

// Update extra keys visibility based on hardware keyboard state
mActivity.updateExtraKeysVisibility();

mTerminalCursorBlinkerStateAlreadySet = false;

if (mActivity.getTerminalView().mEmulator != null) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@
<string name="termux_soft_keyboard_enabled_only_if_no_hardware_on">Soft keyboard will be enabled only if
no hardware keyboard is connected.</string>

<!-- Extra Keys Only If No Hardware -->
<string name="termux_extra_keys_only_if_no_hardware_title">Extra Keys Only If No Hardware</string>
<string name="termux_extra_keys_only_if_no_hardware_off">Extra keys will be shown regardless of hardware keyboard. (Default)</string>
<string name="termux_extra_keys_only_if_no_hardware_on">Extra keys will be hidden when hardware keyboard is connected.</string>


<!-- Terminal View Preferences -->
<string name="termux_terminal_view_preferences_title">Terminal View</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/termux_terminal_io_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
app:summaryOn="@string/termux_soft_keyboard_enabled_only_if_no_hardware_on"
app:title="@string/termux_soft_keyboard_enabled_only_if_no_hardware_title" />

<SwitchPreferenceCompat
app:key="extra_keys_only_if_no_hardware"
app:summaryOff="@string/termux_extra_keys_only_if_no_hardware_off"
app:summaryOn="@string/termux_extra_keys_only_if_no_hardware_on"
app:title="@string/termux_extra_keys_only_if_no_hardware_title" />

</PreferenceCategory>

</PreferenceScreen>
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public void setSoftKeyboardEnabledOnlyIfNoHardware(boolean value) {
SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE, value, false);
}

public boolean isExtraKeysOnlyIfNoHardware() {
return SharedPreferenceUtils.getBoolean(mSharedPreferences, TERMUX_APP.KEY_EXTRA_KEYS_ONLY_IF_NO_HARDWARE, TERMUX_APP.DEFAULT_VALUE_EXTRA_KEYS_ONLY_IF_NO_HARDWARE);
}

public void setExtraKeysOnlyIfNoHardware(boolean value) {
SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_EXTRA_KEYS_ONLY_IF_NO_HARDWARE, value, false);
}



public boolean shouldKeepScreenOn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ public static final class TERMUX_APP {
public static final String KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE = "soft_keyboard_enabled_only_if_no_hardware";
public static final boolean DEFAULT_VALUE_KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE = false;

/**
* Defines the key for whether the extra keys toolbar will be shown only if no hardware keyboard
* attached, for cases where users want to use a hardware keyboard instead.
*/
public static final String KEY_EXTRA_KEYS_ONLY_IF_NO_HARDWARE = "extra_keys_only_if_no_hardware";
public static final boolean DEFAULT_VALUE_EXTRA_KEYS_ONLY_IF_NO_HARDWARE = false;


/**
* Defines the key for whether to always keep screen on.
Expand Down