mirror of
https://github.com/SimpleMobileTools/Simple-Keyboard.git
synced 2025-06-05 21:49:26 +02:00
removing some redundant code
This commit is contained in:
@ -39,16 +39,16 @@ import java.util.*
|
|||||||
*/
|
*/
|
||||||
class MyKeyboard {
|
class MyKeyboard {
|
||||||
/** Horizontal gap default for all rows */
|
/** Horizontal gap default for all rows */
|
||||||
protected var mDefaultHorizontalGap = 0
|
private var mDefaultHorizontalGap = 0
|
||||||
|
|
||||||
/** Default key width */
|
/** Default key width */
|
||||||
protected var mDefaultWidth = 0
|
private var mDefaultWidth = 0
|
||||||
|
|
||||||
/** Default key height */
|
/** Default key height */
|
||||||
protected var mDefaultHeight = 0
|
private var mDefaultHeight = 0
|
||||||
|
|
||||||
/** Default gap between rows */
|
/** Default gap between rows */
|
||||||
protected var mDefaultVerticalGap = 0
|
private var mDefaultVerticalGap = 0
|
||||||
|
|
||||||
/** Is the keyboard in the shifted state */
|
/** Is the keyboard in the shifted state */
|
||||||
var shiftState = SHIFT_OFF
|
var shiftState = SHIFT_OFF
|
||||||
@ -56,9 +56,6 @@ class MyKeyboard {
|
|||||||
/** Key instance for the shift key, if present */
|
/** Key instance for the shift key, if present */
|
||||||
private val mShiftKeys = arrayOf<Key?>(null, null)
|
private val mShiftKeys = arrayOf<Key?>(null, null)
|
||||||
|
|
||||||
/** Key index for the shift key, if present */
|
|
||||||
private val shiftKeyIndices = intArrayOf(-1, -1)
|
|
||||||
|
|
||||||
/** Total height of the keyboard, including the padding and keys */
|
/** Total height of the keyboard, including the padding and keys */
|
||||||
var height = 0
|
var height = 0
|
||||||
|
|
||||||
@ -68,9 +65,6 @@ class MyKeyboard {
|
|||||||
/** List of keys in this keyboard */
|
/** List of keys in this keyboard */
|
||||||
var mKeys: MutableList<Key?>? = null
|
var mKeys: MutableList<Key?>? = null
|
||||||
|
|
||||||
/** List of modifier keys such as Shift & Alt, if any */
|
|
||||||
private var mModifierKeys = ArrayList<Key?>()
|
|
||||||
|
|
||||||
/** Width of the screen available to fit the keyboard */
|
/** Width of the screen available to fit the keyboard */
|
||||||
private var mDisplayWidth = 0
|
private var mDisplayWidth = 0
|
||||||
|
|
||||||
@ -165,7 +159,7 @@ class MyKeyboard {
|
|||||||
this.parent = parent
|
this.parent = parent
|
||||||
var a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
var a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
||||||
defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
|
defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
|
||||||
defaultHeight = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyHeight, parent.mDisplayHeight, parent.mDefaultHeight)
|
defaultHeight = res.getDimension(R.dimen.key_height).toInt()
|
||||||
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
|
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
|
||||||
verticalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_verticalGap, parent.mDisplayHeight, parent.mDefaultVerticalGap)
|
verticalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_verticalGap, parent.mDisplayHeight, parent.mDefaultVerticalGap)
|
||||||
|
|
||||||
@ -272,7 +266,7 @@ class MyKeyboard {
|
|||||||
this.y = y
|
this.y = y
|
||||||
var a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
var a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
||||||
width = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, keyboard.mDisplayWidth, parent.defaultWidth)
|
width = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, keyboard.mDisplayWidth, parent.defaultWidth)
|
||||||
height = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyHeight, keyboard.mDisplayHeight, parent.defaultHeight)
|
height = parent.defaultHeight
|
||||||
gap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, keyboard.mDisplayWidth, parent.defaultHorizontalGap)
|
gap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, keyboard.mDisplayWidth, parent.defaultHorizontalGap)
|
||||||
|
|
||||||
a.recycle()
|
a.recycle()
|
||||||
@ -555,11 +549,11 @@ class MyKeyboard {
|
|||||||
return IntArray(0)
|
return IntArray(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun createRowFromXml(res: Resources, parser: XmlResourceParser?): Row {
|
private fun createRowFromXml(res: Resources, parser: XmlResourceParser?): Row {
|
||||||
return Row(res, this, parser)
|
return Row(res, this, parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun createKeyFromXml(res: Resources, parent: Row, x: Int, y: Int, parser: XmlResourceParser?): Key {
|
private fun createKeyFromXml(res: Resources, parent: Row, x: Int, y: Int, parser: XmlResourceParser?): Key {
|
||||||
return Key(res, parent, x, y, parser)
|
return Key(res, parent, x, y, parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,11 +590,9 @@ class MyKeyboard {
|
|||||||
for (i in mShiftKeys.indices) {
|
for (i in mShiftKeys.indices) {
|
||||||
if (mShiftKeys[i] == null) {
|
if (mShiftKeys[i] == null) {
|
||||||
mShiftKeys[i] = key
|
mShiftKeys[i] = key
|
||||||
shiftKeyIndices[i] = mKeys!!.size - 1
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mModifierKeys.add(key)
|
|
||||||
} else if (key.codes[0] == KEYCODE_ENTER) {
|
} else if (key.codes[0] == KEYCODE_ENTER) {
|
||||||
val enterResourceId = when (mEnterKeyType) {
|
val enterResourceId = when (mEnterKeyType) {
|
||||||
EditorInfo.IME_ACTION_SEARCH -> R.drawable.ic_search_vector
|
EditorInfo.IME_ACTION_SEARCH -> R.drawable.ic_search_vector
|
||||||
@ -646,7 +638,7 @@ class MyKeyboard {
|
|||||||
private fun parseKeyboardAttributes(res: Resources, parser: XmlResourceParser) {
|
private fun parseKeyboardAttributes(res: Resources, parser: XmlResourceParser) {
|
||||||
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
||||||
mDefaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, mDisplayWidth, mDisplayWidth / 10)
|
mDefaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, mDisplayWidth, mDisplayWidth / 10)
|
||||||
mDefaultHeight = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyHeight, mDisplayHeight, 50)
|
mDefaultHeight = res.getDimension(R.dimen.key_height).toInt()
|
||||||
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, mDisplayWidth, 0)
|
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, mDisplayWidth, 0)
|
||||||
mDefaultVerticalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_verticalGap, mDisplayHeight, 0)
|
mDefaultVerticalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_verticalGap, mDisplayHeight, 0)
|
||||||
mProximityThreshold = (mDefaultWidth * SEARCH_DISTANCE).toInt()
|
mProximityThreshold = (mDefaultWidth * SEARCH_DISTANCE).toInt()
|
||||||
|
@ -37,8 +37,6 @@
|
|||||||
<declare-styleable name="MyKeyboard">
|
<declare-styleable name="MyKeyboard">
|
||||||
<!-- Default width of a key, in pixels or percentage of display width. -->
|
<!-- Default width of a key, in pixels or percentage of display width. -->
|
||||||
<attr name="keyWidth" format="dimension|fraction" />
|
<attr name="keyWidth" format="dimension|fraction" />
|
||||||
<!-- Default height of a key, in pixels or percentage of display width. -->
|
|
||||||
<attr name="keyHeight" format="dimension|fraction" />
|
|
||||||
<!-- Default horizontal gap between keys. -->
|
<!-- Default horizontal gap between keys. -->
|
||||||
<attr name="horizontalGap" format="dimension|fraction" />
|
<attr name="horizontalGap" format="dimension|fraction" />
|
||||||
<!-- Default vertical gap between rows of keys. -->
|
<!-- Default vertical gap between rows of keys. -->
|
||||||
|
@ -2,5 +2,7 @@
|
|||||||
<dimen name="popup_max_move_distance">60dp</dimen>
|
<dimen name="popup_max_move_distance">60dp</dimen>
|
||||||
<dimen name="top_small_number_margin_width">12dp</dimen>
|
<dimen name="top_small_number_margin_width">12dp</dimen>
|
||||||
<dimen name="top_small_number_margin_height">18dp</dimen>
|
<dimen name="top_small_number_margin_height">18dp</dimen>
|
||||||
|
<dimen name="key_height">60dp</dimen>
|
||||||
|
|
||||||
<dimen name="preview_text_size">26sp</dimen>
|
<dimen name="preview_text_size">26sp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto"
|
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
app:horizontalGap="0px"
|
app:horizontalGap="0px"
|
||||||
app:keyHeight="60dp"
|
|
||||||
app:keyWidth="10%p"
|
|
||||||
app:verticalGap="0px" />
|
app:verticalGap="0px" />
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto"
|
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
app:keyBackground="@color/color_primary_dark"
|
app:keyBackground="@color/color_primary_dark"
|
||||||
app:keyHeight="60dp"
|
|
||||||
app:keyTextColor="@color/color_accent">
|
app:keyTextColor="@color/color_accent">
|
||||||
<Row>
|
<Row>
|
||||||
<Key
|
<Key
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto"
|
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
app:keyBackground="@color/color_primary_dark"
|
app:keyBackground="@color/color_primary_dark"
|
||||||
app:keyHeight="60dp"
|
|
||||||
app:keyTextColor="@color/color_accent">
|
app:keyTextColor="@color/color_accent">
|
||||||
<Row>
|
<Row>
|
||||||
<Key
|
<Key
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto"
|
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
app:keyBackground="@color/color_primary_dark"
|
app:keyBackground="@color/color_primary_dark"
|
||||||
app:keyHeight="60dp"
|
|
||||||
app:keyTextColor="@color/color_accent">
|
app:keyTextColor="@color/color_accent">
|
||||||
<Row>
|
<Row>
|
||||||
<Key
|
<Key
|
||||||
|
Reference in New Issue
Block a user