Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Keyboard IME #294

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions app/src/main/java/be/scri/helpers/HintUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import be.scri.helpers.portuguese.PTInterfaceVariables
import be.scri.helpers.russian.RUInterfaceVariables
import be.scri.helpers.spanish.ESInterfaceVariables
import be.scri.helpers.swedish.SVInterfaceVariables
import be.scri.services.SimpleKeyboardIME
import be.scri.services.GeneralKeyboardIME

object HintUtils {
fun resetHints(context: Context) {
Expand All @@ -42,18 +42,18 @@ object HintUtils {
}

fun getCommandBarHint(
currentState: SimpleKeyboardIME.ScribeState,
currentState: GeneralKeyboardIME.ScribeState,
language: String,
): String {
val hintMessageForState = getHintForState(currentState)
return hintMessageForState[language] ?: "" // return the placeholder or empty string if not found
}

private fun getHintForState(currentState: SimpleKeyboardIME.ScribeState): Map<String, String> =
private fun getHintForState(currentState: GeneralKeyboardIME.ScribeState): Map<String, String> =
when (currentState) {
SimpleKeyboardIME.ScribeState.TRANSLATE -> getTranslateHints()
SimpleKeyboardIME.ScribeState.CONJUGATE -> getConjugateHints()
SimpleKeyboardIME.ScribeState.PLURAL -> getPluralHints()
GeneralKeyboardIME.ScribeState.TRANSLATE -> getTranslateHints()
GeneralKeyboardIME.ScribeState.CONJUGATE -> getConjugateHints()
GeneralKeyboardIME.ScribeState.PLURAL -> getPluralHints()
else -> emptyMap()
}

Expand Down Expand Up @@ -94,13 +94,13 @@ object HintUtils {
)

fun getPromptText(
currentState: SimpleKeyboardIME.ScribeState,
currentState: GeneralKeyboardIME.ScribeState,
language: String,
): String =
when (currentState) {
SimpleKeyboardIME.ScribeState.TRANSLATE -> getTranslationPrompt(language)
SimpleKeyboardIME.ScribeState.CONJUGATE -> getConjugationPrompt(language)
SimpleKeyboardIME.ScribeState.PLURAL -> getPluralPrompt(language)
GeneralKeyboardIME.ScribeState.TRANSLATE -> getTranslationPrompt(language)
GeneralKeyboardIME.ScribeState.CONJUGATE -> getConjugationPrompt(language)
GeneralKeyboardIME.ScribeState.PLURAL -> getPluralPrompt(language)
else -> ""
}

Expand Down
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
26 changes: 13 additions & 13 deletions app/src/main/java/be/scri/services/EnglishKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ 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.views.MyKeyboardView
import be.scri.helpers.KeyboardBase
import be.scri.views.KeyboardView

class EnglishKeyboardIME : SimpleKeyboardIME("English") {
class EnglishKeyboardIME : GeneralKeyboardIME("English") {
override fun getKeyboardLayoutXML(): Int =
if (getEnablePeriodAndCommaABC()) {
R.xml.keys_letters_english
Expand All @@ -40,8 +40,8 @@ class EnglishKeyboardIME : SimpleKeyboardIME("English") {
override val keyboardSymbols = 1
override val keyboardSymbolShift = 2

override var keyboard: MyKeyboard? = null
override var keyboardView: MyKeyboardView? = null
override var keyboard: KeyboardBase? = null
override var keyboardView: KeyboardView? = null
override var lastShiftPressTS = 0L
override var keyboardMode = keyboardLetters
override var inputTypeClass = InputType.TYPE_CLASS_TEXT
Expand Down Expand Up @@ -72,34 +72,34 @@ class EnglishKeyboardIME : SimpleKeyboardIME("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 : SimpleKeyboardIME("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 : SimpleKeyboardIME("English") {

override fun onCreate() {
super.onCreate()
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
keyboard = KeyboardBase(this, getKeyboardLayoutXML(), enterKeyType)
onCreateInputView()
setupCommandBarTheme(binding)
}
Expand Down
26 changes: 13 additions & 13 deletions app/src/main/java/be/scri/services/FrenchKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ 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.views.MyKeyboardView
import be.scri.helpers.KeyboardBase
import be.scri.views.KeyboardView

class FrenchKeyboardIME : SimpleKeyboardIME("French") {
class FrenchKeyboardIME : GeneralKeyboardIME("French") {
override fun getKeyboardLayoutXML(): Int =
if (getEnablePeriodAndCommaABC()) {
R.xml.keys_letters_french
Expand All @@ -37,8 +37,8 @@ class FrenchKeyboardIME : SimpleKeyboardIME("French") {
}

override lateinit var binding: KeyboardViewCommandOptionsBinding
override var keyboardView: MyKeyboardView? = null
override var keyboard: MyKeyboard? = null
override var keyboardView: KeyboardView? = 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 : SimpleKeyboardIME("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 : SimpleKeyboardIME("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 : SimpleKeyboardIME("French") {

override fun onCreate() {
super.onCreate()
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
keyboard = KeyboardBase(this, getKeyboardLayoutXML(), enterKeyType)
onCreateInputView()
setupCommandBarTheme(binding)
}
Expand Down
Loading
Loading