2222import android .view .KeyEvent ;
2323import com .blankj .utilcode .util .ScreenUtils ;
2424import com .osfans .trime .data .theme .Theme ;
25- import com .osfans .trime .util .ConfigGetter ;
25+ import com .osfans .trime .util .CollectionUtils ;
2626import com .osfans .trime .util .DimensionsKt ;
2727import java .util .ArrayList ;
2828import java .util .List ;
@@ -186,32 +186,38 @@ public Keyboard(String name) {
186186 } else {
187187 keyboardConfig = (Map <String , Object >) theme .keyboards .getObject ("default" );
188188 }
189- mLabelTransform = ConfigGetter . getString (keyboardConfig , "label_transform" , "none" );
190- mAsciiMode = ConfigGetter . getInt (keyboardConfig , "ascii_mode" , 1 );
189+ mLabelTransform = CollectionUtils . obtainString (keyboardConfig , "label_transform" , "none" );
190+ mAsciiMode = CollectionUtils . obtainInt (keyboardConfig , "ascii_mode" , 1 );
191191 if (mAsciiMode == 0 )
192- mAsciiKeyboard = ConfigGetter . getString (keyboardConfig , "ascii_keyboard" , "" );
193- resetAsciiMode = ConfigGetter . getBoolean (keyboardConfig , "reset_ascii_mode" , false );
194- mLock = ConfigGetter . getBoolean (keyboardConfig , "lock" , false );
195- int columns = ConfigGetter . getInt (keyboardConfig , "columns" , 30 );
192+ mAsciiKeyboard = CollectionUtils . obtainString (keyboardConfig , "ascii_keyboard" , "" );
193+ resetAsciiMode = CollectionUtils . obtainBoolean (keyboardConfig , "reset_ascii_mode" , false );
194+ mLock = CollectionUtils . obtainBoolean (keyboardConfig , "lock" , false );
195+ int columns = CollectionUtils . obtainInt (keyboardConfig , "columns" , 30 );
196196 int defaultWidth =
197- (int ) (ConfigGetter . getDouble (keyboardConfig , "width" , 0d ) * mDisplayWidth / 100 );
197+ (int ) (CollectionUtils . obtainFloat (keyboardConfig , "width" , 0f ) * mDisplayWidth / 100 );
198198 if (defaultWidth == 0 ) defaultWidth = mDefaultWidth ;
199199
200200 // 按键高度取值顺序: keys > keyboard/height > style/key_height
201201 // 考虑到key设置height_land需要对皮肤做大量修改,而当部分key设置height而部分没有设时会造成按键高度异常,故取消普通按键的height_land参数
202- int height = ConfigGetter . getPixel ( keyboardConfig , "height" , 0 );
202+ int height = ( int ) DimensionsKt . sp2px ( CollectionUtils . obtainFloat ( keyboardConfig , "height" , 0 ) );
203203 int defaultHeight = (height > 0 ) ? height : mDefaultHeight ;
204204 int rowHeight = defaultHeight ;
205- autoHeightIndex = ConfigGetter . getInt (keyboardConfig , "auto_height_index" , -1 );
205+ autoHeightIndex = CollectionUtils . obtainInt (keyboardConfig , "auto_height_index" , -1 );
206206 List <Map <String , Object >> lm = (List <Map <String , Object >>) keyboardConfig .get ("keys" );
207207
208208 mDefaultHorizontalGap =
209- ConfigGetter .getPixel (
210- keyboardConfig , "horizontal_gap" , theme .style .getFloat ("horizontal_gap" ));
209+ (int )
210+ DimensionsKt .sp2px (
211+ CollectionUtils .obtainFloat (
212+ keyboardConfig , "horizontal_gap" , theme .style .getFloat ("horizontal_gap" )));
211213 mDefaultVerticalGap =
212- ConfigGetter .getPixel (keyboardConfig , "vertical_gap" , theme .style .getFloat ("vertical_gap" ));
214+ (int )
215+ DimensionsKt .sp2px (
216+ CollectionUtils .obtainFloat (
217+ keyboardConfig , "vertical_gap" , theme .style .getFloat ("vertical_gap" )));
213218 mRoundCorner =
214- ConfigGetter .getFloat (keyboardConfig , "round_corner" , theme .style .getFloat ("round_corner" ));
219+ CollectionUtils .obtainFloat (
220+ keyboardConfig , "round_corner" , theme .style .getFloat ("round_corner" ));
215221
216222 Drawable background = theme .colors .getDrawable (keyboardConfig , "keyboard_back_color" );
217223 if (background != null ) mBackground = background ;
@@ -227,9 +233,14 @@ public Keyboard(String name) {
227233 int [] newHeight = new int [0 ];
228234
229235 if (keyboardHeight > 0 ) {
230- int mkeyboardHeight = ConfigGetter .getPixel (keyboardConfig , "keyboard_height" , 0 );
236+ int mkeyboardHeight =
237+ (int )
238+ DimensionsKt .sp2px (CollectionUtils .obtainFloat (keyboardConfig , "keyboard_height" , 0 ));
231239 if (ScreenUtils .isLandscape ()) {
232- int mkeyBoardHeightLand = ConfigGetter .getPixel (keyboardConfig , "keyboard_height_land" , 0 );
240+ int mkeyBoardHeightLand =
241+ (int )
242+ DimensionsKt .sp2px (
243+ CollectionUtils .obtainFloat (keyboardConfig , "keyboard_height_land" , 0 ));
233244 if (mkeyBoardHeightLand > 0 ) mkeyboardHeight = mkeyBoardHeightLand ;
234245 }
235246
@@ -239,7 +250,7 @@ public Keyboard(String name) {
239250 List <Integer > rawHeight = new ArrayList <>();
240251 for (Map <String , Object > mk : lm ) {
241252 int gap = mDefaultHorizontalGap ;
242- int w = (int ) (ConfigGetter . getDouble (mk , "width" , 0 ) * mDisplayWidth / 100 );
253+ int w = (int ) (CollectionUtils . obtainFloat (mk , "width" , 0 ) * mDisplayWidth / 100 );
243254 if (w == 0 && mk .containsKey ("click" )) w = defaultWidth ;
244255 w -= gap ;
245256 if (column >= maxColumns || x + w > mDisplayWidth ) {
@@ -251,7 +262,7 @@ public Keyboard(String name) {
251262 rawHeight .add (rowHeight );
252263 }
253264 if (column == 0 ) {
254- int heightK = ConfigGetter . getPixel ( mk , "height" , 0 );
265+ int heightK = ( int ) DimensionsKt . sp2px ( CollectionUtils . obtainFloat ( mk , "height" , 0 ) );
255266 rowHeight = (heightK > 0 ) ? heightK : defaultHeight ;
256267 }
257268 if (!mk .containsKey ("click" )) { // 無按鍵事件
@@ -323,7 +334,7 @@ public Keyboard(String name) {
323334 try {
324335 for (Map <String , Object > mk : lm ) {
325336 int gap = mDefaultHorizontalGap ;
326- int w = (int ) (ConfigGetter . getDouble (mk , "width" , 0 ) * mDisplayWidth / 100 );
337+ int w = (int ) (CollectionUtils . obtainFloat (mk , "width" , 0 ) * mDisplayWidth / 100 );
327338 if (w == 0 && mk .containsKey ("click" )) w = defaultWidth ;
328339 w -= gap ;
329340 if (column >= maxColumns || x + w > mDisplayWidth ) {
@@ -337,7 +348,7 @@ public Keyboard(String name) {
337348 if (keyboardHeight > 0 ) {
338349 rowHeight = newHeight [row ];
339350 } else {
340- int heightK = ConfigGetter . getPixel ( mk , "height" , 0 );
351+ int heightK = ( int ) DimensionsKt . sp2px ( CollectionUtils . obtainFloat ( mk , "height" , 0 ) );
341352 rowHeight = (heightK > 0 ) ? heightK : defaultHeight ;
342353 }
343354 }
@@ -347,47 +358,85 @@ public Keyboard(String name) {
347358 }
348359
349360 final int defaultKeyTextOffsetX =
350- ConfigGetter .getPixel (
351- keyboardConfig , "key_text_offset_x" , theme .style .getFloat ("key_text_offset_x" ));
361+ (int )
362+ DimensionsKt .sp2px (
363+ CollectionUtils .obtainFloat (
364+ keyboardConfig ,
365+ "key_text_offset_x" ,
366+ theme .style .getFloat ("key_text_offset_x" )));
352367 final int defaultKeyTextOffsetY =
353- ConfigGetter .getPixel (
354- keyboardConfig , "key_text_offset_y" , theme .style .getFloat ("key_text_offset_y" ));
368+ (int )
369+ DimensionsKt .sp2px (
370+ CollectionUtils .obtainFloat (
371+ keyboardConfig ,
372+ "key_text_offset_y" ,
373+ theme .style .getFloat ("key_text_offset_y" )));
355374 final int defaultKeySymbolOffsetX =
356- ConfigGetter .getPixel (
357- keyboardConfig , "key_symbol_offset_x" , theme .style .getFloat ("key_symbol_offset_x" ));
375+ (int )
376+ DimensionsKt .sp2px (
377+ CollectionUtils .obtainFloat (
378+ keyboardConfig ,
379+ "key_symbol_offset_x" ,
380+ theme .style .getFloat ("key_symbol_offset_x" )));
358381 final int defaultKeySymbolOffsetY =
359- ConfigGetter .getPixel (
360- keyboardConfig , "key_symbol_offset_y" , theme .style .getFloat ("key_symbol_offset_y" ));
382+ (int )
383+ DimensionsKt .sp2px (
384+ CollectionUtils .obtainFloat (
385+ keyboardConfig ,
386+ "key_symbol_offset_y" ,
387+ theme .style .getFloat ("key_symbol_offset_y" )));
361388 final int defaultKeyHintOffsetX =
362- ConfigGetter .getPixel (
363- keyboardConfig , "key_hint_offset_x" , theme .style .getFloat ("key_hint_offset_x" ));
389+ (int )
390+ DimensionsKt .sp2px (
391+ CollectionUtils .obtainFloat (
392+ keyboardConfig ,
393+ "key_hint_offset_x" ,
394+ theme .style .getFloat ("key_hint_offset_x" )));
364395 final int defaultKeyHintOffsetY =
365- ConfigGetter .getPixel (
366- keyboardConfig , "key_hint_offset_y" , theme .style .getFloat ("key_hint_offset_y" ));
396+ (int )
397+ DimensionsKt .sp2px (
398+ CollectionUtils .obtainFloat (
399+ keyboardConfig ,
400+ "key_hint_offset_y" ,
401+ theme .style .getFloat ("key_hint_offset_y" )));
367402 final int defaultKeyPressOffsetX =
368- ConfigGetter . getInt (
403+ CollectionUtils . obtainInt (
369404 keyboardConfig , "key_press_offset_x" , theme .style .getInt ("key_press_offset_x" ));
370405 final int defaultKeyPressOffsetY =
371- ConfigGetter . getInt (
406+ CollectionUtils . obtainInt (
372407 keyboardConfig , "key_press_offset_y" , theme .style .getInt ("key_press_offset_y" ));
373408
374409 final Key key = new Key (this , mk );
375410 key .setKey_text_offset_x (
376- ConfigGetter .getPixel (mk , "key_text_offset_x" , defaultKeyTextOffsetX ));
411+ (int )
412+ DimensionsKt .sp2px (
413+ CollectionUtils .obtainFloat (mk , "key_text_offset_x" , defaultKeyTextOffsetX )));
377414 key .setKey_text_offset_y (
378- ConfigGetter .getPixel (mk , "key_text_offset_y" , defaultKeyTextOffsetY ));
415+ (int )
416+ DimensionsKt .sp2px (
417+ CollectionUtils .obtainFloat (mk , "key_text_offset_y" , defaultKeyTextOffsetY )));
379418 key .setKey_symbol_offset_x (
380- ConfigGetter .getPixel (mk , "key_symbol_offset_x" , defaultKeySymbolOffsetX ));
419+ (int )
420+ DimensionsKt .sp2px (
421+ CollectionUtils .obtainFloat (
422+ mk , "key_symbol_offset_x" , defaultKeySymbolOffsetX )));
381423 key .setKey_symbol_offset_y (
382- ConfigGetter .getPixel (mk , "key_symbol_offset_y" , defaultKeySymbolOffsetY ));
424+ (int )
425+ DimensionsKt .sp2px (
426+ CollectionUtils .obtainFloat (
427+ mk , "key_symbol_offset_y" , defaultKeySymbolOffsetY )));
383428 key .setKey_hint_offset_x (
384- ConfigGetter .getPixel (mk , "key_hint_offset_x" , defaultKeyHintOffsetX ));
429+ (int )
430+ DimensionsKt .sp2px (
431+ CollectionUtils .obtainFloat (mk , "key_hint_offset_x" , defaultKeyHintOffsetX )));
385432 key .setKey_hint_offset_y (
386- ConfigGetter .getPixel (mk , "key_hint_offset_y" , defaultKeyHintOffsetY ));
433+ (int )
434+ DimensionsKt .sp2px (
435+ CollectionUtils .obtainFloat (mk , "key_hint_offset_y" , defaultKeyHintOffsetY )));
387436 key .setKey_press_offset_x (
388- ConfigGetter . getInt (mk , "key_press_offset_x" , defaultKeyPressOffsetX ));
437+ CollectionUtils . obtainInt (mk , "key_press_offset_x" , defaultKeyPressOffsetX ));
389438 key .setKey_press_offset_y (
390- ConfigGetter . getInt (mk , "key_press_offset_y" , defaultKeyPressOffsetY ));
439+ CollectionUtils . obtainInt (mk , "key_press_offset_y" , defaultKeyPressOffsetY ));
391440
392441 key .setX (x );
393442 key .setY (y );
0 commit comments