Skip to content

Commit

Permalink
feat: ignore Shift locke for space, number and symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
tumuyan authored and Bambooin committed Aug 5, 2022
1 parent 908637e commit d5ad817
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/src/main/java/com/osfans/trime/data/AppPrefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ class AppPrefs(
const val HOOK_CTRL_CV = "keyboard__hook_ctrl_cv"
const val HOOK_CTRL_LR = "keyboard__hook_ctrl_lr"
const val HOOK_CTRL_ZY = "keyboard__hook_ctrl_zy"
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 SOUND_ENABLED = "keyboard__key_sound"
const val SOUND_VOLUME = "keyboard__key_sound_volume"
Expand Down Expand Up @@ -252,6 +255,15 @@ class AppPrefs(
var hookCtrlZY: Boolean = false
get() = prefs.getPref(HOOK_CTRL_ZY, false)
private set
var hookShiftSpace: Boolean = false
get() = prefs.getPref(HOOK_SHIFT_SPACE, false)
private set
var hookShiftNum: Boolean = false
get() = prefs.getPref(HOOK_SHIFT_NUM, false)
private set
var hookShiftSymbol: Boolean = false
get() = prefs.getPref(HOOK_SHIFT_SYMBOL, false)
private set

var soundEnabled: Boolean = false
get() = prefs.getPref(SOUND_ENABLED, false)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/ime/core/Trime.java
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ public boolean shareText() {
private boolean hookKeyboard(int code, int mask) { // 編輯操作
final @Nullable InputConnection ic = getCurrentInputConnection();
if (ic == null) return false;
if (Event.hasModifier(mask, KeyEvent.META_CTRL_ON)) {
if (mask == KeyEvent.META_CTRL_ON) {

if (VERSION.SDK_INT >= VERSION_CODES.M) {
if (getPrefs().getKeyboard().getHookCtrlZY()) {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/osfans/trime/ime/keyboard/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,12 @@ public boolean setMetaOn(boolean on, boolean keyDown) {
// return setModifier(KeyEvent.META_FUNCTION_ON, on || keyDown);
// }

public boolean isOnlyShiftOn() {
if (mShiftKey != null && mShiftKey.isOn() && mModifierState == KeyEvent.META_SHIFT_ON)
return true;
return false;
}

public boolean resetShifted() {
if (mShiftKey != null && !mShiftKey.isOn()) return setModifier(KeyEvent.META_SHIFT_ON, false);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ private void detectAndSendKey(int index, int x, int y, long eventTime, KeyEventT
// TextEntryState.keyPressedAt(key, x, y);
final int[] codes = new int[MAX_NEARBY_KEYS];
Arrays.fill(codes, NOT_A_KEY);
getKeyIndices(x, y, codes);
// getKeyIndices(x, y, codes); // 这里实际上并没有生效
Timber.d("\t<TrimeInput>\tdetectAndSendKey()\tonEvent, code=%d, key.getEvent", code);
// 可以在这里把 mKeyboard.getModifer() 获取的修饰键状态写入event里
mKeyboardActionListener.onEvent(key.getEvent(type.ordinal()));
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,26 @@ class TextInputManager private constructor() :
}
KeyEvent.KEYCODE_PROG_RED -> trime.showColorDialog() // Color schemes
KeyEvent.KEYCODE_MENU -> trime.showOptionsDialog()
else -> onKey(event.code, event.mask or trime.keyboardSwitcher.currentKeyboard.modifer)
else -> {
if (event.mask == 0 && trime.keyboardSwitcher.currentKeyboard.isOnlyShiftOn) {
if (event.code == KeyEvent.KEYCODE_SPACE && prefs.keyboard.hookShiftSpace) {
onKey(event.code, 0)
return
} else if (event.code >= KeyEvent.KEYCODE_0 && event.code <= KeyEvent.KEYCODE_9 && prefs.keyboard.hookShiftNum) {
onKey(event.code, 0)
return
} else if (prefs.keyboard.hookShiftSymbol) {
if (event.code >= KeyEvent.KEYCODE_GRAVE && event.code <= KeyEvent.KEYCODE_SLASH ||
event.code == KeyEvent.KEYCODE_COMMA ||
event.code == KeyEvent.KEYCODE_PERIOD
) {
onKey(event.code, 0)
return
}
}
}
onKey(event.code, event.mask or trime.keyboardSwitcher.currentKeyboard.modifer)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@
<string name="keyboard__candidate_page_size">每页显示候选词数量</string>
<string name="copy_done">已复制</string>
<string name="delete_done">已删除</string>
<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-array name="keyboard__candidate_page_size_entries" >
<item name="10000">不超出候选栏</item>
<item name="10001">接近于候选栏</item>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@
<string name="keyboard__candidate_page_size">每頁顯示候選詞數量</string>
<string name="copy_done">已複製</string>
<string name="delete_done">已刪除</string>
<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-array name="keyboard__candidate_page_size_entries" >
<item name="10000">不超出候選欄</item>
<item name="10001">接近於候選欄</item>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
<string name="keyboard__candidate_page_size">Candidate item count for each page</string>
<string name="copy_done">Copied to clipboard!</string>
<string name="delete_done">Deleted</string>
<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-array name="keyboard__candidate_page_size_entries" >
<item name="10000">Less than candidate</item>
<item name="10001">close to candidate</item>
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/xml/keyboard_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@
android:title="@string/keyboard__hook_ctrl_zy"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:key="keyboard__hook_shift_space"
android:title="@string/keyboard__hook_shift_space"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:key="keyboard__hook_shift_num"
android:title="@string/keyboard__hook_shift_num"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:key="keyboard__hook_shift_symbol"
android:title="@string/keyboard__hook_shift_symbol"
app:iconSpaceReserved="false" />

</PreferenceCategory>

<PreferenceCategory
Expand Down

0 comments on commit d5ad817

Please sign in to comment.