Allow using a hardware keyboard to unlock the app using a pin code (#4530)

* Allow using a hardware keyboard to unlock the app using a pin code

* Add UI tests to `PinKeypad`

* Also take into account the numpad keys.

Extract this to an extension property in `ui-utils`. Made `ui-utils` also a compose-compatible library (vs `android-utils`, which doesn't have compose dependencies).
This commit is contained in:
Jorge Martin Espinosa
2025-04-07 11:55:35 +02:00
committed by GitHub
parent f8fb9d0c05
commit 9390964b01
5 changed files with 201 additions and 3 deletions

View File

@@ -6,7 +6,7 @@
*/
plugins {
id("io.element.android-library")
id("io.element.android-compose-library")
}
android {

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.ui.utils.time
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.key
/**
* Extension property to get the digit character from a KeyEvent.
* This handles both regular digit keys and numpad keys.
*/
val KeyEvent.digit: Char? get() {
val char = nativeKeyEvent.unicodeChar.toChar()
return when {
Character.isDigit(char) -> char
key == Key.NumPad0 -> '0'
key == Key.NumPad1 -> '1'
key == Key.NumPad2 -> '2'
key == Key.NumPad3 -> '3'
key == Key.NumPad4 -> '4'
key == Key.NumPad5 -> '5'
key == Key.NumPad6 -> '6'
key == Key.NumPad7 -> '7'
key == Key.NumPad8 -> '8'
key == Key.NumPad9 -> '9'
else -> null
}
}