18
18
19
19
package com .osfans .trime .ime .keyboard ;
20
20
21
- import android .content .Context ;
22
- import android .content .res .Configuration ;
23
21
import android .graphics .drawable .Drawable ;
24
- import android .util .DisplayMetrics ;
25
22
import android .view .KeyEvent ;
26
- import androidx . annotation . NonNull ;
23
+ import com . blankj . utilcode . util . ScreenUtils ;
27
24
import com .osfans .trime .data .theme .Config ;
28
25
import com .osfans .trime .util .ConfigGetter ;
29
26
import com .osfans .trime .util .DimensionsKt ;
@@ -96,24 +93,14 @@ public class Keyboard {
96
93
// 特别的,当值为负数时,为倒序序号(-1即倒数第一个);当值大于按键行数时,为最后一行
97
94
private int autoHeightIndex , keyboardHeight ;
98
95
99
- /**
100
- * Creates a keyboard from the given xml key layout file.
101
- *
102
- * @param context the application or service context
103
- */
104
- public Keyboard (@ NonNull Context context ) {
96
+ /** Creates a keyboard from the given xml key layout file. */
97
+ public Keyboard () {
105
98
106
99
// 橫屏模式下,键盘左右两侧到屏幕边缘的距离
107
- final boolean land =
108
- (context .getResources ().getConfiguration ().orientation
109
- == Configuration .ORIENTATION_LANDSCAPE );
110
100
111
101
final Config config = Config .get ();
112
-
113
- final DisplayMetrics dm = context .getResources ().getDisplayMetrics ();
114
- mDisplayWidth = dm .widthPixels ;
115
102
int [] keyboardPadding = config .getKeyboardPadding ();
116
- mDisplayWidth = mDisplayWidth - keyboardPadding [0 ] - keyboardPadding [1 ];
103
+ mDisplayWidth = ScreenUtils . getScreenWidth () - keyboardPadding [0 ] - keyboardPadding [1 ];
117
104
/* Height of the screen */
118
105
// final int mDisplayHeight = dm.heightPixels;
119
106
// Log.v(TAG, "keyboard's display metrics:" + dm);
@@ -130,7 +117,7 @@ public Keyboard(@NonNull Context context) {
130
117
mBackground = config .getColorDrawable ("keyboard_back_color" );
131
118
132
119
keyboardHeight = (int ) DimensionsKt .dp2px (config .style .getFloat ("keyboard_height" ));
133
- if (land ) {
120
+ if (ScreenUtils . isLandscape () ) {
134
121
int keyBoardHeightLand =
135
122
(int ) DimensionsKt .dp2px (config .style .getFloat ("keyboard_height_land" ));
136
123
if (keyBoardHeightLand > 0 ) keyboardHeight = keyBoardHeightLand ;
@@ -150,16 +137,15 @@ public Keyboard(@NonNull Context context) {
150
137
* <p>If the specified number of columns is -1, then the keyboard will fit as many keys as
151
138
* possible in each row.
152
139
*
153
- * @param context the application or service context
154
140
* @param characters the list of characters to display on the keyboard. One key will be created
155
141
* for each character.
156
142
* @param columns the number of columns of keys to display. If this number is greater than the
157
143
* number of keys that can fit in a row, it will be ignored. If this number is -1, the
158
144
* keyboard will fit as many keys as possible in each row.
159
145
* @param horizontalPadding 按鍵水平間距
160
146
*/
161
- public Keyboard (Context context , CharSequence characters , int columns , int horizontalPadding ) {
162
- this (context );
147
+ public Keyboard (CharSequence characters , int columns , int horizontalPadding ) {
148
+ this ();
163
149
int x = 0 ;
164
150
int y = 0 ;
165
151
int column = 0 ;
@@ -190,11 +176,8 @@ public Keyboard(Context context, CharSequence characters, int columns, int horiz
190
176
mTotalHeight = y + mDefaultHeight ;
191
177
}
192
178
193
- public Keyboard (Context context , String name ) {
194
- this (context );
195
- final boolean land =
196
- (context .getResources ().getConfiguration ().orientation
197
- == Configuration .ORIENTATION_LANDSCAPE );
179
+ public Keyboard (String name ) {
180
+ this ();
198
181
Config config = Config .get ();
199
182
final Map <String , ?> keyboardConfig = config .getKeyboard (name );
200
183
mLabelTransform = ConfigGetter .getString (keyboardConfig , "label_transform" , "none" );
@@ -241,7 +224,7 @@ public Keyboard(Context context, String name) {
241
224
242
225
if (keyboardHeight > 0 ) {
243
226
int mkeyboardHeight = ConfigGetter .getPixel (keyboardConfig , "keyboard_height" , 0 );
244
- if (land ) {
227
+ if (ScreenUtils . isLandscape () ) {
245
228
int mkeyBoardHeightLand = ConfigGetter .getPixel (keyboardConfig , "keyboard_height_land" , 0 );
246
229
if (mkeyBoardHeightLand > 0 ) mkeyboardHeight = mkeyBoardHeightLand ;
247
230
}
@@ -388,7 +371,7 @@ public Keyboard(Context context, String name) {
388
371
ConfigGetter .getInt (
389
372
keyboardConfig , "key_press_offset_y" , config .style .getInt ("key_press_offset_y" ));
390
373
391
- final Key key = new Key (context , this , mk );
374
+ final Key key = new Key (this , mk );
392
375
key .setKey_text_offset_x (
393
376
ConfigGetter .getPixel (mk , "key_text_offset_x" , defaultKeyTextOffsetX ));
394
377
key .setKey_text_offset_y (
0 commit comments