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
11 changes: 11 additions & 0 deletions app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.getOrCreate
import helium314.keyboard.latin.RichInputMethodManager
import helium314.keyboard.latin.RichInputMethodSubtype
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.SettingsValues
import helium314.keyboard.latin.utils.InputTypeUtils
import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.ResourceUtils
Expand Down Expand Up @@ -224,6 +225,16 @@ class KeyboardLayoutSet internal constructor(
return this
}

fun setKeyboardOptions(settingsValues: SettingsValues): Builder =
setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey)
.setNumberRowEnabled(settingsValues.mShowsNumberRow)
.setNumberRowInSymbolsEnabled(settingsValues.mShowsNumberRowInSymbols)
.setCompactNumberRowInSymbolsEnabled(settingsValues.mCompactNumberRowInSymbols)
.setLanguageSwitchKeyEnabled(settingsValues.isLanguageSwitchKeyEnabled())
.setEmojiKeyEnabled(settingsValues.mShowsEmojiKey)
.setSplitLayoutEnabled(settingsValues.mIsSplitKeyboardEnabled)
.setOneHandedModeEnabled(settingsValues.mOneHandedModeEnabled)

fun build(): KeyboardLayoutSet {
if (!mSubtypeSpecified) {
throw RuntimeException("KeyboardLayoutSet subtype is not specified")
Expand Down
34 changes: 15 additions & 19 deletions app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,7 @@ class KeyboardSwitcher private constructor() : KeyboardState.SwitchActions {
val richImm = mRichImm ?: RichInputMethodManager.getInstance()
mKeyboardLayoutSet = builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)
.setSubtype(richImm.currentSubtype)
.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey)
.setNumberRowEnabled(settingsValues.mShowsNumberRow)
.setNumberRowInSymbolsEnabled(settingsValues.mShowsNumberRowInSymbols)
.setCompactNumberRowInSymbolsEnabled(settingsValues.mCompactNumberRowInSymbols)
.setLanguageSwitchKeyEnabled(settingsValues.isLanguageSwitchKeyEnabled())
.setEmojiKeyEnabled(settingsValues.mShowsEmojiKey)
.setSplitLayoutEnabled(settingsValues.mIsSplitKeyboardEnabled)
.setOneHandedModeEnabled(oneHandedModeEnabled)
.setKeyboardOptions(settingsValues)
.setInternalAction(internalAction)
.build()
val state = mState ?: return
Expand All @@ -177,14 +170,7 @@ class KeyboardSwitcher private constructor() : KeyboardState.SwitchActions {
val defaults = SubtypeUtilsAdditional.createDefaultSubtype(richImm.currentSubtypeLocale)
mKeyboardLayoutSet = builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)
.setSubtype(RichInputMethodSubtype.get(defaults))
.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey)
.setNumberRowEnabled(settingsValues.mShowsNumberRow)
.setNumberRowInSymbolsEnabled(settingsValues.mShowsNumberRowInSymbols)
.setCompactNumberRowInSymbolsEnabled(settingsValues.mCompactNumberRowInSymbols)
.setLanguageSwitchKeyEnabled(settingsValues.isLanguageSwitchKeyEnabled())
.setEmojiKeyEnabled(settingsValues.mShowsEmojiKey)
.setSplitLayoutEnabled(settingsValues.mIsSplitKeyboardEnabled)
.setOneHandedModeEnabled(oneHandedModeEnabled)
.setKeyboardOptions(settingsValues)
.build()
state.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState, oneHandedModeEnabled)
showToast("error loading the keyboard, falling back to defaults", false)
Expand Down Expand Up @@ -247,6 +233,11 @@ class KeyboardSwitcher private constructor() : KeyboardState.SwitchActions {
mState?.onResetKeyboardStateToAlphabet(currentAutoCapsState, currentRecapitalizeState)
}

// A secondary view may have been shown directly, without changing the keyboard state.
fun returnToAlphabetKeyboard() {
mState?.setAlphabetKeyboard(0, null)
}

