Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ interface KeyboardActionListener {
const val SWIPE_TOUCHPAD_MODE = 5
const val SWIPE_MORE_SUGGESTIONS = 6
const val SWIPE_DELETE_WORD = 7
const val SWIPE_DELETE_SPACE = 8

const val CODE_TOUCHPAD_ON = 1000
const val CODE_TOUCHPAD_OFF = 1001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
false
}
}
KeyboardActionListener.SWIPE_DELETE_SPACE -> {
val code = if (steps < 0) KeyCode.DELETE else Constants.CODE_SPACE
audioAndHapticFeedbackManager.performHapticAndAudioFeedback(
code, keyboardSwitcher.mainKeyboardView, HapticEvent.KEY_PRESS
)
onCodeInput(code, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false)
true
}
else -> false
}

Expand Down
28 changes: 26 additions & 2 deletions app/src/main/java/helium314/keyboard/keyboard/KeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ open class KeyboardView @JvmOverloads constructor(

val isActionKey = key.hasActionKeyBackground() || key.code == Constants.CODE_ENTER
val isSpaceKey = key.code == Constants.CODE_SPACE || key.backgroundType == Key.BACKGROUND_TYPE_SPACEBAR
val isFunctional = key.hasFunctionalBackground() || key.isShift() || key.isModifier() || key.code == KeyCode.DELETE || key.code == KeyCode.SYMBOL_ALPHA
val isFunctional = isHexFunctionalKey(key)

val baseBg = mColors.get(ColorType.KEY_BACKGROUND)

Expand Down Expand Up @@ -592,7 +592,9 @@ open class KeyboardView @JvmOverloads constructor(
paint.color = mColors.get(ColorType.POPUP_KEY_TEXT)
}
} else {
paint.color = key.selectTextColor(params)
val textColor = key.selectTextColor(params)
val hexBg = getHexFunctionalBgColor(key)
paint.color = if (hexBg != null && hasLowContrast(textColor, hexBg)) getContrastingColor(hexBg) else textColor
}
if (mKeyTextShadowRadius > 0.0f) paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor) else paint.clearShadowLayer()
} else {
Expand Down Expand Up @@ -730,6 +732,24 @@ open class KeyboardView @JvmOverloads constructor(

open fun deallocateMemory() { freeOffscreenBuffer() }

private fun isHexFunctionalKey(key: Key) =
key.hasFunctionalBackground() || key.isShift() || key.isModifier() || key.code == KeyCode.DELETE || key.code == KeyCode.SYMBOL_ALPHA

/** Fill color of a functional hex key, which hex draws even when the theme has no key borders. */
private fun getHexFunctionalBgColor(key: Key): Int? {
if (keyboard?.isHexagonal != true || this is PopupKeysKeyboardView) return null
if (key.hasActionKeyBackground() || key.code == Constants.CODE_ENTER) return null
if (key.code == Constants.CODE_SPACE || key.backgroundType == Key.BACKGROUND_TYPE_SPACEBAR) return null
if (!isHexFunctionalKey(key)) return null
return if (key.isPressed) mColors.getPressedColor(ColorType.FUNCTIONAL_KEY_BACKGROUND)
else mColors.get(ColorType.FUNCTIONAL_KEY_BACKGROUND)
}

private fun hasLowContrast(fgColor: Int, bgColor: Int): Boolean {
val compositeBg = getCompositeColor(bgColor, mColors.get(ColorType.MAIN_BACKGROUND))
return ColorUtils.calculateContrast(getCompositeColor(fgColor, compositeBg), compositeBg) < 4.5
}

private fun getContrastingColor(bgColor: Int): Int {
val baseBg = mColors.get(ColorType.MAIN_BACKGROUND)
val compositeBg = getCompositeColor(bgColor, baseBg)
Expand All @@ -756,11 +776,15 @@ open class KeyboardView @JvmOverloads constructor(
private fun setKeyIconColor(key: Key, icon: Drawable, keyboard: Keyboard?) {
val isTextEditMode = KeyboardActionListenerImpl.sPersistentTextEditModeActive || (keyboard?.mId?.mElementId == KeyboardId.ELEMENT_TEXT_EDIT)
val customBgColor = mKeyCustomBgColors[key]
val hexBg = getHexFunctionalBgColor(key)
if (customBgColor != null && isTextEditMode) {
DrawableCompat.setTintList(icon, null)
icon.setColorFilter(getContrastingColor(customBgColor), PorterDuff.Mode.SRC_IN)
} else if (key.hasActionKeyBackground() || (keyboard?.isHexagonal == true && key.code == Constants.CODE_ENTER)) {
mColors.setColor(icon, ColorType.ACTION_KEY_ICON)
} else if (hexBg != null && hasLowContrast(mColors.get(ColorType.KEY_ICON), hexBg)) {
DrawableCompat.setTintList(icon, null)
icon.setColorFilter(getContrastingColor(hexBg), PorterDuff.Mode.SRC_IN)
} else if (key.isShift() && keyboard != null) {
if (keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)
mColors.setColor(icon, ColorType.SHIFT_KEY_ICON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ object KeyboardBottomRowGeometry {
val bottomRowAreaHeight = totalHeight - bottomRowY

val mainKb = KeyboardSwitcher.getInstance().keyboard
if (mainKb != null && mainKb.mOccupiedHeight == totalHeight && (mainKb.mId.isAlphabetKeyboard || mainKb.mId.isAlphaOrSymbolKeyboard)) {
// hex layouts have their space keys in a middle row, so the space key does not mark the bottom row
if (mainKb != null && mainKb.mOccupiedHeight == totalHeight && !mainKb.isHexagonal
&& (mainKb.mId.isAlphabetKeyboard || mainKb.mId.isAlphaOrSymbolKeyboard)) {
val spaceKey = mainKb.sortedKeys.firstOrNull { it.code == Constants.CODE_SPACE }
if (spaceKey != null) {
return Dimensions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ class Settings private constructor() : SharedPreferences.OnSharedPreferenceChang
"toggle_numpad" -> KeyboardActionListener.SWIPE_TOGGLE_NUMPAD
"hide_keyboard" -> KeyboardActionListener.SWIPE_HIDE_KEYBOARD
"delete_word" -> KeyboardActionListener.SWIPE_DELETE_WORD
"delete_space" -> KeyboardActionListener.SWIPE_DELETE_SPACE
else -> KeyboardActionListener.SWIPE_NO_ACTION
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ fun createGestureTypingSettings(context: Context) = listOf(
stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad",
stringResource(R.string.space_swipe_hide_keyboard_entry) to "hide_keyboard",
stringResource(R.string.space_swipe_delete_word_entry) to "delete_word",
"${stringResource(R.string.spoken_description_delete)} / ${stringResource(R.string.spoken_description_space)}" to "delete_space",
stringResource(R.string.action_none) to "none",
)
val ctx = LocalContext.current
Expand Down
Loading