mirror of
https://github.com/SimpleMobileTools/Simple-Keyboard.git
synced 2025-02-07 15:38:38 +01:00
renaming some variables for consistency
This commit is contained in:
parent
61b5f4ff60
commit
74b1fcbb75
@ -46,16 +46,16 @@ class MyKeyboard {
|
||||
private var mDefaultHeight = 0
|
||||
|
||||
/** Is the keyboard in the shifted state */
|
||||
var shiftState = SHIFT_OFF
|
||||
var mShiftState = SHIFT_OFF
|
||||
|
||||
/** Key instance for the shift key, if present */
|
||||
private val mShiftKeys = arrayOf<Key?>(null, null)
|
||||
|
||||
/** Total height of the keyboard, including the padding and keys */
|
||||
var height = 0
|
||||
var mHeight = 0
|
||||
|
||||
/** Total width of the keyboard, including left side gaps and keys, but not any gaps on the right side. */
|
||||
var minWidth = 0
|
||||
var mMinWidth = 0
|
||||
|
||||
/** List of keys in this keyboard */
|
||||
var mKeys: MutableList<Key?>? = null
|
||||
@ -63,9 +63,6 @@ class MyKeyboard {
|
||||
/** Width of the screen available to fit the keyboard */
|
||||
private var mDisplayWidth = 0
|
||||
|
||||
/** Height of the screen */
|
||||
private var mDisplayHeight = 0
|
||||
|
||||
/** What icon should we show at Enter key */
|
||||
private var mEnterKeyType = IME_ACTION_NONE
|
||||
|
||||
@ -75,7 +72,7 @@ class MyKeyboard {
|
||||
private var mCellHeight = 0
|
||||
private var mGridNeighbors: SparseArray<IntArray?>? = null
|
||||
private var mProximityThreshold = 0
|
||||
private val rows = ArrayList<Row?>()
|
||||
private val mRows = ArrayList<Row?>()
|
||||
|
||||
companion object {
|
||||
private const val TAG_KEYBOARD = "Keyboard"
|
||||
@ -348,7 +345,6 @@ class MyKeyboard {
|
||||
constructor(context: Context, @XmlRes xmlLayoutResId: Int, enterKeyType: Int, modeId: Int = 0) {
|
||||
val dm = context.resources.displayMetrics
|
||||
mDisplayWidth = dm.widthPixels
|
||||
mDisplayHeight = dm.heightPixels
|
||||
mDefaultHorizontalGap = 0
|
||||
mDefaultWidth = mDisplayWidth / 10
|
||||
mDefaultHeight = mDefaultWidth
|
||||
@ -376,7 +372,7 @@ class MyKeyboard {
|
||||
var x = 0
|
||||
var y = 0
|
||||
var column = 0
|
||||
minWidth = 0
|
||||
mMinWidth = 0
|
||||
val row = Row(this)
|
||||
row.defaultHeight = mDefaultHeight
|
||||
row.defaultWidth = mDefaultWidth
|
||||
@ -388,7 +384,7 @@ class MyKeyboard {
|
||||
column = 0
|
||||
x = 0
|
||||
y += mDefaultHeight
|
||||
rows.add(row)
|
||||
mRows.add(row)
|
||||
row.mKeys.clear()
|
||||
}
|
||||
|
||||
@ -400,18 +396,18 @@ class MyKeyboard {
|
||||
x += key.width + key.gap
|
||||
mKeys!!.add(key)
|
||||
row.mKeys.add(key)
|
||||
if (x > minWidth) {
|
||||
minWidth = x
|
||||
if (x > mMinWidth) {
|
||||
mMinWidth = x
|
||||
}
|
||||
}
|
||||
height = y + mDefaultHeight
|
||||
rows.add(row)
|
||||
mHeight = y + mDefaultHeight
|
||||
mRows.add(row)
|
||||
}
|
||||
|
||||
fun resize(newWidth: Int, newHeight: Int) {
|
||||
val numRows = rows.size
|
||||
val numRows = mRows.size
|
||||
for (rowIndex in 0 until numRows) {
|
||||
val row = rows[rowIndex] ?: continue
|
||||
val row = mRows[rowIndex] ?: continue
|
||||
val numKeys: Int = row.mKeys.size
|
||||
var totalGap = 0
|
||||
var totalWidth = 0
|
||||
@ -435,15 +431,15 @@ class MyKeyboard {
|
||||
}
|
||||
}
|
||||
|
||||
minWidth = newWidth
|
||||
mMinWidth = 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.
|
||||
}
|
||||
|
||||
fun setShifted(shiftState: Int): Boolean {
|
||||
if (this.shiftState != shiftState) {
|
||||
this.shiftState = shiftState
|
||||
if (this.mShiftState != shiftState) {
|
||||
this.mShiftState = shiftState
|
||||
return true
|
||||
}
|
||||
|
||||
@ -452,8 +448,8 @@ class MyKeyboard {
|
||||
|
||||
private fun computeNearestNeighbors() {
|
||||
// Round-up so we don't have any pixels outside the grid
|
||||
mCellWidth = (minWidth + GRID_WIDTH - 1) / GRID_WIDTH
|
||||
mCellHeight = (height + GRID_HEIGHT - 1) / GRID_HEIGHT
|
||||
mCellWidth = (mMinWidth + GRID_WIDTH - 1) / GRID_WIDTH
|
||||
mCellHeight = (mHeight + GRID_HEIGHT - 1) / GRID_HEIGHT
|
||||
mGridNeighbors = SparseArray<IntArray?>(GRID_SIZE)
|
||||
val indices = IntArray(mKeys!!.size)
|
||||
val gridWidth: Int = GRID_WIDTH * mCellWidth
|
||||
@ -495,7 +491,7 @@ class MyKeyboard {
|
||||
computeNearestNeighbors()
|
||||
}
|
||||
|
||||
if (x in 0 until minWidth && y >= 0 && y < height) {
|
||||
if (x in 0 until mMinWidth && y >= 0 && y < mHeight) {
|
||||
val index = y / mCellHeight * GRID_WIDTH + x / mCellWidth
|
||||
if (index < GRID_SIZE) {
|
||||
return mGridNeighbors!![index]!!
|
||||
@ -531,7 +527,7 @@ class MyKeyboard {
|
||||
inRow = true
|
||||
x = 0
|
||||
currentRow = createRowFromXml(res, parser)
|
||||
rows.add(currentRow)
|
||||
mRows.add(currentRow)
|
||||
} else if (TAG_KEY == tag) {
|
||||
inKey = true
|
||||
key = createKeyFromXml(res, currentRow!!, x, y, parser)
|
||||
@ -561,8 +557,8 @@ class MyKeyboard {
|
||||
if (inKey) {
|
||||
inKey = false
|
||||
x += key!!.gap + key.width
|
||||
if (x > minWidth) {
|
||||
minWidth = x
|
||||
if (x > mMinWidth) {
|
||||
mMinWidth = x
|
||||
}
|
||||
} else if (inRow) {
|
||||
inRow = false
|
||||
@ -573,7 +569,7 @@ class MyKeyboard {
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
height = y
|
||||
mHeight = y
|
||||
}
|
||||
|
||||
private fun parseKeyboardAttributes(res: Resources, parser: XmlResourceParser) {
|
||||
|
@ -39,7 +39,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
||||
override fun onCreateInputView(): View {
|
||||
keyboardView = layoutInflater.inflate(R.layout.keyboard_view_keyboard, null) as MyKeyboardView
|
||||
keyboardView!!.setKeyboard(keyboard!!)
|
||||
keyboardView!!.onKeyboardActionListener = this
|
||||
keyboardView!!.mOnKeyboardActionListener = this
|
||||
return keyboardView!!
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
||||
private fun updateShiftKeyState() {
|
||||
if (keyboardMode == KEYBOARD_LETTERS) {
|
||||
val editorInfo = currentInputEditorInfo
|
||||
if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL && keyboard?.shiftState != SHIFT_ON_PERMANENT) {
|
||||
if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL && keyboard?.mShiftState != SHIFT_ON_PERMANENT) {
|
||||
if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) {
|
||||
keyboard?.setShifted(SHIFT_ON_ONE_CHAR)
|
||||
keyboardView?.invalidateAllKeys()
|
||||
@ -90,8 +90,8 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
||||
|
||||
when (primaryCode) {
|
||||
MyKeyboard.KEYCODE_DELETE -> {
|
||||
if (keyboard!!.shiftState == SHIFT_ON_ONE_CHAR) {
|
||||
keyboard!!.shiftState = SHIFT_OFF
|
||||
if (keyboard!!.mShiftState == SHIFT_ON_ONE_CHAR) {
|
||||
keyboard!!.mShiftState = SHIFT_OFF
|
||||
}
|
||||
|
||||
val selectedText = inputConnection.getSelectedText(0)
|
||||
@ -105,10 +105,10 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
||||
MyKeyboard.KEYCODE_SHIFT -> {
|
||||
if (keyboardMode == KEYBOARD_LETTERS) {
|
||||
when {
|
||||
keyboard!!.shiftState == SHIFT_ON_PERMANENT -> keyboard!!.shiftState = SHIFT_OFF
|
||||
System.currentTimeMillis() - lastShiftPressTS < SHIFT_PERM_TOGGLE_SPEED -> keyboard!!.shiftState = SHIFT_ON_PERMANENT
|
||||
keyboard!!.shiftState == SHIFT_ON_ONE_CHAR -> keyboard!!.shiftState = SHIFT_OFF
|
||||
keyboard!!.shiftState == SHIFT_OFF -> keyboard!!.shiftState = SHIFT_ON_ONE_CHAR
|
||||
keyboard!!.mShiftState == SHIFT_ON_PERMANENT -> keyboard!!.mShiftState = SHIFT_OFF
|
||||
System.currentTimeMillis() - lastShiftPressTS < SHIFT_PERM_TOGGLE_SPEED -> keyboard!!.mShiftState = SHIFT_ON_PERMANENT
|
||||
keyboard!!.mShiftState == SHIFT_ON_ONE_CHAR -> keyboard!!.mShiftState = SHIFT_OFF
|
||||
keyboard!!.mShiftState == SHIFT_OFF -> keyboard!!.mShiftState = SHIFT_ON_ONE_CHAR
|
||||
}
|
||||
|
||||
lastShiftPressTS = System.currentTimeMillis()
|
||||
@ -142,7 +142,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
||||
}
|
||||
else -> {
|
||||
var code = primaryCode.toChar()
|
||||
if (Character.isLetter(code) && keyboard!!.shiftState > SHIFT_OFF) {
|
||||
if (Character.isLetter(code) && keyboard!!.mShiftState > SHIFT_OFF) {
|
||||
code = Character.toUpperCase(code)
|
||||
}
|
||||
|
||||
@ -158,8 +158,8 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
||||
inputConnection.commitText(code.toString(), 1)
|
||||
}
|
||||
|
||||
if (keyboard!!.shiftState == SHIFT_ON_ONE_CHAR && keyboardMode == KEYBOARD_LETTERS) {
|
||||
keyboard!!.shiftState = SHIFT_OFF
|
||||
if (keyboard!!.mShiftState == SHIFT_ON_ONE_CHAR && keyboardMode == KEYBOARD_LETTERS) {
|
||||
keyboard!!.mShiftState = SHIFT_OFF
|
||||
keyboardView!!.invalidateAllKeys()
|
||||
}
|
||||
}
|
||||
@ -176,7 +176,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
||||
keyboard = MyKeyboard(this, R.xml.keys_letters, enterKeyType)
|
||||
|
||||
val editorInfo = currentInputEditorInfo
|
||||
if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL && keyboard?.shiftState != SHIFT_ON_PERMANENT) {
|
||||
if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL && keyboard?.mShiftState != SHIFT_ON_PERMANENT) {
|
||||
if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) {
|
||||
keyboard?.setShifted(SHIFT_ON_ONE_CHAR)
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
private var mKeys = ArrayList<MyKeyboard.Key>()
|
||||
private var mMiniKeyboardSelectedKeyIndex = -1
|
||||
|
||||
var onKeyboardActionListener: OnKeyboardActionListener? = null
|
||||
var mOnKeyboardActionListener: OnKeyboardActionListener? = null
|
||||
private var mVerticalCorrection = 0
|
||||
private var mProximityThreshold = 0
|
||||
private var mPopupPreviewX = 0
|
||||
@ -303,7 +303,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
* @see KeyboardView.setShifted
|
||||
*/
|
||||
private fun isShifted(): Boolean {
|
||||
return mKeyboard?.shiftState ?: SHIFT_OFF > SHIFT_OFF
|
||||
return mKeyboard?.mShiftState ?: SHIFT_OFF > SHIFT_OFF
|
||||
}
|
||||
|
||||
private fun setPopupOffset(x: Int, y: Int) {
|
||||
@ -316,7 +316,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
|
||||
private fun adjustCase(label: CharSequence): CharSequence? {
|
||||
var newLabel: CharSequence? = label
|
||||
if (newLabel != null && newLabel.isNotEmpty() && mKeyboard!!.shiftState > SHIFT_OFF && newLabel.length < 3 && Character.isLowerCase(newLabel[0])) {
|
||||
if (newLabel != null && newLabel.isNotEmpty() && mKeyboard!!.mShiftState > SHIFT_OFF && newLabel.length < 3 && Character.isLowerCase(newLabel[0])) {
|
||||
newLabel = newLabel.toString().toUpperCase()
|
||||
}
|
||||
return newLabel
|
||||
@ -326,11 +326,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
if (mKeyboard == null) {
|
||||
setMeasuredDimension(0, 0)
|
||||
} else {
|
||||
var width: Int = mKeyboard!!.minWidth
|
||||
var width: Int = mKeyboard!!.mMinWidth
|
||||
if (MeasureSpec.getSize(widthMeasureSpec) < width + 10) {
|
||||
width = MeasureSpec.getSize(widthMeasureSpec)
|
||||
}
|
||||
setMeasuredDimension(width, mKeyboard!!.height)
|
||||
setMeasuredDimension(width, mKeyboard!!.mHeight)
|
||||
}
|
||||
}
|
||||
|
||||
@ -467,7 +467,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
paint.setShadowLayer(0f, 0f, 0f, 0)
|
||||
} else if (key.icon != null && mKeyboard != null) {
|
||||
if (key.codes.size == 1 && key.codes.contains(-1)) {
|
||||
val drawableId = when (mKeyboard!!.shiftState) {
|
||||
val drawableId = when (mKeyboard!!.mShiftState) {
|
||||
SHIFT_OFF -> R.drawable.ic_caps_outline_vector
|
||||
SHIFT_ON_ONE_CHAR -> R.drawable.ic_caps_vector
|
||||
else -> R.drawable.ic_caps_underlined_vector
|
||||
@ -570,13 +570,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
// Multi-tap
|
||||
if (mInMultiTap) {
|
||||
if (mTapCount != -1) {
|
||||
onKeyboardActionListener!!.onKey(MyKeyboard.KEYCODE_DELETE, KEY_DELETE)
|
||||
mOnKeyboardActionListener!!.onKey(MyKeyboard.KEYCODE_DELETE, KEY_DELETE)
|
||||
} else {
|
||||
mTapCount = 0
|
||||
}
|
||||
code = key.codes[mTapCount]
|
||||
}
|
||||
onKeyboardActionListener!!.onKey(code, codes)
|
||||
mOnKeyboardActionListener!!.onKey(code, codes)
|
||||
mLastSentIndex = index
|
||||
mLastTapTime = eventTime
|
||||
}
|
||||
@ -834,26 +834,26 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
mMiniKeyboardContainer = inflater.inflate(mPopupLayout, null)
|
||||
mMiniKeyboard = mMiniKeyboardContainer!!.findViewById<View>(R.id.mini_keyboard_view) as MyKeyboardView
|
||||
|
||||
mMiniKeyboard!!.onKeyboardActionListener = object : OnKeyboardActionListener {
|
||||
mMiniKeyboard!!.mOnKeyboardActionListener = object : OnKeyboardActionListener {
|
||||
override fun onKey(primaryCode: Int, keyCodes: IntArray?) {
|
||||
onKeyboardActionListener!!.onKey(primaryCode, keyCodes)
|
||||
mOnKeyboardActionListener!!.onKey(primaryCode, keyCodes)
|
||||
dismissPopupKeyboard()
|
||||
}
|
||||
|
||||
override fun onPress(primaryCode: Int) {
|
||||
onKeyboardActionListener!!.onPress(primaryCode)
|
||||
mOnKeyboardActionListener!!.onPress(primaryCode)
|
||||
}
|
||||
|
||||
override fun onActionUp() {
|
||||
onKeyboardActionListener!!.onActionUp()
|
||||
mOnKeyboardActionListener!!.onActionUp()
|
||||
}
|
||||
|
||||
override fun moveCursorLeft() {
|
||||
onKeyboardActionListener!!.moveCursorLeft()
|
||||
mOnKeyboardActionListener!!.moveCursorLeft()
|
||||
}
|
||||
|
||||
override fun moveCursorRight() {
|
||||
onKeyboardActionListener!!.moveCursorRight()
|
||||
mOnKeyboardActionListener!!.moveCursorRight()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1012,7 +1012,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
}
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||
mMiniKeyboard?.mKeys?.firstOrNull { it.focused }?.apply {
|
||||
onKeyboardActionListener!!.onKey(codes[0], codes.toIntArray())
|
||||
mOnKeyboardActionListener!!.onKey(codes[0], codes.toIntArray())
|
||||
}
|
||||
mMiniKeyboardSelectedKeyIndex = -1
|
||||
dismissPopupKeyboard()
|
||||
@ -1064,7 +1064,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
0
|
||||
}
|
||||
|
||||
onKeyboardActionListener!!.onPress(onPressKey)
|
||||
mOnKeyboardActionListener!!.onPress(onPressKey)
|
||||
|
||||
var wasHandled = false
|
||||
if (mCurrentKey >= 0 && mKeys[mCurrentKey].repeatable) {
|
||||
@ -1123,12 +1123,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
|
||||
if (diff < -mSpaceMoveThreshold) {
|
||||
for (i in diff / mSpaceMoveThreshold until 0) {
|
||||
onKeyboardActionListener?.moveCursorLeft()
|
||||
mOnKeyboardActionListener?.moveCursorLeft()
|
||||
}
|
||||
mLastSpaceMoveX = mLastX
|
||||
} else if (diff > mSpaceMoveThreshold) {
|
||||
for (i in 0 until diff / mSpaceMoveThreshold) {
|
||||
onKeyboardActionListener?.moveCursorRight()
|
||||
mOnKeyboardActionListener?.moveCursorRight()
|
||||
}
|
||||
mLastSpaceMoveX = mLastX
|
||||
}
|
||||
@ -1176,7 +1176,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
|
||||
invalidateKey(keyIndex)
|
||||
mRepeatKeyIndex = NOT_A_KEY
|
||||
onKeyboardActionListener!!.onActionUp()
|
||||
mOnKeyboardActionListener!!.onActionUp()
|
||||
mIsLongPressingSpace = false
|
||||
}
|
||||
MotionEvent.ACTION_CANCEL -> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user