fun onPressKey(code: Int, isSinglePointer: Boolean, currentAutoCapsState: Int, currentRecapitalizeState: RecapitalizeMode?) {
mState?.onPressKey(code, isSinglePointer, currentAutoCapsState, currentRecapitalizeState)
}
Expand Down Expand Up @@ -296,16 +287,21 @@ class KeyboardSwitcher private constructor() : KeyboardState.SwitchActions {

override fun setCustomKeyboard(customIndex: Int) {
if (DEBUG_ACTION) Log.d(TAG, "setCustomKeyboard: $customIndex")
val elementId = when (customIndex) {
setKeyboard(customKeyboardElementId(customIndex), KeyboardSwitchState.OTHER)
}

val activeAlphabetKeyboardId: Int
get() = customKeyboardElementId(mState?.lastCustomIndex ?: 0)

private fun customKeyboardElementId(customIndex: Int): Int =
when (customIndex) {
1 -> KeyboardId.ELEMENT_CUSTOM1
2 -> KeyboardId.ELEMENT_CUSTOM2
3 -> KeyboardId.ELEMENT_CUSTOM3
4 -> KeyboardId.ELEMENT_CUSTOM4
5 -> KeyboardId.ELEMENT_CUSTOM5
else -> KeyboardId.ELEMENT_ALPHABET
}
setKeyboard(elementId, KeyboardSwitchState.OTHER)
}

fun isImeSuppressedByHardwareKeyboard(
settingsValues: SettingsValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class EmojiPalettesView @JvmOverloads constructor(
private var mIsDownloadingEmojiDict = false
private var mOriginalActionListener: KeyboardActionListener? = null
private var mSearchKeyboardLayoutSet: KeyboardLayoutSet? = null
private var mSearchAlphabetKeyboardId = KeyboardId.ELEMENT_ALPHABET

private var mEditorInfo: EditorInfo? = null

Expand Down Expand Up @@ -499,7 +500,7 @@ class EmojiPalettesView @JvmOverloads constructor(
val bottomRow = findViewById<MainKeyboardView>(R.id.bottom_row_keyboard)
val currentElementId = bottomRow.keyboard?.mId?.mElementId ?: KeyboardId.ELEMENT_ALPHABET
val isOnSymbols = currentElementId == KeyboardId.ELEMENT_SYMBOLS || currentElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED
val targetId = if (isOnSymbols) KeyboardId.ELEMENT_ALPHABET else KeyboardId.ELEMENT_SYMBOLS
val targetId = if (isOnSymbols) mSearchAlphabetKeyboardId else KeyboardId.ELEMENT_SYMBOLS
bottomRow.setKeyboard(layoutSet.getKeyboard(targetId))
bottomRow.setKeyPreviewPopupEnabled(Settings.getValues().mKeyPreviewPopupOn)
}
Expand All @@ -511,7 +512,7 @@ class EmojiPalettesView @JvmOverloads constructor(
KeyboardId.ELEMENT_SYMBOLS -> KeyboardId.ELEMENT_SYMBOLS_SHIFTED
KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> KeyboardId.ELEMENT_SYMBOLS
KeyboardId.ELEMENT_ALPHABET -> KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED
else -> KeyboardId.ELEMENT_ALPHABET
else -> mSearchAlphabetKeyboardId
}
bottomRow.setKeyboard(layoutSet.getKeyboard(targetId))
bottomRow.setKeyPreviewPopupEnabled(Settings.getValues().mKeyPreviewPopupOn)
Expand Down Expand Up @@ -638,15 +639,16 @@ class EmojiPalettesView @JvmOverloads constructor(

val builder = KeyboardLayoutSet.Builder(ctx, null)
builder.setSubtype(RichInputMethodManager.getInstance().currentSubtype)
builder.setSplitLayoutEnabled(Settings.getValues().mIsSplitKeyboardEnabled)
builder.setKeyboardOptions(Settings.getValues())
builder.setKeyboardGeometry(
ResourceUtils.getKeyboardWidth(ctx, Settings.getValues()),
ResourceUtils.getSecondaryKeyboardHeight(resources, Settings.getValues())
)

val searchKeyboardLayoutSet = builder.build()
mSearchKeyboardLayoutSet = searchKeyboardLayoutSet
bottomRow.setKeyboard(searchKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET))
mSearchAlphabetKeyboardId = KeyboardSwitcher.getInstance().activeAlphabetKeyboardId
bottomRow.setKeyboard(searchKeyboardLayoutSet.getKeyboard(mSearchAlphabetKeyboardId))
bottomRow.setKeyPreviewPopupEnabled(Settings.getValues().mKeyPreviewPopupOn)

mSearchBar?.requestFocus()
Expand All @@ -657,12 +659,17 @@ class EmojiPalettesView @JvmOverloads constructor(
}
}

private fun stopSearchMode() {
private fun stopSearchMode(returnToKeyboard: Boolean = true) {
Log.d("EmojiSearch", "stopSearchMode")
if (!mInSearchMode) return
mInSearchMode = false

setupBottomRowKeyboard(null, mOriginalActionListener)
if (returnToKeyboard) {
setupBottomRowKeyboard(null, mOriginalActionListener)
} else {
// Do not take PointerTracker back from the panel that is replacing us.
findViewById<MainKeyboardView>(R.id.bottom_row_keyboard)?.setKeyboardActionListener(mOriginalActionListener)
}
setupCategoryTabs()

mEmojiCategoryPageIndicatorView?.visibility = View.GONE
Expand All @@ -677,8 +684,8 @@ class EmojiPalettesView @JvmOverloads constructor(
PointerTracker.setKeyboardActionListener(it)
}

if (isAttachedToWindow) {
KeyboardSwitcher.getInstance().setAlphabetKeyboard()
if (returnToKeyboard && isAttachedToWindow) {
KeyboardSwitcher.getInstance().returnToAlphabetKeyboard()
}

if (isInLayout) {
Expand Down Expand Up @@ -724,7 +731,7 @@ class EmojiPalettesView @JvmOverloads constructor(
editorInfo: EditorInfo?,
keyboardActionListener: KeyboardActionListener?
) {
stopSearchMode()
stopSearchMode(returnToKeyboard = false)
mEditorInfo = editorInfo
mKeyboardActionListener = keyboardActionListener ?: KeyboardActionListener.EMPTY_LISTENER
initialize()
Expand Down Expand Up @@ -760,11 +767,11 @@ class EmojiPalettesView @JvmOverloads constructor(

private fun setupBottomRowKeyboard(editorInfo: EditorInfo?, keyboardActionListener: KeyboardActionListener?) {
val keyboardView = findViewById<MainKeyboardView>(R.id.bottom_row_keyboard) ?: return
keyboardView.setKeyboardActionListener(keyboardActionListener)
if (!isAttachedToWindow) return

keyboardView.setKeyPreviewPopupEnabled(Settings.getValues().mKeyPreviewPopupOn)
val ei = editorInfo ?: mEditorInfo
keyboardView.setKeyboardActionListener(keyboardActionListener)

try {
PointerTracker.switchTo(keyboardView)
Expand Down Expand Up @@ -856,7 +863,7 @@ class EmojiPalettesView @JvmOverloads constructor(
if (!initialized) return

if (mInSearchMode) {
stopSearchMode()
stopSearchMode(returnToKeyboard = false)
}

getRecentsKeyboard().flushPendingRecentKeys()
Expand Down Expand Up @@ -1023,14 +1030,14 @@ class EmojiPalettesView @JvmOverloads constructor(

override fun setVisibility(visibility: Int) {
if (visibility != View.VISIBLE && mInSearchMode) {
stopSearchMode()
stopSearchMode(returnToKeyboard = false)
}
super.setVisibility(visibility)
}

override fun onDetachedFromWindow() {
if (mInSearchMode) {
stopSearchMode()
stopSearchMode(returnToKeyboard = false)
}
super.onDetachedFromWindow()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class KeyboardState(private val switchActions: SwitchActions) {
private var mode = Mode.ALPHABET
private var modeBeforeNumpad = Mode.ALPHABET
// ponytail: track active custom layout index, 0 means default
private var lastCustomIndex = 0
var lastCustomIndex = 0
private set
private var isSymbolShifted = false
private var prevMainKeyboardWasShiftLocked = false
private var prevSymbolsKeyboardWasShifted = false
Expand Down Expand Up @@ -249,7 +250,7 @@ class KeyboardState(private val switchActions: SwitchActions) {
}
}

private fun setAlphabetKeyboard(autoCapsFlags: Int, recapitalizeMode: RecapitalizeMode?) {
fun setAlphabetKeyboard(autoCapsFlags: Int, recapitalizeMode: RecapitalizeMode?) {
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "setAlphabetKeyboard: ${stateToString(autoCapsFlags, recapitalizeMode)}")
}
Expand Down
Loading
Loading