From ed00de9606fbe98d8054a9671e41b0f9a138da33 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 8 Jan 2022 23:08:08 +0100 Subject: [PATCH] refer to our keyboard attributes, not the system ones --- .../keyboard/helpers/MyKeyboard.kt | 54 ++---- .../res/layout/keyboard_popup_keyboard.xml | 9 +- app/src/main/res/values/attrs.xml | 85 +++++++++ app/src/main/res/values/styles.xml | 85 --------- app/src/main/res/xml/keys_layout.xml | 176 +++++++++--------- 5 files changed, 194 insertions(+), 215 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt index 5914144..af61d72 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt @@ -24,9 +24,9 @@ import android.text.TextUtils import android.util.TypedValue import android.util.Xml import androidx.annotation.XmlRes +import com.simplemobiletools.commons.helpers.mydebug import com.simplemobiletools.keyboard.R -import org.xmlpull.v1.XmlPullParserException -import java.io.IOException +import java.io.FileNotFoundException import java.util.* /** @@ -87,7 +87,7 @@ class MyKeyboard { var mKeys: MutableList? = null /** List of modifier keys such as Shift & Alt, if any */ - private var mModifierKeys: MutableList? = null + private var mModifierKeys = ArrayList() /** Width of the screen available to fit the keyboard */ private var mDisplayWidth = 0 @@ -160,6 +160,7 @@ class MyKeyboard { /** Vertical gap following this row. */ var verticalGap = 0 + var mKeys = ArrayList() /** @@ -255,8 +256,7 @@ class MyKeyboard { /** * Flags that specify the anchoring to edges of the keyboard for detecting touch events * 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]. + * [MyKeyboard.EDGE_LEFT], [MyKeyboard.EDGE_RIGHT], [MyKeyboard.EDGE_TOP] and [MyKeyboard.EDGE_BOTTOM]. */ var edgeFlags: Int @@ -275,8 +275,7 @@ class MyKeyboard { /** Create a key with the given top-left coordinate and extract its attributes from * the XML parser. * @param res resources associated with the caller's context - * @param parent the row that this key belongs to. The row must already be attached to - * a [Keyboard]. + * @param parent the row that this key belongs to. The row must already be attached to a [MyKeyboard]. * @param x the x coordinate of the top-left * @param y the y coordinate of the top-left * @param parser the XML parser containing the attributes for this key @@ -315,8 +314,9 @@ class MyKeyboard { icon?.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight) - label = a.getText(R.styleable.Keyboard_Key_keyLabel) + label = a.getText(R.styleable.Keyboard_Key_keyLabel) ?: "" text = a.getText(R.styleable.Keyboard_Key_keyOutputText) + if (!TextUtils.isEmpty(label)) { codes = arrayListOf(label[0].toInt()) } @@ -378,6 +378,7 @@ class MyKeyboard { try { values[count++] = st.nextToken().toInt() } catch (nfe: NumberFormatException) { + mydebug("NumberFormatException $nfe") } } return values @@ -454,26 +455,6 @@ class MyKeyboard { } } - /** - * Creates a keyboard from the given xml key layout file. Weeds out rows - * that have a keyboard mode defined but don't match the specified mode. - * @param context the application or service context - * @param xmlLayoutResId the resource file that contains the keyboard layout and keys. - * @param modeId keyboard mode identifier - * @param width sets width of keyboard - * @param height sets height of keyboard - */ - constructor(context: Context, @XmlRes xmlLayoutResId: Int, modeId: Int, width: Int, height: Int) { - mDisplayWidth = width - mDisplayHeight = height - mDefaultHorizontalGap = 0 - mDefaultWidth = mDisplayWidth / 10 - mDefaultVerticalGap = 0 - mDefaultHeight = mDefaultWidth - mKeys = ArrayList() - mKeyboardMode = modeId - loadKeyboard(context, context.resources.getXml(xmlLayoutResId)) - } /** * Creates a keyboard from the given xml key layout file. Weeds out rows * that have a keyboard mode defined but don't match the specified mode. @@ -640,12 +621,12 @@ class MyKeyboard { * point is out of range, then an array of size zero is returned. */ fun getNearestKeys(x: Int, y: Int): IntArray { - if (x in 0 until minWidth && y >= 0 && y < height) { + /*if (x in 0 until minWidth && y >= 0 && y < height) { val index: Int = y / mCellHeight * GRID_WIDTH + x / mCellWidth if (index < GRID_SIZE) { return mGridNeighbors[index]!! } - } + }*/ return IntArray(0) } @@ -660,25 +641,24 @@ class MyKeyboard { private fun loadKeyboard(context: Context, parser: XmlResourceParser) { var inKey = false var inRow = false - val leftMostKey = false var row = 0 var x = 0 var y = 0 var key: Key? = null var currentRow: Row? = null val res = context.resources - var skipRow = false try { var event: Int while (parser.next().also { event = it } != XmlResourceParser.END_DOCUMENT) { if (event == XmlResourceParser.START_TAG) { val tag = parser.name if (TAG_ROW == tag) { + //mydebug("row $currentRow") inRow = true x = 0 currentRow = createRowFromXml(res, parser) rows.add(currentRow) - skipRow = currentRow.mode != 0 && currentRow.mode != mKeyboardMode + val skipRow = currentRow.mode != 0 && currentRow.mode != mKeyboardMode if (skipRow) { skipToEndOfRow(parser) inRow = false @@ -696,9 +676,9 @@ class MyKeyboard { break } } - mModifierKeys!!.add(key) + mModifierKeys.add(key) } else if (key.codes[0] == KEYCODE_ALT) { - mModifierKeys!!.add(key) + mModifierKeys.add(key) } currentRow.mKeys.add(key) } else if (TAG_KEYBOARD == tag) { @@ -719,12 +699,12 @@ class MyKeyboard { } } } - } catch (e: Exception) { + } catch (e: FileNotFoundException) { + mydebug("Exception $e") } height = y - mDefaultVerticalGap } - @Throws(XmlPullParserException::class, IOException::class) private fun skipToEndOfRow(parser: XmlResourceParser) { var event: Int while (parser.next().also { event = it } != XmlResourceParser.END_DOCUMENT) { diff --git a/app/src/main/res/layout/keyboard_popup_keyboard.xml b/app/src/main/res/layout/keyboard_popup_keyboard.xml index de8cc5c..c24d59e 100644 --- a/app/src/main/res/layout/keyboard_popup_keyboard.xml +++ b/app/src/main/res/layout/keyboard_popup_keyboard.xml @@ -1,4 +1,5 @@ diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 1def718..3eeccdc 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -3,4 +3,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5321ae9..ba9809d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -20,89 +20,4 @@ #BB000000 2.75 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/xml/keys_layout.xml b/app/src/main/res/xml/keys_layout.xml index be8d302..ef51e00 100644 --- a/app/src/main/res/xml/keys_layout.xml +++ b/app/src/main/res/xml/keys_layout.xml @@ -1,129 +1,129 @@ - + + app:codes="113" + app:keyEdgeFlags="left" + app:keyLabel="q" /> + app:codes="119" + app:keyLabel="w" /> + app:codes="101" + app:keyLabel="e" /> + app:codes="114" + app:keyLabel="r" /> + app:codes="116" + app:keyLabel="t" /> + app:codes="121" + app:keyLabel="y" /> + app:codes="117" + app:keyLabel="u" /> + app:codes="105" + app:keyLabel="i" /> + app:codes="111" + app:keyLabel="o" /> + app:codes="112" + app:keyEdgeFlags="right" + app:keyLabel="p" /> + app:codes="97" + app:horizontalGap="5%" + app:keyEdgeFlags="left" + app:keyLabel="a" /> + app:codes="115" + app:keyLabel="s" /> + app:codes="100" + app:keyLabel="d" /> + app:codes="102" + app:keyLabel="f" /> + app:codes="103" + app:keyLabel="g" /> + app:codes="104" + app:keyLabel="h" /> + app:codes="106" + app:keyLabel="j" /> + app:codes="107" + app:keyLabel="k" /> + app:codes="108" + app:keyLabel="l" /> + app:codes="-1" + app:keyEdgeFlags="left" + app:keyIcon="@drawable/ic_caps_outline_vector" + app:keyWidth="15%p" /> + app:codes="122" + app:keyLabel="z" /> + app:codes="120" + app:keyLabel="x" /> + app:codes="99" + app:keyLabel="c" /> + app:codes="118" + app:keyLabel="v" /> + app:codes="98" + app:keyLabel="b" /> + app:codes="110" + app:keyLabel="n" /> + app:codes="109" + app:keyLabel="m" /> + app:codes="-5" + app:iconPreview="@null" + app:isRepeatable="true" + app:keyEdgeFlags="right" + app:keyIcon="@drawable/ic_clear_vector" + app:keyWidth="15%p" /> - + + app:codes="44" + app:keyEdgeFlags="left" + app:keyLabel="," + app:keyWidth="10%p" /> + app:codes="32" + app:iconPreview="@null" + app:isRepeatable="true" + app:keyLabel="" + app:keyWidth="60%p" /> + app:codes="46" + app:keyLabel="." /> + app:codes="-4" + app:keyEdgeFlags="right" + app:keyIcon="@drawable/ic_enter_vector" + app:keyWidth="20%p" />