Skip to content

Commit

Permalink
feat: add switch to not reset shift state for arrow keys
Browse files Browse the repository at this point in the history
  • Loading branch information
if-can committed Jan 9, 2025
1 parent 13589b8 commit 257cdca
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/osfans/trime/data/prefs/AppPrefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class AppPrefs(
const val HOOK_SHIFT_SPACE = "keyboard__hook_shift_space"
const val HOOK_SHIFT_NUM = "keyboard__hook_shift_num"
const val HOOK_SHIFT_SYMBOL = "keyboard__hook_shift_symbol"
const val HOOK_SHIFT_ARROW = "keyboard__hook_shift_arrow"

const val SOUND_ENABLED = "keyboard__key_sound"
const val SOUND_VOLUME = "keyboard__key_sound_volume"
Expand Down Expand Up @@ -165,6 +166,7 @@ class AppPrefs(
val hookShiftSpace by bool(HOOK_SHIFT_SPACE, false)
val hookShiftNum by bool(HOOK_SHIFT_NUM, false)
val hookShiftSymbol by bool(HOOK_SHIFT_SYMBOL, false)
val hookShiftArrow by bool(HOOK_SHIFT_ARROW, true)

val soundEnabled by bool(SOUND_ENABLED, false)
var customSoundEnabled by bool(CUSTOM_SOUND_ENABLED, false)
Expand Down
21 changes: 19 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.graphics.drawable.StateListDrawable
import android.os.SystemClock
import android.view.GestureDetector
import android.view.GestureDetector.SimpleOnGestureListener
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import androidx.lifecycle.findViewTreeLifecycleOwner
Expand Down Expand Up @@ -681,6 +682,18 @@ class KeyboardView(
}
}

private val hookShiftArrow get() = AppPrefs.defaultInstance().keyboard.hookShiftArrow

fun isHookShiftArrow(keyCode: Int): Boolean {
if (!hookShiftArrow) return false

return when (keyCode) {
in KeyEvent.KEYCODE_DPAD_UP..KeyEvent.KEYCODE_DPAD_RIGHT -> true
KeyEvent.KEYCODE_MOVE_HOME, KeyEvent.KEYCODE_MOVE_END -> true
else -> false
}
}

private fun detectAndSendKey(
index: Int,
x: Int,
Expand All @@ -707,7 +720,9 @@ class KeyboardView(
key.getAction(behavior)?.let { keyboardActionListener?.onAction(it) }
releaseKey(code)
Timber.d("detectAndSendKey: refreshModifier")
refreshModifier()
if (!isHookShiftArrow(code)) {
refreshModifier()
}
}
mLastSentIndex = index
mLastTapTime = eventTime
Expand Down Expand Up @@ -802,7 +817,9 @@ class KeyboardView(
mAbortKey = true
keyboardActionListener?.onAction(it)
releaseKey(it.code)
refreshModifier()
if (!isHookShiftArrow(it.code)) {
refreshModifier()
}
return true
}
Timber.w("only set isShifted, no others modifierkey")
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="keyboard__hook_shift_space">点击空格时,忽略Shift的锁定状态</string>
<string name="keyboard__hook_shift_num">点击0-9时,忽略Shift的锁定状态</string>
<string name="keyboard__hook_shift_symbol">点击符号键时,忽略Shift的锁定状态</string>
<string name="keyboard__hook_shift_arrow">点击方向键时,不重置Shift的锁定状态</string>
<string name="toolkit">工具箱</string>
<string name="export">导出</string>
<string name="scroll_to_bottom">跳到最后</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="keyboard__hook_shift_space">點擊空格時,忽略Shift的鎖定狀態</string>
<string name="keyboard__hook_shift_num">點擊0-9時,忽略Shift的鎖定狀態</string>
<string name="keyboard__hook_shift_symbol">點擊符號鍵時,忽略Shift的鎖定狀態</string>
<string name="keyboard__hook_shift_arrow">點選方向鍵時,不重置Shift的鎖定狀態</string>
<string name="export">匯出</string>
<string name="scroll_to_bottom">跳到最後</string>
<string name="app_crash_message">抱歉,但我們為您帶來了一些紀錄檔以供調查。</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="keyboard__hook_shift_space">Ignore Shift locked for Space</string>
<string name="keyboard__hook_shift_num">Ignore Shift locked for 0-9</string>
<string name="keyboard__hook_shift_symbol">Ignore Shift locked for Symbol keys</string>
<string name="keyboard__hook_shift_arrow">Not reset Shift state for arrow keys</string>
<string name="exception_logcat_created">Logcat process is already created</string>
<string name="app_crash">Application crashed</string>
<string name="app_crash_message">Sorry, but we bring you some logs to investigate.</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/keyboard_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
android:title="@string/keyboard__hook_shift_symbol"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:key="keyboard__hook_shift_arrow"
android:title="@string/keyboard__hook_shift_arrow"
android:defaultValue="true"
app:iconSpaceReserved="false" />
</PreferenceCategory>

<PreferenceCategory
Expand Down

0 comments on commit 257cdca

Please sign in to comment.