Refactor: ExtraKeysView now use CombinedSequence

This commit is contained in:
zt515 2017-08-26 00:07:26 +08:00
parent 5f8f165a5b
commit 4f6696ead6
7 changed files with 27 additions and 17 deletions

View File

@ -49,8 +49,8 @@ class OldExtraKeysConfigureFile(configureFile: File) : NeoConfigureFile(configur
visitor.onEnterContext(index.toString()) visitor.onEnterContext(index.toString())
visitor.getCurrentContext() visitor.getCurrentContext()
.defineAttribute(NeoExtraKey.EKS_META_WITH_ENTER, NeoLangValue(button.withEnter)) .defineAttribute(NeoExtraKey.EKS_META_WITH_ENTER, NeoLangValue(button.withEnter))
.defineAttribute(NeoExtraKey.EKS_META_DISPLAY, NeoLangValue(button.buttonText!!)) .defineAttribute(NeoExtraKey.EKS_META_DISPLAY, NeoLangValue(button.buttonKeys!!))
.defineAttribute(NeoExtraKey.EKS_META_CODE, NeoLangValue(button.buttonText!!)) .defineAttribute(NeoExtraKey.EKS_META_CODE, NeoLangValue(button.buttonKeys!!))
visitor.onExitContext() visitor.onExitContext()
} }
} }

View File

@ -4,4 +4,4 @@ package io.neoterm.frontend.terminal.eks.button
* @author kiva * @author kiva
*/ */
open class ControlButton(text: String) : TextButton(text, false) open class ControlButton(text: String) : TextButton(text, false)

View File

