diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6a69a66..1012cdd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,6 +8,7 @@ - + diff --git a/app/src/main/java/io/neoterm/App.kt b/app/src/main/java/io/neoterm/App.kt new file mode 100644 index 0000000..b1254f5 --- /dev/null +++ b/app/src/main/java/io/neoterm/App.kt @@ -0,0 +1,16 @@ +package io.neoterm + +import android.app.Application +import io.neoterm.customize.font.FontManager +import io.neoterm.preference.NeoPreference + +/** + * @author kiva + */ +class App : Application() { + override fun onCreate() { + super.onCreate() + FontManager.init(this) + NeoPreference.init(this) + } +} \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/backend/TerminalColors.java b/app/src/main/java/io/neoterm/backend/TerminalColors.java index e226b22..9398161 100755 --- a/app/src/main/java/io/neoterm/backend/TerminalColors.java +++ b/app/src/main/java/io/neoterm/backend/TerminalColors.java @@ -24,7 +24,11 @@ public final class TerminalColors { /** Reset all indexed colors with the default color from the color theme. */ public void reset() { - System.arraycopy(COLOR_SCHEME.mDefaultColors, 0, mCurrentColors, 0, TextStyle.NUM_INDEXED_COLORS); + reset(COLOR_SCHEME); + } + + public void reset(TerminalColorScheme colorScheme) { + System.arraycopy(colorScheme.mDefaultColors, 0, mCurrentColors, 0, TextStyle.NUM_INDEXED_COLORS); } /** diff --git a/app/src/main/java/io/neoterm/customize/color/ColorSchemeManager.kt b/app/src/main/java/io/neoterm/customize/color/ColorSchemeManager.kt new file mode 100644 index 0000000..13242f0 --- /dev/null +++ b/app/src/main/java/io/neoterm/customize/color/ColorSchemeManager.kt @@ -0,0 +1,18 @@ +package io.neoterm.customize.color + +import io.neoterm.backend.TerminalEmulator + +/** + * @author kiva + */ +object ColorSchemeManager { + fun applyColorScheme(emulator: TerminalEmulator?, colorScheme: NeoColorScheme?) { + if (emulator != null && colorScheme != null) { + colorScheme.applyLocal(emulator) + } + } + + fun applyGlobalColorScheme(colorScheme: NeoColorScheme?) { + colorScheme?.applyGlobal() + } +} \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/customize/color/NeoTermColorScheme.kt b/app/src/main/java/io/neoterm/customize/color/NeoColorScheme.kt similarity index 50% rename from app/src/main/java/io/neoterm/customize/color/NeoTermColorScheme.kt rename to app/src/main/java/io/neoterm/customize/color/NeoColorScheme.kt index e4d692f..f39422b 100644 --- a/app/src/main/java/io/neoterm/customize/color/NeoTermColorScheme.kt +++ b/app/src/main/java/io/neoterm/customize/color/NeoColorScheme.kt @@ -1,17 +1,25 @@ package io.neoterm.customize.color +import io.neoterm.backend.TerminalColorScheme import io.neoterm.backend.TerminalColors +import io.neoterm.backend.TerminalEmulator /** * @author kiva */ -open class NeoTermColorScheme { +open class NeoColorScheme { var foreground: String? = null var background: String? = null var cursor: String? = null var color: MutableMap = mutableMapOf() - fun apply() { + fun applyGlobal() { TerminalColors.COLOR_SCHEME.updateWith(foreground, background, cursor, color) } + + fun applyLocal(emulator: TerminalEmulator) { + val scheme = TerminalColorScheme() + scheme.updateWith(foreground, background, cursor, color) + emulator.mColors.reset(scheme) + } } \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/customize/color/builtin/MaterialColorScheme.kt b/app/src/main/java/io/neoterm/customize/color/builtin/MaterialColorScheme.kt index 0611a73..23017ed 100644 --- a/app/src/main/java/io/neoterm/customize/color/builtin/MaterialColorScheme.kt +++ b/app/src/main/java/io/neoterm/customize/color/builtin/MaterialColorScheme.kt @@ -1,11 +1,11 @@ package io.neoterm.customize.color.builtin -import io.neoterm.customize.color.NeoTermColorScheme +import io.neoterm.customize.color.NeoColorScheme /** * @author kiva */ -class MaterialColorScheme : NeoTermColorScheme() { +class MaterialColorScheme : NeoColorScheme() { init { foreground = "#263238" background = "#263238" diff --git a/app/src/main/java/io/neoterm/customize/font/FontManager.kt b/app/src/main/java/io/neoterm/customize/font/FontManager.kt index bb001b9..1395623 100644 --- a/app/src/main/java/io/neoterm/customize/font/FontManager.kt +++ b/app/src/main/java/io/neoterm/customize/font/FontManager.kt @@ -7,17 +7,19 @@ import android.graphics.Typeface * @author kiva */ object FontManager { - private lateinit var DEFAULT_FONT: Typeface + private lateinit var DEFAULT_FONT: NeoFont + private lateinit var fonts: MutableList fun init(context: Context) { - DEFAULT_FONT = Typeface.createFromAsset(context.assets, "font.ttf") + fonts = mutableListOf() + DEFAULT_FONT = NeoFont(Typeface.createFromAsset(context.assets, "font.ttf")) } - fun getDefaultFont(): Typeface { + fun getDefaultFont(): NeoFont { return DEFAULT_FONT } - fun getCurrentFont(): Typeface { - return DEFAULT_FONT + fun getCurrentFont(): NeoFont { + return getDefaultFont() } } \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/customize/font/NeoFont.kt b/app/src/main/java/io/neoterm/customize/font/NeoFont.kt new file mode 100644 index 0000000..e40a5d9 --- /dev/null +++ b/app/src/main/java/io/neoterm/customize/font/NeoFont.kt @@ -0,0 +1,13 @@ +package io.neoterm.customize.font + +import android.graphics.Typeface +import io.neoterm.view.TerminalView + +/** + * @author kiva + */ +class NeoFont(val typeface: Typeface) { + fun applyLocal(terminalView: TerminalView?) { + terminalView?.setTypeface(typeface) + } +} \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt b/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt index 1f879bd..2aae5a6 100644 --- a/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt +++ b/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt @@ -19,7 +19,6 @@ import android.widget.ImageButton import de.mrapp.android.tabswitcher.* import io.neoterm.R import io.neoterm.backend.TerminalSession -import io.neoterm.customize.font.FontManager import io.neoterm.customize.eks.EksConfigLoader import io.neoterm.customize.eks.builtin.BuiltinEksKeys import io.neoterm.customize.setup.BaseFileInstaller @@ -52,8 +51,6 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference super.onCreate(savedInstanceState) NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION) - FontManager.init(this) - NeoPreference.init(this) val fullscreen = NeoPreference.loadBoolean(R.string.key_ui_fullscreen, false) if (fullscreen) { diff --git a/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt b/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt new file mode 100644 index 0000000..0dbf4b9 --- /dev/null +++ b/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt @@ -0,0 +1,51 @@ +package io.neoterm.ui.customization + +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.Toolbar +import android.view.MenuItem +import io.neoterm.R +import io.neoterm.backend.TerminalSession +import io.neoterm.customize.NeoTermPath +import io.neoterm.utils.TerminalUtils +import io.neoterm.view.BasicSessionCallback +import io.neoterm.view.BasicViewClient +import io.neoterm.view.TerminalView + +/** + * @author kiva + */ +class CustomizationActivity: AppCompatActivity() { + lateinit var terminalView: TerminalView + lateinit var viewClient: BasicViewClient + lateinit var sessionCallback: BasicSessionCallback + lateinit var session: TerminalSession + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.ui_customization) + val toolbar = findViewById(R.id.custom_toolbar) as Toolbar + setSupportActionBar(toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + + terminalView = findViewById(R.id.terminal_view) as TerminalView + viewClient = BasicViewClient(terminalView) + sessionCallback = BasicSessionCallback(terminalView) + TerminalUtils.setupTerminalView(terminalView, viewClient) + session = TerminalUtils.createSession(this, "${NeoTermPath.USR_PATH}/bin/applets/echo", + arrayOf("echo", "Hello NeoTerm."), null, null, sessionCallback, false) + terminalView.attachSession(session) + } + + override fun onDestroy() { + super.onDestroy() + session.finishIfRunning() + } + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + when (item?.itemId) { + android.R.id.home -> finish() + } + return super.onOptionsItemSelected(item) + } +} \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/utils/TerminalUtils.kt b/app/src/main/java/io/neoterm/utils/TerminalUtils.kt index c51cf61..57ad46f 100644 --- a/app/src/main/java/io/neoterm/utils/TerminalUtils.kt +++ b/app/src/main/java/io/neoterm/utils/TerminalUtils.kt @@ -5,13 +5,24 @@ import android.widget.Toast import io.neoterm.R import io.neoterm.backend.TerminalSession import io.neoterm.customize.NeoTermPath +import io.neoterm.customize.font.FontManager import io.neoterm.preference.NeoPreference +import io.neoterm.view.BasicViewClient +import io.neoterm.view.TerminalView import java.io.File /** * @author kiva */ object TerminalUtils { + fun setupTerminalView(terminalView: TerminalView, terminalViewClient: BasicViewClient? = null) { + terminalView.textSize = NeoPreference.loadInt(NeoPreference.KEY_FONT_SIZE, 30) + terminalView.setTypeface(FontManager.getCurrentFont().typeface) + if (terminalViewClient != null) { + terminalView.setOnKeyListener(terminalViewClient) + } + } + fun createSession(context: Context, executablePath: String?, arguments: Array?, cwd: String?, env: Array?, sessionCallback: TerminalSession.SessionChangedCallback?, systemShell: Boolean): TerminalSession { var executablePath = executablePath var arguments = arguments diff --git a/app/src/main/java/io/neoterm/view/BasicSessionCallback.kt b/app/src/main/java/io/neoterm/view/BasicSessionCallback.kt new file mode 100644 index 0000000..abf3e47 --- /dev/null +++ b/app/src/main/java/io/neoterm/view/BasicSessionCallback.kt @@ -0,0 +1,29 @@ +package io.neoterm.view + +import io.neoterm.backend.TerminalSession + +/** + * @author kiva + */ +class BasicSessionCallback(var terminalView: TerminalView) : TerminalSession.SessionChangedCallback { + override fun onTextChanged(changedSession: TerminalSession?) { + if (changedSession != null) { + terminalView.onScreenUpdated() + } + } + + override fun onTitleChanged(changedSession: TerminalSession?) { + } + + override fun onSessionFinished(finishedSession: TerminalSession?) { + } + + override fun onClipboardText(session: TerminalSession?, text: String?) { + } + + override fun onBell(session: TerminalSession?) { + } + + override fun onColorsChanged(session: TerminalSession?) { + } +} diff --git a/app/src/main/java/io/neoterm/view/BasicViewClient.kt b/app/src/main/java/io/neoterm/view/BasicViewClient.kt new file mode 100644 index 0000000..802830f --- /dev/null +++ b/app/src/main/java/io/neoterm/view/BasicViewClient.kt @@ -0,0 +1,55 @@ +package io.neoterm.view + +import android.view.KeyEvent +import android.view.MotionEvent +import io.neoterm.backend.TerminalSession + +/** + * @author kiva + */ +class BasicViewClient(val terminalView: TerminalView) : TerminalViewClient { + override fun onScale(scale: Float): Float { + if (scale < 0.9f || scale > 1.1f) { + val increase = scale > 1f + val changedSize = (if (increase) 1 else -1) * 2 + val fontSize = terminalView.textSize + changedSize + terminalView.textSize = fontSize + return 1.0f + } + return scale + } + + override fun onSingleTapUp(e: MotionEvent?) { + } + + override fun shouldBackButtonBeMappedToEscape(): Boolean { + return false + } + + override fun copyModeChanged(copyMode: Boolean) { + } + + override fun onKeyDown(keyCode: Int, e: KeyEvent?, session: TerminalSession?): Boolean { + return false + } + + override fun onKeyUp(keyCode: Int, e: KeyEvent?): Boolean { + return false + } + + override fun readControlKey(): Boolean { + return false + } + + override fun readAltKey(): Boolean { + return false + } + + override fun onCodePoint(codePoint: Int, ctrlDown: Boolean, session: TerminalSession?): Boolean { + return false + } + + override fun onLongPress(event: MotionEvent?): Boolean { + return false + } +} diff --git a/app/src/main/java/io/neoterm/view/ExtraKeysView.java b/app/src/main/java/io/neoterm/view/ExtraKeysView.java index cc77a73..d27c855 100755 --- a/app/src/main/java/io/neoterm/view/ExtraKeysView.java +++ b/app/src/main/java/io/neoterm/view/ExtraKeysView.java @@ -185,7 +185,7 @@ public final class ExtraKeysView extends LinearLayout { button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle); } - button.setTypeface(FontManager.INSTANCE.getDefaultFont()); + button.setTypeface(FontManager.INSTANCE.getCurrentFont().getTypeface()); button.setText(extraButton.buttonText); button.setTextColor(NORMAL_TEXT_COLOR); button.setAllCaps(false); diff --git a/app/src/main/java/io/neoterm/view/TerminalDialog.kt b/app/src/main/java/io/neoterm/view/TerminalDialog.kt index 1c7a59f..c1593fe 100644 --- a/app/src/main/java/io/neoterm/view/TerminalDialog.kt +++ b/app/src/main/java/io/neoterm/view/TerminalDialog.kt @@ -1,104 +1,35 @@ package io.neoterm.view +import android.annotation.SuppressLint import android.app.AlertDialog import android.content.Context import android.content.DialogInterface -import android.graphics.Typeface -import android.view.KeyEvent import android.view.LayoutInflater -import android.view.MotionEvent import android.view.View import io.neoterm.R import io.neoterm.backend.TerminalSession -import io.neoterm.preference.NeoPreference import io.neoterm.utils.TerminalUtils -import io.neoterm.view.TerminalView -import io.neoterm.view.TerminalViewClient /** * @author kiva */ class TerminalDialog(val context: Context, var cancelListener: DialogInterface.OnCancelListener?) { - class MinimalViewClient : TerminalViewClient { - override fun onScale(scale: Float): Float { - return scale - } - override fun onSingleTapUp(e: MotionEvent?) { - } - - override fun shouldBackButtonBeMappedToEscape(): Boolean { - return false - } - - override fun copyModeChanged(copyMode: Boolean) { - } - - override fun onKeyDown(keyCode: Int, e: KeyEvent?, session: TerminalSession?): Boolean { - return false - } - - override fun onKeyUp(keyCode: Int, e: KeyEvent?): Boolean { - return false - } - - override fun readControlKey(): Boolean { - return false - } - - override fun readAltKey(): Boolean { - return false - } - - override fun onCodePoint(codePoint: Int, ctrlDown: Boolean, session: TerminalSession?): Boolean { - return false - } - - override fun onLongPress(event: MotionEvent?): Boolean { - return false - } - } - - class MinimalSessionCallback(var terminalView: TerminalView) : TerminalSession.SessionChangedCallback { - override fun onTextChanged(changedSession: TerminalSession?) { - if (changedSession != null) { - terminalView.onScreenUpdated() - } - } - - override fun onTitleChanged(changedSession: TerminalSession?) { - } - - override fun onSessionFinished(finishedSession: TerminalSession?) { - } - - override fun onClipboardText(session: TerminalSession?, text: String?) { - } - - override fun onBell(session: TerminalSession?) { - } - - override fun onColorsChanged(session: TerminalSession?) { - } - } - - var view: View + @SuppressLint("InflateParams") + var view: View = LayoutInflater.from(context).inflate(R.layout.ui_term_dialog, null, false) var terminalView: TerminalView - var terminalViewClient: MinimalViewClient - var terminalSessionCallback: MinimalSessionCallback + var terminalViewClient: BasicViewClient + var terminalSessionCallback: BasicSessionCallback var dialog: AlertDialog? = null var terminalSession: TerminalSession? = null init { - view = LayoutInflater.from(context).inflate(R.layout.ui_term_dialog, null, false) - terminalView = view.findViewById(R.id.terminal_view_dialog) as TerminalView - terminalView.textSize = NeoPreference.loadInt(NeoPreference.KEY_FONT_SIZE, 30) - terminalView.setTypeface(Typeface.MONOSPACE) + terminalViewClient = BasicViewClient(terminalView) + TerminalUtils.setupTerminalView(terminalView, terminalViewClient) - terminalViewClient = MinimalViewClient() terminalView.setOnKeyListener(terminalViewClient) - terminalSessionCallback = MinimalSessionCallback(terminalView) + terminalSessionCallback = BasicSessionCallback(terminalView) } fun execute(executablePath: String, arguments: Array?) { diff --git a/app/src/main/java/io/neoterm/view/tab/TermTab.kt b/app/src/main/java/io/neoterm/view/tab/TermTab.kt index e60dd30..57e57ef 100644 --- a/app/src/main/java/io/neoterm/view/tab/TermTab.kt +++ b/app/src/main/java/io/neoterm/view/tab/TermTab.kt @@ -7,7 +7,8 @@ import android.view.inputmethod.InputMethodManager import de.mrapp.android.tabswitcher.Tab import io.neoterm.R import io.neoterm.backend.TerminalSession -import io.neoterm.customize.color.NeoTermColorScheme +import io.neoterm.customize.color.ColorSchemeManager +import io.neoterm.customize.color.NeoColorScheme import io.neoterm.preference.NeoPreference import org.greenrobot.eventbus.EventBus @@ -21,8 +22,8 @@ class TermTab(title: CharSequence) : Tab(title) { var viewClient: TermViewClient? = null var toolbar: Toolbar? = null - fun changeColorScheme(colorScheme: NeoTermColorScheme?) { - colorScheme?.apply() + fun changeColorScheme(colorScheme: NeoColorScheme?) { + ColorSchemeManager.applyColorScheme(termSession?.emulator, colorScheme) viewClient?.extraKeysView?.setBackgroundColor(Color.parseColor(colorScheme?.background)) } diff --git a/app/src/main/java/io/neoterm/view/tab/TermTabDecorator.kt b/app/src/main/java/io/neoterm/view/tab/TermTabDecorator.kt index bcbdebe..7889efb 100644 --- a/app/src/main/java/io/neoterm/view/tab/TermTabDecorator.kt +++ b/app/src/main/java/io/neoterm/view/tab/TermTabDecorator.kt @@ -1,7 +1,6 @@ package io.neoterm.view.tab import android.content.Context -import android.graphics.Typeface import android.os.Bundle import android.support.v7.widget.Toolbar import android.view.LayoutInflater @@ -12,9 +11,9 @@ import de.mrapp.android.tabswitcher.Tab import de.mrapp.android.tabswitcher.TabSwitcher import de.mrapp.android.tabswitcher.TabSwitcherDecorator import io.neoterm.R -import io.neoterm.customize.font.FontManager import io.neoterm.preference.NeoPreference import io.neoterm.ui.NeoTermActivity +import io.neoterm.utils.TerminalUtils import io.neoterm.view.ExtraKeysView import io.neoterm.view.TerminalView @@ -69,8 +68,7 @@ class TermTabDecorator(val context: NeoTermActivity) : TabSwitcherDecorator() { if (view == null) { return } - view.textSize = NeoPreference.loadInt(NeoPreference.KEY_FONT_SIZE, 30) - view.setTypeface(FontManager.getCurrentFont()) + TerminalUtils.setupTerminalView(view) context.fullScreenToggleButton.setStatus(NeoPreference.loadBoolean(R.string.key_ui_fullscreen, false)) if (tab is TermTab) { diff --git a/app/src/main/res/layout/ui_customization.xml b/app/src/main/res/layout/ui_customization.xml new file mode 100644 index 0000000..0b76d45 --- /dev/null +++ b/app/src/main/res/layout/ui_customization.xml @@ -0,0 +1,76 @@ + + + + + + + +