Merge pull request #167 from Merkost/space_fix

Space button fix in phone keybord type
This commit is contained in:
Tibor Kaputa 2023-05-18 09:20:45 +02:00 committed by GitHub
commit 8e6852de1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 8 deletions

View File

@ -201,8 +201,14 @@ class MyKeyboard {
a.recycle()
a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard_Key)
label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: ""
code = a.getInt(R.styleable.MyKeyboard_Key_code, 0)
if (label.isNotEmpty() && code == 0) {
code = label[0].code
}
popupCharacters = a.getText(R.styleable.MyKeyboard_Key_popupCharacters)
popupResId = a.getResourceId(R.styleable.MyKeyboard_Key_popupKeyboard, 0)
repeatable = a.getBoolean(R.styleable.MyKeyboard_Key_isRepeatable, false)
@ -213,12 +219,9 @@ class MyKeyboard {
secondaryIcon = a.getDrawable(R.styleable.MyKeyboard_Key_secondaryKeyIcon)
secondaryIcon?.setBounds(0, 0, secondaryIcon!!.intrinsicWidth, secondaryIcon!!.intrinsicHeight)
label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: ""
topSmallNumber = a.getString(R.styleable.MyKeyboard_Key_topSmallNumber) ?: ""
if (label.isNotEmpty() && code != KEYCODE_MODE_CHANGE && code != KEYCODE_SHIFT) {
code = label[0].code
}
a.recycle()
}

View File

@ -164,7 +164,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
// If the keyboard is set to symbols and the user presses space, we usually should switch back to the letters keyboard.
// However, avoid doing that in cases when the EditText for example requires numbers as the input.
// We can detect that by the text not changing on pressing Space.
if (keyboardMode != KEYBOARD_LETTERS && code == MyKeyboard.KEYCODE_SPACE) {
if (keyboardMode != KEYBOARD_LETTERS && keyboardMode != KEYBOARD_PHONE && code == MyKeyboard.KEYCODE_SPACE) {
val originalText = inputConnection.getExtractedText(ExtractedTextRequest(), 0)?.text ?: return
inputConnection.commitText(codeChar.toString(), 1)
val newText = inputConnection.getExtractedText(ExtractedTextRequest(), 0)?.text

View File

@ -569,6 +569,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
for (i in 0 until keyCount) {
val key = keys[i]
val code = key.code
// TODO: Space key background on a KEYBOARD_PHONE should not be applied
setupKeyBackground(key, code, canvas)
// Switch the character to uppercase if shift is pressed

View File

@ -41,13 +41,32 @@
</RelativeLayout>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/text_edittext"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/change_keyboard_holder"
android:layout_margin="@dimen/activity_margin" />
android:orientation="vertical">
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/text_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginTop="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin"
android:layout_marginBottom="@dimen/activity_margin" />
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/text_editphone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginTop="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin"
android:layout_marginBottom="@dimen/activity_margin"
android:inputType="phone" />
</LinearLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>