Skip to content

Commit

Permalink
fix: keyboard symbol is not usable on API 21/22
Browse files Browse the repository at this point in the history
  • Loading branch information
david-allison committed Aug 27, 2021
1 parent 9ff0506 commit df35e6c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/reviewer/Binding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,32 @@
package com.ichi2.anki.reviewer

import android.content.Context
import android.os.Build
import android.text.TextUtils
import android.util.Pair
import android.view.KeyEvent
import androidx.annotation.VisibleForTesting
import com.ichi2.anki.cardviewer.Gesture
import com.ichi2.compat.CompatHelper
import com.ichi2.utils.StringUtil
import timber.log.Timber
import java.util.*

class Binding private constructor(private val modifierKeys: ModifierKeys?, private val keycode: Int?, private val unicodeCharacter: Char?, private val gesture: Gesture?) {

private fun getKeyCodePrefix(): String {
// KEY_PREFIX is not usable before API 23
val keyPrefix = if (CompatHelper.getSdkVersion() >= Build.VERSION_CODES.M) KEY_PREFIX.toString() else ""

if (keycode == null) {
return KEY_PREFIX.toString()
return keyPrefix
}

if (KeyEvent.isGamepadButton(keycode)) {
return GAMEPAD_PREFIX
}

return KEY_PREFIX.toString()
return keyPrefix
}
fun toDisplayString(context: Context?): String {
val string = StringBuilder()
Expand Down Expand Up @@ -187,7 +192,10 @@ class Binding private constructor(private val modifierKeys: ModifierKeys?, priva
companion object {
const val FORBIDDEN_UNICODE_CHAR = MappableBinding.PREF_SEPARATOR

/** https://www.fileformat.info/info/unicode/char/2328/index.htm (Keyboard) */
/**
* https://www.fileformat.info/info/unicode/char/2328/index.htm (Keyboard)
* This is not usable on API 21 or 22
*/
const val KEY_PREFIX = '\u2328'

/** https://www.fileformat.info/info/unicode/char/235d/index.htm (similar to a finger) */
Expand Down

0 comments on commit df35e6c

Please # to comment.