Refactor: Project structure

This commit is contained in:
zt515 2017-07-21 18:07:58 +08:00
parent 668f877883
commit 438e1e4d24
36 changed files with 175 additions and 176 deletions

View File

@ -92,10 +92,10 @@ public class TerminalSession extends TerminalOutput {
/** Callback which gets notified when a session finishes or changes title. */ /** Callback which gets notified when a session finishes or changes title. */
final SessionChangedCallback mChangeCallback; 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; 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; int mShellExitStatus;
/** /**
@ -227,7 +227,7 @@ public class TerminalSession extends TerminalOutput {
}.start(); }.start();
} }
/** Write data to the shell process. */ /** Write data to the executablePath process. */
@Override @Override
public void write(byte[] data, int offset, int count) { public void write(byte[] data, int offset, int count) {
if (mShellPid > 0) mTerminalToProcessIOQueue.write(data, offset, count); if (mShellPid > 0) mTerminalToProcessIOQueue.write(data, offset, count);
@ -285,7 +285,7 @@ public class TerminalSession extends TerminalOutput {
notifyScreenUpdate(); notifyScreenUpdate();
} }
/** Finish this terminal session by sending SIGKILL to the shell. */ /** Finish this terminal session by sending SIGKILL to the executablePath. */
public void finishIfRunning() { public void finishIfRunning() {
if (isRunning()) { if (isRunning()) {
try { try {

View File

@ -0,0 +1,51 @@
package io.neoterm.frontend
import io.neoterm.backend.TerminalSession
/**
* @author kiva
*/
class ShellParameter {
var executablePath: String? = null
var arguments: Array<String>? = null
var cwd: String? = null
var initialCommand: String? = null
var env: Array<Pair<String, String>>? = null
var sessionCallback: TerminalSession.SessionChangedCallback? = null
var systemShell: Boolean = false
fun executablePath(executablePath: String?): ShellParameter {
this.executablePath = executablePath
return this
}
fun arguments(arguments: Array<String>?): 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<Pair<String, String>>?): 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
}
}

View File

@ -1,12 +1,12 @@
package io.neoterm.terminal package io.neoterm.frontend
import android.content.Context import android.content.Context
import android.widget.Toast import android.widget.Toast
import io.neoterm.R import io.neoterm.R
import io.neoterm.backend.TerminalSession import io.neoterm.backend.TerminalSession
import io.neoterm.frontend.client.TermSessionCallback
import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoPreference
import io.neoterm.preference.NeoTermPath import io.neoterm.preference.NeoTermPath
import io.neoterm.terminal.client.TermSessionCallback
import java.io.File import java.io.File
/** /**
@ -25,15 +25,15 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
} }
class Builder { class Builder {
private var shell: String? = null private var executablePath: String? = null
private var cwd: String? = null private var cwd: String? = null
private var args: MutableList<String>? = null private var args: MutableList<String>? = null
private var env: MutableList<Pair<String, String>>? = null private var env: MutableList<Pair<String, String>>? = null
private var changeCallback: SessionChangedCallback? = null private var changeCallback: SessionChangedCallback? = null
private var systemShell = false private var systemShell = false
fun shell(shell: String?): Builder { fun executablePath(shell: String?): Builder {
this.shell = shell this.executablePath = shell
return this return this
} }
@ -107,7 +107,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
fun create(context: Context): ShellTermSession { fun create(context: Context): ShellTermSession {
val cwd = this.cwd ?: NeoTermPath.HOME_PATH val cwd = this.cwd ?: NeoTermPath.HOME_PATH
var shell = this.shell ?: var shell = this.executablePath ?:
if (systemShell) if (systemShell)
"/system/bin/sh" "/system/bin/sh"
else else
@ -119,7 +119,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
} }
val args = this.args ?: mutableListOf(shell) 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() val callback = changeCallback ?: TermSessionCallback()
return ShellTermSession(shell, cwd, args.toTypedArray(), env, callback) 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<String> { private fun buildEnvironment(cwd: String?, systemShell: Boolean): Array<String> {
var cwd = cwd val cwd = cwd ?: NeoTermPath.HOME_PATH
File(NeoTermPath.HOME_PATH).mkdirs() File(NeoTermPath.HOME_PATH).mkdirs()
if (cwd == null) cwd = NeoTermPath.HOME_PATH
val termEnv = "TERM=xterm-256color" val termEnv = "TERM=xterm-256color"
val homeEnv = "HOME=" + NeoTermPath.HOME_PATH val homeEnv = "HOME=" + NeoTermPath.HOME_PATH
val androidRootEnv = "ANDROID_ROOT=" + System.getenv("ANDROID_ROOT") val androidRootEnv = "ANDROID_ROOT=" + System.getenv("ANDROID_ROOT")

View File

@ -1,11 +1,11 @@
package io.neoterm.terminal.client package io.neoterm.frontend.client
import android.util.Log import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import io.neoterm.customize.completion.AutoCompleteManager import io.neoterm.frontend.completion.AutoCompleteManager
import io.neoterm.customize.completion.CompleteCandidate import io.neoterm.frontend.completion.CompleteCandidate
import io.neoterm.view.AutoCompletePopupWindow import io.neoterm.frontend.completion.AutoCompletePopupWindow
import io.neoterm.view.OnAutoCompleteListener import io.neoterm.frontend.completion.OnAutoCompleteListener
import io.neoterm.view.TerminalView import io.neoterm.view.TerminalView
import java.util.* import java.util.*

View File

@ -1,8 +1,8 @@
package io.neoterm.terminal.client package io.neoterm.frontend.client
import io.neoterm.backend.TerminalSession import io.neoterm.backend.TerminalSession
import io.neoterm.view.ExtraKeysView import io.neoterm.view.ExtraKeysView
import io.neoterm.view.OnAutoCompleteListener import io.neoterm.frontend.completion.OnAutoCompleteListener
import io.neoterm.view.TerminalView import io.neoterm.view.TerminalView
/** /**

View File

@ -1,4 +1,4 @@
package io.neoterm.terminal.client package io.neoterm.frontend.client
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager

View File

@ -1,4 +1,4 @@
package io.neoterm.terminal.client package io.neoterm.frontend.client
/** /**
* @author kiva * @author kiva

View File

@ -1,4 +1,4 @@
package io.neoterm.terminal.client package io.neoterm.frontend.client
import android.content.Context import android.content.Context
import android.media.AudioManager import android.media.AudioManager

View File

@ -1,4 +1,4 @@
package io.neoterm.customize.completion package io.neoterm.frontend.completion
/** /**
* @author kiva * @author kiva
@ -10,7 +10,7 @@ object AutoCompleteManager {
val programs = arrayOf("ls", "clean", "exit", "apt", "neoterm-normalize-binary", "less", "ln", "lsof") val programs = arrayOf("ls", "clean", "exit", "apt", "neoterm-normalize-binary", "less", "ln", "lsof")
val desc = arrayOf("List files and directories", val desc = arrayOf("List files and directories",
"Clear screen", "Clear screen",
"Exit current shell", "Exit current executablePath",
"Installing, Updating, Upgrading packages", "Installing, Updating, Upgrading packages",
"Fix program error caused by linux shebang", "Fix program error caused by linux shebang",
"View files", "View files",

View File

@ -1,4 +1,4 @@
package io.neoterm.view package io.neoterm.frontend.completion
import android.content.Context import android.content.Context
import android.view.Gravity import android.view.Gravity
@ -12,7 +12,7 @@ import android.widget.TextView
import io.neoterm.R import io.neoterm.R
import io.neoterm.backend.TerminalColors import io.neoterm.backend.TerminalColors
import io.neoterm.customize.color.ColorSchemeManager import io.neoterm.customize.color.ColorSchemeManager
import io.neoterm.customize.completion.CompleteCandidate import io.neoterm.view.TerminalView
/** /**
* @author kiva * @author kiva

View File

@ -1,4 +1,4 @@
package io.neoterm.customize.completion package io.neoterm.frontend.completion
/** /**
* @author kiva * @author kiva

View File

@ -1,4 +1,4 @@
package io.neoterm.view; package io.neoterm.frontend.completion;
/** /**
* @author Kiva * @author Kiva

View File

@ -1,4 +1,4 @@
package io.neoterm.view package io.neoterm.frontend.floating
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.AlertDialog import android.app.AlertDialog
@ -8,7 +8,11 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import io.neoterm.R import io.neoterm.R
import io.neoterm.backend.TerminalSession 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.utils.TerminalUtils
import io.neoterm.view.TerminalView
/** /**
* @author kiva * @author kiva
@ -53,7 +57,12 @@ class TerminalDialog(val context: Context) {
} }
.create() .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) terminalView.attachSession(terminalSession)
return this return this
} }

View File

@ -0,0 +1,7 @@
package io.neoterm.frontend.floating
/**
* @author kiva
*/
class TerminalWindowView {
}

View File

@ -1,6 +1,7 @@
package io.neoterm.view package io.neoterm.frontend.tinyclient
import io.neoterm.backend.TerminalSession import io.neoterm.backend.TerminalSession
import io.neoterm.view.TerminalView
/** /**
* @author kiva * @author kiva

View File

@ -1,10 +1,12 @@
package io.neoterm.view package io.neoterm.frontend.tinyclient
import android.content.Context import android.content.Context
import android.view.KeyEvent import android.view.KeyEvent
import android.view.MotionEvent import android.view.MotionEvent
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import io.neoterm.backend.TerminalSession import io.neoterm.backend.TerminalSession
import io.neoterm.view.TerminalView
import io.neoterm.view.TerminalViewClient
/** /**
* @author kiva * @author kiva

View File

@ -15,6 +15,7 @@ import android.support.v4.content.WakefulBroadcastReceiver
import io.neoterm.R import io.neoterm.R
import io.neoterm.backend.EmulatorDebug import io.neoterm.backend.EmulatorDebug
import io.neoterm.backend.TerminalSession import io.neoterm.backend.TerminalSession
import io.neoterm.frontend.ShellParameter
import io.neoterm.ui.term.NeoTermActivity import io.neoterm.ui.term.NeoTermActivity
import io.neoterm.utils.TerminalUtils import io.neoterm.utils.TerminalUtils
import java.util.* import java.util.*
@ -76,11 +77,8 @@ class NeoTermService : Service() {
val sessions: List<TerminalSession> val sessions: List<TerminalSession>
get() = mTerminalSessions get() = mTerminalSessions
fun createTermSession(executablePath: String?, arguments: Array<String>?, fun createTermSession(parameter: ShellParameter): TerminalSession {
cwd: String?, initialCommand: String?, val session = TerminalUtils.createShellSession(this, parameter)
env: Array<Pair<String, String>>?, sessionCallback:
TerminalSession.SessionChangedCallback?, systemShell: Boolean): TerminalSession {
val session = TerminalUtils.createShellSession(this, executablePath, arguments, cwd, initialCommand, env, sessionCallback, systemShell)
mTerminalSessions.add(session) mTerminalSessions.add(session)
updateNotification() updateNotification()
return session return session

View File

@ -16,11 +16,12 @@ import io.neoterm.backend.TerminalSession
import io.neoterm.customize.color.ColorSchemeManager import io.neoterm.customize.color.ColorSchemeManager
import io.neoterm.preference.NeoTermPath import io.neoterm.preference.NeoTermPath
import io.neoterm.customize.font.FontManager import io.neoterm.customize.font.FontManager
import io.neoterm.frontend.ShellParameter
import io.neoterm.utils.FileUtils import io.neoterm.utils.FileUtils
import io.neoterm.utils.MediaUtils import io.neoterm.utils.MediaUtils
import io.neoterm.utils.TerminalUtils import io.neoterm.utils.TerminalUtils
import io.neoterm.view.BasicSessionCallback import io.neoterm.frontend.tinyclient.BasicSessionCallback
import io.neoterm.view.BasicViewClient import io.neoterm.frontend.tinyclient.BasicViewClient
import io.neoterm.view.ExtraKeysView import io.neoterm.view.ExtraKeysView
import io.neoterm.view.TerminalView import io.neoterm.view.TerminalView
import java.io.File import java.io.File
@ -56,8 +57,14 @@ class CustomizationActivity : AppCompatActivity() {
viewClient = BasicViewClient(terminalView) viewClient = BasicViewClient(terminalView)
sessionCallback = BasicSessionCallback(terminalView) sessionCallback = BasicSessionCallback(terminalView)
TerminalUtils.setupTerminalView(terminalView, viewClient) 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) terminalView.attachSession(session)
findViewById(R.id.custom_install_font_button).setOnClickListener { findViewById(R.id.custom_install_font_button).setOnClickListener {

View File

@ -1,6 +0,0 @@
package io.neoterm.ui.floating
/**
* @author kiva
*/
class FloatingNeoTerm

View File

@ -29,11 +29,8 @@ import io.neoterm.preference.NeoPreference
import io.neoterm.preference.NeoTermPath import io.neoterm.preference.NeoTermPath
import io.neoterm.ui.pm.adapter.PackageAdapter import io.neoterm.ui.pm.adapter.PackageAdapter
import io.neoterm.ui.pm.model.PackageModel import io.neoterm.ui.pm.model.PackageModel
import io.neoterm.utils.FileUtils
import io.neoterm.utils.PackageUtils import io.neoterm.utils.PackageUtils
import io.neoterm.view.TerminalDialog import io.neoterm.frontend.floating.TerminalDialog
import java.io.File
import java.net.URL
/** /**
* @author kiva * @author kiva

View File

@ -4,12 +4,11 @@ import android.app.AlertDialog
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AppCompatPreferenceActivity import android.support.v7.app.AppCompatPreferenceActivity
import android.view.MenuItem import android.view.MenuItem
import android.widget.Toast
import io.neoterm.R import io.neoterm.R
import io.neoterm.backend.TerminalSession import io.neoterm.backend.TerminalSession
import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoPreference
import io.neoterm.preference.NeoTermPath import io.neoterm.preference.NeoTermPath
import io.neoterm.view.TerminalDialog import io.neoterm.frontend.floating.TerminalDialog
/** /**
* @author kiva * @author kiva

View File

@ -21,8 +21,7 @@ import io.neoterm.customize.setup.BaseFileInstaller
import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoPreference
import io.neoterm.preference.NeoTermPath import io.neoterm.preference.NeoTermPath
import io.neoterm.utils.PackageUtils import io.neoterm.utils.PackageUtils
import io.neoterm.utils.TerminalUtils import io.neoterm.frontend.floating.TerminalDialog
import io.neoterm.view.TerminalDialog
import java.util.* import java.util.*
@ -112,7 +111,7 @@ class SetupActivity : AppCompatActivity() {
} }
private fun executeAptUpdate() { private fun executeAptUpdate() {
TerminalUtils.executeApt(this, "update", { exitStatus, dialog -> PackageUtils.executeApt(this, "update", { exitStatus, dialog ->
if (exitStatus == 0) { if (exitStatus == 0) {
dialog.dismiss() dialog.dismiss()
aptUpdated = true aptUpdated = true
@ -124,7 +123,7 @@ class SetupActivity : AppCompatActivity() {
} }
private fun executeAptUpgrade() { private fun executeAptUpgrade() {
TerminalUtils.executeApt(this, "upgrade", { exitStatus, dialog -> PackageUtils.executeApt(this, "upgrade", { exitStatus, dialog ->
if (exitStatus == 0) { if (exitStatus == 0) {
dialog.dismiss() dialog.dismiss()
} else { } else {

View File

@ -26,6 +26,7 @@ import io.neoterm.customize.color.ColorSchemeManager
import io.neoterm.customize.eks.EksKeysManager import io.neoterm.customize.eks.EksKeysManager
import io.neoterm.customize.font.FontManager import io.neoterm.customize.font.FontManager
import io.neoterm.customize.setup.BaseFileInstaller import io.neoterm.customize.setup.BaseFileInstaller
import io.neoterm.frontend.ShellParameter
import io.neoterm.preference.NeoPermission import io.neoterm.preference.NeoPermission
import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoPreference
import io.neoterm.services.NeoTermService 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.pm.PackageManagerActivity
import io.neoterm.ui.settings.SettingActivity import io.neoterm.ui.settings.SettingActivity
import io.neoterm.ui.setup.SetupActivity 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.TermTab
import io.neoterm.ui.term.tab.TermTabDecorator 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.TabCloseEvent
import io.neoterm.ui.term.tab.event.TitleChangedEvent import io.neoterm.ui.term.tab.event.TitleChangedEvent
import io.neoterm.ui.term.tab.event.ToggleFullScreenEvent 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) { private fun addNewSession(sessionName: String?, systemShell: Boolean, animation: Animation) {
val sessionCallback = TermSessionCallback() val sessionCallback = TermSessionCallback()
val viewClient = TermViewClient(this) 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) { if (sessionName != null) {
session.mSessionName = sessionName session.mSessionName = sessionName

View File

@ -14,9 +14,10 @@ import android.widget.Toast
import io.neoterm.R import io.neoterm.R
import io.neoterm.customize.script.UserScript import io.neoterm.customize.script.UserScript
import io.neoterm.customize.script.UserScriptManager import io.neoterm.customize.script.UserScriptManager
import io.neoterm.frontend.ShellParameter
import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoPreference
import io.neoterm.services.NeoTermService import io.neoterm.services.NeoTermService
import io.neoterm.terminal.client.TermSessionCallback import io.neoterm.frontend.client.TermSessionCallback
import io.neoterm.utils.TerminalUtils import io.neoterm.utils.TerminalUtils
import java.io.File import java.io.File
@ -68,9 +69,12 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
} }
private fun openTerm(initialCommand: String?) { private fun openTerm(initialCommand: String?) {
val session = termService!!.createTermSession(null, // TODO: check whether system executablePath we should use
null, null, initialCommand, val parameter = ShellParameter()
null, TermSessionCallback(), false) .initialCommand(initialCommand)
.callback(TermSessionCallback())
.systemShell(false)
val session = termService!!.createTermSession(parameter)
// Set current session to our new one // Set current session to our new one
// In order to switch to it when entering NeoTermActivity // In order to switch to it when entering NeoTermActivity

View File

@ -7,8 +7,8 @@ import de.mrapp.android.tabswitcher.Tab
import io.neoterm.R import io.neoterm.R
import io.neoterm.customize.color.ColorSchemeManager import io.neoterm.customize.color.ColorSchemeManager
import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoPreference
import io.neoterm.terminal.client.TermDataHolder import io.neoterm.frontend.client.TermDataHolder
import io.neoterm.terminal.client.TermUiPresenter import io.neoterm.frontend.client.TermUiPresenter
import io.neoterm.ui.term.tab.event.TabCloseEvent import io.neoterm.ui.term.tab.event.TabCloseEvent
import io.neoterm.ui.term.tab.event.TitleChangedEvent import io.neoterm.ui.term.tab.event.TitleChangedEvent
import io.neoterm.ui.term.tab.event.ToggleFullScreenEvent import io.neoterm.ui.term.tab.event.ToggleFullScreenEvent

View File

@ -12,11 +12,11 @@ import io.neoterm.BuildConfig
import io.neoterm.R import io.neoterm.R
import io.neoterm.customize.color.ColorSchemeManager import io.neoterm.customize.color.ColorSchemeManager
import io.neoterm.preference.NeoPreference 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.ui.term.NeoTermActivity
import io.neoterm.utils.TerminalUtils import io.neoterm.utils.TerminalUtils
import io.neoterm.view.ExtraKeysView import io.neoterm.view.ExtraKeysView
import io.neoterm.view.OnAutoCompleteListener import io.neoterm.frontend.completion.OnAutoCompleteListener
import io.neoterm.view.TerminalView import io.neoterm.view.TerminalView
/** /**

View File

@ -1,8 +1,11 @@
package io.neoterm.utils package io.neoterm.utils
import android.content.Context
import io.neoterm.R import io.neoterm.R
import io.neoterm.backend.TerminalSession
import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoPreference
import io.neoterm.preference.NeoTermPath import io.neoterm.preference.NeoTermPath
import io.neoterm.frontend.floating.TerminalDialog
import java.io.File import java.io.File
/** /**
@ -23,4 +26,17 @@ object PackageUtils {
.append("\n") .append("\n")
.toString() .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")
}
} }

View File

@ -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()
}
}

View File

@ -4,11 +4,10 @@ import android.content.Context
import io.neoterm.R import io.neoterm.R
import io.neoterm.backend.TerminalSession import io.neoterm.backend.TerminalSession
import io.neoterm.customize.font.FontManager 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.NeoPreference
import io.neoterm.preference.NeoTermPath
import io.neoterm.terminal.ShellTermSession
import io.neoterm.view.ExtraKeysView import io.neoterm.view.ExtraKeysView
import io.neoterm.view.TerminalDialog
import io.neoterm.view.TerminalView import io.neoterm.view.TerminalView
import io.neoterm.view.TerminalViewClient import io.neoterm.view.TerminalViewClient
@ -31,20 +30,17 @@ object TerminalUtils {
fun setupTerminalSession(session: TerminalSession?) { fun setupTerminalSession(session: TerminalSession?) {
} }
fun createShellSession(context: Context, executablePath: String?, arguments: Array<String>?, fun createShellSession(context: Context, parameter: ShellParameter): TerminalSession {
cwd: String?, initialCommand: String?, env: Array<Pair<String, String>>?, val initCommand = parameter.initialCommand ?:
sessionCallback: TerminalSession.SessionChangedCallback?,
systemShell: Boolean): TerminalSession {
val initCommand = initialCommand ?:
NeoPreference.loadString(R.string.key_general_initial_command, "") NeoPreference.loadString(R.string.key_general_initial_command, "")
val session = ShellTermSession.Builder() val session = ShellTermSession.Builder()
.shell(executablePath) .executablePath(parameter.executablePath)
.currentWorkingDirectory(cwd) .currentWorkingDirectory(parameter.cwd)
.callback(sessionCallback) .callback(parameter.sessionCallback)
.systemShell(systemShell) .systemShell(parameter.systemShell)
.envArray(env) .envArray(parameter.env)
.argArray(arguments) .argArray(parameter.arguments)
.create(context) .create(context)
setupTerminalSession(session) setupTerminalSession(session)
session.initialCommand = initCommand session.initialCommand = initCommand
@ -70,17 +66,4 @@ object TerminalUtils {
builder.append('"') builder.append('"')
return builder.toString() 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")
}
} }

View File

@ -6,7 +6,6 @@ import android.graphics.Typeface
import android.util.AttributeSet import android.util.AttributeSet
import android.view.Gravity import android.view.Gravity
import android.view.HapticFeedbackConstants import android.view.HapticFeedbackConstants
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import android.widget.HorizontalScrollView import android.widget.HorizontalScrollView
@ -16,27 +15,13 @@ import android.widget.ToggleButton
import java.io.File import java.io.File
import java.util.ArrayList import java.util.ArrayList
import io.neoterm.customize.eks.EksConfig
import io.neoterm.customize.eks.EksConfigParser import io.neoterm.customize.eks.EksConfigParser
import io.neoterm.customize.font.FontManager
import io.neoterm.preference.NeoTermPath import io.neoterm.preference.NeoTermPath
import io.neoterm.utils.FileUtils import io.neoterm.utils.FileUtils
import io.neoterm.view.eks.ControlButton import io.neoterm.view.eks.ControlButton
import io.neoterm.view.eks.ExtraButton import io.neoterm.view.eks.ExtraButton
import io.neoterm.view.eks.StatedControlButton 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 * A view showing extra keys (such as Escape, Ctrl, Alt) not normally available on an Android soft
* keyboard. * keyboard.

View File

@ -35,6 +35,7 @@ import io.neoterm.backend.KeyHandler;
import io.neoterm.backend.TerminalBuffer; import io.neoterm.backend.TerminalBuffer;
import io.neoterm.backend.TerminalEmulator; import io.neoterm.backend.TerminalEmulator;
import io.neoterm.backend.TerminalSession; import io.neoterm.backend.TerminalSession;
import io.neoterm.frontend.completion.OnAutoCompleteListener;
/** /**
* View displaying and interacting with a {@link TerminalSession}. * View displaying and interacting with a {@link TerminalSession}.

View File

@ -2,8 +2,6 @@ package io.neoterm.view.eks
import android.view.View import android.view.View
import io.neoterm.view.ExtraKeysView
/** /**
* @author kiva * @author kiva
*/ */

View File

@ -2,8 +2,6 @@ package io.neoterm.view.eks
import android.view.View import android.view.View
import io.neoterm.view.ExtraKeysView
/** /**
* @author kiva * @author kiva
*/ */

View File

@ -39,7 +39,7 @@
<string name="ui_settings">界面设置</string> <string name="ui_settings">界面设置</string>
<string name="shell_not_found">Shell %s 未找到, 请先安装.</string> <string name="shell_not_found">Shell %s 未找到, 请先安装.</string>
<string name="installer_message">正在安装</string> <string name="installer_message">正在安装</string>
<string name="installer_install_zsh_required">将要安装 oh-my-zsh 并将您的登录 shell 切换到 zsh</string> <string name="installer_install_zsh_required">将要安装 oh-my-zsh 并将您的登录 executablePath 切换到 zsh</string>
<string name="fullscreen_mode_changed">全屏模式已改变,请重启 NeoTerm</string> <string name="fullscreen_mode_changed">全屏模式已改变,请重启 NeoTerm</string>
<string name="permission_denied">NeoTerm 无法取得必需的权限,正在退出</string> <string name="permission_denied">NeoTerm 无法取得必需的权限,正在退出</string>
<string name="error">还有这种操作?</string> <string name="error">还有这种操作?</string>

View File

@ -51,7 +51,7 @@
<string name="crash_stack_trace">Stack Trace</string> <string name="crash_stack_trace">Stack Trace</string>
<string name="installer_message">Installing</string> <string name="installer_message">Installing</string>
<string name="installer_install_zsh_required">We are about to install oh-my-zsh and switch your login shell to zsh</string> <string name="installer_install_zsh_required">We are about to install oh-my-zsh and switch your login executablePath to zsh</string>
<string name="pref_general_bell">Bell</string> <string name="pref_general_bell">Bell</string>
<string name="pref_general_bell_desc">Bell when receiving \'\\a\'</string> <string name="pref_general_bell_desc">Bell when receiving \'\\a\'</string>
@ -60,7 +60,7 @@
<string name="pref_general_backspace_map_to_esc">BackSpace Mapped to Esc</string> <string name="pref_general_backspace_map_to_esc">BackSpace Mapped to Esc</string>
<string name="pref_general_backspace_map_to_esc_desc">Send esc when backspace is pressed</string> <string name="pref_general_backspace_map_to_esc_desc">Send esc when backspace is pressed</string>
<string name="pref_general_shell" translatable="false">Shell</string> <string name="pref_general_shell" translatable="false">Shell</string>
<string name="pref_general_shell_desc">Which shell should we use when login</string> <string name="pref_general_shell_desc">Which executablePath should we use when login</string>
<string name="pref_general_program_selection">Program Selection</string> <string name="pref_general_program_selection">Program Selection</string>
<string name="pref_general_program_selection_desc">When both Neo Term and your Android OS have a program, which one should we choose?</string> <string name="pref_general_program_selection_desc">When both Neo Term and your Android OS have a program, which one should we choose?</string>
<string name="pref_general_initial_command">Initial Command</string> <string name="pref_general_initial_command">Initial Command</string>

4
gradlew.bat vendored
View File

@ -5,7 +5,7 @@
@rem @rem
@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 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. @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% "%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 :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 if "%ERRORLEVEL%"=="0" goto mainEnd
:fail :fail