@@ -58,6 +58,9 @@ import splitties.systemservices.layoutInflater
5858import timber.log.Timber
5959import java.lang.reflect.Method
6060import java.util.Arrays
61+ import kotlin.math.abs
62+ import kotlin.math.max
63+ import kotlin.math.min
6164
6265/* * 顯示[鍵盤][Keyboard]及[按鍵][Key] */
6366
@@ -128,8 +131,8 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
128131 private var mKeyTextColor: ColorStateList ? = null
129132 private var mKeyBackColor: StateListDrawable ? = null
130133
131- private var key_symbol_color = 0
132- private var hilited_key_symbol_color = 0
134+ private var keySymbolColor = 0
135+ private var hilitedKeySymbolColor = 0
133136 private var mSymbolSize = 0
134137 private val mPaintSymbol: Paint
135138 private var mShadowRadius = 0f
@@ -337,8 +340,8 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
337340
338341 fun reset () {
339342 val theme = ThemeManager .activeTheme
340- key_symbol_color = ColorManager .getColor(" key_symbol_color" )!!
341- hilited_key_symbol_color = ColorManager .getColor(" hilited_key_symbol_color" )!!
343+ keySymbolColor = ColorManager .getColor(" key_symbol_color" )!!
344+ hilitedKeySymbolColor = ColorManager .getColor(" hilited_key_symbol_color" )!!
342345 mShadowColor = ColorManager .getColor(" shadow_color" )!!
343346 mSymbolSize = sp2px(theme.style.getFloat(" symbol_text_size" )).toInt()
344347 mKeyTextSize = sp2px(theme.style.getFloat(" key_text_size" )).toInt()
@@ -384,7 +387,7 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
384387 showPreview = prefs.keyboard.popupKeyPressEnabled
385388 mPaint.setTypeface(FontManager .getTypeface(" key_font" ))
386389 mPaintSymbol.setTypeface(FontManager .getTypeface(" symbol_font" ))
387- mPaintSymbol.color = key_symbol_color
390+ mPaintSymbol.color = keySymbolColor
388391 mPaintSymbol.textSize = mSymbolSize.toFloat()
389392 mPreviewText.typeface = FontManager .getTypeface(" preview_font" )
390393 handleEnterLabel(theme)
@@ -445,8 +448,8 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
445448 if (mPossiblePoly) return false
446449 val deltaX = me2.x - me1!! .x // distance X
447450 val deltaY = me2.y - me1.y // distance Y
448- val absX = Math . abs(deltaX) // absolute value of distance X
449- val absY = Math . abs(deltaY) // absolute value of distance Y
451+ val absX = abs(deltaX) // absolute value of distance X
452+ val absY = abs(deltaY) // absolute value of distance Y
450453 val travel = // threshold distance
451454 // I don't really know what getSwipeTravelHi is.
452455 // For any one see this plz change the method name to something
@@ -621,7 +624,7 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
621624 * @param key 按下的修饰键(非组合键)
622625 * @return
623626 */
624- fun setModifier (key : Key ): Boolean {
627+ private fun setModifier (key : Key ): Boolean {
625628 if (mKeyboard != null ) {
626629 if (mKeyboard!! .clikModifierKey(key.isShiftLock, key.modifierKeyOnMask)) {
627630 invalidateAllKeys()
@@ -694,7 +697,7 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
694697 }
695698 }
696699
697- val isShifted: Boolean
700+ private val isShifted: Boolean
698701 /* *
699702 * Returns the state of the shift key of the keyboard, if any.
700703 *
@@ -777,7 +780,7 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
777780 val length = keys.size
778781 var dimensionSum = 0
779782 for (key in keys) {
780- dimensionSum + = Math . min(key.width, key.height) + key.gap
783+ dimensionSum + = min(key.width, key.height) + key.gap
781784 }
782785 if (dimensionSum < 0 || length == 0 ) return
783786 mProximityThreshold = (dimensionSum * Keyboard .SEARCH_DISTANCE / length).toInt()
@@ -813,8 +816,8 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
813816 (mBuffer!! .width != width || mBuffer!! .height != height)
814817 ) {
815818 // Make sure our bitmap is at least 1x1
816- val width = Math . max(1 , width)
817- val height = Math . max(1 , height)
819+ val width = max(1 , width)
820+ val height = max(1 , height)
818821 mBuffer = Bitmap .createBitmap(width, height, Bitmap .Config .ARGB_8888 )
819822 mCanvas = Canvas (mBuffer!! )
820823 }
@@ -885,7 +888,7 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
885888 ? : mKeyTextColor!! .getColorForState(drawableState, 0 )
886889 color = key.getSymbolColorForState(drawableState)
887890 mPaintSymbol.color = color
888- ? : if (key.isPressed) hilited_key_symbol_color else key_symbol_color
891+ ? : if (key.isPressed) hilitedKeySymbolColor else keySymbolColor
889892
890893 // Switch the character to uppercase if shift is pressed
891894 var label = key.getLabel()
@@ -1153,7 +1156,7 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
11531156 MeasureSpec .makeMeasureSpec(0 , MeasureSpec .UNSPECIFIED ),
11541157 )
11551158 val popupWidth =
1156- Math . max(
1159+ max(
11571160 mPreviewText.measuredWidth,
11581161 key.width + mPreviewText.paddingLeft + mPreviewText.paddingRight,
11591162 )
@@ -1250,12 +1253,7 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
12501253 )
12511254 onBufferDraw()
12521255 Timber .d(" \t <TrimeInput>\t invalidateKey()\t invalidate" )
1253- invalidate(
1254- key.x + paddingLeft,
1255- key.y + paddingTop,
1256- key.x + key.width + paddingLeft,
1257- key.y + key.height + paddingTop,
1258- )
1256+ invalidate()
12591257 Timber .d(" \t <TrimeInput>\t invalidateKey()\t finish" )
12601258 }
12611259
@@ -1387,10 +1385,10 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
13871385 var mPopupX = popupKey.x + paddingLeft
13881386 var mPopupY = popupKey.y + paddingTop
13891387 mPopupX = mPopupX + popupKey.width - mMiniKeyboardContainer!! .measuredWidth
1390- mPopupY = mPopupY - mMiniKeyboardContainer.measuredHeight
1388+ mPopupY - = mMiniKeyboardContainer.measuredHeight
13911389 val x = mPopupX + mMiniKeyboardContainer.paddingRight + mCoordinates[0 ]
13921390 val y = mPopupY + mMiniKeyboardContainer.paddingBottom + mCoordinates[1 ]
1393- mMiniKeyboard.setPopupOffset(Math . max(x, 0 ), y)
1391+ mMiniKeyboard.setPopupOffset(max(x, 0 ), y)
13941392
13951393 // todo 只处理了shift
13961394 Timber .w(" only set isShifted, no others modifierkey" )
@@ -1586,10 +1584,10 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
15861584 if (prefs.keyboard.swipeEnabled) {
15871585 val dx = touchX - touchX0
15881586 val dy = touchY - touchY0
1589- val absX = Math . abs(dx)
1590- val absY = Math . abs(dy)
1587+ val absX = abs(dx)
1588+ val absY = abs(dy)
15911589 val travel = if (isFastInput && isClickAtLast) prefs.keyboard.swipeTravelHi else prefs.keyboard.swipeTravel
1592- if (Math . max(absY, absX) > travel && touchOnePoint) {
1590+ if (max(absY, absX) > travel && touchOnePoint) {
15931591 Timber .d(" \t <TrimeInput>\t onModifiedTouchEvent()\t touch" )
15941592 var type = KeyEventType .CLICK
15951593 type =
@@ -1861,8 +1859,8 @@ class KeyboardView(context: Context?, attrs: AttributeSet?) : View(context, attr
18611859 vel = dist / dur * units // pixels/frame.
18621860 accumY = if (accumY == 0f ) vel else (accumY + vel) * .5f
18631861 }
1864- xVelocity = if (accumX < 0.0f ) Math . max(accumX, - maxVelocity) else Math . min(accumX, maxVelocity)
1865- yVelocity = if (accumY < 0.0f ) Math . max(accumY, - maxVelocity) else Math . min(accumY, maxVelocity)
1862+ xVelocity = if (accumX < 0.0f ) max(accumX, - maxVelocity) else min(accumX, maxVelocity)
1863+ yVelocity = if (accumY < 0.0f ) max(accumY, - maxVelocity) else min(accumY, maxVelocity)
18661864 }
18671865
18681866 companion object {
0 commit comments