Skip to content

Commit 7a9a691

Browse files
committed
fix: wrong key background
1 parent 3d0c03d commit 7a9a691

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

app/src/main/java/com/osfans/trime/ime/keyboard/Key.java

+22-11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.osfans.trime.data.Config;
2929
import com.osfans.trime.ime.enums.KeyEventType;
3030
import com.osfans.trime.util.ConfigGetter;
31+
import java.text.MessageFormat;
32+
import java.util.Arrays;
3133
import java.util.Locale;
3234
import java.util.Map;
3335
import timber.log.Timber;
@@ -48,13 +50,14 @@ public class Key {
4850
public static final int[] KEY_STATE_PRESSED = {android.R.attr.state_pressed};
4951
public static final int[][] KEY_STATES =
5052
new int[][] {
51-
KEY_STATE_PRESSED_ON, // 0
52-
KEY_STATE_PRESSED_OFF, // 1
53-
KEY_STATE_NORMAL_ON, // 2
54-
KEY_STATE_NORMAL_OFF, // 3
55-
KEY_STATE_PRESSED, // 4
56-
KEY_STATE_NORMAL // 5
53+
KEY_STATE_PRESSED_ON, // 0 "hilited_on_key_back_color" 锁定时按下的背景
54+
KEY_STATE_PRESSED_OFF, // 1 "hilited_off_key_back_color" 功能键按下的背景
55+
KEY_STATE_NORMAL_ON, // 2 "on_key_back_color" 锁定时背景
56+
KEY_STATE_NORMAL_OFF, // 3 "off_key_back_color" 功能键背景
57+
KEY_STATE_PRESSED, // 4 "hilited_key_back_color" 按键按下的背景
58+
KEY_STATE_NORMAL // 5 "key_back_color" 按键背景
5759
};
60+
5861
public static Map<String, Map<String, String>> presetKeys;
5962
private static final int EVENT_NUM = KeyEventType.values().length;
6063
public Event[] events = new Event[EVENT_NUM];
@@ -321,9 +324,7 @@ public int getKey_offset_y() {
321324
}
322325

323326
private boolean isNormal(int[] drawableState) {
324-
return (drawableState == KEY_STATE_NORMAL
325-
|| drawableState == KEY_STATE_NORMAL_ON
326-
|| drawableState == KEY_STATE_NORMAL_OFF);
327+
return (drawableState == KEY_STATE_NORMAL || drawableState == KEY_STATE_NORMAL_OFF);
327328
}
328329

329330
public Drawable getBackColorForState(int[] drawableState) {
@@ -428,8 +429,6 @@ public void printModifierKeyState() {
428429
public int[] getCurrentDrawableState() {
429430
int[] states = KEY_STATE_NORMAL;
430431
boolean isShifted = isTrimeModifierKey() && mKeyboard.hasModifier(getModifierKeyOnMask());
431-
// only for modiferKey debug
432-
if (isTrimeModifierKey()) mKeyboard.printModifierKeyState("getCurrentDrawableState");
433432

434433
if (isShifted || on) {
435434
if (pressed) {
@@ -450,6 +449,18 @@ public int[] getCurrentDrawableState() {
450449
}
451450
}
452451
}
452+
453+
// only for modiferKey debug
454+
if (isTrimeModifierKey())
455+
mKeyboard.printModifierKeyState(
456+
MessageFormat.format(
457+
"getCurrentDrawableState() Key={0} states={1} on={2} isShifted={3} pressed={4} sticky={5}",
458+
getLabel(),
459+
Arrays.asList(KEY_STATES).indexOf(states),
460+
on,
461+
isShifted,
462+
pressed,
463+
getClick().isSticky()));
453464
return states;
454465
}
455466

app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.java

+1
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ private void onBufferDraw() {
897897
int[] drawableState = key.getCurrentDrawableState();
898898
keyBackground = key.getBackColorForState(drawableState);
899899
if (keyBackground == null) {
900+
Timber.i("onBufferDraw() keyBackground==null, key=%s", key.getLabel());
900901
try {
901902
final int index = (int) findStateDrawableIndex.invoke(mKeyBackColor, drawableState);
902903
keyBackground = (Drawable) getStateDrawable.invoke(mKeyBackColor, index);

0 commit comments

Comments
 (0)