diff --git a/app/src/main/java/io/neoterm/component/font/FontComponent.kt b/app/src/main/java/io/neoterm/component/font/FontComponent.kt index ac12117..9043dfa 100644 --- a/app/src/main/java/io/neoterm/component/font/FontComponent.kt +++ b/app/src/main/java/io/neoterm/component/font/FontComponent.kt @@ -8,6 +8,7 @@ import io.neoterm.R import io.neoterm.frontend.preference.NeoPreference import io.neoterm.frontend.preference.NeoTermPath import io.neoterm.frontend.component.NeoComponent +import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.terminal.TerminalView import io.neoterm.frontend.terminal.eks.ExtraKeysView import io.neoterm.utils.AssetsUtils @@ -17,8 +18,6 @@ import java.io.File * @author kiva */ class FontComponent : NeoComponent { - private val DEFAULT_FONT_NAME = "SourceCodePro" - private lateinit var DEFAULT_FONT: NeoFont private lateinit var fonts: MutableMap @@ -35,10 +34,11 @@ class FontComponent : NeoComponent { } fun getCurrentFontName(): String { - var currentFontName = NeoPreference.loadString(R.string.key_customization_font, DEFAULT_FONT_NAME) + val defaultFont = DefaultPreference.defaultFont + var currentFontName = NeoPreference.loadString(R.string.key_customization_font, defaultFont) if (!fonts.containsKey(currentFontName)) { - currentFontName = DEFAULT_FONT_NAME - NeoPreference.store(R.string.key_customization_font, DEFAULT_FONT_NAME) + currentFontName = defaultFont + NeoPreference.store(R.string.key_customization_font, defaultFont) } return currentFontName } @@ -64,8 +64,10 @@ class FontComponent : NeoComponent { val font = NeoFont(file) fonts.put(fontName, font) } - if (fonts.containsKey(DEFAULT_FONT_NAME)) { - DEFAULT_FONT = fonts[DEFAULT_FONT_NAME]!! + + val defaultFont = DefaultPreference.defaultFont + if (fonts.containsKey(defaultFont)) { + DEFAULT_FONT = fonts[defaultFont]!! return true } return false @@ -83,7 +85,8 @@ class FontComponent : NeoComponent { } private fun loadDefaultFontFromAsset(context: Context): NeoFont { - return NeoFont(Typeface.createFromAsset(context.assets, "fonts/$DEFAULT_FONT_NAME.ttf")) + val defaultFont = DefaultPreference.defaultFont + return NeoFont(Typeface.createFromAsset(context.assets, "fonts/$defaultFont.ttf")) } private fun extractDefaultFont(context: Context): Boolean { @@ -108,18 +111,20 @@ class FontComponent : NeoComponent { fonts = mutableMapOf() val context = App.get() - val defaultFontFile = fontFile(DEFAULT_FONT_NAME) + val defaultFont = DefaultPreference.defaultFont + val defaultFontFile = fontFile(defaultFont) + if (!defaultFontFile.exists()) { if (!extractDefaultFont(context)) { DEFAULT_FONT = loadDefaultFontFromAsset(context) - fonts.put(DEFAULT_FONT_NAME, DEFAULT_FONT) + fonts.put(defaultFont, DEFAULT_FONT) return } } if (!reloadFonts()) { DEFAULT_FONT = loadDefaultFontFromAsset(context) - fonts.put(DEFAULT_FONT_NAME, DEFAULT_FONT) + fonts.put(defaultFont, DEFAULT_FONT) } } } \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/component/session/SessionComponent.kt b/app/src/main/java/io/neoterm/component/session/SessionComponent.kt index f30f8b1..580abcf 100644 --- a/app/src/main/java/io/neoterm/component/session/SessionComponent.kt +++ b/app/src/main/java/io/neoterm/component/session/SessionComponent.kt @@ -8,6 +8,7 @@ import io.neoterm.NeoXorgSettings import io.neoterm.R import io.neoterm.frontend.component.NeoComponent import io.neoterm.frontend.logging.NLog +import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.preference.NeoPreference import io.neoterm.frontend.preference.NeoTermPath import io.neoterm.frontend.session.shell.ShellParameter @@ -101,7 +102,8 @@ class SessionComponent : NeoComponent { fun createSession(context: Context, parameter: ShellParameter): ShellTermSession { val initCommand = parameter.initialCommand ?: - NeoPreference.loadString(R.string.key_general_initial_command, "") + NeoPreference.loadString(R.string.key_general_initial_command, + DefaultPreference.initialCommand) val session = ShellTermSession.Builder() .executablePath(parameter.executablePath) diff --git a/app/src/main/java/io/neoterm/frontend/preference/DefaultPreference.kt b/app/src/main/java/io/neoterm/frontend/preference/DefaultPreference.kt index a0ad3d6..6534208 100644 --- a/app/src/main/java/io/neoterm/frontend/preference/DefaultPreference.kt +++ b/app/src/main/java/io/neoterm/frontend/preference/DefaultPreference.kt @@ -1,9 +1,13 @@ package io.neoterm.frontend.preference +import io.neoterm.component.color.DefaultColorScheme + /** * @author kiva */ object DefaultPreference { + const val fontSize = 30 + const val enableBell = false const val enableVibrate = false const val enableExecveWrapper = true @@ -13,8 +17,10 @@ object DefaultPreference { const val enableSwitchNextTab = false const val enableExtraKeys = true const val enableExplicitExtraKeysWeight = false + const val enableBackButtonBeMappedToEscape = false const val enableSpecialVolumeKeys = false - const val loginShell = "bash" + const val loginShell = "sh" const val initialCommand = "" + const val defaultFont = "SourceCodePro" } 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 c5d33cc..fe1a7f8 100644 --- a/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt +++ b/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt @@ -138,7 +138,7 @@ object NeoPreference { } fun getLoginShell(): String { - val loginProgramName = loadString(R.string.key_general_shell, "sh") + val loginProgramName = loadString(R.string.key_general_shell, DefaultPreference.loginShell) // Some programs like ssh needs it val shell = File(NeoTermPath.NEOTERM_SHELL_PATH) @@ -179,7 +179,7 @@ object NeoPreference { } fun getFontSize(): Int { - return loadInt(NeoPreference.KEY_FONT_SIZE, 30) + return loadInt(NeoPreference.KEY_FONT_SIZE, DefaultPreference.fontSize) } 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 690b19b..e83ff86 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 @@ -4,6 +4,7 @@ import android.content.Context import io.neoterm.App import io.neoterm.R import io.neoterm.backend.TerminalSession +import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.session.shell.client.TermSessionCallback import io.neoterm.frontend.preference.NeoPreference import io.neoterm.frontend.preference.NeoTermPath @@ -183,7 +184,8 @@ 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, true)) { + if (NeoPreference.loadBoolean(R.string.key_general_use_execve_wrapper, + DefaultPreference.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 1a769f1..e00f77e 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 @@ -7,6 +7,7 @@ import android.media.SoundPool import android.os.Vibrator import io.neoterm.R import io.neoterm.backend.TerminalSession +import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.preference.NeoPreference /** @@ -43,7 +44,7 @@ class TermSessionCallback : TerminalSession.SessionChangedCallback { override fun onBell(session: TerminalSession?) { val termView = termData?.termView ?: return - if (NeoPreference.loadBoolean(R.string.key_general_bell, false)) { + if (NeoPreference.loadBoolean(R.string.key_general_bell, DefaultPreference.enableBell)) { if (soundPool == null) { soundPool = SoundPool.Builder().setMaxStreams(1).build() bellId = soundPool!!.load(termView.context, R.raw.bell, 1) @@ -51,7 +52,7 @@ class TermSessionCallback : TerminalSession.SessionChangedCallback { soundPool?.play(bellId, 1f, 1f, 0, 0, 1f) } - if (NeoPreference.loadBoolean(R.string.key_general_vibrate, false)) { + if (NeoPreference.loadBoolean(R.string.key_general_vibrate, DefaultPreference.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 961e351..409a0e1 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 @@ -12,6 +12,7 @@ import io.neoterm.backend.KeyHandler import io.neoterm.backend.TerminalSession 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.terminal.TerminalViewClient @@ -44,7 +45,8 @@ class TermViewClient(val context: Context) : TerminalViewClient { } override fun shouldBackButtonBeMappedToEscape(): Boolean { - return NeoPreference.loadBoolean(R.string.key_generaL_backspace_map_to_esc, false) + return NeoPreference.loadBoolean(R.string.key_generaL_backspace_map_to_esc, + DefaultPreference.enableBackButtonBeMappedToEscape) } override fun copyModeChanged(copyMode: Boolean) { @@ -196,7 +198,7 @@ class TermViewClient(val context: Context) : TerminalViewClient { } // Volume keys as special keys val volumeAsSpecialKeys = NeoPreference.loadBoolean(R.string.key_general_volume_as_control, - false) + DefaultPreference.enableSpecialVolumeKeys) val inputDevice = event.device if (inputDevice != null && inputDevice.keyboardType == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { @@ -230,7 +232,8 @@ class TermViewClient(val context: Context) : TerminalViewClient { private fun updateExtraKeysVisibility(): Boolean { val extraKeysView = termData?.extraKeysView ?: return false - return if (NeoPreference.loadBoolean(R.string.key_ui_eks_enabled, true)) { + return if (NeoPreference.loadBoolean(R.string.key_ui_eks_enabled, + DefaultPreference.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 cd401ab..e755249 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 @@ -8,6 +8,7 @@ import android.widget.GridLayout import android.widget.LinearLayout import io.neoterm.R import io.neoterm.component.eks.NeoExtraKey +import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.preference.NeoPreference import io.neoterm.frontend.preference.NeoTermPath import io.neoterm.frontend.session.shell.client.event.ToggleImeEvent @@ -161,7 +162,8 @@ class ExtraKeysView(context: Context, attrs: AttributeSet) : LinearLayout(contex val line = LinearLayout(context) val layoutParams = - if (NeoPreference.loadBoolean(R.string.key_ui_eks_weight_explicit, false)) + if (NeoPreference.loadBoolean(R.string.key_ui_eks_weight_explicit, + DefaultPreference.enableExplicitExtraKeysWeight)) 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/settings/GeneralSettingsActivity.kt b/app/src/main/java/io/neoterm/ui/settings/GeneralSettingsActivity.kt index 8101688..e5b6319 100644 --- a/app/src/main/java/io/neoterm/ui/settings/GeneralSettingsActivity.kt +++ b/app/src/main/java/io/neoterm/ui/settings/GeneralSettingsActivity.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.MenuItem import io.neoterm.R import io.neoterm.frontend.logging.NLog +import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.preference.NeoPreference import io.neoterm.utils.PackageUtils @@ -19,7 +20,7 @@ class GeneralSettingsActivity : BasePreferenceActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(true) addPreferencesFromResource(R.xml.setting_general) - val currentShell = NeoPreference.loadString(R.string.key_general_shell, "sh") + val currentShell = NeoPreference.loadString(R.string.key_general_shell, DefaultPreference.loginShell) findPreference(getString(R.string.key_general_shell)).setOnPreferenceChangeListener { _, value -> val shellName = value.toString() val newShell = NeoPreference.findLoginProgram(shellName) 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 72d46d9..d89b25a 100644 --- a/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt +++ b/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt @@ -21,6 +21,7 @@ import io.neoterm.App import io.neoterm.R import io.neoterm.backend.TerminalSession import io.neoterm.component.setup.BaseFileInstaller +import io.neoterm.frontend.preference.DefaultPreference import io.neoterm.frontend.session.shell.client.TermSessionCallback import io.neoterm.frontend.session.shell.client.TermViewClient import io.neoterm.frontend.session.shell.client.event.* @@ -62,7 +63,8 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION) - val fullscreen = NeoPreference.loadBoolean(R.string.key_ui_fullscreen, false) + val fullscreen = NeoPreference.loadBoolean(R.string.key_ui_fullscreen, + DefaultPreference.enableFullScreen) if (fullscreen) { window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) @@ -99,8 +101,10 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference return } - if (NeoPreference.loadBoolean(R.string.key_ui_fullscreen, false) - || NeoPreference.loadBoolean(R.string.key_ui_hide_toolbar, false)) { + if (NeoPreference.loadBoolean(R.string.key_ui_fullscreen, + DefaultPreference.enableFullScreen) + || NeoPreference.loadBoolean(R.string.key_ui_hide_toolbar, + DefaultPreference.enableAutoHideToolbar)) { val toolbarHeight = toolbar.height.toFloat() val translationY = if (visible) 0.toFloat() else -toolbarHeight if (visible) { @@ -292,7 +296,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { if (key == getString(R.string.key_ui_fullscreen)) { - setFullScreenMode(NeoPreference.loadBoolean(key, false)) + setFullScreenMode(NeoPreference.loadBoolean(key, DefaultPreference.enableFullScreen)) } else if (key == getString(R.string.key_customization_color_scheme)) { if (tabSwitcher.count > 0) { val tab = tabSwitcher.selectedTab @@ -661,7 +665,8 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference if (tabSwitcher.count > 1) { var index = tabSwitcher.indexOf(tab) - if (NeoPreference.loadBoolean(R.string.key_ui_next_tab_anim, false)) { + if (NeoPreference.loadBoolean(R.string.key_ui_next_tab_anim, + DefaultPreference.enableSwitchNextTab)) { // 关闭当前窗口后,向下一个窗口切换 if (--index < 0) index = tabSwitcher.count - 1 } else {