some code style updates

This commit is contained in:
tibbi 2022-01-08 20:21:22 +01:00
parent 1e4906c48d
commit 850878cfe8
3 changed files with 88 additions and 172 deletions

View File

@ -20,7 +20,6 @@ import android.content.res.Resources
import android.content.res.TypedArray
import android.content.res.XmlResourceParser
import android.graphics.drawable.Drawable
import android.inputmethodservice.Keyboard
import android.text.TextUtils
import android.util.TypedValue
import android.util.Xml
@ -71,7 +70,6 @@ class MyKeyboard {
/** Is the keyboard in the shifted state */
var isShifted = false
private set
/** Key instance for the shift key, if present */
private val mShiftKeys = arrayOf<Key?>(null, null)
@ -92,17 +90,15 @@ class MyKeyboard {
*/
/** Total height of the keyboard, including the padding and keys */
var height = 0
private set
/**
* Total width of the keyboard, including left side gaps and keys, but not any gaps on the
* right side.
*/
var minWidth = 0
private set
/** List of keys in this keyboard */
private var mKeys: MutableList<Key?>? = null
var mKeys: MutableList<Key?>? = null
/** List of modifier keys such as Shift & Alt, if any */
private var mModifierKeys: MutableList<Key?>? = null
@ -122,8 +118,6 @@ class MyKeyboard {
private val rows = ArrayList<Row?>()
companion object {
const val TAG = "Keyboard"
// Keyboard XML Tags
private const val TAG_KEYBOARD = "Keyboard"
private const val TAG_ROW = "Row"
@ -160,7 +154,7 @@ class MyKeyboard {
/**
* Container for keys in the keyboard. All keys in a row are at the same Y-coordinate.
* Some of the key size defaults can be overridden per row from what the [Keyboard]
* Some of the key size defaults can be overridden per row from what the [MyKeyboard]
* defines.
* @attr ref android.R.styleable#Keyboard_keyWidth
* @attr ref android.R.styleable#Keyboard_keyHeight
@ -185,7 +179,7 @@ class MyKeyboard {
/**
* Edge flags for this row of keys. Possible values that can be assigned are
* [EDGE_TOP][Keyboard.EDGE_TOP] and [EDGE_BOTTOM][Keyboard.EDGE_BOTTOM]
* [EDGE_TOP][MyKeyboard.EDGE_TOP] and [EDGE_BOTTOM][MyKeyboard.EDGE_BOTTOM]
*/
var rowEdgeFlags = 0
@ -242,7 +236,7 @@ class MyKeyboard {
var codes = ArrayList<Int>()
/** Label to display */
var label: CharSequence? = null
var label: CharSequence = ""
/** Icon to display instead of a label. Icon takes precedence over a label */
var icon: Drawable? = null
@ -283,8 +277,8 @@ class MyKeyboard {
/**
* Flags that specify the anchoring to edges of the keyboard for detecting touch events
* that are just out of the boundary of the key. This is a bit mask of
* [Keyboard.EDGE_LEFT], [Keyboard.EDGE_RIGHT], [Keyboard.EDGE_TOP] and
* [Keyboard.EDGE_BOTTOM].
* [MyKeyboard.EDGE_LEFT], [MyKeyboard.EDGE_RIGHT], [MyKeyboard.EDGE_TOP] and
* [MyKeyboard.EDGE_BOTTOM].
*/
var edgeFlags: Int
@ -292,7 +286,7 @@ class MyKeyboard {
var modifier = false
/** The keyboard that this key belongs to */
private val keyboard: MyKeyboard
private val keyboard: MyKeyboard = parent.parent
/**
* If this key pops up a mini keyboard, this is the resource id for the XML layout for that
@ -332,46 +326,29 @@ class MyKeyboard {
}
iconPreview = a.getDrawable(R.styleable.Keyboard_Key_iconPreview)
if (iconPreview != null) {
iconPreview!!.setBounds(
0, 0, iconPreview!!.intrinsicWidth,
iconPreview!!.intrinsicHeight
)
}
popupCharacters = a.getText(
R.styleable.Keyboard_Key_popupCharacters
)
popupResId = a.getResourceId(
R.styleable.Keyboard_Key_popupKeyboard, 0
)
repeatable = a.getBoolean(
R.styleable.Keyboard_Key_isRepeatable, false
)
modifier = a.getBoolean(
R.styleable.Keyboard_Key_isModifier, false
)
sticky = a.getBoolean(
R.styleable.Keyboard_Key_isSticky, false
)
iconPreview?.setBounds(0, 0, iconPreview!!.intrinsicWidth, iconPreview!!.intrinsicHeight)
popupCharacters = a.getText(R.styleable.Keyboard_Key_popupCharacters)
popupResId = a.getResourceId(R.styleable.Keyboard_Key_popupKeyboard, 0)
repeatable = a.getBoolean(R.styleable.Keyboard_Key_isRepeatable, false)
modifier = a.getBoolean(R.styleable.Keyboard_Key_isModifier, false)
sticky = a.getBoolean(R.styleable.Keyboard_Key_isSticky, false)
edgeFlags = a.getInt(R.styleable.Keyboard_Key_keyEdgeFlags, 0)
edgeFlags = edgeFlags or parent.rowEdgeFlags
icon = a.getDrawable(
R.styleable.Keyboard_Key_keyIcon
)
if (icon != null) {
icon!!.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight)
}
icon = a.getDrawable(R.styleable.Keyboard_Key_keyIcon)
icon?.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight)
label = a.getText(R.styleable.Keyboard_Key_keyLabel)
text = a.getText(R.styleable.Keyboard_Key_keyOutputText)
if (!TextUtils.isEmpty(label)) {
codes = arrayListOf(label!![0].toInt())
codes = arrayListOf(label[0].toInt())
}
a.recycle()
}
/** Create an empty key with no attributes. */
init {
keyboard = parent.parent
height = parent.defaultHeight
width = parent.defaultWidth
gap = parent.defaultHorizontalGap
@ -415,7 +392,7 @@ class MyKeyboard {
fun parseCSV(value: String): ArrayList<Int> {
var count = 0
var lastIndex = 0
if (value.length > 0) {
if (value.isNotEmpty()) {
count++
while (value.indexOf(",", lastIndex + 1).also { lastIndex = it } > 0) {
count++
@ -496,26 +473,12 @@ class MyKeyboard {
}
companion object {
private val KEY_STATE_NORMAL_ON = intArrayOf(
android.R.attr.state_checkable,
android.R.attr.state_checked
)
private val KEY_STATE_PRESSED_ON = intArrayOf(
android.R.attr.state_pressed,
android.R.attr.state_checkable,
android.R.attr.state_checked
)
private val KEY_STATE_NORMAL_OFF = intArrayOf(
android.R.attr.state_checkable
)
private val KEY_STATE_PRESSED_OFF = intArrayOf(
android.R.attr.state_pressed,
android.R.attr.state_checkable
)
private val KEY_STATE_NORMAL_ON = intArrayOf(android.R.attr.state_checkable, android.R.attr.state_checked)
private val KEY_STATE_PRESSED_ON = intArrayOf(android.R.attr.state_pressed, android.R.attr.state_checkable, android.R.attr.state_checked)
private val KEY_STATE_NORMAL_OFF = intArrayOf(android.R.attr.state_checkable)
private val KEY_STATE_PRESSED_OFF = intArrayOf(android.R.attr.state_pressed, android.R.attr.state_checkable)
private val KEY_STATE_NORMAL = intArrayOf()
private val KEY_STATE_PRESSED = intArrayOf(
android.R.attr.state_pressed
)
private val KEY_STATE_PRESSED = intArrayOf(android.R.attr.state_pressed)
}
}
@ -539,7 +502,6 @@ class MyKeyboard {
mDefaultVerticalGap = 0
mDefaultHeight = mDefaultWidth
mKeys = ArrayList()
mModifierKeys = ArrayList()
mKeyboardMode = modeId
loadKeyboard(context, context.resources.getXml(xmlLayoutResId))
}
@ -566,7 +528,6 @@ class MyKeyboard {
mDefaultVerticalGap = 0
mDefaultHeight = mDefaultWidth
mKeys = ArrayList()
mModifierKeys = ArrayList()
mKeyboardMode = modeId
loadKeyboard(context, context.resources.getXml(xmlLayoutResId))
}
@ -587,10 +548,8 @@ class MyKeyboard {
* number of keys that can fit in a row, it will be ignored. If this number is -1, the
* keyboard will fit as many keys as possible in each row.
*/
constructor(
context: Context, layoutTemplateResId: Int,
characters: CharSequence, columns: Int, horizontalPadding: Int
) : this(context, layoutTemplateResId) {
constructor(context: Context, layoutTemplateResId: Int, characters: CharSequence, columns: Int, horizontalPadding: Int) :
this(context, layoutTemplateResId) {
var x = 0
var y = 0
var column = 0
@ -602,15 +561,15 @@ class MyKeyboard {
row.verticalGap = mDefaultVerticalGap
row.rowEdgeFlags = EDGE_TOP or EDGE_BOTTOM
val maxColumns = if (columns == -1) Int.MAX_VALUE else columns
for (i in 0 until characters.length) {
val c = characters[i]
if (column >= maxColumns
|| x + mDefaultWidth + horizontalPadding > mDisplayWidth
for (element in characters) {
val c = element
if (column >= maxColumns || x + mDefaultWidth + horizontalPadding > mDisplayWidth
) {
x = 0
y += mDefaultVerticalGap + mDefaultHeight
column = 0
}
val key = Key(row)
key.x = x
key.y = y
@ -654,23 +613,18 @@ class MyKeyboard {
}
}
}
minWidth = newWidth
// TODO: This does not adjust the vertical placement according to the new size.
// The main problem in the previous code was horizontal placement/size, but we should
// also recalculate the vertical sizes/positions when we get this resize call.
}
val keys: List<Key?>?
get() = mKeys
val modifierKeys: List<Key?>?
get() = mModifierKeys
fun setShifted(shiftState: Boolean): Boolean {
for (shiftKey in mShiftKeys) {
if (shiftKey != null) {
shiftKey.on = shiftState
}
shiftKey?.on = shiftState
}
if (isShifted != shiftState) {
isShifted = shiftState
return true
@ -678,9 +632,6 @@ class MyKeyboard {
return false
}
val shiftKeyIndex: Int
get() = shiftKeyIndices[0]
private fun computeNearestNeighbors() {
// Round-up so we don't have any pixels outside the grid
mCellWidth = (minWidth + GRID_WIDTH - 1) / GRID_WIDTH
@ -720,11 +671,11 @@ class MyKeyboard {
* @return the array of integer indices for the nearest keys to the given point. If the given
* point is out of range, then an array of size zero is returned.
*/
fun getNearestKeys(x: Int, y: Int): IntArray? {
if (x >= 0 && x < minWidth && y >= 0 && y < height) {
fun getNearestKeys(x: Int, y: Int): IntArray {
if (x in 0 until minWidth && y >= 0 && y < height) {
val index: Int = y / mCellHeight * GRID_WIDTH + x / mCellWidth
if (index < GRID_SIZE) {
return mGridNeighbors[index]
return mGridNeighbors[index]!!
}
}
return IntArray(0)
@ -809,41 +760,20 @@ class MyKeyboard {
private fun skipToEndOfRow(parser: XmlResourceParser) {
var event: Int
while (parser.next().also { event = it } != XmlResourceParser.END_DOCUMENT) {
if (event == XmlResourceParser.END_TAG
&& parser.name == TAG_ROW
) {
if (event == XmlResourceParser.END_TAG && parser.name == TAG_ROW) {
break
}
}
}
private fun parseKeyboardAttributes(res: Resources, parser: XmlResourceParser) {
val a = res.obtainAttributes(
Xml.asAttributeSet(parser),
R.styleable.Keyboard
)
mDefaultWidth = getDimensionOrFraction(
a,
R.styleable.Keyboard_keyWidth,
mDisplayWidth, mDisplayWidth / 10
)
mDefaultHeight = getDimensionOrFraction(
a,
R.styleable.Keyboard_keyHeight,
mDisplayHeight, 50
)
mDefaultHorizontalGap = getDimensionOrFraction(
a,
R.styleable.Keyboard_horizontalGap,
mDisplayWidth, 0
)
mDefaultVerticalGap = getDimensionOrFraction(
a,
R.styleable.Keyboard_verticalGap,
mDisplayHeight, 0
)
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.Keyboard)
mDefaultWidth = getDimensionOrFraction(a, R.styleable.Keyboard_keyWidth, mDisplayWidth, mDisplayWidth / 10)
mDefaultHeight = getDimensionOrFraction(a, R.styleable.Keyboard_keyHeight, mDisplayHeight, 50)
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.Keyboard_horizontalGap, mDisplayWidth, 0)
mDefaultVerticalGap = getDimensionOrFraction(a, R.styleable.Keyboard_verticalGap, mDisplayHeight, 0)
mProximityThreshold = (mDefaultWidth * SEARCH_DISTANCE) as Int
mProximityThreshold = mProximityThreshold * mProximityThreshold // Square it for comparison
mProximityThreshold *= mProximityThreshold // Square it for comparison
a.recycle()
}
}

View File

@ -7,17 +7,18 @@ import android.view.KeyEvent
import android.view.View
import com.simplemobiletools.commons.extensions.performHapticFeedback
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.helpers.MyKeyboard
import com.simplemobiletools.keyboard.views.MyKeyboardView
// based on https://www.androidauthority.com/lets-build-custom-keyboard-android-832362/
class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionListener {
private var keyboard: Keyboard? = null
private var keyboard: MyKeyboard? = null
private var keyboardView: MyKeyboardView? = null
private var caps = false
override fun onCreateInputView(): View {
keyboardView = layoutInflater.inflate(R.layout.keyboard_view_keyboard, null) as MyKeyboardView
keyboard = Keyboard(this, R.xml.keys_layout)
keyboard = MyKeyboard(this, R.xml.keys_layout)
keyboardView!!.setKeyboard(keyboard!!)
keyboardView!!.onKeyboardActionListener = this
return keyboardView!!
@ -31,7 +32,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
val inputConnection = currentInputConnection
if (inputConnection != null) {
when (primaryCode) {
Keyboard.KEYCODE_DELETE -> {
MyKeyboard.KEYCODE_DELETE -> {
val selectedText = inputConnection.getSelectedText(0)
if (TextUtils.isEmpty(selectedText)) {
inputConnection.deleteSurroundingText(1, 0)
@ -41,12 +42,12 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
keyboard!!.isShifted = caps
keyboardView!!.invalidateAllKeys()
}
Keyboard.KEYCODE_SHIFT -> {
MyKeyboard.KEYCODE_SHIFT -> {
caps = !caps
keyboard!!.isShifted = caps
keyboardView!!.invalidateAllKeys()
}
Keyboard.KEYCODE_DONE -> inputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER))
MyKeyboard.KEYCODE_DONE -> inputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER))
else -> {
var code = primaryCode.toChar()
if (Character.isLetter(code) && caps) {

View File

@ -18,6 +18,7 @@ import android.view.accessibility.AccessibilityManager
import android.widget.PopupWindow
import android.widget.TextView
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.helpers.MyKeyboard
import java.util.*
/**
@ -96,7 +97,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
fun swipeUp()
}
private var mKeyboard: Keyboard? = null
private var mKeyboard: MyKeyboard? = null
private var mCurrentKeyIndex: Int = NOT_A_KEY
private var mLabelTextSize = 0
@ -121,8 +122,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
private var mPopupParent: View
private var mMiniKeyboardOffsetX = 0
private var mMiniKeyboardOffsetY = 0
private val mMiniKeyboardCache: MutableMap<Keyboard.Key, View?>
private var mKeys = ArrayList<Keyboard.Key>()
private val mMiniKeyboardCache: MutableMap<MyKeyboard.Key, View?>
private var mKeys = ArrayList<MyKeyboard.Key>()
/**
* Returns the [OnKeyboardActionListener] object.
* @return the listener attached to this keyboard
@ -178,7 +179,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
private var mRepeatKeyIndex: Int = NOT_A_KEY
private var mPopupLayout = 0
private var mAbortKey = false
private var mInvalidatedKey: Keyboard.Key? = null
private var mInvalidatedKey: MyKeyboard.Key? = null
private val mClipRegion = Rect(0, 0, 0, 0)
private var mPossiblePoly = false
private val mSwipeTracker: SwipeTracker = SwipeTracker()
@ -225,7 +226,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
companion object {
private const val NOT_A_KEY = -1
private val KEY_DELETE = intArrayOf(Keyboard.KEYCODE_DELETE)
private val KEY_DELETE = intArrayOf(MyKeyboard.KEYCODE_DELETE)
private val LONG_PRESSABLE_STATE_SET = intArrayOf(R.attr.state_long_pressable)
private const val MSG_SHOW_PREVIEW = 1
private const val MSG_REMOVE_PREVIEW = 2
@ -387,7 +388,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
* @see .getKeyboard
* @param keyboard the keyboard to display in this view
*/
fun setKeyboard(keyboard: Keyboard) {
fun setKeyboard(keyboard: MyKeyboard) {
if (mKeyboard != null) {
showPreview(NOT_A_KEY)
}
@ -395,8 +396,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
// Remove any pending messages
removeMessages()
mKeyboard = keyboard
val keys = mKeyboard!!.keys
mKeys = keys.toMutableList() as ArrayList<Keyboard.Key>
val keys = mKeyboard!!.mKeys
mKeys = keys!!.toMutableList() as ArrayList<MyKeyboard.Key>
requestLayout()
// Hint to reallocate the buffer if the size changed
mKeyboardChanged = true
@ -416,13 +417,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
* @see KeyboardView.isShifted
*/
fun setShifted(shifted: Boolean): Boolean {
if (mKeyboard != null) {
if (mKeyboard!!.setShifted(shifted)) {
if (mKeyboard?.setShifted(shifted) == true) {
// The whole keyboard probably needs to be redrawn
invalidateAllKeys()
return true
}
}
return false
}
@ -433,11 +432,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
* @see KeyboardView.setShifted
*/
fun isShifted(): Boolean {
return if (mKeyboard != null) {
mKeyboard!!.isShifted
} else {
false
}
return mKeyboard?.isShifted ?: false
}
fun setPopupParent(v: View) {
@ -487,7 +482,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
* the touch distance from a key's center to avoid taking a square root.
* @param keyboard
*/
private fun computeProximityThreshold(keyboard: Keyboard?) {
private fun computeProximityThreshold(keyboard: MyKeyboard?) {
if (keyboard == null) {
return
}
@ -510,9 +505,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
public override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
if (mKeyboard != null) {
//mKeyboard.resize(w, h)
}
mKeyboard?.resize(w, h)
// Release the buffer, if any and it will be reallocated on the next draw
mBuffer = null
}
@ -578,11 +571,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
keyBackground!!.state = drawableState
// Switch the character to uppercase if shift is pressed
val label = if (key.label == null) {
null
} else {
adjustCase(key.label).toString()
}
val label = adjustCase(key.label)?.toString()
val bounds = keyBackground.bounds
if (key.width != bounds.right || key.height != bounds.bottom) {
@ -611,11 +600,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
// Turn off drop shadow
paint.setShadowLayer(0f, 0f, 0f, 0)
} else if (key.icon != null) {
val drawableX = (key.width - padding.left - padding.right - key.icon.intrinsicWidth) / 2 + padding.left
val drawableY = (key.height - key.icon.intrinsicHeight) / 2
val drawableX = (key.width - padding.left - padding.right - key.icon!!.intrinsicWidth) / 2 + padding.left
val drawableY = (key.height - key.icon!!.intrinsicHeight) / 2
canvas.translate(drawableX.toFloat(), drawableY.toFloat())
key.icon.setBounds(0, 0, key.icon.intrinsicWidth, key.icon.intrinsicHeight)
key.icon.draw(canvas)
key.icon!!.setBounds(0, 0, key.icon!!.intrinsicWidth, key.icon!!.intrinsicHeight)
key.icon!!.draw(canvas)
canvas.translate(-drawableX.toFloat(), -drawableY.toFloat())
}
canvas.translate((-key.x - kbdPaddingLeft).toFloat(), (-key.y - kbdPaddingTop).toFloat())
@ -708,7 +697,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
// Multi-tap
if (mInMultiTap) {
if (mTapCount != -1) {
onKeyboardActionListener!!.onKey(Keyboard.KEYCODE_DELETE, KEY_DELETE)
onKeyboardActionListener!!.onKey(MyKeyboard.KEYCODE_DELETE, KEY_DELETE)
} else {
mTapCount = 0
}
@ -725,7 +714,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
/**
* Handle multi-tap keys by producing the key label for the current multi-tap state.
*/
private fun getPreviewText(key: Keyboard.Key): CharSequence? {
private fun getPreviewText(key: MyKeyboard.Key): CharSequence? {
return if (mInMultiTap) {
// Multi-tap
mPreviewLabel.setLength(0)
@ -835,10 +824,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val popupWidth = Math.max(mPreviewText!!.measuredWidth, key.width + mPreviewText!!.paddingLeft + mPreviewText!!.paddingRight)
val popupHeight = mPreviewHeight
val lp = mPreviewText!!.layoutParams
if (lp != null) {
lp.width = popupWidth
lp.height = popupHeight
}
lp?.width = popupWidth
lp?.height = popupHeight
if (!mPreviewCentered) {
mPopupPreviewX = key.x - mPreviewText!!.paddingLeft + paddingLeft
@ -895,12 +882,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val event = AccessibilityEvent.obtain(eventType)
onInitializeAccessibilityEvent(event)
val text: String = when (code) {
Keyboard.KEYCODE_ALT -> context.getString(R.string.keyboardview_keycode_alt)
Keyboard.KEYCODE_CANCEL -> context.getString(R.string.keyboardview_keycode_cancel)
Keyboard.KEYCODE_DELETE -> context.getString(R.string.keyboardview_keycode_delete)
Keyboard.KEYCODE_DONE -> context.getString(R.string.keyboardview_keycode_done)
Keyboard.KEYCODE_MODE_CHANGE -> context.getString(R.string.keyboardview_keycode_mode_change)
Keyboard.KEYCODE_SHIFT -> context.getString(R.string.keyboardview_keycode_shift)
MyKeyboard.KEYCODE_ALT -> context.getString(R.string.keyboardview_keycode_alt)
MyKeyboard.KEYCODE_CANCEL -> context.getString(R.string.keyboardview_keycode_cancel)
MyKeyboard.KEYCODE_DELETE -> context.getString(R.string.keyboardview_keycode_delete)
MyKeyboard.KEYCODE_DONE -> context.getString(R.string.keyboardview_keycode_done)
MyKeyboard.KEYCODE_MODE_CHANGE -> context.getString(R.string.keyboardview_keycode_mode_change)
MyKeyboard.KEYCODE_SHIFT -> context.getString(R.string.keyboardview_keycode_shift)
'\n'.toInt() -> context.getString(R.string.keyboardview_keycode_enter)
else -> code.toChar().toString()
}
@ -973,7 +960,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
* @return true if the long press is handled, false otherwise. Subclasses should call the
* method on the base class if the subclass doesn't wish to handle the call.
*/
protected fun onLongPress(popupKey: Keyboard.Key): Boolean {
protected fun onLongPress(popupKey: MyKeyboard.Key): Boolean {
val popupKeyboardId = popupKey.popupResId
if (popupKeyboardId != 0) {
mMiniKeyboardContainer = mMiniKeyboardCache[popupKey]
@ -1009,10 +996,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
//mInputView.setSuggest(mSuggest);
val keyboard: Keyboard = if (popupKey.popupCharacters != null) {
Keyboard(context, popupKeyboardId, popupKey.popupCharacters, -1, paddingLeft + paddingRight)
val keyboard = if (popupKey.popupCharacters != null) {
MyKeyboard(context, popupKeyboardId, popupKey.popupCharacters!!, -1, paddingLeft + paddingRight)
} else {
Keyboard(context, popupKeyboardId)
MyKeyboard(context, popupKeyboardId)
}
mMiniKeyboard!!.setKeyboard(keyboard)
@ -1282,11 +1269,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
private fun removeMessages() {
if (mHandler != null) {
mHandler!!.removeMessages(MSG_REPEAT)
mHandler!!.removeMessages(MSG_LONGPRESS)
mHandler!!.removeMessages(MSG_SHOW_PREVIEW)
}
mHandler?.removeMessages(MSG_REPEAT)
mHandler?.removeMessages(MSG_LONGPRESS)
mHandler?.removeMessages(MSG_SHOW_PREVIEW)
}
public override fun onDetachedFromWindow() {