0
0
mirror of https://github.com/florisboard/florisboard.git synced 2024-09-20 03:52:18 +02:00

Re-implement key hints

This commit is contained in:
Patrick Goldinger 2021-04-30 16:07:29 +02:00
parent 0a84c78740
commit 3de07c30c6
3 changed files with 26 additions and 16 deletions

View File

@ -44,6 +44,7 @@ class TextKey(override val data: KeyData) : Key(data) {
var computedData: TextKeyData = TextKeyData.UNSPECIFIED
private set
val computedPopups: MutablePopupSet<TextKeyData> = MutablePopupSet()
var computedHint: TextKeyData? = null
fun compute(evaluator: TextComputingEvaluator) {
val keyboardMode = evaluator.getKeyboard().mode
@ -61,6 +62,7 @@ class TextKey(override val data: KeyData) : Key(data) {
} else {
computedData = computed
computedPopups.clear()
computedPopups.hint = computedHint?.computeTextKeyData(evaluator)
if (computed is BasicTextKeyData && computed.popup != null) {
computedPopups.merge(computed.popup, evaluator)
}

View File

@ -276,9 +276,17 @@ class TextKeyboardView : View, ThemeManager.OnThemeUpdatedListener, SwipeGesture
event.getX(pointerIndex).roundToInt(), event.getY(pointerIndex).roundToInt()
)
if (key != null && key.isEnabled) {
var keyHintMode = KeyHintMode.DISABLED
if (prefs.keyboard.hintedNumberRowMode != KeyHintMode.DISABLED && key.computedPopups.hint?.type == KeyType.NUMERIC) {
keyHintMode = prefs.keyboard.hintedNumberRowMode
}
if (prefs.keyboard.hintedSymbolsMode != KeyHintMode.DISABLED && key.computedPopups.hint?.type == KeyType.CHARACTER) {
keyHintMode = prefs.keyboard.hintedSymbolsMode
}
florisboard.textInputManager.inputEventDispatcher.send(InputKeyEvent.down(key.computedData))
if (prefs.keyboard.popupEnabled) {
popupManager.show(key, KeyHintMode.DISABLED)
popupManager.show(key, keyHintMode)
}
florisboard.keyPressVibrate()
florisboard.keyPressSound(key.computedData)
@ -318,7 +326,7 @@ class TextKeyboardView : View, ThemeManager.OnThemeUpdatedListener, SwipeGesture
else -> {
longPressHandler.postDelayed(delayMillis) {
if (key.computedPopups.isNotEmpty()) {
popupManager.extend(key, KeyHintMode.DISABLED)
popupManager.extend(key, keyHintMode)
florisboard.keyPressVibrate()
florisboard.keyPressSound(key.computedData)
}
@ -902,12 +910,13 @@ class TextKeyboardView : View, ThemeManager.OnThemeUpdatedListener, SwipeGesture
val hintedLabel = key.hintedLabel
if (hintedLabel != null) {
labelPaint.apply {
hintedLabelPaint.apply {
color = keyForeground.toSolidColor().color
textSize = labelPaintTextSize
val centerX = key.visibleBounds.width() * 5.0f / 6.0f
val centerY = key.visibleBounds.height() * 1.0f / 6.0f + (hintedLabelPaint.textSize - hintedLabelPaint.descent()) / 2
canvas.drawText(hintedLabel, centerX, centerY, labelPaint)
alpha = 170
textSize = hintedLabelPaintTextSize
val centerX = key.visibleBounds.left + key.visibleBounds.width() * 5.0f / 6.0f
val centerY = key.visibleBounds.top + key.visibleBounds.height() * 1.0f / 6.0f + (hintedLabelPaint.textSize - hintedLabelPaint.descent()) / 2
canvas.drawText(hintedLabel, centerX, centerY, hintedLabelPaint)
}
}

View File

@ -18,7 +18,6 @@ package dev.patrickgold.florisboard.ime.text.layout
import dev.patrickgold.florisboard.debug.LogTopic
import dev.patrickgold.florisboard.debug.flogDebug
import dev.patrickgold.florisboard.debug.flogError
import dev.patrickgold.florisboard.debug.flogWarning
import dev.patrickgold.florisboard.ime.core.PrefHelper
import dev.patrickgold.florisboard.ime.core.Subtype
@ -27,7 +26,6 @@ import dev.patrickgold.florisboard.ime.extension.AssetRef
import dev.patrickgold.florisboard.ime.extension.AssetSource
import dev.patrickgold.florisboard.ime.popup.PopupExtension
import dev.patrickgold.florisboard.ime.popup.PopupManager
import dev.patrickgold.florisboard.ime.popup.PopupMapping
import dev.patrickgold.florisboard.ime.text.key.*
import dev.patrickgold.florisboard.ime.text.keyboard.*
import kotlinx.coroutines.*
@ -207,7 +205,7 @@ class LayoutManager {
}
}
/*// Add hints to keys
// Add hints to keys
if (keyboardMode == KeyboardMode.CHARACTERS) {
val symbolsComputedArrangement = computeKeyboardAsync(KeyboardMode.SYMBOLS, subtype, prefs).await().arrangement
val minRow = if (prefs.keyboard.numberRow) { 1 } else { 0 }
@ -218,16 +216,17 @@ class LayoutManager {
val symbolRow = symbolsComputedArrangement.getOrNull(r - minRow)
if (symbolRow != null) {
for ((k, key) in row.withIndex()) {
val symbol = symbolRow.getOrNull(k)
if (r == minRow && key.data == KeyType.CHARACTER && symbol?.type == KeyType.NUMERIC) {
key.popup.hint = symbol
} else if (r > minRow && key.type == KeyType.CHARACTER && symbol?.type == KeyType.CHARACTER) {
key.popup.hint = symbol
val symbol = symbolRow.getOrNull(k)?.data?.computeTextKeyData(DefaultTextComputingEvaluator)
val type = (key.data as? TextKeyData)?.type ?: KeyType.UNSPECIFIED
if (r == minRow && type == KeyType.CHARACTER && symbol?.type == KeyType.NUMERIC) {
key.computedHint = symbol
} else if (r > minRow && type == KeyType.CHARACTER && symbol?.type == KeyType.CHARACTER) {
key.computedHint = symbol
}
}
}
}
}*/
}
val array = Array(computedArrangement.size) { computedArrangement[it] }
return TextKeyboard(