Refactor: Project structure
This commit is contained in:
parent
668f877883
commit
438e1e4d24
@ -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 {
|
||||
|
51
app/src/main/java/io/neoterm/frontend/ShellParameter.kt
Normal file
51
app/src/main/java/io/neoterm/frontend/ShellParameter.kt
Normal 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
|
||||
}
|
||||
}
|
@ -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<String>, env: Array<String>, 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<String>? = null
|
||||
private var env: MutableList<Pair<String, String>>? = 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<String> {
|
||||
var cwd = cwd
|
||||
private fun buildEnvironment(cwd: String?, systemShell: Boolean): Array<String> {
|
||||
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")
|
@ -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.*
|
||||
|
@ -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
|
||||
|
||||
/**
|
@ -1,4 +1,4 @@
|
||||
package io.neoterm.terminal.client
|
||||
package io.neoterm.frontend.client
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
@ -1,4 +1,4 @@
|
||||
package io.neoterm.terminal.client
|
||||
package io.neoterm.frontend.client
|
||||
|
||||
/**
|
||||
* @author kiva
|
@ -1,4 +1,4 @@
|
||||
package io.neoterm.terminal.client
|
||||
package io.neoterm.frontend.client
|
||||
|
||||
import android.content.Context
|
||||
import android.media.AudioManager
|
@ -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",
|
@ -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
|
@ -1,4 +1,4 @@
|
||||
package io.neoterm.customize.completion
|
||||
package io.neoterm.frontend.completion
|
||||
|
||||
/**
|
||||
* @author kiva
|
@ -1,4 +1,4 @@
|
||||
package io.neoterm.view;
|
||||
package io.neoterm.frontend.completion;
|
||||
|
||||
/**
|
||||
* @author Kiva
|
@ -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
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package io.neoterm.frontend.floating
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
class TerminalWindowView {
|
||||
}
|
@ -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
|
@ -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
|
@ -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<TerminalSession>
|
||||
get() = mTerminalSessions
|
||||
|
||||
fun createTermSession(executablePath: String?, arguments: Array<String>?,
|
||||
cwd: String?, initialCommand: String?,
|
||||
env: Array<Pair<String, String>>?, 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
|
||||
|
@ -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 {
|
||||
|
@ -1,6 +0,0 @@
|
||||
package io.neoterm.ui.floating
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
class FloatingNeoTerm
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
/**
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
@ -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()
|
||||
}
|
||||
}
|
@ -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<String>?,
|
||||
cwd: String?, initialCommand: String?, env: Array<Pair<String, String>>?,
|
||||
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")
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
@ -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}.
|
||||
|
@ -2,8 +2,6 @@ package io.neoterm.view.eks
|
||||
|
||||
import android.view.View
|
||||
|
||||
import io.neoterm.view.ExtraKeysView
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
|
@ -2,8 +2,6 @@ package io.neoterm.view.eks
|
||||
|
||||
import android.view.View
|
||||
|
||||
import io.neoterm.view.ExtraKeysView
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
|
@ -39,7 +39,7 @@
|
||||
<string name="ui_settings">界面设置</string>
|
||||
<string name="shell_not_found">Shell %s 未找到, 请先安装.</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="permission_denied">NeoTerm 无法取得必需的权限,正在退出</string>
|
||||
<string name="error">还有这种操作?</string>
|
||||
|
@ -51,7 +51,7 @@
|
||||
<string name="crash_stack_trace">Stack Trace</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_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_desc">Send esc when backspace is pressed</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_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>
|
||||
|
4
gradlew.bat
vendored
4
gradlew.bat
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user