Feature: Customize EKS

This commit is contained in:
zt515
2017-06-15 12:09:53 +08:00
parent 93d4a29d47
commit 2ee0d17fdf
16 changed files with 191 additions and 113 deletions

View File

@ -0,0 +1,12 @@
package io.neoterm.customize
/**
* @author kiva
*/
object NeoTermPath {
const val ROOT_PATH = "/data/data/io.neoterm/files"
const val USR_PATH = "$ROOT_PATH/usr"
const val HOME_PATH = "$ROOT_PATH/home"
const val EKS_PATH = "$USR_PATH/share/eks"
}

View File

@ -0,0 +1,12 @@
package io.neoterm.customize.shortcut
import io.neoterm.view.ExtraKeysView
/**
* @author kiva
*/
class ShortcutConfig {
var version: Int = -1
val programNames: MutableList<String> = mutableListOf()
val shortcutKeys: MutableList<ExtraKeysView.ExtraButton> = mutableListOf()
}

View File

@ -0,0 +1,97 @@
package io.neoterm.customize.shortcut
import io.neoterm.view.ExtraKeysView
import java.io.*
/**
* @author kiva
*/
class ShortcutConfigParser {
companion object {
const val PARSER_VERSION = 1
}
private lateinit var source: BufferedReader
fun setInput(file: File) {
source = BufferedReader(FileReader(file))
}
fun setInput(bufferedReader: BufferedReader) {
source = bufferedReader
}
fun setInput(inputStream: BufferedInputStream) {
source = BufferedReader(InputStreamReader(inputStream))
}
fun parse(): ShortcutConfig {
val config = ShortcutConfig()
var line: String? = source.readLine()
while (line != null) {
line = line.trim().trimEnd()
if (line.isEmpty() || line.startsWith("#")) {
line = source.readLine()
continue
}
if (line.startsWith("version")) {
parseHeader(line, config)
} else if (line.startsWith("program")) {
parseProgram(line, config)
} else if (line.startsWith("define")) {
parseKeyDefine(line, config)
}
line = source.readLine()
}
if (config.version < 0) {
throw RuntimeException("Not a valid shortcut config file")
}
if (config.programNames.size == 0) {
throw RuntimeException("At least one program name should be given")
}
return config
}
private fun parseKeyDefine(line: String, config: ShortcutConfig) {
val keyDefine = line.substring("define".length).trim().trimEnd()
val keyValues = keyDefine.split(" ")
if (keyValues.size < 2) {
throw RuntimeException("Bad define")
}
val buttonText = keyValues[0]
val withEnter = keyValues[1] == "true"
config.shortcutKeys.add(ExtraKeysView.TextButton(buttonText, withEnter))
}
private fun parseProgram(line: String, config: ShortcutConfig) {
val programNames = line.substring("program".length).trim().trimEnd()
if (programNames.isEmpty()) {
return
}
for (name in programNames.split(" ")) {
config.programNames.add(name)
}
}
private fun parseHeader(line: String, config: ShortcutConfig) {
val version: Int
val versionString = line.substring("version".length).trim().trimEnd()
try {
version = Integer.parseInt(versionString)
} catch (e: NumberFormatException) {
throw RuntimeException("Bad version '$versionString'")
}
if (version > ShortcutConfigParser.PARSER_VERSION) {
throw RuntimeException("Required version: $version, please upgrade your app")
}
config.version = version
}
}

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import io.neoterm.backend.TerminalSession
import io.neoterm.customize.NeoTermPath
import io.neoterm.services.NeoTermService
import java.io.File
@ -13,10 +14,6 @@ import java.io.File
*/
object NeoTermPreference {
const val ROOT_PATH = "/data/data/io.neoterm/files"
const val USR_PATH = ROOT_PATH + "/usr"
const val HOME_PATH = ROOT_PATH + "/home"
const val KEY_FONT_SIZE = "neoterm_general_font_size"
const val KEY_CURRENT_SESSION = "neoterm_service_current_session"
@ -89,12 +86,12 @@ object NeoTermPreference {
fun buildEnvironment(cwd: String?, systemShell: Boolean): Array<String> {
var cwd = cwd
File(HOME_PATH).mkdirs()
File(NeoTermPath.HOME_PATH).mkdirs()
if (cwd == null) cwd = HOME_PATH
if (cwd == null) cwd = NeoTermPath.HOME_PATH
val termEnv = "TERM=xterm-256color"
val homeEnv = "HOME=" + HOME_PATH
val homeEnv = "HOME=" + NeoTermPath.HOME_PATH
val androidRootEnv = "ANDROID_ROOT=" + System.getenv("ANDROID_ROOT")
val androidDataEnv = "ANDROID_DATA=" + System.getenv("ANDROID_DATA")
val externalStorageEnv = "EXTERNAL_STORAGE=" + System.getenv("EXTERNAL_STORAGE")
@ -105,11 +102,11 @@ object NeoTermPreference {
} else {
val ps1Env = "PS1=$ "
val ldEnv = "LD_LIBRARY_PATH=$USR_PATH/lib"
val ldEnv = "LD_LIBRARY_PATH=${NeoTermPath.USR_PATH}/lib"
val langEnv = "LANG=en_US.UTF-8"
val pathEnv = "PATH=$USR_PATH/bin:$USR_PATH/bin/applets"
val pathEnv = "PATH=${NeoTermPath.USR_PATH}/bin:${NeoTermPath.USR_PATH}/bin/applets"
val pwdEnv = "PWD=" + cwd
val tmpdirEnv = "TMPDIR=$USR_PATH/tmp"
val tmpdirEnv = "TMPDIR=${NeoTermPath.USR_PATH}/tmp"
return arrayOf(termEnv, homeEnv, ps1Env, ldEnv, langEnv, pathEnv, pwdEnv, androidRootEnv, androidDataEnv, externalStorageEnv, tmpdirEnv)
}

View File

@ -1,25 +0,0 @@
package io.neoterm.ui
import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.design.widget.Snackbar
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import io.neoterm.R
class AboutActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
val toolbar = findViewById(R.id.about_toolbar) as Toolbar
setSupportActionBar(toolbar)
val fab = findViewById(R.id.about_fab) as FloatingActionButton
fab.setOnClickListener({ view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
})
}
}

View File

@ -1,6 +1,7 @@
package io.neoterm.ui.settings
import android.os.Bundle
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatPreferenceActivity
import android.view.MenuItem
import io.neoterm.R
@ -15,6 +16,14 @@ class SettingActivity : AppCompatPreferenceActivity() {
supportActionBar.title = getString(R.string.settings)
supportActionBar.setDisplayHomeAsUpEnabled(true)
addPreferencesFromResource(R.xml.settings_main)
findPreference(getString(R.string.about)).setOnPreferenceClickListener {
AlertDialog.Builder(this@SettingActivity)
.setTitle(R.string.about)
.setMessage("Hello World!")
.setPositiveButton(android.R.string.yes, null)
.show()
return@setOnPreferenceClickListener true
}
}
override fun onBuildHeaders(target: MutableList<Header>?) {