Preference: Update profile

This commit is contained in:
zt515 2017-12-08 23:26:18 +08:00
parent 1eef869145
commit a2a3a86fa1
7 changed files with 70 additions and 33 deletions

View File

@ -179,33 +179,69 @@ object NeoPreference {
} }
fun getFontSize(): Int { fun getFontSize(): Int {
return loadInt(NeoPreference.KEY_FONT_SIZE, DefaultPreference.fontSize) return loadInt(NeoPreference.KEY_FONT_SIZE,
DefaultPreference.fontSize)
} }
fun getInitialCommand(): String { 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 { fun isBellEnabled(): Boolean {
return loadBoolean(R.string.key_general_bell, DefaultPreference.enableBell) return loadBoolean(R.string.key_general_bell,
DefaultPreference.enableBell)
} }
fun isVibrateEnabled(): Boolean { fun isVibrateEnabled(): Boolean {
return loadBoolean(R.string.key_general_vibrate, DefaultPreference.enableVibrate) return loadBoolean(R.string.key_general_vibrate,
DefaultPreference.enableVibrate)
} }
fun isExecveWrapperEnabled() : Boolean { 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 { 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 { 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) { // fun storeWindowSize(context: Context, width: Int, height: Int) {
// store(KEY_FLOATING_WIDTH, width) // store(KEY_FLOATING_WIDTH, width)

View File

@ -18,6 +18,8 @@ class ShellProfile {
var enableExecveWrapper = DefaultPreference.enableExecveWrapper var enableExecveWrapper = DefaultPreference.enableExecveWrapper
var enableSpecialVolumeKeys = DefaultPreference.enableSpecialVolumeKeys var enableSpecialVolumeKeys = DefaultPreference.enableSpecialVolumeKeys
var enableAutoCompletion = DefaultPreference.enableAutoCompletion var enableAutoCompletion = DefaultPreference.enableAutoCompletion
var enableBackButtonBeMappedToEscape = DefaultPreference.enableBackButtonBeMappedToEscape
var enableExtraKeys = DefaultPreference.enableExtraKeys
var profileFont: String var profileFont: String
var profileColorScheme: String var profileColorScheme: String
@ -36,5 +38,7 @@ class ShellProfile {
enableExecveWrapper = NeoPreference.isExecveWrapperEnabled() enableExecveWrapper = NeoPreference.isExecveWrapperEnabled()
enableSpecialVolumeKeys = NeoPreference.isSpecialVolumeKeysEnabled() enableSpecialVolumeKeys = NeoPreference.isSpecialVolumeKeysEnabled()
enableAutoCompletion = NeoPreference.isAutoCompletionEnabled() enableAutoCompletion = NeoPreference.isAutoCompletionEnabled()
enableBackButtonBeMappedToEscape = NeoPreference.isBackButtonBeMappedToEscapeEnabled()
enableExtraKeys = NeoPreference.isExtraKeysEnabled()
} }
} }

View File

@ -19,7 +19,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
val shellProfile: ShellProfile) val shellProfile: ShellProfile)
: TerminalSession(shellPath, cwd, args, env, changeCallback) { : 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) { override fun initializeEmulator(columns: Int, rows: Int) {
super.initializeEmulator(columns, rows) super.initializeEmulator(columns, rows)
@ -202,8 +202,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
var ldPreloadEnv = "" var ldPreloadEnv = ""
// execve(2) wrapper to avoid incorrect shebang // execve(2) wrapper to avoid incorrect shebang
if (NeoPreference.loadBoolean(R.string.key_general_use_execve_wrapper, if (shellProfile.enableExecveWrapper) {
DefaultPreference.enableExecveWrapper)) {
ldPreloadEnv = "LD_PRELOAD=${App.get().applicationInfo.nativeLibraryDir}/libnexec.so" ldPreloadEnv = "LD_PRELOAD=${App.get().applicationInfo.nativeLibraryDir}/libnexec.so"
} }

View File

@ -9,6 +9,7 @@ import io.neoterm.R
import io.neoterm.backend.TerminalSession import io.neoterm.backend.TerminalSession
import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.preference.DefaultPreference
import io.neoterm.frontend.preference.NeoPreference import io.neoterm.frontend.preference.NeoPreference
import io.neoterm.frontend.session.shell.ShellTermSession
/** /**
* @author kiva * @author kiva
@ -43,8 +44,9 @@ class TermSessionCallback : TerminalSession.SessionChangedCallback {
override fun onBell(session: TerminalSession?) { override fun onBell(session: TerminalSession?) {
val termView = termData?.termView ?: return 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) { if (soundPool == null) {
soundPool = SoundPool.Builder().setMaxStreams(1).build() soundPool = SoundPool.Builder().setMaxStreams(1).build()
bellId = soundPool!!.load(termView.context, R.raw.bell, 1) 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) 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 val vibrator = termView.context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
vibrator.vibrate(100) vibrator.vibrate(100)
} }

View File

@ -14,6 +14,7 @@ import io.neoterm.component.eks.ExtraKeysComponent
import io.neoterm.frontend.component.ComponentManager import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.preference.DefaultPreference
import io.neoterm.frontend.preference.NeoPreference import io.neoterm.frontend.preference.NeoPreference
import io.neoterm.frontend.session.shell.ShellTermSession
import io.neoterm.frontend.terminal.TerminalViewClient import io.neoterm.frontend.terminal.TerminalViewClient
@ -37,16 +38,14 @@ class TermViewClient(val context: Context) : TerminalViewClient {
} }
override fun onSingleTapUp(e: MotionEvent?) { override fun onSingleTapUp(e: MotionEvent?) {
val termView = termData?.termView val termView = termData?.termView ?: return
if (termView != null) { (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager) .showSoftInput(termView, InputMethodManager.SHOW_IMPLICIT)
.showSoftInput(termView, InputMethodManager.SHOW_IMPLICIT)
}
} }
override fun shouldBackButtonBeMappedToEscape(): Boolean { override fun shouldBackButtonBeMappedToEscape(): Boolean {
return NeoPreference.loadBoolean(R.string.key_generaL_backspace_map_to_esc, val shellSession = termData?.termSession as ShellTermSession? ?: return false
DefaultPreference.enableBackButtonBeMappedToEscape) return shellSession.shellProfile.enableBackButtonBeMappedToEscape
} }
override fun copyModeChanged(copyMode: Boolean) { override fun copyModeChanged(copyMode: Boolean) {
@ -196,9 +195,11 @@ class TermViewClient(val context: Context) : TerminalViewClient {
if (event == null) { if (event == null) {
return false return false
} }
val shellSession = termData?.termSession as ShellTermSession? ?: return false
// Volume keys as special keys // Volume keys as special keys
val volumeAsSpecialKeys = NeoPreference.loadBoolean(R.string.key_general_volume_as_control, val volumeAsSpecialKeys = shellSession.shellProfile.enableSpecialVolumeKeys
DefaultPreference.enableSpecialVolumeKeys)
val inputDevice = event.device val inputDevice = event.device
if (inputDevice != null && inputDevice.keyboardType == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { if (inputDevice != null && inputDevice.keyboardType == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
@ -231,9 +232,9 @@ class TermViewClient(val context: Context) : TerminalViewClient {
private fun updateExtraKeysVisibility(): Boolean { private fun updateExtraKeysVisibility(): Boolean {
val extraKeysView = termData?.extraKeysView ?: return false val extraKeysView = termData?.extraKeysView ?: return false
val shellSession = termData?.termSession as ShellTermSession? ?: return false
return if (NeoPreference.loadBoolean(R.string.key_ui_eks_enabled, return if (shellSession.shellProfile.enableExtraKeys) {
DefaultPreference.enableExtraKeys)) {
extraKeysView.visibility = View.VISIBLE extraKeysView.visibility = View.VISIBLE
true true
} else { } else {

View File

@ -162,8 +162,7 @@ class ExtraKeysView(context: Context, attrs: AttributeSet) : LinearLayout(contex
val line = LinearLayout(context) val line = LinearLayout(context)
val layoutParams = val layoutParams =
if (NeoPreference.loadBoolean(R.string.key_ui_eks_weight_explicit, if (NeoPreference.isExplicitExtraKeysWeightEnabled())
DefaultPreference.enableExplicitExtraKeysWeight))
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f) LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
else else
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,

View File

@ -63,8 +63,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION) NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION)
val fullscreen = NeoPreference.loadBoolean(R.string.key_ui_fullscreen, val fullscreen = NeoPreference.isFullScreenEnabled()
DefaultPreference.enableFullScreen)
if (fullscreen) { if (fullscreen) {
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN) WindowManager.LayoutParams.FLAG_FULLSCREEN)
@ -101,10 +100,8 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
return return
} }
if (NeoPreference.loadBoolean(R.string.key_ui_fullscreen, if (NeoPreference.isFullScreenEnabled()
DefaultPreference.enableFullScreen) || NeoPreference.isHideToolbarEnabled()) {
|| NeoPreference.loadBoolean(R.string.key_ui_hide_toolbar,
DefaultPreference.enableAutoHideToolbar)) {
val toolbarHeight = toolbar.height.toFloat() val toolbarHeight = toolbar.height.toFloat()
val translationY = if (visible) 0.toFloat() else -toolbarHeight val translationY = if (visible) 0.toFloat() else -toolbarHeight
if (visible) { if (visible) {
@ -665,8 +662,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
if (tabSwitcher.count > 1) { if (tabSwitcher.count > 1) {
var index = tabSwitcher.indexOf(tab) var index = tabSwitcher.indexOf(tab)
if (NeoPreference.loadBoolean(R.string.key_ui_next_tab_anim, if (NeoPreference.isNextTabEnabled()) {
DefaultPreference.enableSwitchNextTab)) {
// 关闭当前窗口后,向下一个窗口切换 // 关闭当前窗口后,向下一个窗口切换
if (--index < 0) index = tabSwitcher.count - 1 if (--index < 0) index = tabSwitcher.count - 1
} else { } else {