Skip to content

Commit

Permalink
Rename MyKeyboard to KeyboardBase
Browse files Browse the repository at this point in the history
  • Loading branch information
Linfye committed Jan 7, 2025
1 parent 19e13f0 commit bc158e7
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import java.io.IOException
* @attr ref android.R.styleable#Keyboard_horizontalGap
*/
@Suppress("LongMethod", "NestedBlockDepth", "CyclomaticComplexMethod")
class MyKeyboard {
class KeyboardBase {
/** Horizontal gap default for all rows */
private var mDefaultHorizontalGap = 0

Expand Down Expand Up @@ -104,7 +104,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 [MyKeyboard] defines.
* what the [KeyboardBase] defines.
* @attr ref android.R.styleable#Keyboard_keyWidth
* @attr ref android.R.styleable#Keyboard_horizontalGap
*/
Expand All @@ -120,19 +120,19 @@ class MyKeyboard {

var mKeys = ArrayList<Key>()

var parent: MyKeyboard
var parent: KeyboardBase

constructor(parent: MyKeyboard) {
constructor(parent: KeyboardBase) {
this.parent = parent
}

constructor(res: Resources, parent: MyKeyboard, parser: XmlResourceParser?) {
constructor(res: Resources, parent: KeyboardBase, parser: XmlResourceParser?) {
this.parent = parent
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.KeyboardBase)
defaultWidth =
getDimensionOrFraction(
a,
R.styleable.MyKeyboard_keyWidth,
R.styleable.KeyboardBase_keyWidth,
parent.mDisplayWidth,
parent.mDefaultWidth,
)
Expand All @@ -145,7 +145,7 @@ class MyKeyboard {
defaultHorizontalGap =
getDimensionOrFraction(
a,
R.styleable.MyKeyboard_horizontalGap,
R.styleable.KeyboardBase_horizontalGap,
parent.mDisplayWidth,
parent.mDefaultHorizontalGap,
)
Expand Down Expand Up @@ -209,7 +209,7 @@ 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 [MyKeyboard.EDGE_LEFT], [MyKeyboard.EDGE_RIGHT].
* This is a bit mask of [KeyboardBase.EDGE_LEFT], [KeyboardBase.EDGE_RIGHT].
*/
private var edgeFlags = 0

Expand All @@ -224,7 +224,7 @@ class MyKeyboard {

/** Create a key with the given top-left coordinate and extract its attributes from the XML parser.
* @param res resources associated with the caller's context
* @param parent the row that this key belongs to. The row must already be attached to a [MyKeyboard].
* @param parent the row that this key belongs to. The row must already be attached to a [KeyboardBase].
* @param x the x coordinate of the top-left
* @param y the y coordinate of the top-left
* @param parser the XML parser containing the attributes for this key
Expand All @@ -235,13 +235,13 @@ class MyKeyboard {
var a =
res.obtainAttributes(
Xml.asAttributeSet(parser),
R.styleable.MyKeyboard,
R.styleable.KeyboardBase,
)

width =
getDimensionOrFraction(
a,
R.styleable.MyKeyboard_keyWidth,
R.styleable.KeyboardBase_keyWidth,
keyboard.mDisplayWidth,
parent.defaultWidth,
)
Expand All @@ -251,25 +251,25 @@ class MyKeyboard {
gap =
getDimensionOrFraction(
a,
R.styleable.MyKeyboard_horizontalGap,
R.styleable.KeyboardBase_horizontalGap,
keyboard.mDisplayWidth,
parent.defaultHorizontalGap,
)
this.x += gap

a.recycle()
a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard_Key)
code = a.getInt(R.styleable.MyKeyboard_Key_code, 0)

popupCharacters = a.getText(R.styleable.MyKeyboard_Key_popupCharacters)
popupResId = a.getResourceId(R.styleable.MyKeyboard_Key_popupKeyboard, 0)
repeatable = a.getBoolean(R.styleable.MyKeyboard_Key_isRepeatable, false)
edgeFlags = a.getInt(R.styleable.MyKeyboard_Key_keyEdgeFlags, 0)
icon = a.getDrawable(R.styleable.MyKeyboard_Key_keyIcon)
a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.KeyboardBase_Key)
code = a.getInt(R.styleable.KeyboardBase_Key_code, 0)

popupCharacters = a.getText(R.styleable.KeyboardBase_Key_popupCharacters)
popupResId = a.getResourceId(R.styleable.KeyboardBase_Key_popupKeyboard, 0)
repeatable = a.getBoolean(R.styleable.KeyboardBase_Key_isRepeatable, false)
edgeFlags = a.getInt(R.styleable.KeyboardBase_Key_keyEdgeFlags, 0)
icon = a.getDrawable(R.styleable.KeyboardBase_Key_keyIcon)
icon?.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight)

label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: ""
topSmallNumber = a.getString(R.styleable.MyKeyboard_Key_topSmallNumber) ?: ""
label = a.getText(R.styleable.KeyboardBase_Key_keyLabel) ?: ""
topSmallNumber = a.getString(R.styleable.KeyboardBase_Key_topSmallNumber) ?: ""

if (label.isNotEmpty() && code != KEYCODE_MODE_CHANGE && code != KEYCODE_SHIFT) {
code = label[0].code
Expand Down Expand Up @@ -465,9 +465,9 @@ class MyKeyboard {
}
}
} catch (e: XmlPullParserException) {
Log.e("MyKeyboard", "XML Parsing error: ${e.message}")
Log.e("KeyboardBase", "XML Parsing error: ${e.message}")
} catch (e: IOException) {
Log.e("MyKeyboard", "I/O error: ${e.message}")
Log.e("KeyboardBase", "I/O error: ${e.message}")
}
mHeight = y
}
Expand All @@ -476,12 +476,12 @@ class MyKeyboard {
res: Resources,
parser: XmlResourceParser,
) {
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
val keyWidthResId = R.styleable.MyKeyboard_keyWidth
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.KeyboardBase)
val keyWidthResId = R.styleable.KeyboardBase_keyWidth
val defaultWidth = mDisplayWidth / WIDTH_DIVIDER
mDefaultWidth = getDimensionOrFraction(a, keyWidthResId, mDisplayWidth, defaultWidth)
mDefaultHeight = res.getDimension(R.dimen.key_height).toInt()
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, mDisplayWidth, 0)
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.KeyboardBase_horizontalGap, mDisplayWidth, 0)
a.recycle()
}

Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/be/scri/services/EnglishKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import android.view.View
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.databinding.KeyboardViewCommandOptionsBinding
import be.scri.helpers.MyKeyboard
import be.scri.helpers.KeyboardBase
import be.scri.views.KeyboardView

class EnglishKeyboardIME : GeneralKeyboardIME("English") {
Expand All @@ -40,7 +40,7 @@ class EnglishKeyboardIME : GeneralKeyboardIME("English") {
override val keyboardSymbols = 1
override val keyboardSymbolShift = 2

override var keyboard: MyKeyboard? = null
override var keyboard: KeyboardBase? = null
override var keyboardView: KeyboardView? = null
override var lastShiftPressTS = 0L
override var keyboardMode = keyboardLetters
Expand Down Expand Up @@ -72,34 +72,34 @@ class EnglishKeyboardIME : GeneralKeyboardIME("English") {
if (keyboard == null || inputConnection == null) {
return
}
if (code != MyKeyboard.KEYCODE_SHIFT) {
if (code != KeyboardBase.KEYCODE_SHIFT) {
lastShiftPressTS = 0
}

when (code) {
MyKeyboard.KEYCODE_DELETE -> {
KeyboardBase.KEYCODE_DELETE -> {
handleKeycodeDelete()
keyboardView!!.invalidateAllKeys()
disableAutoSuggest()
}

MyKeyboard.KEYCODE_SHIFT -> {
KeyboardBase.KEYCODE_SHIFT -> {
super.handleKeyboardLetters(keyboardMode, keyboardView)
keyboardView!!.invalidateAllKeys()
disableAutoSuggest()
}

MyKeyboard.KEYCODE_ENTER -> {
KeyboardBase.KEYCODE_ENTER -> {
handleKeycodeEnter()
disableAutoSuggest()
}

MyKeyboard.KEYCODE_MODE_CHANGE -> {
KeyboardBase.KEYCODE_MODE_CHANGE -> {
handleModeChange(keyboardMode, keyboardView, this)
disableAutoSuggest()
}

MyKeyboard.KEYCODE_SPACE -> {
KeyboardBase.KEYCODE_SPACE -> {
handleElseCondition(code, keyboardMode, binding = null)
updateAutoSuggestText(nounTypeSuggestion)
}
Expand All @@ -122,7 +122,7 @@ class EnglishKeyboardIME : GeneralKeyboardIME("English") {
Log.d("Debug", "$autosuggestEmojis")
Log.d("MY-TAG", "$nounTypeSuggestion")
updateButtonText(isAutoSuggestEnabled, autosuggestEmojis)
if (code != MyKeyboard.KEYCODE_SHIFT) {
if (code != KeyboardBase.KEYCODE_SHIFT) {
super.updateShiftKeyState()
}
}
Expand All @@ -148,7 +148,7 @@ class EnglishKeyboardIME : GeneralKeyboardIME("English") {

override fun onCreate() {
super.onCreate()
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
keyboard = KeyboardBase(this, getKeyboardLayoutXML(), enterKeyType)
onCreateInputView()
setupCommandBarTheme(binding)
}
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/be/scri/services/FrenchKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import android.view.View
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.databinding.KeyboardViewCommandOptionsBinding
import be.scri.helpers.MyKeyboard
import be.scri.helpers.KeyboardBase
import be.scri.views.KeyboardView

class FrenchKeyboardIME : GeneralKeyboardIME("French") {
Expand All @@ -38,7 +38,7 @@ class FrenchKeyboardIME : GeneralKeyboardIME("French") {

override lateinit var binding: KeyboardViewCommandOptionsBinding
override var keyboardView: KeyboardView? = null
override var keyboard: MyKeyboard? = null
override var keyboard: KeyboardBase? = null
override var enterKeyType = IME_ACTION_NONE
override val keyboardLetters = 0
override val keyboardSymbols = 1
Expand Down Expand Up @@ -68,34 +68,34 @@ class FrenchKeyboardIME : GeneralKeyboardIME("French") {
if (keyboard == null || inputConnection == null) {
return
}
if (code != MyKeyboard.KEYCODE_SHIFT) {
if (code != KeyboardBase.KEYCODE_SHIFT) {
lastShiftPressTS = 0
}

when (code) {
MyKeyboard.KEYCODE_DELETE -> {
KeyboardBase.KEYCODE_DELETE -> {
handleKeycodeDelete()
keyboardView!!.invalidateAllKeys()
disableAutoSuggest()
}

MyKeyboard.KEYCODE_SHIFT -> {
KeyboardBase.KEYCODE_SHIFT -> {
super.handleKeyboardLetters(keyboardMode, keyboardView)
keyboardView!!.invalidateAllKeys()
disableAutoSuggest()
}

MyKeyboard.KEYCODE_ENTER -> {
KeyboardBase.KEYCODE_ENTER -> {
handleKeycodeEnter()
disableAutoSuggest()
}

MyKeyboard.KEYCODE_MODE_CHANGE -> {
KeyboardBase.KEYCODE_MODE_CHANGE -> {
handleModeChange(keyboardMode, keyboardView, this)
disableAutoSuggest()
}

MyKeyboard.KEYCODE_SPACE -> {
KeyboardBase.KEYCODE_SPACE -> {
handleElseCondition(code, keyboardMode, binding = null)
updateAutoSuggestText(nounTypeSuggestion)
}
Expand All @@ -118,7 +118,7 @@ class FrenchKeyboardIME : GeneralKeyboardIME("French") {
Log.d("Debug", "$autosuggestEmojis")
Log.d("MY-TAG", "$nounTypeSuggestion")
updateButtonText(isAutoSuggestEnabled, autosuggestEmojis)
if (code != MyKeyboard.KEYCODE_SHIFT) {
if (code != KeyboardBase.KEYCODE_SHIFT) {
super.updateShiftKeyState()
}
}
Expand All @@ -144,7 +144,7 @@ class FrenchKeyboardIME : GeneralKeyboardIME("French") {

override fun onCreate() {
super.onCreate()
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
keyboard = KeyboardBase(this, getKeyboardLayoutXML(), enterKeyType)
onCreateInputView()
setupCommandBarTheme(binding)
}
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/be/scri/services/GeneralKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import be.scri.databinding.KeyboardViewCommandOptionsBinding
import be.scri.databinding.KeyboardViewKeyboardBinding
import be.scri.helpers.DatabaseHelper
import be.scri.helpers.HintUtils
import be.scri.helpers.MyKeyboard
import be.scri.helpers.KeyboardBase
import be.scri.helpers.SHIFT_OFF
import be.scri.helpers.SHIFT_ON_ONE_CHAR
import be.scri.helpers.SHIFT_ON_PERMANENT
Expand All @@ -65,7 +65,7 @@ abstract class GeneralKeyboardIME(
abstract val keyboardSymbols: Int
abstract val keyboardSymbolShift: Int

abstract var keyboard: MyKeyboard?
abstract var keyboard: KeyboardBase?
abstract var keyboardView: KeyboardView?
abstract var lastShiftPressTS: Long
abstract var keyboardMode: Int
Expand Down Expand Up @@ -116,7 +116,7 @@ abstract class GeneralKeyboardIME(
override fun onCreate() {
super.onCreate()
keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater)
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
keyboard = KeyboardBase(this, getKeyboardLayoutXML(), enterKeyType)
onCreateInputView()
setupCommandBarTheme(binding)
}
Expand All @@ -138,11 +138,11 @@ abstract class GeneralKeyboardIME(
updateCommandBarHintandPrompt()
enterKeyType =
if (isCommandMode) {
MyKeyboard.MyCustomActions.IME_ACTION_COMMAND
KeyboardBase.MyCustomActions.IME_ACTION_COMMAND
} else {
currentEnterKeyType!!
}
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
keyboard = KeyboardBase(this, getKeyboardLayoutXML(), enterKeyType)
}

fun getIsAccentCharacterDisabled(): Boolean {
Expand Down Expand Up @@ -347,7 +347,7 @@ abstract class GeneralKeyboardIME(

override fun onInitializeInterface() {
super.onInitializeInterface()
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
keyboard = KeyboardBase(this, getKeyboardLayoutXML(), enterKeyType)
}

override fun hasTextBeforeCursor(): Boolean {
Expand Down Expand Up @@ -534,7 +534,7 @@ abstract class GeneralKeyboardIME(
emojiKeywords = dbHelper.getEmojiKeywords(languageAlias)
nounKeywords = dbHelper.getNounKeywords(languageAlias)

keyboard = MyKeyboard(this, keyboardXml, enterKeyType)
keyboard = KeyboardBase(this, keyboardXml, enterKeyType)
keyboardView?.setKeyboard(keyboard!!)
}

Expand Down Expand Up @@ -570,7 +570,7 @@ abstract class GeneralKeyboardIME(
override fun onActionUp() {
if (switchToLetters) {
keyboardMode = keyboardLetters
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
keyboard = KeyboardBase(this, getKeyboardLayoutXML(), enterKeyType)

val editorInfo = currentInputEditorInfo
if (
Expand Down Expand Up @@ -653,7 +653,7 @@ abstract class GeneralKeyboardIME(
this.keyboardMode = keyboardLetters
getKeyboardLayoutXML()
}
keyboard = MyKeyboard(context, keyboardXml, enterKeyType)
keyboard = KeyboardBase(context, keyboardXml, enterKeyType)
keyboardView?.invalidateAllKeys()
keyboardView?.setKeyboard(keyboard!!)
}
Expand Down Expand Up @@ -688,7 +688,7 @@ abstract class GeneralKeyboardIME(
this.keyboardMode = keyboardSymbols
R.xml.keys_symbols
}
keyboard = MyKeyboard(this, keyboardXml, enterKeyType)
keyboard = KeyboardBase(this, keyboardXml, enterKeyType)
keyboardView!!.setKeyboard(keyboard!!)
}
}
Expand Down Expand Up @@ -752,7 +752,7 @@ abstract class GeneralKeyboardIME(
}
} else {
// Handling space key logic.
if (keyboardMode != keyboardLetters && code == MyKeyboard.KEYCODE_SPACE) {
if (keyboardMode != keyboardLetters && code == KeyboardBase.KEYCODE_SPACE) {
binding?.commandBar?.text = " "
val originalText = inputConnection.getExtractedText(ExtractedTextRequest(), 0).text
inputConnection.commitText(codeChar.toString(), 1)
Expand Down
Loading

0 comments on commit bc158e7

Please sign in to comment.