diff --git a/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt b/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt index 1592974..1507b71 100644 --- a/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt +++ b/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt @@ -179,33 +179,69 @@ object NeoPreference { } fun getFontSize(): Int { - return loadInt(NeoPreference.KEY_FONT_SIZE, DefaultPreference.fontSize) + return loadInt(NeoPreference.KEY_FONT_SIZE, + DefaultPreference.fontSize) } fun getInitialCommand(): String { - return loadString(R.string.key_general_initial_command, DefaultPreference.initialCommand) + return loadString(R.string.key_general_initial_command, + DefaultPreference.initialCommand) } fun isBellEnabled(): Boolean { - return loadBoolean(R.string.key_general_bell, DefaultPreference.enableBell) + return loadBoolean(R.string.key_general_bell, + DefaultPreference.enableBell) } fun isVibrateEnabled(): Boolean { - return loadBoolean(R.string.key_general_vibrate, DefaultPreference.enableVibrate) + return loadBoolean(R.string.key_general_vibrate, + DefaultPreference.enableVibrate) } fun isExecveWrapperEnabled() : Boolean { - return loadBoolean(R.string.key_general_use_execve_wrapper, DefaultPreference.enableExecveWrapper) + return loadBoolean(R.string.key_general_use_execve_wrapper, + DefaultPreference.enableExecveWrapper) } fun isSpecialVolumeKeysEnabled() : Boolean { - return loadBoolean(R.string.key_general_volume_as_control, DefaultPreference.enableSpecialVolumeKeys) + return loadBoolean(R.string.key_general_volume_as_control, + DefaultPreference.enableSpecialVolumeKeys) } fun isAutoCompletionEnabled() : Boolean { - return loadBoolean(R.string.key_general_auto_completion, DefaultPreference.enableAutoCompletion) + return loadBoolean(R.string.key_general_auto_completion, + DefaultPreference.enableAutoCompletion) } + fun isBackButtonBeMappedToEscapeEnabled(): Boolean { + return loadBoolean(R.string.key_generaL_backspace_map_to_esc, + DefaultPreference.enableBackButtonBeMappedToEscape) + } + + fun isExtraKeysEnabled(): Boolean { + return loadBoolean(R.string.key_ui_eks_enabled, + DefaultPreference.enableExtraKeys) + } + + fun isExplicitExtraKeysWeightEnabled() :Boolean { + return NeoPreference.loadBoolean(R.string.key_ui_eks_weight_explicit, + DefaultPreference.enableExplicitExtraKeysWeight) + } + + fun isFullScreenEnabled() : Boolean { + return NeoPreference.loadBoolean(R.string.key_ui_fullscreen, + DefaultPreference.enableFullScreen) + } + + fun isHideToolbarEnabled() :Boolean { + return NeoPreference.loadBoolean(R.string.key_ui_hide_toolbar, + DefaultPreference.enableAutoHideToolbar) + } + + fun isNextTabEnabled() :Boolean { + return NeoPreference.loadBoolean(R.string.key_ui_next_tab_anim, + DefaultPreference.enableSwitchNextTab) + } // fun storeWindowSize(context: Context, width: Int, height: Int) { // store(KEY_FLOATING_WIDTH, width) diff --git a/app/src/main/java/io/neoterm/frontend/session/shell/ShellProfile.kt b/app/src/main/java/io/neoterm/frontend/session/shell/ShellProfile.kt index dbf9151..f31c96c 100644 --- a/app/src/main/java/io/neoterm/frontend/session/shell/ShellProfile.kt +++ b/app/src/main/java/io/neoterm/frontend/session/shell/ShellProfile.kt @@ -18,6 +18,8 @@ class ShellProfile { var enableExecveWrapper = DefaultPreference.enableExecveWrapper var enableSpecialVolumeKeys = DefaultPreference.enableSpecialVolumeKeys var enableAutoCompletion = DefaultPreference.enableAutoCompletion + var enableBackButtonBeMappedToEscape = DefaultPreference.enableBackButtonBeMappedToEscape + var enableExtraKeys = DefaultPreference.enableExtraKeys var profileFont: String var profileColorScheme: String @@ -36,5 +38,7 @@ class ShellProfile { enableExecveWrapper = NeoPreference.isExecveWrapperEnabled() enableSpecialVolumeKeys = NeoPreference.isSpecialVolumeKeysEnabled() enableAutoCompletion = NeoPreference.isAutoCompletionEnabled() + enableBackButtonBeMappedToEscape = NeoPreference.isBackButtonBeMappedToEscapeEnabled() + enableExtraKeys = NeoPreference.isExtraKeysEnabled() } } \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/frontend/session/shell/ShellTermSession.kt b/app/src/main/java/io/neoterm/frontend/session/shell/ShellTermSession.kt index 52497f0..a88827b 100644 --- a/app/src/main/java/io/neoterm/frontend/session/shell/ShellTermSession.kt +++ b/app/src/main/java/io/neoterm/frontend/session/shell/ShellTermSession.kt @@ -19,7 +19,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String, val shellProfile: ShellProfile) : TerminalSession(shellPath, cwd, args, env, changeCallback) { - var exitPrompt = App.get().getString(R.string.process_exit_prompt) + private var exitPrompt = App.get().getString(R.string.process_exit_prompt) override fun initializeEmulator(columns: Int, rows: Int) { super.initializeEmulator(columns, rows) @@ -202,8 +202,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String, var ldPreloadEnv = "" // execve(2) wrapper to avoid incorrect shebang - if (NeoPreference.loadBoolean(R.string.key_general_use_execve_wrapper, - DefaultPreference.enableExecveWrapper)) { + if (shellProfile.enableExecveWrapper) { ldPreloadEnv = "LD_PRELOAD=${App.get().applicationInfo.nativeLibraryDir}/libnexec.so" } diff --git a/app/src/main/java/io/neoterm/frontend/session/shell/client/TermSessionCallback.kt b/app/src/main/java/io/neoterm/frontend/session/shell/client/TermSessionCallback.kt index e00f77e..34c1e44 100644 --- a/app/src/main/java/io/neoterm/frontend/session/shell/client/TermSessionCallback.kt +++ b/app/src/main/java/io/neoterm/frontend/session/shell/client/TermSessionCallback.kt @@ -9,6 +9,7 @@ import io.neoterm.R import io.neoterm.backend.TerminalSession import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.preference.NeoPreference +import io.neoterm.frontend.session.shell.ShellTermSession /** * @author kiva @@ -43,8 +44,9 @@ class TermSessionCallback : TerminalSession.SessionChangedCallback { override fun onBell(session: TerminalSession?) { val termView = termData?.termView ?: return + val shellSession = session as ShellTermSession - if (NeoPreference.loadBoolean(R.string.key_general_bell, DefaultPreference.enableBell)) { + if (shellSession.shellProfile.enableBell) { if (soundPool == null) { soundPool = SoundPool.Builder().setMaxStreams(1).build() bellId = soundPool!!.load(termView.context, R.raw.bell, 1) @@ -52,7 +54,7 @@ class TermSessionCallback : TerminalSession.SessionChangedCallback { soundPool?.play(bellId, 1f, 1f, 0, 0, 1f) } - if (NeoPreference.loadBoolean(R.string.key_general_vibrate, DefaultPreference.enableVibrate)) { + if (shellSession.shellProfile.enableVibrate) { val vibrator = termView.context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator vibrator.vibrate(100) } diff --git a/app/src/main/java/io/neoterm/frontend/session/shell/client/TermViewClient.kt b/app/src/main/java/io/neoterm/frontend/session/shell/client/TermViewClient.kt index 409a0e1..fe576ad 100644 --- a/app/src/main/java/io/neoterm/frontend/session/shell/client/TermViewClient.kt +++ b/app/src/main/java/io/neoterm/frontend/session/shell/client/TermViewClient.kt @@ -14,6 +14,7 @@ import io.neoterm.component.eks.ExtraKeysComponent import io.neoterm.frontend.component.ComponentManager import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.preference.NeoPreference +import io.neoterm.frontend.session.shell.ShellTermSession import io.neoterm.frontend.terminal.TerminalViewClient @@ -37,16 +38,14 @@ class TermViewClient(val context: Context) : TerminalViewClient { } override fun onSingleTapUp(e: MotionEvent?) { - val termView = termData?.termView - if (termView != null) { - (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager) - .showSoftInput(termView, InputMethodManager.SHOW_IMPLICIT) - } + val termView = termData?.termView ?: return + (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager) + .showSoftInput(termView, InputMethodManager.SHOW_IMPLICIT) } override fun shouldBackButtonBeMappedToEscape(): Boolean { - return NeoPreference.loadBoolean(R.string.key_generaL_backspace_map_to_esc, - DefaultPreference.enableBackButtonBeMappedToEscape) + val shellSession = termData?.termSession as ShellTermSession? ?: return false + return shellSession.shellProfile.enableBackButtonBeMappedToEscape } override fun copyModeChanged(copyMode: Boolean) { @@ -196,9 +195,11 @@ class TermViewClient(val context: Context) : TerminalViewClient { if (event == null) { return false } + + val shellSession = termData?.termSession as ShellTermSession? ?: return false + // Volume keys as special keys - val volumeAsSpecialKeys = NeoPreference.loadBoolean(R.string.key_general_volume_as_control, - DefaultPreference.enableSpecialVolumeKeys) + val volumeAsSpecialKeys = shellSession.shellProfile.enableSpecialVolumeKeys val inputDevice = event.device if (inputDevice != null && inputDevice.keyboardType == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { @@ -231,9 +232,9 @@ class TermViewClient(val context: Context) : TerminalViewClient { private fun updateExtraKeysVisibility(): Boolean { val extraKeysView = termData?.extraKeysView ?: return false + val shellSession = termData?.termSession as ShellTermSession? ?: return false - return if (NeoPreference.loadBoolean(R.string.key_ui_eks_enabled, - DefaultPreference.enableExtraKeys)) { + return if (shellSession.shellProfile.enableExtraKeys) { extraKeysView.visibility = View.VISIBLE true } else { diff --git a/app/src/main/java/io/neoterm/frontend/terminal/eks/ExtraKeysView.kt b/app/src/main/java/io/neoterm/frontend/terminal/eks/ExtraKeysView.kt index e755249..bdcf103 100755 --- a/app/src/main/java/io/neoterm/frontend/terminal/eks/ExtraKeysView.kt +++ b/app/src/main/java/io/neoterm/frontend/terminal/eks/ExtraKeysView.kt @@ -162,8 +162,7 @@ class ExtraKeysView(context: Context, attrs: AttributeSet) : LinearLayout(contex val line = LinearLayout(context) val layoutParams = - if (NeoPreference.loadBoolean(R.string.key_ui_eks_weight_explicit, - DefaultPreference.enableExplicitExtraKeysWeight)) + if (NeoPreference.isExplicitExtraKeysWeightEnabled()) LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f) else LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, diff --git a/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt b/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt index d89b25a..49b19ec 100644 --- a/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt +++ b/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt @@ -63,8 +63,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION) - val fullscreen = NeoPreference.loadBoolean(R.string.key_ui_fullscreen, - DefaultPreference.enableFullScreen) + val fullscreen = NeoPreference.isFullScreenEnabled() if (fullscreen) { window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) @@ -101,10 +100,8 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference return } - if (NeoPreference.loadBoolean(R.string.key_ui_fullscreen, - DefaultPreference.enableFullScreen) - || NeoPreference.loadBoolean(R.string.key_ui_hide_toolbar, - DefaultPreference.enableAutoHideToolbar)) { + if (NeoPreference.isFullScreenEnabled() + || NeoPreference.isHideToolbarEnabled()) { val toolbarHeight = toolbar.height.toFloat() val translationY = if (visible) 0.toFloat() else -toolbarHeight if (visible) { @@ -665,8 +662,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference if (tabSwitcher.count > 1) { var index = tabSwitcher.indexOf(tab) - if (NeoPreference.loadBoolean(R.string.key_ui_next_tab_anim, - DefaultPreference.enableSwitchNextTab)) { + if (NeoPreference.isNextTabEnabled()) { // 关闭当前窗口后,向下一个窗口切换 if (--index < 0) index = tabSwitcher.count - 1 } else {