19
19
package com .osfans .trime ;
20
20
21
21
import android .content .Context ;
22
+ import android .text .TextUtils ;
22
23
import androidx .annotation .NonNull ;
23
24
import com .osfans .trime .ime .core .Trime ;
24
25
import com .osfans .trime .setup .Config ;
26
+ import com .osfans .trime .util .DataUtils ;
25
27
import java .io .File ;
26
28
import java .util .ArrayList ;
27
29
import java .util .HashMap ;
@@ -279,7 +281,7 @@ public static String getComposingText() {
279
281
}
280
282
281
283
public Rime (Context context , boolean full_check ) {
282
- init (context , full_check );
284
+ init (full_check );
283
285
self = this ;
284
286
}
285
287
@@ -296,12 +298,15 @@ private static boolean getStatus() {
296
298
return get_status (mStatus );
297
299
}
298
300
299
- private static void init (Context context , boolean full_check ) {
301
+ private static void init (boolean full_check ) {
300
302
mOnMessage = false ;
301
303
304
+ final String sharedDataDir = DataUtils .getSharedDataDir ();
305
+ final String userDataDir = DataUtils .getUserDataDir ();
306
+
302
307
// Initialize librime APIs
303
- setup (Config . get ( context ). getSharedDataDir (), Config . get ( context ). getUserDataDir () );
304
- initialize (Config . get ( context ). getSharedDataDir (), Config . get ( context ). getUserDataDir () );
308
+ setup (sharedDataDir , userDataDir );
309
+ initialize (sharedDataDir , userDataDir );
305
310
306
311
check (full_check );
307
312
set_notification_handler ();
@@ -490,7 +495,7 @@ public static boolean selectSchema(int id) {
490
495
491
496
public static Rime get (Context context , boolean full_check ) {
492
497
if (self == null ) {
493
- if (full_check ) Config .deployOpencc (context );
498
+ if (full_check ) Config .deployOpencc ();
494
499
self = new Rime (context , full_check );
495
500
}
496
501
return self ;
@@ -517,31 +522,26 @@ public static void RimeSetCaretPos(int caret_pos) {
517
522
public static void onMessage (String message_type , String message_value ) {
518
523
mOnMessage = true ;
519
524
Timber .i ("message: [%s] %s" , message_type , message_value );
520
- Trime trime = Trime .getService ();
525
+ final Trime trime = Trime .getService ();
521
526
switch (message_type ) {
522
527
case "schema" :
523
528
initSchema ();
524
- if (trime != null ) {
525
- trime .initKeyboard ();
526
- }
529
+ trime .initKeyboard ();
527
530
break ;
528
531
case "option" :
529
532
getStatus ();
530
533
getContexts (); // 切換中英文、簡繁體時更新候選
531
- if (trime != null ) {
532
- boolean value = !message_value .startsWith ("!" );
533
- String option = message_value .substring (value ? 0 : 1 );
534
- trime .onOptionChanged (option , value );
535
- }
534
+ final boolean value = !message_value .startsWith ("!" );
535
+ final String option = message_value .substring (value ? 0 : 1 );
536
+ trime .onOptionChanged (option , value );
536
537
break ;
537
538
}
538
539
mOnMessage = false ;
539
540
}
540
541
541
542
public static String openccConvert (String line , String name ) {
542
- if (name != null && name .length () > 0 ) {
543
- Trime trime = Trime .getService ();
544
- File f = new File (Config .get (trime ).getResDataDir ("opencc" ), name );
543
+ if (!TextUtils .isEmpty (name )) {
544
+ final File f = new File (DataUtils .getAssetsDir ("opencc" ), name );
545
545
if (f .exists ()) return opencc_convert (line , f .getAbsolutePath ());
546
546
}
547
547
return line ;
0 commit comments