rename our attributes from Keyboard to MyKeyboard
This commit is contained in:
parent
6281d4e205
commit
d82a72b32d
|
@ -20,7 +20,6 @@ import android.content.res.Resources
|
||||||
import android.content.res.TypedArray
|
import android.content.res.TypedArray
|
||||||
import android.content.res.XmlResourceParser
|
import android.content.res.XmlResourceParser
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.text.TextUtils
|
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.util.Xml
|
import android.util.Xml
|
||||||
import androidx.annotation.XmlRes
|
import androidx.annotation.XmlRes
|
||||||
|
@ -177,16 +176,16 @@ class MyKeyboard {
|
||||||
|
|
||||||
constructor(res: Resources, parent: MyKeyboard, parser: XmlResourceParser?) {
|
constructor(res: Resources, parent: MyKeyboard, parser: XmlResourceParser?) {
|
||||||
this.parent = parent
|
this.parent = parent
|
||||||
var a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.Keyboard)
|
var a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
||||||
defaultWidth = getDimensionOrFraction(a, R.styleable.Keyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
|
defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
|
||||||
defaultHeight = getDimensionOrFraction(a, R.styleable.Keyboard_keyHeight, parent.mDisplayHeight, parent.mDefaultHeight)
|
defaultHeight = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyHeight, parent.mDisplayHeight, parent.mDefaultHeight)
|
||||||
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.Keyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
|
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
|
||||||
verticalGap = getDimensionOrFraction(a, R.styleable.Keyboard_verticalGap, parent.mDisplayHeight, parent.mDefaultVerticalGap)
|
verticalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_verticalGap, parent.mDisplayHeight, parent.mDefaultVerticalGap)
|
||||||
|
|
||||||
a.recycle()
|
a.recycle()
|
||||||
a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.Keyboard_Row)
|
a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard_Row)
|
||||||
rowEdgeFlags = a.getInt(R.styleable.Keyboard_Row_rowEdgeFlags, 0)
|
rowEdgeFlags = a.getInt(R.styleable.MyKeyboard_Row_rowEdgeFlags, 0)
|
||||||
mode = a.getResourceId(R.styleable.Keyboard_Row_keyboardMode, 0)
|
mode = a.getResourceId(R.styleable.MyKeyboard_Row_keyboardMode, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,40 +290,40 @@ class MyKeyboard {
|
||||||
constructor(res: Resources, parent: Row, x: Int, y: Int, parser: XmlResourceParser?) : this(parent) {
|
constructor(res: Resources, parent: Row, x: Int, y: Int, parser: XmlResourceParser?) : this(parent) {
|
||||||
this.x = x
|
this.x = x
|
||||||
this.y = y
|
this.y = y
|
||||||
var a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.Keyboard)
|
var a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
||||||
width = getDimensionOrFraction(a, R.styleable.Keyboard_keyWidth, keyboard.mDisplayWidth, parent.defaultWidth)
|
width = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, keyboard.mDisplayWidth, parent.defaultWidth)
|
||||||
height = getDimensionOrFraction(a, R.styleable.Keyboard_keyHeight, keyboard.mDisplayHeight, parent.defaultHeight)
|
height = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyHeight, keyboard.mDisplayHeight, parent.defaultHeight)
|
||||||
gap = getDimensionOrFraction(a, R.styleable.Keyboard_horizontalGap, keyboard.mDisplayWidth, parent.defaultHorizontalGap)
|
gap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, keyboard.mDisplayWidth, parent.defaultHorizontalGap)
|
||||||
|
|
||||||
a.recycle()
|
a.recycle()
|
||||||
a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.Keyboard_Key)
|
a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard_Key)
|
||||||
this.x += gap
|
this.x += gap
|
||||||
val codesValue = TypedValue()
|
val codesValue = TypedValue()
|
||||||
|
|
||||||
a.getValue(R.styleable.Keyboard_Key_codes, codesValue)
|
a.getValue(R.styleable.MyKeyboard_Key_codes, codesValue)
|
||||||
if (codesValue.type == TypedValue.TYPE_INT_DEC || codesValue.type == TypedValue.TYPE_INT_HEX) {
|
if (codesValue.type == TypedValue.TYPE_INT_DEC || codesValue.type == TypedValue.TYPE_INT_HEX) {
|
||||||
codes = arrayListOf(codesValue.data)
|
codes = arrayListOf(codesValue.data)
|
||||||
} else if (codesValue.type == TypedValue.TYPE_STRING) {
|
} else if (codesValue.type == TypedValue.TYPE_STRING) {
|
||||||
codes = parseCSV(codesValue.string.toString())
|
codes = parseCSV(codesValue.string.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
iconPreview = a.getDrawable(R.styleable.Keyboard_Key_iconPreview)
|
iconPreview = a.getDrawable(R.styleable.MyKeyboard_Key_iconPreview)
|
||||||
iconPreview?.setBounds(0, 0, iconPreview!!.intrinsicWidth, iconPreview!!.intrinsicHeight)
|
iconPreview?.setBounds(0, 0, iconPreview!!.intrinsicWidth, iconPreview!!.intrinsicHeight)
|
||||||
|
|
||||||
popupCharacters = a.getText(R.styleable.Keyboard_Key_popupCharacters)
|
popupCharacters = a.getText(R.styleable.MyKeyboard_Key_popupCharacters)
|
||||||
popupResId = a.getResourceId(R.styleable.Keyboard_Key_popupKeyboard, 0)
|
popupResId = a.getResourceId(R.styleable.MyKeyboard_Key_popupKeyboard, 0)
|
||||||
repeatable = a.getBoolean(R.styleable.Keyboard_Key_isRepeatable, false)
|
repeatable = a.getBoolean(R.styleable.MyKeyboard_Key_isRepeatable, false)
|
||||||
modifier = a.getBoolean(R.styleable.Keyboard_Key_isModifier, false)
|
modifier = a.getBoolean(R.styleable.MyKeyboard_Key_isModifier, false)
|
||||||
sticky = a.getBoolean(R.styleable.Keyboard_Key_isSticky, false)
|
sticky = a.getBoolean(R.styleable.MyKeyboard_Key_isSticky, false)
|
||||||
edgeFlags = a.getInt(R.styleable.Keyboard_Key_keyEdgeFlags, 0)
|
edgeFlags = a.getInt(R.styleable.MyKeyboard_Key_keyEdgeFlags, 0)
|
||||||
edgeFlags = edgeFlags or parent.rowEdgeFlags
|
edgeFlags = edgeFlags or parent.rowEdgeFlags
|
||||||
icon = a.getDrawable(R.styleable.Keyboard_Key_keyIcon)
|
icon = a.getDrawable(R.styleable.MyKeyboard_Key_keyIcon)
|
||||||
icon?.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight)
|
icon?.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight)
|
||||||
|
|
||||||
label = a.getText(R.styleable.Keyboard_Key_keyLabel) ?: ""
|
label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: ""
|
||||||
text = a.getText(R.styleable.Keyboard_Key_keyOutputText)
|
text = a.getText(R.styleable.MyKeyboard_Key_keyOutputText)
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(label)) {
|
if (label.isNotEmpty()) {
|
||||||
codes = arrayListOf(label[0].toInt())
|
codes = arrayListOf(label[0].toInt())
|
||||||
}
|
}
|
||||||
a.recycle()
|
a.recycle()
|
||||||
|
@ -707,11 +706,11 @@ 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.Keyboard)
|
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
||||||
mDefaultWidth = getDimensionOrFraction(a, R.styleable.Keyboard_keyWidth, mDisplayWidth, mDisplayWidth / 10)
|
mDefaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, mDisplayWidth, mDisplayWidth / 10)
|
||||||
mDefaultHeight = getDimensionOrFraction(a, R.styleable.Keyboard_keyHeight, mDisplayHeight, 50)
|
mDefaultHeight = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyHeight, mDisplayHeight, 50)
|
||||||
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.Keyboard_horizontalGap, mDisplayWidth, 0)
|
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, mDisplayWidth, 0)
|
||||||
mDefaultVerticalGap = getDimensionOrFraction(a, R.styleable.Keyboard_verticalGap, mDisplayHeight, 0)
|
mDefaultVerticalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_verticalGap, mDisplayHeight, 0)
|
||||||
mProximityThreshold = (mDefaultWidth * SEARCH_DISTANCE).toInt()
|
mProximityThreshold = (mDefaultWidth * SEARCH_DISTANCE).toInt()
|
||||||
mProximityThreshold *= mProximityThreshold // Square it for comparison
|
mProximityThreshold *= mProximityThreshold // Square it for comparison
|
||||||
a.recycle()
|
a.recycle()
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<attr name="shadowRadius" format="float" />
|
<attr name="shadowRadius" format="float" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="Keyboard">
|
<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. -->
|
<!-- Default height of a key, in pixels or percentage of display width. -->
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
<attr name="verticalGap" format="dimension|fraction" />
|
<attr name="verticalGap" format="dimension|fraction" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="Keyboard_Row">
|
<declare-styleable name="MyKeyboard_Row">
|
||||||
<!-- Row edge flags. -->
|
<!-- Row edge flags. -->
|
||||||
<attr name="rowEdgeFlags">
|
<attr name="rowEdgeFlags">
|
||||||
<!-- Row is anchored to the top of the keyboard. -->
|
<!-- Row is anchored to the top of the keyboard. -->
|
||||||
|
@ -57,7 +57,7 @@
|
||||||
<attr name="keyboardMode" format="reference" />
|
<attr name="keyboardMode" format="reference" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="Keyboard_Key">
|
<declare-styleable name="MyKeyboard_Key">
|
||||||
<!-- The unicode value or comma-separated values that this key outputs. -->
|
<!-- The unicode value or comma-separated values that this key outputs. -->
|
||||||
<attr name="codes" format="integer|string" />
|
<attr name="codes" format="integer|string" />
|
||||||
<!-- The XML keyboard layout of any popup keyboard. -->
|
<!-- The XML keyboard layout of any popup keyboard. -->
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<MyKeyboard 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:keyHeight="60dp"
|
||||||
app:keyTextColor="@color/color_accent"
|
app:keyTextColor="@color/color_accent"
|
||||||
|
@ -126,4 +126,4 @@
|
||||||
app:keyIcon="@drawable/ic_enter_vector"
|
app:keyIcon="@drawable/ic_enter_vector"
|
||||||
app:keyWidth="20%p" />
|
app:keyWidth="20%p" />
|
||||||
</Row>
|
</Row>
|
||||||
</MyKeyboard>
|
</Keyboard>
|
||||||
|
|
Loading…
Reference in New Issue