removing the keyboard.row style attributes

This commit is contained in:
tibbi 2022-01-21 18:52:43 +01:00
parent 4d20e0c047
commit 7457808c49
6 changed files with 8 additions and 52 deletions

View File

@ -115,10 +115,7 @@ class MyKeyboard {
* Some of the key size defaults can be overridden per row from what the [MyKeyboard]
* defines.
* @attr ref android.R.styleable#Keyboard_keyWidth
* @attr ref android.R.styleable#Keyboard_keyHeight
* @attr ref android.R.styleable#Keyboard_horizontalGap
* @attr ref android.R.styleable#Keyboard_Row_rowEdgeFlags
* @attr ref android.R.styleable#Keyboard_Row_keyboardMode
*/
class Row {
/** Default width of a key in this row. */
@ -132,12 +129,6 @@ class MyKeyboard {
var mKeys = ArrayList<Key>()
/**
* Edge flags for this row of keys. Possible values that can be assigned are
* [EDGE_TOP][MyKeyboard.EDGE_TOP] and [EDGE_BOTTOM][MyKeyboard.EDGE_BOTTOM]
*/
var rowEdgeFlags = 0
/** The keyboard mode for this row */
var mode = 0
var parent: MyKeyboard
@ -148,15 +139,11 @@ class MyKeyboard {
constructor(res: Resources, parent: MyKeyboard, parser: XmlResourceParser?) {
this.parent = parent
var a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
defaultHeight = res.getDimension(R.dimen.key_height).toInt()
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
a.recycle()
a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard_Row)
rowEdgeFlags = a.getInt(R.styleable.MyKeyboard_Row_rowEdgeFlags, 0)
mode = a.getResourceId(R.styleable.MyKeyboard_Row_keyboardMode, 0)
}
}
@ -229,7 +216,7 @@ class MyKeyboard {
* that are just out of the boundary of the key. This is a bit mask of
* [MyKeyboard.EDGE_LEFT], [MyKeyboard.EDGE_RIGHT], [MyKeyboard.EDGE_TOP] and [MyKeyboard.EDGE_BOTTOM].
*/
var edgeFlags: Int
var edgeFlags = 0
/** Whether this is a modifier key, such as Shift or Alt */
var modifier = false
@ -280,7 +267,6 @@ class MyKeyboard {
modifier = a.getBoolean(R.styleable.MyKeyboard_Key_isModifier, false)
sticky = a.getBoolean(R.styleable.MyKeyboard_Key_isSticky, false)
edgeFlags = a.getInt(R.styleable.MyKeyboard_Key_keyEdgeFlags, 0)
edgeFlags = edgeFlags or parent.rowEdgeFlags
icon = a.getDrawable(R.styleable.MyKeyboard_Key_keyIcon)
icon?.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight)
@ -299,7 +285,6 @@ class MyKeyboard {
height = parent.defaultHeight
width = parent.defaultWidth
gap = parent.defaultHorizontalGap
edgeFlags = parent.rowEdgeFlags
}
fun onPressed() {
@ -413,7 +398,6 @@ class MyKeyboard {
row.defaultHeight = mDefaultHeight
row.defaultWidth = mDefaultWidth
row.defaultHorizontalGap = mDefaultHorizontalGap
row.rowEdgeFlags = EDGE_TOP or EDGE_BOTTOM
characters.forEachIndexed { index, character ->
val key = Key(row)
@ -534,6 +518,7 @@ class MyKeyboard {
return mGridNeighbors!![index]!!
}
}
return IntArray(0)
}
@ -564,11 +549,6 @@ class MyKeyboard {
x = 0
currentRow = createRowFromXml(res, parser)
rows.add(currentRow)
val skipRow = currentRow.mode != 0 && currentRow.mode != mKeyboardMode
if (skipRow) {
skipToEndOfRow(parser)
inRow = false
}
} else if (TAG_KEY == tag) {
inKey = true
key = createKeyFromXml(res, currentRow!!, x, y, parser)
@ -613,15 +593,6 @@ class MyKeyboard {
height = y
}
private fun skipToEndOfRow(parser: XmlResourceParser) {
var event: Int
while (parser.next().also { event = it } != XmlResourceParser.END_DOCUMENT) {
if (event == XmlResourceParser.END_TAG && parser.name == TAG_ROW) {
break
}
}
}
private fun parseKeyboardAttributes(res: Resources, parser: XmlResourceParser) {
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
mDefaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, mDisplayWidth, mDisplayWidth / 10)

View File

@ -195,10 +195,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val attributes = context.obtainStyledAttributes(attrs, R.styleable.MyKeyboardView, 0, defStyleRes)
val inflate = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val keyTextSize = 0
val n = attributes.indexCount
val indexCnt = attributes.indexCount
try {
for (i in 0 until n) {
for (i in 0 until indexCnt) {
val attr = attributes.getIndex(i)
when (attr) {
R.styleable.MyKeyboardView_keyTextSize -> mKeyTextSize = attributes.getDimensionPixelSize(attr, 18)

View File

@ -5,29 +5,14 @@
</declare-styleable>
<declare-styleable name="MyKeyboardView">
<!-- Size of the text for character keys. -->
<attr name="keyTextSize" format="dimension" />
</declare-styleable>
<declare-styleable name="MyKeyboard">
<!-- Default width of a key in percentage of display width. -->
<attr name="keyWidth" format="fraction" />
<!-- Default horizontal gap between keys. -->
<attr name="horizontalGap" format="fraction" />
</declare-styleable>
<declare-styleable name="MyKeyboard_Row">
<!-- Row edge flags. -->
<attr name="rowEdgeFlags">
<!-- Row is anchored to the top of the keyboard. -->
<flag name="top" value="4" />
<!-- Row is anchored to the bottom of the keyboard. -->
<flag name="bottom" value="8" />
</attr>
<!-- Mode of the keyboard. If the mode doesn't match the requested keyboard mode, the row will be skipped. -->
<attr name="keyboardMode" format="reference" />
</declare-styleable>
<declare-styleable name="MyKeyboard_Key">
<!-- The unicode value or comma-separated values that this key outputs. -->
<attr name="codes" format="integer|string" />

View File

@ -144,7 +144,7 @@
app:keyIcon="@drawable/ic_clear_vector"
app:keyWidth="15%p" />
</Row>
<Row app:rowEdgeFlags="bottom">
<Row>
<Key
app:codes="-2"
app:keyEdgeFlags="left"

View File

@ -102,7 +102,7 @@
app:keyIcon="@drawable/ic_clear_vector"
app:keyWidth="15%p" />
</Row>
<Row app:rowEdgeFlags="bottom">
<Row>
<Key
app:codes="-2"
app:keyEdgeFlags="left"

View File

@ -102,7 +102,7 @@
app:keyIcon="@drawable/ic_clear_vector"
app:keyWidth="15%p" />
</Row>
<Row app:rowEdgeFlags="bottom">
<Row>
<Key
app:codes="-2"
app:keyEdgeFlags="left"