28
28
import com .osfans .trime .data .Config ;
29
29
import com .osfans .trime .ime .enums .KeyEventType ;
30
30
import com .osfans .trime .util .ConfigGetter ;
31
+ import java .util .Locale ;
31
32
import java .util .Map ;
32
33
import timber .log .Timber ;
33
34
@@ -62,10 +63,7 @@ public class Key {
62
63
private static String symbols ;
63
64
private static final KeyCharacterMap kcm = KeyCharacterMap .load (KeyCharacterMap .VIRTUAL_KEYBOARD );
64
65
private final Keyboard mKeyboard ;
65
- private Event ascii ;
66
- private Event composing ;
67
- private Event has_menu ;
68
- private Event paging ;
66
+
69
67
private boolean send_bindings = true ;
70
68
private int width ;
71
69
private int height ;
@@ -117,34 +115,29 @@ public Key(Context context, Keyboard parent, Map<String, Object> mk) {
117
115
this (parent );
118
116
String s ;
119
117
Config config = Config .get (context );
120
- for (int i = 0 ; i < EVENT_NUM ; i ++) {
121
- String [] eventTypes =
122
- new String [] {
123
- "click" , "long_click" , "swipe_left" , "swipe_right" , "swipe_up" , "swipe_down" , "combo"
124
- };
125
- String eventType = eventTypes [i ];
126
- s = Config .getString (mk , eventType );
127
- if (!TextUtils .isEmpty (s )) events [i ] = new Event (mKeyboard , s );
128
- else if (i == KeyEventType .CLICK .ordinal ()) events [i ] = new Event (mKeyboard , "" );
129
- }
130
- s = ConfigGetter .getString (mk , "composing" , "" );
131
- if (!TextUtils .isEmpty (s )) composing = new Event (mKeyboard , s );
132
- s = ConfigGetter .getString (mk , "has_menu" , "" );
133
- if (!TextUtils .isEmpty (s )) has_menu = new Event (mKeyboard , s );
134
- s = ConfigGetter .getString (mk , "paging" , "" );
135
- if (!TextUtils .isEmpty (s )) paging = new Event (mKeyboard , s );
136
- if (composing != null || has_menu != null || paging != null )
137
- mKeyboard .getmComposingKeys ().add (this );
138
- s = ConfigGetter .getString (mk , "ascii" , "" );
139
- if (!TextUtils .isEmpty (s )) ascii = new Event (mKeyboard , s );
140
- label = ConfigGetter .getString (mk , "label" , "" );
141
- labelSymbol = ConfigGetter .getString (mk , "label_symbol" , "" );
142
- hint = ConfigGetter .getString (mk , "hint" , "" );
143
- if (mk .containsKey ("send_bindings" )) {
144
- send_bindings = ConfigGetter .getBoolean (mk , "send_bindings" , true );
145
- } else if (composing == null && has_menu == null && paging == null ) {
146
- send_bindings = false ;
118
+ {
119
+ boolean hasComposingKey = false ;
120
+
121
+ for (int i = 0 ; i < EVENT_NUM - 1 ; i ++) {
122
+ String eventType = (KeyEventType .Companion .valueOf (i )).toString ().toLowerCase (Locale .ROOT );
123
+ s = ConfigGetter .getString (mk , eventType , "" );
124
+ if (!TextUtils .isEmpty (s )) {
125
+ events [i ] = new Event (mKeyboard , s );
126
+ if (i < KeyEventType .COMBO .ordinal ()) hasComposingKey = true ;
127
+ } else if (i == KeyEventType .CLICK .ordinal ()) events [i ] = new Event (mKeyboard , "" );
128
+ }
129
+ if (hasComposingKey ) mKeyboard .getComposingKeys ().add (this );
130
+
131
+ label = ConfigGetter .getString (mk , "label" , "" );
132
+ labelSymbol = ConfigGetter .getString (mk , "label_symbol" , "" );
133
+ hint = ConfigGetter .getString (mk , "hint" , "" );
134
+ if (mk .containsKey ("send_bindings" )) {
135
+ send_bindings = ConfigGetter .getBoolean (mk , "send_bindings" , true );
136
+ } else if (!hasComposingKey ) {
137
+ send_bindings = false ;
138
+ }
147
139
}
140
+
148
141
mKeyboard .setModiferKey (getCode (), this );
149
142
key_text_size = ConfigGetter .getPixel (mk , "key_text_size" , 0 );
150
143
symbol_text_size = ConfigGetter .getPixel (mk , "symbol_text_size" , 0 );
@@ -534,22 +527,26 @@ public boolean isShiftLock() {
534
527
*/
535
528
public boolean sendBindings (int type ) {
536
529
Event e = null ;
537
- if (type > 0 && type <= EVENT_NUM ) e = events [type ];
530
+ if (type != KeyEventType . CLICK . ordinal () && type >= 0 && type <= EVENT_NUM ) e = events [type ];
538
531
if (e != null ) return true ;
539
- if (ascii != null && Rime .isAsciiMode ()) return false ;
532
+ if (events [ KeyEventType . ASCII . ordinal ()] != null && Rime .isAsciiMode ()) return false ;
540
533
if (send_bindings ) {
541
- if (paging != null && Rime .isPaging ()) return true ;
542
- if (has_menu != null && Rime .hasMenu ()) return true ;
543
- if (composing != null && Rime .isComposing ()) return true ;
534
+ if (events [ KeyEventType . PAGING . ordinal ()] != null && Rime .isPaging ()) return true ;
535
+ if (events [ KeyEventType . HAS_MENU . ordinal ()] != null && Rime .hasMenu ()) return true ;
536
+ if (events [ KeyEventType . COMPOSING . ordinal ()] != null && Rime .isComposing ()) return true ;
544
537
}
545
538
return false ;
546
539
}
547
540
548
541
private Event getEvent () {
549
- if (ascii != null && Rime .isAsciiMode ()) return ascii ;
550
- if (paging != null && Rime .isPaging ()) return paging ;
551
- if (has_menu != null && Rime .hasMenu ()) return has_menu ;
552
- if (composing != null && Rime .isComposing ()) return composing ;
542
+ if (events [KeyEventType .ASCII .ordinal ()] != null && Rime .isAsciiMode ())
543
+ return events [KeyEventType .ASCII .ordinal ()];
544
+ if (events [KeyEventType .PAGING .ordinal ()] != null && Rime .isPaging ())
545
+ return events [KeyEventType .PAGING .ordinal ()];
546
+ if (events [KeyEventType .HAS_MENU .ordinal ()] != null && Rime .hasMenu ())
547
+ return events [KeyEventType .HAS_MENU .ordinal ()];
548
+ if (events [KeyEventType .COMPOSING .ordinal ()] != null && Rime .isComposing ())
549
+ return events [KeyEventType .COMPOSING .ordinal ()];
553
550
return getClick ();
554
551
}
555
552
@@ -567,13 +564,17 @@ public boolean hasEvent(int i) {
567
564
568
565
public Event getEvent (int i ) {
569
566
Event e = null ;
570
- if (i > 0 && i <= EVENT_NUM ) e = events [i ];
567
+ if (i != KeyEventType . CLICK . ordinal () && i >= 0 && i <= EVENT_NUM ) e = events [i ];
571
568
if (e != null ) return e ;
572
- if (ascii != null && Rime .isAsciiMode ()) return ascii ;
569
+ if (events [KeyEventType .ASCII .ordinal ()] != null && Rime .isAsciiMode ())
570
+ return events [KeyEventType .ASCII .ordinal ()];
573
571
if (send_bindings ) {
574
- if (paging != null && Rime .isPaging ()) return paging ;
575
- if (has_menu != null && Rime .hasMenu ()) return has_menu ;
576
- if (composing != null && Rime .isComposing ()) return composing ;
572
+ if (events [KeyEventType .PAGING .ordinal ()] != null && Rime .isPaging ())
573
+ return events [KeyEventType .PAGING .ordinal ()];
574
+ if (events [KeyEventType .HAS_MENU .ordinal ()] != null && Rime .hasMenu ())
575
+ return events [KeyEventType .HAS_MENU .ordinal ()];
576
+ if (events [KeyEventType .COMPOSING .ordinal ()] != null && Rime .isComposing ())
577
+ return events [KeyEventType .COMPOSING .ordinal ()];
577
578
}
578
579
return getClick ();
579
580
}
@@ -588,7 +589,9 @@ public int getCode(int type) {
588
589
589
590
public String getLabel () {
590
591
Event event = getEvent ();
591
- if (!TextUtils .isEmpty (label ) && event == getClick () && (ascii == null && !Rime .isAsciiMode ()))
592
+ if (!TextUtils .isEmpty (label )
593
+ && event == getClick ()
594
+ && (events [KeyEventType .ASCII .ordinal ()] == null && !Rime .isAsciiMode ()))
592
595
return label ; // 中文狀態顯示標籤
593
596
return event .getLabel ();
594
597
}
0 commit comments