diff --git a/app/src/main/java/io/neoterm/backend/TerminalSession.java b/app/src/main/java/io/neoterm/backend/TerminalSession.java index 0969a43..4a0da59 100755 --- a/app/src/main/java/io/neoterm/backend/TerminalSession.java +++ b/app/src/main/java/io/neoterm/backend/TerminalSession.java @@ -92,10 +92,10 @@ public class TerminalSession extends TerminalOutput { /** Callback which gets notified when a session finishes or changes title. */ final SessionChangedCallback mChangeCallback; - /** The pid of the shell process. 0 if not started and -1 if finished running. */ + /** The pid of the executablePath process. 0 if not started and -1 if finished running. */ int mShellPid; - /** The exit status of the shell process. Only valid if ${@link #mShellPid} is -1. */ + /** The exit status of the executablePath process. Only valid if ${@link #mShellPid} is -1. */ int mShellExitStatus; /** @@ -227,7 +227,7 @@ public class TerminalSession extends TerminalOutput { }.start(); } - /** Write data to the shell process. */ + /** Write data to the executablePath process. */ @Override public void write(byte[] data, int offset, int count) { if (mShellPid > 0) mTerminalToProcessIOQueue.write(data, offset, count); @@ -285,7 +285,7 @@ public class TerminalSession extends TerminalOutput { notifyScreenUpdate(); } - /** Finish this terminal session by sending SIGKILL to the shell. */ + /** Finish this terminal session by sending SIGKILL to the executablePath. */ public void finishIfRunning() { if (isRunning()) { try { diff --git a/app/src/main/java/io/neoterm/frontend/ShellParameter.kt b/app/src/main/java/io/neoterm/frontend/ShellParameter.kt new file mode 100644 index 0000000..5bd863b --- /dev/null +++ b/app/src/main/java/io/neoterm/frontend/ShellParameter.kt @@ -0,0 +1,51 @@ +package io.neoterm.frontend + +import io.neoterm.backend.TerminalSession + +/** + * @author kiva + */ +class ShellParameter { + var executablePath: String? = null + var arguments: Array? = null + var cwd: String? = null + var initialCommand: String? = null + var env: Array>? = null + var sessionCallback: TerminalSession.SessionChangedCallback? = null + var systemShell: Boolean = false + + fun executablePath(executablePath: String?): ShellParameter { + this.executablePath = executablePath + return this + } + + fun arguments(arguments: Array?): ShellParameter { + this.arguments = arguments + return this + } + + fun currentWorkingDirectory(cwd: String?): ShellParameter { + this.cwd = cwd + return this + } + + fun initialCommand(initialCommand: String?): ShellParameter { + this.initialCommand = initialCommand + return this + } + + fun environment(env: Array>?): ShellParameter { + this.env = env + return this + } + + fun callback(callback: TerminalSession.SessionChangedCallback?): ShellParameter { + this.sessionCallback = callback + return this + } + + fun systemShell(systemShell: Boolean): ShellParameter { + this.systemShell = systemShell + return this + } +} \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/terminal/ShellTermSession.kt b/app/src/main/java/io/neoterm/frontend/ShellTermSession.kt similarity index 93% rename from app/src/main/java/io/neoterm/terminal/ShellTermSession.kt rename to app/src/main/java/io/neoterm/frontend/ShellTermSession.kt index ab15adc..91772c9 100644 --- a/app/src/main/java/io/neoterm/terminal/ShellTermSession.kt +++ b/app/src/main/java/io/neoterm/frontend/ShellTermSession.kt @@ -1,19 +1,19 @@ -package io.neoterm.terminal +package io.neoterm.frontend import android.content.Context import android.widget.Toast import io.neoterm.R import io.neoterm.backend.TerminalSession +import io.neoterm.frontend.client.TermSessionCallback import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoTermPath -import io.neoterm.terminal.client.TermSessionCallback import java.io.File /** * @author kiva */ open class ShellTermSession private constructor(shellPath: String, cwd: String, args: Array, env: Array, changeCallback: SessionChangedCallback) : TerminalSession(shellPath, cwd, args, env, changeCallback) { - var initialCommand : String? = null + var initialCommand: String? = null override fun initializeEmulator(columns: Int, rows: Int) { super.initializeEmulator(columns, rows) @@ -25,15 +25,15 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String, } class Builder { - private var shell: String? = null + private var executablePath: String? = null private var cwd: String? = null private var args: MutableList? = null private var env: MutableList>? = null private var changeCallback: SessionChangedCallback? = null private var systemShell = false - fun shell(shell: String?): Builder { - this.shell = shell + fun executablePath(shell: String?): Builder { + this.executablePath = shell return this } @@ -107,7 +107,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String, fun create(context: Context): ShellTermSession { val cwd = this.cwd ?: NeoTermPath.HOME_PATH - var shell = this.shell ?: + var shell = this.executablePath ?: if (systemShell) "/system/bin/sh" else @@ -119,7 +119,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String, } val args = this.args ?: mutableListOf(shell) - val env = transformEnvironment(this.env) ?: buildEnvironment(cwd, systemShell, shell) + val env = transformEnvironment(this.env) ?: buildEnvironment(cwd, systemShell) val callback = changeCallback ?: TermSessionCallback() return ShellTermSession(shell, cwd, args.toTypedArray(), env, callback) } @@ -135,12 +135,10 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String, } - private fun buildEnvironment(cwd: String?, systemShell: Boolean, executablePath: String): Array { - var cwd = cwd + private fun buildEnvironment(cwd: String?, systemShell: Boolean): Array { + val cwd = cwd ?: NeoTermPath.HOME_PATH File(NeoTermPath.HOME_PATH).mkdirs() - if (cwd == null) cwd = NeoTermPath.HOME_PATH - val termEnv = "TERM=xterm-256color" val homeEnv = "HOME=" + NeoTermPath.HOME_PATH val androidRootEnv = "ANDROID_ROOT=" + System.getenv("ANDROID_ROOT") diff --git a/app/src/main/java/io/neoterm/terminal/client/TermCompleteListener.kt b/app/src/main/java/io/neoterm/frontend/client/TermCompleteListener.kt similarity index 89% rename from app/src/main/java/io/neoterm/terminal/client/TermCompleteListener.kt rename to app/src/main/java/io/neoterm/frontend/client/TermCompleteListener.kt index 93699fd..10b6975 100644 --- a/app/src/main/java/io/neoterm/terminal/client/TermCompleteListener.kt +++ b/app/src/main/java/io/neoterm/frontend/client/TermCompleteListener.kt @@ -1,11 +1,11 @@ -package io.neoterm.terminal.client +package io.neoterm.frontend.client import android.util.Log import android.view.KeyEvent -import io.neoterm.customize.completion.AutoCompleteManager -import io.neoterm.customize.completion.CompleteCandidate -import io.neoterm.view.AutoCompletePopupWindow -import io.neoterm.view.OnAutoCompleteListener +import io.neoterm.frontend.completion.AutoCompleteManager +import io.neoterm.frontend.completion.CompleteCandidate +import io.neoterm.frontend.completion.AutoCompletePopupWindow +import io.neoterm.frontend.completion.OnAutoCompleteListener import io.neoterm.view.TerminalView import java.util.* diff --git a/app/src/main/java/io/neoterm/terminal/client/TermDataHolder.kt b/app/src/main/java/io/neoterm/frontend/client/TermDataHolder.kt similarity index 93% rename from app/src/main/java/io/neoterm/terminal/client/TermDataHolder.kt rename to app/src/main/java/io/neoterm/frontend/client/TermDataHolder.kt index 74c67e3..9f03650 100644 --- a/app/src/main/java/io/neoterm/terminal/client/TermDataHolder.kt +++ b/app/src/main/java/io/neoterm/frontend/client/TermDataHolder.kt @@ -1,8 +1,8 @@ -package io.neoterm.terminal.client +package io.neoterm.frontend.client import io.neoterm.backend.TerminalSession import io.neoterm.view.ExtraKeysView -import io.neoterm.view.OnAutoCompleteListener +import io.neoterm.frontend.completion.OnAutoCompleteListener import io.neoterm.view.TerminalView /** diff --git a/app/src/main/java/io/neoterm/terminal/client/TermSessionCallback.kt b/app/src/main/java/io/neoterm/frontend/client/TermSessionCallback.kt similarity index 98% rename from app/src/main/java/io/neoterm/terminal/client/TermSessionCallback.kt rename to app/src/main/java/io/neoterm/frontend/client/TermSessionCallback.kt index 5c675b4..c0ec1da 100644 --- a/app/src/main/java/io/neoterm/terminal/client/TermSessionCallback.kt +++ b/app/src/main/java/io/neoterm/frontend/client/TermSessionCallback.kt @@ -1,4 +1,4 @@ -package io.neoterm.terminal.client +package io.neoterm.frontend.client import android.content.ClipData import android.content.ClipboardManager diff --git a/app/src/main/java/io/neoterm/terminal/client/TermUiPresenter.kt b/app/src/main/java/io/neoterm/frontend/client/TermUiPresenter.kt similarity index 85% rename from app/src/main/java/io/neoterm/terminal/client/TermUiPresenter.kt rename to app/src/main/java/io/neoterm/frontend/client/TermUiPresenter.kt index ba2acec..234cf9a 100644 --- a/app/src/main/java/io/neoterm/terminal/client/TermUiPresenter.kt +++ b/app/src/main/java/io/neoterm/frontend/client/TermUiPresenter.kt @@ -1,4 +1,4 @@ -package io.neoterm.terminal.client +package io.neoterm.frontend.client /** * @author kiva diff --git a/app/src/main/java/io/neoterm/terminal/client/TermViewClient.kt b/app/src/main/java/io/neoterm/frontend/client/TermViewClient.kt similarity index 99% rename from app/src/main/java/io/neoterm/terminal/client/TermViewClient.kt rename to app/src/main/java/io/neoterm/frontend/client/TermViewClient.kt index 7b67c2f..764014e 100644 --- a/app/src/main/java/io/neoterm/terminal/client/TermViewClient.kt +++ b/app/src/main/java/io/neoterm/frontend/client/TermViewClient.kt @@ -1,4 +1,4 @@ -package io.neoterm.terminal.client +package io.neoterm.frontend.client import android.content.Context import android.media.AudioManager diff --git a/app/src/main/java/io/neoterm/customize/completion/AutoCompleteManager.kt b/app/src/main/java/io/neoterm/frontend/completion/AutoCompleteManager.kt similarity index 92% rename from app/src/main/java/io/neoterm/customize/completion/AutoCompleteManager.kt rename to app/src/main/java/io/neoterm/frontend/completion/AutoCompleteManager.kt index 792c909..ab404fa 100644 --- a/app/src/main/java/io/neoterm/customize/completion/AutoCompleteManager.kt +++ b/app/src/main/java/io/neoterm/frontend/completion/AutoCompleteManager.kt @@ -1,4 +1,4 @@ -package io.neoterm.customize.completion +package io.neoterm.frontend.completion /** * @author kiva @@ -10,7 +10,7 @@ object AutoCompleteManager { val programs = arrayOf("ls", "clean", "exit", "apt", "neoterm-normalize-binary", "less", "ln", "lsof") val desc = arrayOf("List files and directories", "Clear screen", - "Exit current shell", + "Exit current executablePath", "Installing, Updating, Upgrading packages", "Fix program error caused by linux shebang", "View files", diff --git a/app/src/main/java/io/neoterm/view/AutoCompletePopupWindow.kt b/app/src/main/java/io/neoterm/frontend/completion/AutoCompletePopupWindow.kt similarity index 98% rename from app/src/main/java/io/neoterm/view/AutoCompletePopupWindow.kt rename to app/src/main/java/io/neoterm/frontend/completion/AutoCompletePopupWindow.kt index 4d420ab..98dc21d 100644 --- a/app/src/main/java/io/neoterm/view/AutoCompletePopupWindow.kt +++ b/app/src/main/java/io/neoterm/frontend/completion/AutoCompletePopupWindow.kt @@ -1,4 +1,4 @@ -package io.neoterm.view +package io.neoterm.frontend.completion import android.content.Context import android.view.Gravity @@ -12,7 +12,7 @@ import android.widget.TextView import io.neoterm.R import io.neoterm.backend.TerminalColors import io.neoterm.customize.color.ColorSchemeManager -import io.neoterm.customize.completion.CompleteCandidate +import io.neoterm.view.TerminalView /** * @author kiva diff --git a/app/src/main/java/io/neoterm/customize/completion/CompleteCandidate.kt b/app/src/main/java/io/neoterm/frontend/completion/CompleteCandidate.kt similarity index 79% rename from app/src/main/java/io/neoterm/customize/completion/CompleteCandidate.kt rename to app/src/main/java/io/neoterm/frontend/completion/CompleteCandidate.kt index 38a83bf..7bec640 100644 --- a/app/src/main/java/io/neoterm/customize/completion/CompleteCandidate.kt +++ b/app/src/main/java/io/neoterm/frontend/completion/CompleteCandidate.kt @@ -1,4 +1,4 @@ -package io.neoterm.customize.completion +package io.neoterm.frontend.completion /** * @author kiva diff --git a/app/src/main/java/io/neoterm/view/OnAutoCompleteListener.java b/app/src/main/java/io/neoterm/frontend/completion/OnAutoCompleteListener.java similarity index 82% rename from app/src/main/java/io/neoterm/view/OnAutoCompleteListener.java rename to app/src/main/java/io/neoterm/frontend/completion/OnAutoCompleteListener.java index ab8d678..f585760 100755 --- a/app/src/main/java/io/neoterm/view/OnAutoCompleteListener.java +++ b/app/src/main/java/io/neoterm/frontend/completion/OnAutoCompleteListener.java @@ -1,4 +1,4 @@ -package io.neoterm.view; +package io.neoterm.frontend.completion; /** * @author Kiva diff --git a/app/src/main/java/io/neoterm/view/TerminalDialog.kt b/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt similarity index 86% rename from app/src/main/java/io/neoterm/view/TerminalDialog.kt rename to app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt index 9397896..b58b1a7 100644 --- a/app/src/main/java/io/neoterm/view/TerminalDialog.kt +++ b/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt @@ -1,4 +1,4 @@ -package io.neoterm.view +package io.neoterm.frontend.floating import android.annotation.SuppressLint import android.app.AlertDialog @@ -8,7 +8,11 @@ import android.view.LayoutInflater import android.view.View import io.neoterm.R import io.neoterm.backend.TerminalSession +import io.neoterm.frontend.tinyclient.BasicSessionCallback +import io.neoterm.frontend.tinyclient.BasicViewClient +import io.neoterm.frontend.ShellParameter import io.neoterm.utils.TerminalUtils +import io.neoterm.view.TerminalView /** * @author kiva @@ -53,7 +57,12 @@ class TerminalDialog(val context: Context) { } .create() - terminalSession = TerminalUtils.createShellSession(context, executablePath, arguments, null, null, null, terminalSessionCallback, false) + val parameter = ShellParameter() + .executablePath(executablePath) + .arguments(arguments) + .callback(terminalSessionCallback) + .systemShell(false) + terminalSession = TerminalUtils.createShellSession(context, parameter) terminalView.attachSession(terminalSession) return this } diff --git a/app/src/main/java/io/neoterm/frontend/floating/TerminalWindowView.kt b/app/src/main/java/io/neoterm/frontend/floating/TerminalWindowView.kt new file mode 100644 index 0000000..845b603 --- /dev/null +++ b/app/src/main/java/io/neoterm/frontend/floating/TerminalWindowView.kt @@ -0,0 +1,7 @@ +package io.neoterm.frontend.floating + +/** + * @author kiva + */ +class TerminalWindowView { +} \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/view/BasicSessionCallback.kt b/app/src/main/java/io/neoterm/frontend/tinyclient/BasicSessionCallback.kt similarity index 91% rename from app/src/main/java/io/neoterm/view/BasicSessionCallback.kt rename to app/src/main/java/io/neoterm/frontend/tinyclient/BasicSessionCallback.kt index a834599..25beb98 100644 --- a/app/src/main/java/io/neoterm/view/BasicSessionCallback.kt +++ b/app/src/main/java/io/neoterm/frontend/tinyclient/BasicSessionCallback.kt @@ -1,6 +1,7 @@ -package io.neoterm.view +package io.neoterm.frontend.tinyclient import io.neoterm.backend.TerminalSession +import io.neoterm.view.TerminalView /** * @author kiva diff --git a/app/src/main/java/io/neoterm/view/BasicViewClient.kt b/app/src/main/java/io/neoterm/frontend/tinyclient/BasicViewClient.kt similarity index 93% rename from app/src/main/java/io/neoterm/view/BasicViewClient.kt rename to app/src/main/java/io/neoterm/frontend/tinyclient/BasicViewClient.kt index 45ccbff..81c9fd3 100644 --- a/app/src/main/java/io/neoterm/view/BasicViewClient.kt +++ b/app/src/main/java/io/neoterm/frontend/tinyclient/BasicViewClient.kt @@ -1,10 +1,12 @@ -package io.neoterm.view +package io.neoterm.frontend.tinyclient import android.content.Context import android.view.KeyEvent import android.view.MotionEvent import android.view.inputmethod.InputMethodManager import io.neoterm.backend.TerminalSession +import io.neoterm.view.TerminalView +import io.neoterm.view.TerminalViewClient /** * @author kiva diff --git a/app/src/main/java/io/neoterm/services/NeoTermService.kt b/app/src/main/java/io/neoterm/services/NeoTermService.kt index 7afa37a..0ca432d 100644 --- a/app/src/main/java/io/neoterm/services/NeoTermService.kt +++ b/app/src/main/java/io/neoterm/services/NeoTermService.kt @@ -15,6 +15,7 @@ import android.support.v4.content.WakefulBroadcastReceiver import io.neoterm.R import io.neoterm.backend.EmulatorDebug import io.neoterm.backend.TerminalSession +import io.neoterm.frontend.ShellParameter import io.neoterm.ui.term.NeoTermActivity import io.neoterm.utils.TerminalUtils import java.util.* @@ -76,11 +77,8 @@ class NeoTermService : Service() { val sessions: List get() = mTerminalSessions - fun createTermSession(executablePath: String?, arguments: Array?, - cwd: String?, initialCommand: String?, - env: Array>?, sessionCallback: - TerminalSession.SessionChangedCallback?, systemShell: Boolean): TerminalSession { - val session = TerminalUtils.createShellSession(this, executablePath, arguments, cwd, initialCommand, env, sessionCallback, systemShell) + fun createTermSession(parameter: ShellParameter): TerminalSession { + val session = TerminalUtils.createShellSession(this, parameter) mTerminalSessions.add(session) updateNotification() return session diff --git a/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt b/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt index 66261ff..a3ee811 100644 --- a/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt +++ b/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt @@ -16,11 +16,12 @@ import io.neoterm.backend.TerminalSession import io.neoterm.customize.color.ColorSchemeManager import io.neoterm.preference.NeoTermPath import io.neoterm.customize.font.FontManager +import io.neoterm.frontend.ShellParameter import io.neoterm.utils.FileUtils import io.neoterm.utils.MediaUtils import io.neoterm.utils.TerminalUtils -import io.neoterm.view.BasicSessionCallback -import io.neoterm.view.BasicViewClient +import io.neoterm.frontend.tinyclient.BasicSessionCallback +import io.neoterm.frontend.tinyclient.BasicViewClient import io.neoterm.view.ExtraKeysView import io.neoterm.view.TerminalView import java.io.File @@ -56,8 +57,14 @@ class CustomizationActivity : AppCompatActivity() { viewClient = BasicViewClient(terminalView) sessionCallback = BasicSessionCallback(terminalView) TerminalUtils.setupTerminalView(terminalView, viewClient) - session = TerminalUtils.createShellSession(this, "${NeoTermPath.USR_PATH}/bin/applets/echo", - arrayOf("echo", "Hello NeoTerm."), null, null, null, sessionCallback, false) + + val parameter = ShellParameter() + .executablePath("${NeoTermPath.USR_PATH}/bin/applets/echo") + .arguments(arrayOf("echo", "Hello NeoTerm.")) + .callback(sessionCallback) + .systemShell(false) + + session = TerminalUtils.createShellSession(this, parameter) terminalView.attachSession(session) findViewById(R.id.custom_install_font_button).setOnClickListener { diff --git a/app/src/main/java/io/neoterm/ui/floating/FloatingNeoTerm.kt b/app/src/main/java/io/neoterm/ui/floating/FloatingNeoTerm.kt deleted file mode 100644 index d9df1e0..0000000 --- a/app/src/main/java/io/neoterm/ui/floating/FloatingNeoTerm.kt +++ /dev/null @@ -1,6 +0,0 @@ -package io.neoterm.ui.floating - -/** - * @author kiva - */ -class FloatingNeoTerm \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt b/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt index ae927f3..5a34c63 100644 --- a/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt +++ b/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt @@ -29,11 +29,8 @@ import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoTermPath import io.neoterm.ui.pm.adapter.PackageAdapter import io.neoterm.ui.pm.model.PackageModel -import io.neoterm.utils.FileUtils import io.neoterm.utils.PackageUtils -import io.neoterm.view.TerminalDialog -import java.io.File -import java.net.URL +import io.neoterm.frontend.floating.TerminalDialog /** * @author kiva diff --git a/app/src/main/java/io/neoterm/ui/settings/UISettingsActivity.kt b/app/src/main/java/io/neoterm/ui/settings/UISettingsActivity.kt index dcbcfd1..b1affe6 100644 --- a/app/src/main/java/io/neoterm/ui/settings/UISettingsActivity.kt +++ b/app/src/main/java/io/neoterm/ui/settings/UISettingsActivity.kt @@ -4,12 +4,11 @@ import android.app.AlertDialog import android.os.Bundle import android.support.v7.app.AppCompatPreferenceActivity import android.view.MenuItem -import android.widget.Toast import io.neoterm.R import io.neoterm.backend.TerminalSession import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoTermPath -import io.neoterm.view.TerminalDialog +import io.neoterm.frontend.floating.TerminalDialog /** * @author kiva diff --git a/app/src/main/java/io/neoterm/ui/setup/SetupActivity.kt b/app/src/main/java/io/neoterm/ui/setup/SetupActivity.kt index bd5472a..62dc775 100644 --- a/app/src/main/java/io/neoterm/ui/setup/SetupActivity.kt +++ b/app/src/main/java/io/neoterm/ui/setup/SetupActivity.kt @@ -21,8 +21,7 @@ import io.neoterm.customize.setup.BaseFileInstaller import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoTermPath import io.neoterm.utils.PackageUtils -import io.neoterm.utils.TerminalUtils -import io.neoterm.view.TerminalDialog +import io.neoterm.frontend.floating.TerminalDialog import java.util.* @@ -112,7 +111,7 @@ class SetupActivity : AppCompatActivity() { } private fun executeAptUpdate() { - TerminalUtils.executeApt(this, "update", { exitStatus, dialog -> + PackageUtils.executeApt(this, "update", { exitStatus, dialog -> if (exitStatus == 0) { dialog.dismiss() aptUpdated = true @@ -124,7 +123,7 @@ class SetupActivity : AppCompatActivity() { } private fun executeAptUpgrade() { - TerminalUtils.executeApt(this, "upgrade", { exitStatus, dialog -> + PackageUtils.executeApt(this, "upgrade", { exitStatus, dialog -> if (exitStatus == 0) { dialog.dismiss() } else { 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 3a3273c..35ba429 100644 --- a/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt +++ b/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt @@ -26,6 +26,7 @@ import io.neoterm.customize.color.ColorSchemeManager import io.neoterm.customize.eks.EksKeysManager import io.neoterm.customize.font.FontManager import io.neoterm.customize.setup.BaseFileInstaller +import io.neoterm.frontend.ShellParameter import io.neoterm.preference.NeoPermission import io.neoterm.preference.NeoPreference import io.neoterm.services.NeoTermService @@ -33,10 +34,10 @@ import io.neoterm.ui.bonus.BonusActivity import io.neoterm.ui.pm.PackageManagerActivity import io.neoterm.ui.settings.SettingActivity import io.neoterm.ui.setup.SetupActivity -import io.neoterm.terminal.client.TermSessionCallback +import io.neoterm.frontend.client.TermSessionCallback import io.neoterm.ui.term.tab.TermTab import io.neoterm.ui.term.tab.TermTabDecorator -import io.neoterm.terminal.client.TermViewClient +import io.neoterm.frontend.client.TermViewClient import io.neoterm.ui.term.tab.event.TabCloseEvent import io.neoterm.ui.term.tab.event.TitleChangedEvent import io.neoterm.ui.term.tab.event.ToggleFullScreenEvent @@ -403,8 +404,11 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference private fun addNewSession(sessionName: String?, systemShell: Boolean, animation: Animation) { val sessionCallback = TermSessionCallback() val viewClient = TermViewClient(this) - val session = termService!!.createTermSession(null, null, - null, null, null, sessionCallback, systemShell) + + val parameter = ShellParameter() + .callback(sessionCallback) + .systemShell(systemShell) + val session = termService!!.createTermSession(parameter) if (sessionName != null) { session.mSessionName = sessionName diff --git a/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt b/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt index 9b3f92e..549cba6 100644 --- a/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt +++ b/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt @@ -14,9 +14,10 @@ import android.widget.Toast import io.neoterm.R import io.neoterm.customize.script.UserScript import io.neoterm.customize.script.UserScriptManager +import io.neoterm.frontend.ShellParameter import io.neoterm.preference.NeoPreference import io.neoterm.services.NeoTermService -import io.neoterm.terminal.client.TermSessionCallback +import io.neoterm.frontend.client.TermSessionCallback import io.neoterm.utils.TerminalUtils import java.io.File @@ -68,9 +69,12 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection { } private fun openTerm(initialCommand: String?) { - val session = termService!!.createTermSession(null, - null, null, initialCommand, - null, TermSessionCallback(), false) + // TODO: check whether system executablePath we should use + val parameter = ShellParameter() + .initialCommand(initialCommand) + .callback(TermSessionCallback()) + .systemShell(false) + val session = termService!!.createTermSession(parameter) // Set current session to our new one // In order to switch to it when entering NeoTermActivity diff --git a/app/src/main/java/io/neoterm/ui/term/tab/TermTab.kt b/app/src/main/java/io/neoterm/ui/term/tab/TermTab.kt index e33e7a1..5847597 100644 --- a/app/src/main/java/io/neoterm/ui/term/tab/TermTab.kt +++ b/app/src/main/java/io/neoterm/ui/term/tab/TermTab.kt @@ -7,8 +7,8 @@ import de.mrapp.android.tabswitcher.Tab import io.neoterm.R import io.neoterm.customize.color.ColorSchemeManager import io.neoterm.preference.NeoPreference -import io.neoterm.terminal.client.TermDataHolder -import io.neoterm.terminal.client.TermUiPresenter +import io.neoterm.frontend.client.TermDataHolder +import io.neoterm.frontend.client.TermUiPresenter import io.neoterm.ui.term.tab.event.TabCloseEvent import io.neoterm.ui.term.tab.event.TitleChangedEvent import io.neoterm.ui.term.tab.event.ToggleFullScreenEvent diff --git a/app/src/main/java/io/neoterm/ui/term/tab/TermTabDecorator.kt b/app/src/main/java/io/neoterm/ui/term/tab/TermTabDecorator.kt index bd50712..6d6d8b1 100644 --- a/app/src/main/java/io/neoterm/ui/term/tab/TermTabDecorator.kt +++ b/app/src/main/java/io/neoterm/ui/term/tab/TermTabDecorator.kt @@ -12,11 +12,11 @@ import io.neoterm.BuildConfig import io.neoterm.R import io.neoterm.customize.color.ColorSchemeManager import io.neoterm.preference.NeoPreference -import io.neoterm.terminal.client.TermCompleteListener +import io.neoterm.frontend.client.TermCompleteListener import io.neoterm.ui.term.NeoTermActivity import io.neoterm.utils.TerminalUtils import io.neoterm.view.ExtraKeysView -import io.neoterm.view.OnAutoCompleteListener +import io.neoterm.frontend.completion.OnAutoCompleteListener import io.neoterm.view.TerminalView /** diff --git a/app/src/main/java/io/neoterm/utils/PackageUtils.kt b/app/src/main/java/io/neoterm/utils/PackageUtils.kt index 37e3a27..1861c39 100644 --- a/app/src/main/java/io/neoterm/utils/PackageUtils.kt +++ b/app/src/main/java/io/neoterm/utils/PackageUtils.kt @@ -1,8 +1,11 @@ package io.neoterm.utils +import android.content.Context import io.neoterm.R +import io.neoterm.backend.TerminalSession import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoTermPath +import io.neoterm.frontend.floating.TerminalDialog import java.io.File /** @@ -23,4 +26,17 @@ object PackageUtils { .append("\n") .toString() } + + fun executeApt(context: Context, subCommand: String, callback: (Int, TerminalDialog) -> Unit) { + TerminalDialog(context) + .onFinish(object : TerminalDialog.SessionFinishedCallback { + override fun onSessionFinished(dialog: TerminalDialog, finishedSession: TerminalSession?) { + val exit = finishedSession?.exitStatus ?: 1 + callback(exit, dialog) + } + }) + .imeEnabled(true) + .execute(NeoTermPath.APT_BIN_PATH, arrayOf("apt", subCommand)) + .show("apt $subCommand") + } } \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/utils/ShakeUtils.kt b/app/src/main/java/io/neoterm/utils/ShakeUtils.kt deleted file mode 100644 index fbee5e2..0000000 --- a/app/src/main/java/io/neoterm/utils/ShakeUtils.kt +++ /dev/null @@ -1,52 +0,0 @@ -package io.neoterm.utils - -import android.content.Context -import android.hardware.Sensor -import android.hardware.SensorEvent -import android.hardware.SensorEventListener -import android.hardware.SensorManager - -class ShakeUtils(context: Context) : SensorEventListener { - companion object { - private val SHAKE_SENSITIVITY = 14 - } - - private val mSensorManager: SensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager - private var mOnShakeListener: OnShakeListener? = null - - fun setOnShakeListener(onShakeListener: OnShakeListener) { - mOnShakeListener = onShakeListener - } - - fun onResume() { - mSensorManager.registerListener(this, - mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), - SensorManager.SENSOR_DELAY_NORMAL) - } - - fun onPause() { - mSensorManager.unregisterListener(this) - } - - override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) { - - } - - override fun onSensorChanged(event: SensorEvent) { - val sensorType = event.sensor.type - //values[0]:X, values[1]:Y, values[2]:Z - val values = event.values - if (sensorType == Sensor.TYPE_ACCELEROMETER) { - //这里可以调节摇一摇的灵敏度 - if (Math.abs(values[0]) > SHAKE_SENSITIVITY || Math.abs(values[1]) > SHAKE_SENSITIVITY || Math.abs(values[2]) > SHAKE_SENSITIVITY) { - if (mOnShakeListener != null) { - mOnShakeListener!!.onShake() - } - } - } - } - - interface OnShakeListener { - fun onShake() - } -} \ 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 49bb490..bfea20d 100644 --- a/app/src/main/java/io/neoterm/utils/TerminalUtils.kt +++ b/app/src/main/java/io/neoterm/utils/TerminalUtils.kt @@ -4,11 +4,10 @@ import android.content.Context import io.neoterm.R import io.neoterm.backend.TerminalSession import io.neoterm.customize.font.FontManager +import io.neoterm.frontend.ShellParameter +import io.neoterm.frontend.ShellTermSession import io.neoterm.preference.NeoPreference -import io.neoterm.preference.NeoTermPath -import io.neoterm.terminal.ShellTermSession import io.neoterm.view.ExtraKeysView -import io.neoterm.view.TerminalDialog import io.neoterm.view.TerminalView import io.neoterm.view.TerminalViewClient @@ -31,20 +30,17 @@ object TerminalUtils { fun setupTerminalSession(session: TerminalSession?) { } - fun createShellSession(context: Context, executablePath: String?, arguments: Array?, - cwd: String?, initialCommand: String?, env: Array>?, - sessionCallback: TerminalSession.SessionChangedCallback?, - systemShell: Boolean): TerminalSession { - val initCommand = initialCommand ?: + fun createShellSession(context: Context, parameter: ShellParameter): TerminalSession { + val initCommand = parameter.initialCommand ?: NeoPreference.loadString(R.string.key_general_initial_command, "") val session = ShellTermSession.Builder() - .shell(executablePath) - .currentWorkingDirectory(cwd) - .callback(sessionCallback) - .systemShell(systemShell) - .envArray(env) - .argArray(arguments) + .executablePath(parameter.executablePath) + .currentWorkingDirectory(parameter.cwd) + .callback(parameter.sessionCallback) + .systemShell(parameter.systemShell) + .envArray(parameter.env) + .argArray(parameter.arguments) .create(context) setupTerminalSession(session) session.initialCommand = initCommand @@ -70,17 +66,4 @@ object TerminalUtils { builder.append('"') return builder.toString() } - - fun executeApt(context: Context, subCommand: String, callback: (Int, TerminalDialog) -> Unit) { - TerminalDialog(context) - .onFinish(object : TerminalDialog.SessionFinishedCallback { - override fun onSessionFinished(dialog: TerminalDialog, finishedSession: TerminalSession?) { - val exit = finishedSession?.exitStatus ?: 1 - callback(exit, dialog) - } - }) - .imeEnabled(true) - .execute(NeoTermPath.APT_BIN_PATH, arrayOf("apt", subCommand)) - .show("apt $subCommand") - } } \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/view/ExtraKeysView.kt b/app/src/main/java/io/neoterm/view/ExtraKeysView.kt index 0318eec..9a031fe 100755 --- a/app/src/main/java/io/neoterm/view/ExtraKeysView.kt +++ b/app/src/main/java/io/neoterm/view/ExtraKeysView.kt @@ -6,7 +6,6 @@ import android.graphics.Typeface import android.util.AttributeSet import android.view.Gravity import android.view.HapticFeedbackConstants -import android.view.View import android.view.ViewGroup import android.widget.Button import android.widget.HorizontalScrollView @@ -16,27 +15,13 @@ import android.widget.ToggleButton import java.io.File import java.util.ArrayList -import io.neoterm.customize.eks.EksConfig import io.neoterm.customize.eks.EksConfigParser -import io.neoterm.customize.font.FontManager import io.neoterm.preference.NeoTermPath import io.neoterm.utils.FileUtils import io.neoterm.view.eks.ControlButton import io.neoterm.view.eks.ExtraButton import io.neoterm.view.eks.StatedControlButton -import io.neoterm.view.eks.ExtraButton.Companion.KEY_ARROW_DOWN -import io.neoterm.view.eks.ExtraButton.Companion.KEY_ARROW_LEFT -import io.neoterm.view.eks.ExtraButton.Companion.KEY_ARROW_RIGHT -import io.neoterm.view.eks.ExtraButton.Companion.KEY_ARROW_UP -import io.neoterm.view.eks.ExtraButton.Companion.KEY_CTRL -import io.neoterm.view.eks.ExtraButton.Companion.KEY_END -import io.neoterm.view.eks.ExtraButton.Companion.KEY_ESC -import io.neoterm.view.eks.ExtraButton.Companion.KEY_HOME -import io.neoterm.view.eks.ExtraButton.Companion.KEY_PAGE_DOWN -import io.neoterm.view.eks.ExtraButton.Companion.KEY_PAGE_UP -import io.neoterm.view.eks.ExtraButton.Companion.KEY_TAB - /** * A view showing extra keys (such as Escape, Ctrl, Alt) not normally available on an Android soft * keyboard. diff --git a/app/src/main/java/io/neoterm/view/TerminalView.java b/app/src/main/java/io/neoterm/view/TerminalView.java index 4e9d3d7..c5c9401 100755 --- a/app/src/main/java/io/neoterm/view/TerminalView.java +++ b/app/src/main/java/io/neoterm/view/TerminalView.java @@ -35,6 +35,7 @@ import io.neoterm.backend.KeyHandler; import io.neoterm.backend.TerminalBuffer; import io.neoterm.backend.TerminalEmulator; import io.neoterm.backend.TerminalSession; +import io.neoterm.frontend.completion.OnAutoCompleteListener; /** * View displaying and interacting with a {@link TerminalSession}. diff --git a/app/src/main/java/io/neoterm/view/eks/ControlButton.kt b/app/src/main/java/io/neoterm/view/eks/ControlButton.kt index 6dbcaf3..5da221f 100644 --- a/app/src/main/java/io/neoterm/view/eks/ControlButton.kt +++ b/app/src/main/java/io/neoterm/view/eks/ControlButton.kt @@ -2,8 +2,6 @@ package io.neoterm.view.eks import android.view.View -import io.neoterm.view.ExtraKeysView - /** * @author kiva */ diff --git a/app/src/main/java/io/neoterm/view/eks/TextButton.kt b/app/src/main/java/io/neoterm/view/eks/TextButton.kt index e32cc73..718b462 100644 --- a/app/src/main/java/io/neoterm/view/eks/TextButton.kt +++ b/app/src/main/java/io/neoterm/view/eks/TextButton.kt @@ -2,8 +2,6 @@ package io.neoterm.view.eks import android.view.View -import io.neoterm.view.ExtraKeysView - /** * @author kiva */ diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index fe2848c..21dfd71 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -39,7 +39,7 @@ 界面设置 Shell %s 未找到, 请先安装. 正在安装 - 将要安装 oh-my-zsh 并将您的登录 shell 切换到 zsh + 将要安装 oh-my-zsh 并将您的登录 executablePath 切换到 zsh 全屏模式已改变,请重启 NeoTerm NeoTerm 无法取得必需的权限,正在退出 还有这种操作? diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 44239c6..85ec47b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,7 +51,7 @@ Stack Trace Installing - We are about to install oh-my-zsh and switch your login shell to zsh + We are about to install oh-my-zsh and switch your login executablePath to zsh Bell Bell when receiving \'\\a\' @@ -60,7 +60,7 @@ BackSpace Mapped to Esc Send esc when backspace is pressed Shell - Which shell should we use when login + Which executablePath should we use when login Program Selection When both Neo Term and your Android OS have a program, which one should we choose? Initial Command diff --git a/gradlew.bat b/gradlew.bat index aec9973..2a53aa8 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -5,7 +5,7 @@ @rem @rem ########################################################################## -@rem Set local scope for the variables with windows NT shell +@rem Set local scope for the variables with windows NT executablePath if "%OS%"=="Windows_NT" setlocal @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @@ -75,7 +75,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end -@rem End local scope for the variables with windows NT shell +@rem End local scope for the variables with windows NT executablePath if "%ERRORLEVEL%"=="0" goto mainEnd :fail