|
24 | 24 | import com.osfans.trime.data.DataManager; |
25 | 25 | import com.osfans.trime.data.opencc.OpenCCDictManager; |
26 | 26 | import com.osfans.trime.data.schema.SchemaManager; |
27 | | -import java.io.BufferedReader; |
28 | | -import java.io.CharArrayWriter; |
29 | | -import java.io.File; |
30 | | -import java.io.FileReader; |
31 | | -import java.io.FileWriter; |
32 | | -import java.io.IOException; |
33 | | -import java.util.HashMap; |
34 | 27 | import java.util.Map; |
| 28 | +import kotlin.Pair; |
35 | 29 | import kotlinx.coroutines.channels.BufferOverflow; |
36 | 30 | import kotlinx.coroutines.flow.FlowKt; |
37 | 31 | import kotlinx.coroutines.flow.MutableSharedFlow; |
@@ -354,71 +348,11 @@ public static String getSchemaName() { |
354 | 348 |
|
355 | 349 | public static boolean selectSchema(String schemaId) { |
356 | 350 | Timber.d("Selecting schemaId=%s", schemaId); |
357 | | - overWriteSchema(schemaId); |
358 | 351 | boolean b = selectRimeSchema(schemaId); |
359 | 352 | getContexts(); |
360 | 353 | return b; |
361 | 354 | } |
362 | 355 |
|
363 | | - // 刷新当前输入方案 |
364 | | - public static void applySchemaChange() { |
365 | | - String schema_id = getCurrentRimeSchema(); |
366 | | - // 实测直接select_schema(schema_id)方案没有重新载入,切换到不存在的方案,再切回去(会产生1秒的额外耗时).需要找到更好的方法 |
367 | | - // 不发生覆盖则不生效 |
368 | | - if (overWriteSchema(schema_id)) { |
369 | | - selectRimeSchema("nill"); |
370 | | - selectRimeSchema(schema_id); |
371 | | - } |
372 | | - getContexts(); |
373 | | - } |
374 | | - // 临时修改scheme文件参数 |
375 | | - // 临时修改build后的scheme可以避免build过程的耗时 |
376 | | - // 另外实际上jni读入yaml、修改、导出的效率并不高 |
377 | | - private static boolean overWriteSchema(String schema_id) { |
378 | | - Map<String, String> map = new HashMap<>(); |
379 | | - String page_size = AppPrefs.defaultInstance().getKeyboard().getCandidatePageSize(); |
380 | | - Timber.d("overWriteSchema() page_size=" + page_size); |
381 | | - if (!page_size.equals("0")) { |
382 | | - map.put("page_size", page_size); |
383 | | - } |
384 | | - if (map.isEmpty()) return false; |
385 | | - return overWriteSchema(schema_id, map); |
386 | | - } |
387 | | - |
388 | | - private static boolean overWriteSchema(String schema_id, Map<String, String> map) { |
389 | | - if (schema_id == null) schema_id = getCurrentRimeSchema(); |
390 | | - File file = |
391 | | - new File(Rime.getRimeUserDataDir() + File.separator + "build", schema_id + ".schema.yaml"); |
392 | | - try { |
393 | | - FileReader in = new FileReader(file); |
394 | | - BufferedReader bufIn = new BufferedReader(in); |
395 | | - CharArrayWriter tempStream = new CharArrayWriter(); |
396 | | - String line = null; |
397 | | - read: |
398 | | - while ((line = bufIn.readLine()) != null) { |
399 | | - for (String k : map.keySet()) { |
400 | | - String key = k + ": "; |
401 | | - if (line.contains(key)) { |
402 | | - String value = ": " + map.get(k) + System.getProperty("line.separator"); |
403 | | - tempStream.write(line.replaceFirst(":.+", value)); |
404 | | - map.remove(k); |
405 | | - continue read; |
406 | | - } |
407 | | - } |
408 | | - tempStream.write(line); |
409 | | - tempStream.append(System.getProperty("line.separator")); |
410 | | - } |
411 | | - bufIn.close(); |
412 | | - FileWriter out = new FileWriter(file); |
413 | | - tempStream.writeTo(out); |
414 | | - out.close(); |
415 | | - } catch (IOException e) { |
416 | | - e.printStackTrace(); |
417 | | - return false; |
418 | | - } |
419 | | - return map.isEmpty(); |
420 | | - } |
421 | | - |
422 | 356 | public static Rime get(boolean full_check) { |
423 | 357 | if (self == null) { |
424 | 358 | if (full_check) { |
@@ -491,6 +425,9 @@ public static native boolean deployRimeConfigFile( |
491 | 425 | public static native Map<String, Object> getRimeConfigMap( |
492 | 426 | @NonNull String configId, @NonNull String key); |
493 | 427 |
|
| 428 | + public static native void setRimeCustomConfigInt( |
| 429 | + @NonNull String configId, @NonNull Pair<String, Integer>[] keyValuePairs); |
| 430 | + |
494 | 431 | // testing |
495 | 432 | public static native boolean simulateKeySequence(@NonNull String keySequence); |
496 | 433 |
|
|
0 commit comments