Skip to content

Commit e3c850c

Browse files
committed
chore(util): rename YamlUtils to ConfigGetter
Also mark JvmStatic annotations so Java parts can access these static method directly instead of by ugly `INSTANCE`
1 parent 269522b commit e3c850c

File tree

8 files changed

+79
-72
lines changed

8 files changed

+79
-72
lines changed

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

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import androidx.annotation.NonNull;
2424
import com.osfans.trime.core.Rime;
2525
import com.osfans.trime.setup.Config;
26-
import com.osfans.trime.util.YamlUtils;
26+
import com.osfans.trime.util.ConfigGetter;
2727
import java.util.HashMap;
2828
import java.util.List;
2929
import java.util.Locale;
@@ -71,15 +71,15 @@ public Event(Keyboard keyboard, @NonNull String s) {
7171
if (Key.presetKeys.containsKey(s)) {
7272
// todo 把presetKeys缓存为presetKeyEvents,减少重新载入
7373
Map<String, ?> presetKey = Key.presetKeys.get(s);
74-
command = YamlUtils.INSTANCE.getString(presetKey, "command", "");
75-
option = YamlUtils.INSTANCE.getString(presetKey, "option", "");
76-
select = YamlUtils.INSTANCE.getString(presetKey, "select", "");
77-
toggle = YamlUtils.INSTANCE.getString(presetKey, "toggle", "");
78-
label = YamlUtils.INSTANCE.getString(presetKey, "label", "");
79-
preview = YamlUtils.INSTANCE.getString(presetKey, "preview", "");
80-
shiftLock = YamlUtils.INSTANCE.getString(presetKey, "shift_lock", "");
81-
commit = YamlUtils.INSTANCE.getString(presetKey, "commit", "");
82-
String send = YamlUtils.INSTANCE.getString(presetKey, "send", "");
74+
command = ConfigGetter.getString(presetKey, "command", "");
75+
option = ConfigGetter.getString(presetKey, "option", "");
76+
select = ConfigGetter.getString(presetKey, "select", "");
77+
toggle = ConfigGetter.getString(presetKey, "toggle", "");
78+
label = ConfigGetter.getString(presetKey, "label", "");
79+
preview = ConfigGetter.getString(presetKey, "preview", "");
80+
shiftLock = ConfigGetter.getString(presetKey, "shift_lock", "");
81+
commit = ConfigGetter.getString(presetKey, "commit", "");
82+
String send = ConfigGetter.getString(presetKey, "send", "");
8383
if (TextUtils.isEmpty(send) && !TextUtils.isEmpty(command))
8484
send = "function"; // command默認發function
8585
int[] sends = parseSend(send);
@@ -89,9 +89,9 @@ public Event(Keyboard keyboard, @NonNull String s) {
8989
text = Config.getString(presetKey, "text");
9090
if (code < 0 && TextUtils.isEmpty(text)) text = s;
9191
if (presetKey.containsKey("states")) states = (List<?>) presetKey.get("states");
92-
sticky = YamlUtils.INSTANCE.getBoolean(presetKey, "sticky", false);
93-
repeatable = YamlUtils.INSTANCE.getBoolean(presetKey, "repeatable", false);
94-
functional = YamlUtils.INSTANCE.getBoolean(presetKey, "functional", true);
92+
sticky = ConfigGetter.getBoolean(presetKey, "sticky", false);
93+
repeatable = ConfigGetter.getBoolean(presetKey, "repeatable", false);
94+
functional = ConfigGetter.getBoolean(presetKey, "functional", true);
9595
} else if ((code = getClickCode(s)) >= 0) {
9696
parseLabel();
9797
} else {

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.osfans.trime.core.Rime;
2828
import com.osfans.trime.ime.enums.KeyEventType;
2929
import com.osfans.trime.setup.Config;
30-
import com.osfans.trime.util.YamlUtils;
30+
import com.osfans.trime.util.ConfigGetter;
3131
import java.util.List;
3232
import java.util.Map;
3333
import timber.log.Timber;
@@ -129,34 +129,34 @@ public Key(Context context, Keyboard parent, Map<String, Object> mk) {
129129
if (!TextUtils.isEmpty(s)) events[i] = new Event(mKeyboard, s);
130130
else if (i == KeyEventType.CLICK.ordinal()) events[i] = new Event(mKeyboard, "");
131131
}
132-
s = YamlUtils.INSTANCE.getString(mk, "composing", "");
132+
s = ConfigGetter.getString(mk, "composing", "");
133133
if (!TextUtils.isEmpty(s)) composing = new Event(mKeyboard, s);
134-
s = YamlUtils.INSTANCE.getString(mk, "has_menu", "");
134+
s = ConfigGetter.getString(mk, "has_menu", "");
135135
if (!TextUtils.isEmpty(s)) has_menu = new Event(mKeyboard, s);
136-
s = YamlUtils.INSTANCE.getString(mk, "paging", "");
136+
s = ConfigGetter.getString(mk, "paging", "");
137137
if (!TextUtils.isEmpty(s)) paging = new Event(mKeyboard, s);
138138
if (composing != null || has_menu != null || paging != null)
139139
mKeyboard.getmComposingKeys().add(this);
140-
s = YamlUtils.INSTANCE.getString(mk, "ascii", "");
140+
s = ConfigGetter.getString(mk, "ascii", "");
141141
if (!TextUtils.isEmpty(s)) ascii = new Event(mKeyboard, s);
142-
label = YamlUtils.INSTANCE.getString(mk, "label", "");
143-
labelSymbol = YamlUtils.INSTANCE.getString(mk, "label_symbol", "");
144-
hint = YamlUtils.INSTANCE.getString(mk, "hint", "");
142+
label = ConfigGetter.getString(mk, "label", "");
143+
labelSymbol = ConfigGetter.getString(mk, "label_symbol", "");
144+
hint = ConfigGetter.getString(mk, "hint", "");
145145
if (mk.containsKey("send_bindings")) {
146-
send_bindings = YamlUtils.INSTANCE.getBoolean(mk, "send_bindings", true);
146+
send_bindings = ConfigGetter.getBoolean(mk, "send_bindings", true);
147147
} else if (composing == null && has_menu == null && paging == null) {
148148
send_bindings = false;
149149
}
150150
mKeyboard.setModiferKey(getCode(), this);
151-
key_text_size = YamlUtils.INSTANCE.getPixel(mk, "key_text_size", 0);
152-
symbol_text_size = YamlUtils.INSTANCE.getPixel(mk, "symbol_text_size", 0);
151+
key_text_size = ConfigGetter.getPixel(mk, "key_text_size", 0);
152+
symbol_text_size = ConfigGetter.getPixel(mk, "symbol_text_size", 0);
153153
key_text_color = Config.getColor(context, mk, "key_text_color");
154154
hilited_key_text_color = Config.getColor(context, mk, "hilited_key_text_color");
155155
key_back_color = config.getDrawable(mk, "key_back_color");
156156
hilited_key_back_color = config.getDrawable(mk, "hilited_key_back_color");
157157
key_symbol_color = Config.getColor(context, mk, "key_symbol_color");
158158
hilited_key_symbol_color = Config.getColor(context, mk, "hilited_key_symbol_color");
159-
round_corner = YamlUtils.INSTANCE.getFloat(mk, "round_corner", 0);
159+
round_corner = ConfigGetter.getFloat(mk, "round_corner", 0);
160160
}
161161

162162
public static List<String> getAndroidKeys() {

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

+35-35
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import android.view.KeyEvent;
2626
import androidx.annotation.NonNull;
2727
import com.osfans.trime.setup.Config;
28-
import com.osfans.trime.util.YamlUtils;
28+
import com.osfans.trime.util.ConfigGetter;
2929
import java.util.ArrayList;
3030
import java.util.List;
3131
import java.util.Map;
@@ -195,33 +195,33 @@ public Keyboard(Context context, String name) {
195195
== Configuration.ORIENTATION_LANDSCAPE);
196196
Config config = Config.get(context);
197197
final Map<String, ?> keyboardConfig = config.getKeyboard(name);
198-
mLabelTransform = YamlUtils.INSTANCE.getString(keyboardConfig, "label_transform", "none");
199-
mAsciiMode = YamlUtils.INSTANCE.getInt(keyboardConfig, "ascii_mode", 1);
198+
mLabelTransform = ConfigGetter.getString(keyboardConfig, "label_transform", "none");
199+
mAsciiMode = ConfigGetter.getInt(keyboardConfig, "ascii_mode", 1);
200200
if (mAsciiMode == 0)
201-
mAsciiKeyboard = YamlUtils.INSTANCE.getString(keyboardConfig, "ascii_keyboard", "");
202-
resetAsciiMode = YamlUtils.INSTANCE.getBoolean(keyboardConfig, "reset_ascii_mode", false);
203-
mLock = YamlUtils.INSTANCE.getBoolean(keyboardConfig, "lock", false);
204-
int columns = YamlUtils.INSTANCE.getInt(keyboardConfig, "columns", 30);
201+
mAsciiKeyboard = ConfigGetter.getString(keyboardConfig, "ascii_keyboard", "");
202+
resetAsciiMode = ConfigGetter.getBoolean(keyboardConfig, "reset_ascii_mode", false);
203+
mLock = ConfigGetter.getBoolean(keyboardConfig, "lock", false);
204+
int columns = ConfigGetter.getInt(keyboardConfig, "columns", 30);
205205
int defaultWidth =
206-
(int) (YamlUtils.INSTANCE.getDouble(keyboardConfig, "width", 0d) * mDisplayWidth / 100);
206+
(int) (ConfigGetter.getDouble(keyboardConfig, "width", 0d) * mDisplayWidth / 100);
207207
if (defaultWidth == 0) defaultWidth = mDefaultWidth;
208208

209209
// 按键高度取值顺序: keys > keyboard/height > style/key_height
210210
// 考虑到key设置height_land需要对皮肤做大量修改,而当部分key设置height而部分没有设时会造成按键高度异常,故取消普通按键的height_land参数
211-
int height = YamlUtils.INSTANCE.getPixel(keyboardConfig, "height", 0);
211+
int height = ConfigGetter.getPixel(keyboardConfig, "height", 0);
212212
int defaultHeight = (height > 0) ? height : mDefaultHeight;
213213
int rowHeight = defaultHeight;
214-
autoHeightIndex = YamlUtils.INSTANCE.getInt(keyboardConfig, "auto_height_index", -1);
214+
autoHeightIndex = ConfigGetter.getInt(keyboardConfig, "auto_height_index", -1);
215215
List<Map<String, Object>> lm = (List<Map<String, Object>>) keyboardConfig.get("keys");
216216

217217
mDefaultHorizontalGap =
218-
YamlUtils.INSTANCE.getPixel(
218+
ConfigGetter.getPixel(
219219
keyboardConfig, "horizontal_gap", config.getFloat("horizontal_gap", 3));
220220
mDefaultVerticalGap =
221-
YamlUtils.INSTANCE.getPixel(
221+
ConfigGetter.getPixel(
222222
keyboardConfig, "vertical_gap", config.getFloat("vertical_gap", 5));
223223
mRoundCorner =
224-
YamlUtils.INSTANCE.getFloat(
224+
ConfigGetter.getFloat(
225225
keyboardConfig, "round_corner", config.getFloat("round_corner", 5));
226226

227227
Drawable background = config.getDrawable(keyboardConfig, "keyboard_back_color");
@@ -238,10 +238,10 @@ public Keyboard(Context context, String name) {
238238
int[] newHeight = new int[0];
239239

240240
if (keyboardHeight > 0) {
241-
int mkeyboardHeight = YamlUtils.INSTANCE.getPixel(keyboardConfig, "keyboard_height", 0);
241+
int mkeyboardHeight = ConfigGetter.getPixel(keyboardConfig, "keyboard_height", 0);
242242
if (land) {
243243
int mkeyBoardHeightLand =
244-
YamlUtils.INSTANCE.getPixel(keyboardConfig, "keyboard_height_land", 0);
244+
ConfigGetter.getPixel(keyboardConfig, "keyboard_height_land", 0);
245245
if (mkeyBoardHeightLand > 0) mkeyboardHeight = mkeyBoardHeightLand;
246246
}
247247

@@ -251,7 +251,7 @@ public Keyboard(Context context, String name) {
251251
List<Integer> rawHeight = new ArrayList<>();
252252
for (Map<String, Object> mk : lm) {
253253
int gap = mDefaultHorizontalGap;
254-
int w = (int) (YamlUtils.INSTANCE.getDouble(mk, "width", 0) * mDisplayWidth / 100);
254+
int w = (int) (ConfigGetter.getDouble(mk, "width", 0) * mDisplayWidth / 100);
255255
if (w == 0 && mk.containsKey("click")) w = defaultWidth;
256256
w -= gap;
257257
if (column >= maxColumns || x + w > mDisplayWidth) {
@@ -263,7 +263,7 @@ public Keyboard(Context context, String name) {
263263
rawHeight.add(rowHeight);
264264
}
265265
if (column == 0) {
266-
int heightK = YamlUtils.INSTANCE.getPixel(mk, "height", 0);
266+
int heightK = ConfigGetter.getPixel(mk, "height", 0);
267267
rowHeight = (heightK > 0) ? heightK : defaultHeight;
268268
}
269269
if (!mk.containsKey("click")) { // 無按鍵事件
@@ -334,7 +334,7 @@ public Keyboard(Context context, String name) {
334334

335335
for (Map<String, Object> mk : lm) {
336336
int gap = mDefaultHorizontalGap;
337-
int w = (int) (YamlUtils.INSTANCE.getDouble(mk, "width", 0) * mDisplayWidth / 100);
337+
int w = (int) (ConfigGetter.getDouble(mk, "width", 0) * mDisplayWidth / 100);
338338
if (w == 0 && mk.containsKey("click")) w = defaultWidth;
339339
w -= gap;
340340
if (column >= maxColumns || x + w > mDisplayWidth) {
@@ -348,7 +348,7 @@ public Keyboard(Context context, String name) {
348348
if (keyboardHeight > 0) {
349349
rowHeight = newHeight[row];
350350
} else {
351-
int heightK = YamlUtils.INSTANCE.getPixel(mk, "height", 0);
351+
int heightK = ConfigGetter.getPixel(mk, "height", 0);
352352
rowHeight = (heightK > 0) ? heightK : defaultHeight;
353353
}
354354
}
@@ -358,47 +358,47 @@ public Keyboard(Context context, String name) {
358358
}
359359

360360
final int defaultKeyTextOffsetX =
361-
YamlUtils.INSTANCE.getPixel(
361+
ConfigGetter.getPixel(
362362
keyboardConfig, "key_text_offset_x", config.getFloat("key_text_offset_x"));
363363
final int defaultKeyTextOffsetY =
364-
YamlUtils.INSTANCE.getPixel(
364+
ConfigGetter.getPixel(
365365
keyboardConfig, "key_text_offset_y", config.getFloat("key_text_offset_y"));
366366
final int defaultKeySymbolOffsetX =
367-
YamlUtils.INSTANCE.getPixel(
367+
ConfigGetter.getPixel(
368368
keyboardConfig, "key_symbol_offset_x", config.getFloat("key_symbol_offset_x"));
369369
final int defaultKeySymbolOffsetY =
370-
YamlUtils.INSTANCE.getPixel(
370+
ConfigGetter.getPixel(
371371
keyboardConfig, "key_symbol_offset_y", config.getFloat("key_symbol_offset_y"));
372372
final int defaultKeyHintOffsetX =
373-
YamlUtils.INSTANCE.getPixel(
373+
ConfigGetter.getPixel(
374374
keyboardConfig, "key_hint_offset_x", config.getFloat("key_hint_offset_x"));
375375
final int defaultKeyHintOffsetY =
376-
YamlUtils.INSTANCE.getPixel(
376+
ConfigGetter.getPixel(
377377
keyboardConfig, "key_hint_offset_y", config.getFloat("key_hint_offset_y"));
378378
final int defaultKeyPressOffsetX =
379-
YamlUtils.INSTANCE.getInt(
379+
ConfigGetter.getInt(
380380
keyboardConfig, "key_press_offset_x", config.getInt("key_press_offset_x"));
381381
final int defaultKeyPressOffsetY =
382-
YamlUtils.INSTANCE.getInt(
382+
ConfigGetter.getInt(
383383
keyboardConfig, "key_press_offset_y", config.getInt("key_press_offset_y"));
384384

385385
final Key key = new Key(context, this, mk);
386386
key.setKey_text_offset_x(
387-
YamlUtils.INSTANCE.getPixel(mk, "key_text_offset_x", defaultKeyTextOffsetX));
387+
ConfigGetter.getPixel(mk, "key_text_offset_x", defaultKeyTextOffsetX));
388388
key.setKey_text_offset_y(
389-
YamlUtils.INSTANCE.getPixel(mk, "key_text_offset_y", defaultKeyTextOffsetY));
389+
ConfigGetter.getPixel(mk, "key_text_offset_y", defaultKeyTextOffsetY));
390390
key.setKey_symbol_offset_x(
391-
YamlUtils.INSTANCE.getPixel(mk, "key_symbol_offset_x", defaultKeySymbolOffsetX));
391+
ConfigGetter.getPixel(mk, "key_symbol_offset_x", defaultKeySymbolOffsetX));
392392
key.setKey_symbol_offset_y(
393-
YamlUtils.INSTANCE.getPixel(mk, "key_symbol_offset_y", defaultKeySymbolOffsetY));
393+
ConfigGetter.getPixel(mk, "key_symbol_offset_y", defaultKeySymbolOffsetY));
394394
key.setKey_hint_offset_x(
395-
YamlUtils.INSTANCE.getPixel(mk, "key_hint_offset_x", defaultKeyHintOffsetX));
395+
ConfigGetter.getPixel(mk, "key_hint_offset_x", defaultKeyHintOffsetX));
396396
key.setKey_hint_offset_y(
397-
YamlUtils.INSTANCE.getPixel(mk, "key_hint_offset_y", defaultKeyHintOffsetY));
397+
ConfigGetter.getPixel(mk, "key_hint_offset_y", defaultKeyHintOffsetY));
398398
key.setKey_press_offset_x(
399-
YamlUtils.INSTANCE.getInt(mk, "key_press_offset_x", defaultKeyPressOffsetX));
399+
ConfigGetter.getInt(mk, "key_press_offset_x", defaultKeyPressOffsetX));
400400
key.setKey_press_offset_y(
401-
YamlUtils.INSTANCE.getInt(mk, "key_press_offset_y", defaultKeyPressOffsetY));
401+
ConfigGetter.getInt(mk, "key_press_offset_y", defaultKeyPressOffsetY));
402402

403403
key.setX(x);
404404
key.setY(y);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import android.media.SoundPool;
66
import android.view.KeyEvent;
77
import com.osfans.trime.util.DataUtils;
8-
import com.osfans.trime.util.YamlUtils;
8+
import com.osfans.trime.util.ConfigGetter;
99
import java.io.File;
1010
import java.util.ArrayList;
1111
import java.util.List;
@@ -53,7 +53,7 @@ public Sound(String soundPackageName) {
5353
melody = new int[1];
5454
progress = -1;
5555

56-
Map<String, ?> m = YamlUtils.INSTANCE.loadMap(soundPackageName + ".sound", "");
56+
Map<String, ?> m = ConfigGetter.loadMap(soundPackageName + ".sound", "");
5757
if (m != null) {
5858
String path = DataUtils.getUserDataDir() + File.separator + "sound" + File.separator;
5959
if (m.containsKey("folder")) path = path + m.get("folder") + File.separator;

app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.osfans.trime.ime.core.Trime;
1818
import com.osfans.trime.ime.enums.SymbolKeyboardType;
1919
import com.osfans.trime.setup.Config;
20-
import com.osfans.trime.util.YamlUtils;
20+
import com.osfans.trime.util.ConfigGetter;
2121
import java.io.File;
2222
import java.util.ArrayList;
2323
import java.util.List;
@@ -111,7 +111,7 @@ public void calcPadding(int width) {
111111
// liquid_keyboard/margin_x定义了每个键左右两边的间隙,也就是说相邻两个键间隙是x2,而horizontal_gap定义的是spacer,使用时需要/2
112112
if (liquid_config != null) {
113113
if (liquid_config.containsKey("margin_x")) {
114-
Object o = YamlUtils.INSTANCE.getPixel(liquid_config, "margin_x", 0);
114+
Object o = ConfigGetter.getPixel(liquid_config, "margin_x", 0);
115115
margin_x = (int) o;
116116
}
117117
}

app/src/main/java/com/osfans/trime/ime/text/Composition.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import com.osfans.trime.ime.core.Trime;
4848
import com.osfans.trime.ime.keyboard.Event;
4949
import com.osfans.trime.setup.Config;
50-
import com.osfans.trime.util.YamlUtils;
50+
import com.osfans.trime.util.ConfigGetter;
5151
import java.util.List;
5252
import java.util.Map;
5353
import timber.log.Timber;
@@ -315,7 +315,7 @@ private void appendComposition(Map<String, ?> m) {
315315
ss.setSpan(new CompositionSpan(), start, end, span);
316316
ss.setSpan(new AbsoluteSizeSpan(text_size), start, end, span);
317317
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && m.containsKey("letter_spacing")) {
318-
final float size = YamlUtils.INSTANCE.getFloat(m, "letter_spacing", 0);
318+
final float size = ConfigGetter.getFloat(m, "letter_spacing", 0);
319319
if (size != 0f) ss.setSpan(new LetterSpacingSpan(size), start, end, span);
320320
}
321321
start = composition_pos[0] + r.getStart();

app/src/main/java/com/osfans/trime/setup/Config.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import com.osfans.trime.ime.symbol.TabManager;
4545
import com.osfans.trime.util.AppVersionUtils;
4646
import com.osfans.trime.util.DataUtils;
47-
import com.osfans.trime.util.YamlUtils;
47+
import com.osfans.trime.util.ConfigGetter;
4848
import java.io.File;
4949
import java.io.FileInputStream;
5050
import java.io.FileOutputStream;
@@ -409,10 +409,10 @@ private void init(boolean skip_delopy) {
409409
}
410410
Timber.d("init() deploy_config_file done");
411411

412-
Map<String, ?> m = YamlUtils.INSTANCE.loadMap(themeName, "");
412+
Map<String, ?> m = ConfigGetter.loadMap(themeName, "");
413413
if (m == null) {
414414
themeName = defaultName;
415-
m = YamlUtils.INSTANCE.loadMap(themeName, "");
415+
m = ConfigGetter.loadMap(themeName, "");
416416
}
417417
Timber.d("init() load_map done");
418418
final Map<?, ?> mk = (Map<?, ?>) m.get("android_keys");
@@ -740,7 +740,7 @@ public float getFloat(String key) {
740740
public float getLiquidFloat(String key) {
741741
if (liquidKeyboard != null) {
742742
if (liquidKeyboard.containsKey(key)) {
743-
return YamlUtils.INSTANCE.getFloat(liquidKeyboard, key, 0);
743+
return ConfigGetter.getFloat(liquidKeyboard, key, 0);
744744
}
745745
}
746746
return getFloat(key);
@@ -969,7 +969,7 @@ public int getRepeatInterval() {
969969
public int getLiquidPixel(String key) {
970970
if (liquidKeyboard != null) {
971971
if (liquidKeyboard.containsKey(key)) {
972-
return YamlUtils.INSTANCE.getPixel(liquidKeyboard, key, 0);
972+
return ConfigGetter.getPixel(liquidKeyboard, key, 0);
973973
}
974974
}
975975
return getPixel(key);

0 commit comments

Comments
 (0)