This commit is contained in:
Helium314 2024-04-20 12:43:58 +02:00
parent eea2dd4ee8
commit bd453c26cd
3 changed files with 16 additions and 2 deletions

View file

@ -7,6 +7,8 @@
package helium314.keyboard.accessibility
import android.content.Context
import android.media.AudioDeviceInfo
import android.media.AudioDeviceInfo.*
import android.media.AudioManager
import android.os.Build
import android.os.SystemClock
@ -72,7 +74,19 @@ class AccessibilityUtils private constructor() {
if (speakPassword) return false
}
// Always speak if the user is listening through headphones.
return if (mAudioManager.isWiredHeadsetOn || mAudioManager.isBluetoothA2dpOn) {
val listeningThroughHeadphones = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@Suppress("deprecation") // no replacement available
mAudioManager.isWiredHeadsetOn || mAudioManager.isBluetoothA2dpOn
} else {
// try the same as the deprecated thing above, for what we can assume to be headphones
mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any {
when (it.type) {
TYPE_WIRED_HEADSET, TYPE_WIRED_HEADPHONES, TYPE_BLUETOOTH_SCO, TYPE_BLUETOOTH_A2DP, TYPE_USB_HEADSET, TYPE_HEARING_AID, TYPE_BLE_HEADSET -> true
else -> false
}
}
}
return if (listeningThroughHeadphones) {
false
} else InputTypeUtils.isPasswordInputType(editorInfo.inputType)
// Don't speak if the IME is connected to a password field.

View file

@ -795,7 +795,6 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
// currently always holo is applied in readAttributes
private fun layoutInfos(params: KeyboardParams): LayoutInfos {
val layout = params.mId.mSubtype.keyboardLayoutSetName
val language = params.mId.locale.language
// only for alphabet, but some exceptions for shift layouts
val enableProximityCharsCorrection = params.mId.isAlphabetKeyboard && when (layout) {
"bengali_akkhor", "georgian", "hindi", "lao", "nepali_romanized", "nepali_traditional", "sinhala", "thai" ->

View file

@ -195,6 +195,7 @@ private fun getDefaultEnabledSubtypes(): List<InputMethodSubtype> {
/** string for for identifying a subtype, does not contain all necessary information to actually create it */
private fun InputMethodSubtype.prefString(): String {
if (DebugFlags.DEBUG_ENABLED && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && locale().toLanguageTag() == "und") {
@Suppress("deprecation") // it's debug logging, better get all information
Log.e(TAG, "unknown language, should not happen ${locale}, $languageTag, $extraValue, ${hashCode()}, $nameResId")
}
return locale().toLanguageTag() + LOCALE_LAYOUT_SEPARATOR + SubtypeLocaleUtils.getKeyboardLayoutSetName(this)