@ -8,6 +8,7 @@ import android.widget.Button
import io.neoterm.R import io.neoterm.R
import io.neoterm.frontend.terminal.TerminalView import io.neoterm.frontend.terminal.TerminalView
import io.neoterm.frontend.terminal.eks.combine.CombinedSequence
/** /**
* @author kiva * @author kiva
@ -15,11 +16,11 @@ import io.neoterm.frontend.terminal.TerminalView
abstract class IExtraButton : View.OnClickListener { abstract class IExtraButton : View.OnClickListener {
var buttonText: String? = null var buttonKeys: CombinedSequence? = null
var displayText: String? = null var displayText: String? = null
override fun toString(): String { override fun toString(): String {
return "${this.javaClass.simpleName} { display: $displayText, code: $buttonText }" return "${this.javaClass.simpleName} { display: $displayText, code: ${buttonKeys?.keys} }"
} }
abstract override fun onClick(view: View) abstract override fun onClick(view: View)
@ -35,12 +36,17 @@ abstract class IExtraButton : View.OnClickListener {
val KEY_PAGE_DOWN = "PgDn" val KEY_PAGE_DOWN = "PgDn"
val KEY_HOME = "Home" val KEY_HOME = "Home"
val KEY_END = "End" val KEY_END = "End"
val KEY_ARROW_UP_TEXT = "Up"
val KEY_ARROW_DOWN_TEXT = "Down"
val KEY_ARROW_LEFT_TEXT = "Left"
val KEY_ARROW_RIGHT_TEXT = "Right"
val KEY_SHOW_ALL_BUTTONS = "···"
val KEY_TOGGLE_IME = "Im"
val KEY_ARROW_UP = "" val KEY_ARROW_UP = ""
val KEY_ARROW_DOWN = "" val KEY_ARROW_DOWN = ""
val KEY_ARROW_LEFT = "" val KEY_ARROW_LEFT = ""
val KEY_ARROW_RIGHT = "" val KEY_ARROW_RIGHT = ""
val KEY_SHOW_ALL_BUTTONS = "···"
val KEY_TOGGLE_IME = "Im"
var NORMAL_TEXT_COLOR = 0xFFFFFFFF.toInt() var NORMAL_TEXT_COLOR = 0xFFFFFFFF.toInt()
var SELECTED_TEXT_COLOR = 0xFF80DEEA.toInt() var SELECTED_TEXT_COLOR = 0xFF80DEEA.toInt()
@ -55,6 +61,10 @@ abstract class IExtraButton : View.OnClickListener {
KEY_ARROW_LEFT -> keyCode = KeyEvent.KEYCODE_DPAD_LEFT KEY_ARROW_LEFT -> keyCode = KeyEvent.KEYCODE_DPAD_LEFT
KEY_ARROW_RIGHT -> keyCode = KeyEvent.KEYCODE_DPAD_RIGHT KEY_ARROW_RIGHT -> keyCode = KeyEvent.KEYCODE_DPAD_RIGHT
KEY_ARROW_DOWN -> keyCode = KeyEvent.KEYCODE_DPAD_DOWN KEY_ARROW_DOWN -> keyCode = KeyEvent.KEYCODE_DPAD_DOWN
KEY_ARROW_UP_TEXT -> keyCode = KeyEvent.KEYCODE_DPAD_UP
KEY_ARROW_LEFT_TEXT -> keyCode = KeyEvent.KEYCODE_DPAD_LEFT
KEY_ARROW_RIGHT_TEXT -> keyCode = KeyEvent.KEYCODE_DPAD_RIGHT
KEY_ARROW_DOWN_TEXT -> keyCode = KeyEvent.KEYCODE_DPAD_DOWN
KEY_PAGE_UP -> keyCode = KeyEvent.KEYCODE_PAGE_UP KEY_PAGE_UP -> keyCode = KeyEvent.KEYCODE_PAGE_UP
KEY_PAGE_DOWN -> keyCode = KeyEvent.KEYCODE_PAGE_DOWN KEY_PAGE_DOWN -> keyCode = KeyEvent.KEYCODE_PAGE_DOWN
KEY_HOME -> keyCode = KeyEvent.KEYCODE_MOVE_HOME KEY_HOME -> keyCode = KeyEvent.KEYCODE_MOVE_HOME

View File

@ -30,7 +30,7 @@ open class StatedControlButton @JvmOverloads constructor(text: String, var initS
return outerButton return outerButton
} }
fun setStatus(status: Boolean?) { private fun setStatus(status: Boolean?) {
val button = toggleButton val button = toggleButton
if (button != null && status != null) { if (button != null && status != null) {
button.isChecked = status button.isChecked = status

View File

@ -4,22 +4,22 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.widget.Button import android.widget.Button
import io.neoterm.frontend.terminal.eks.combine.CombinedSequence
/** /**
* @author kiva * @author kiva
*/ */
open class TextButton @JvmOverloads constructor(text: String, withEnter: Boolean = false) : IExtraButton() { open class TextButton constructor(text: String, val withEnter: Boolean = false) : IExtraButton() {
var withEnter = false
init { init {
this.buttonText = text this.buttonKeys = CombinedSequence.solveString(text)
this.displayText = text this.displayText = text
this.withEnter = withEnter
} }
override fun onClick(view: View) { override fun onClick(view: View) {
sendKey(view, buttonText!!) buttonKeys!!.keys.forEach {
sendKey(view, it)
}
if (withEnter) { if (withEnter) {
sendKey(view, "\n") sendKey(view, "\n")
} }

View File

@ -1,4 +1,4 @@
package io.neoterm.component.eks.combine package io.neoterm.frontend.terminal.eks.combine
/** /**
* <Ctrl> <Alt> <Delete> * <Ctrl> <Alt> <Delete>
@ -16,7 +16,7 @@ class CombinedSequence private constructor() {
keyString.split(' ').forEach { keyString.split(' ').forEach {
val key = if (it.startsWith('<') && it.endsWith('>')) { val key = if (it.startsWith('<') && it.endsWith('>')) {
// is a sequence // is a sequence
it.substring(1, it.length - 1).toUpperCase() it.substring(1, it.length - 1)
} else { } else {
// is a normal string // is a normal string
it it

View File

@ -1,6 +1,6 @@
package io.neoterm package io.neoterm
import io.neoterm.component.eks.combine.CombinedSequence import io.neoterm.frontend.terminal.eks.combine.CombinedSequence
import org.junit.Test import org.junit.Test
/** /**