From 964690707b17520ab49102fd83752d2279cb504a Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 22 May 2023 13:14:18 +1000 Subject: [PATCH 1/7] Refactored language constants to a single enum --- .../keyboard/extensions/Context.kt | 37 +------- .../keyboard/helpers/Config.kt | 4 +- .../keyboard/helpers/Constants.kt | 84 +++++++++++++++---- .../keyboard/services/SimpleKeyboardIME.kt | 19 +---- 4 files changed, 76 insertions(+), 68 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 855438d..8b842be 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -149,40 +149,9 @@ fun Context.setupKeyboardDialogStuff( } fun Context.getKeyboardLanguages(): ArrayList { - return arrayListOf( - RadioItem(LANGUAGE_BENGALI, getKeyboardLanguageText(LANGUAGE_BENGALI)), - RadioItem(LANGUAGE_BULGARIAN, getKeyboardLanguageText(LANGUAGE_BULGARIAN)), - RadioItem(LANGUAGE_ENGLISH_QWERTY, getKeyboardLanguageText(LANGUAGE_ENGLISH_QWERTY)), - RadioItem(LANGUAGE_ENGLISH_QWERTZ, getKeyboardLanguageText(LANGUAGE_ENGLISH_QWERTZ)), - RadioItem(LANGUAGE_ENGLISH_DVORAK, getKeyboardLanguageText(LANGUAGE_ENGLISH_DVORAK)), - RadioItem(LANGUAGE_FRENCH, getKeyboardLanguageText(LANGUAGE_FRENCH)), - RadioItem(LANGUAGE_GERMAN, getKeyboardLanguageText(LANGUAGE_GERMAN)), - RadioItem(LANGUAGE_GREEK, getKeyboardLanguageText(LANGUAGE_GREEK)), - RadioItem(LANGUAGE_LITHUANIAN, getKeyboardLanguageText(LANGUAGE_LITHUANIAN)), - RadioItem(LANGUAGE_ROMANIAN, getKeyboardLanguageText(LANGUAGE_ROMANIAN)), - RadioItem(LANGUAGE_RUSSIAN, getKeyboardLanguageText(LANGUAGE_RUSSIAN)), - RadioItem(LANGUAGE_SLOVENIAN, getKeyboardLanguageText(LANGUAGE_SLOVENIAN)), - RadioItem(LANGUAGE_SPANISH, getKeyboardLanguageText(LANGUAGE_SPANISH)), - RadioItem(LANGUAGE_TURKISH_Q, getKeyboardLanguageText(LANGUAGE_TURKISH_Q)), - ) + val languages = Language.values().map { RadioItem(it.ordinal, it.getName(this)) } + return ArrayList(languages) } -fun Context.getKeyboardLanguageText(language: Int): String { - return when (language) { - LANGUAGE_BENGALI -> getString(R.string.translation_bengali) - LANGUAGE_BULGARIAN -> getString(R.string.translation_bulgarian) - LANGUAGE_ENGLISH_DVORAK -> "${getString(R.string.translation_english)} (DVORAK)" - LANGUAGE_ENGLISH_QWERTZ -> "${getString(R.string.translation_english)} (QWERTZ)" - LANGUAGE_FRENCH -> getString(R.string.translation_french) - LANGUAGE_GERMAN -> getString(R.string.translation_german) - LANGUAGE_GREEK -> getString(R.string.translation_greek) - LANGUAGE_LITHUANIAN -> getString(R.string.translation_lithuanian) - LANGUAGE_ROMANIAN -> getString(R.string.translation_romanian) - LANGUAGE_RUSSIAN -> getString(R.string.translation_russian) - LANGUAGE_SLOVENIAN -> getString(R.string.translation_slovenian) - LANGUAGE_SPANISH -> getString(R.string.translation_spanish) - LANGUAGE_TURKISH_Q -> "${getString(R.string.translation_turkish)} (Q)" - else -> "${getString(R.string.translation_english)} (QWERTY)" - } -} +fun Context.getKeyboardLanguageText(language: Int) = Language.getKeyboardName(this, language) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt index cb17a74..8ebf81f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt @@ -44,9 +44,9 @@ class Config(context: Context) : BaseConfig(context) { private fun getDefaultLanguage(): Int { val conf = context.resources.configuration return if (conf.locale.toString().toLowerCase(Locale.getDefault()).startsWith("ru_")) { - LANGUAGE_RUSSIAN + Language.RUSSIAN.ordinal } else { - LANGUAGE_ENGLISH_QWERTY + Language.ENGLISH_QWERTY.ordinal } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt index 78a59fc..a52e400 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt @@ -1,5 +1,9 @@ package com.simplemobiletools.keyboard.helpers +import android.content.Context +import androidx.annotation.StringRes +import com.simplemobiletools.keyboard.R + const val SHIFT_OFF = 0 const val SHIFT_ON_ONE_CHAR = 1 const val SHIFT_ON_PERMANENT = 2 @@ -21,20 +25,72 @@ const val SHOW_NUMBERS_ROW = "show_numbers_row" const val ITEM_SECTION_LABEL = 0 const val ITEM_CLIP = 1 -const val LANGUAGE_ENGLISH_QWERTY = 0 -const val LANGUAGE_RUSSIAN = 1 -const val LANGUAGE_FRENCH = 2 -const val LANGUAGE_ENGLISH_QWERTZ = 3 -const val LANGUAGE_SPANISH = 4 -const val LANGUAGE_GERMAN = 5 -const val LANGUAGE_ENGLISH_DVORAK = 6 -const val LANGUAGE_ROMANIAN = 7 -const val LANGUAGE_SLOVENIAN = 8 -const val LANGUAGE_BULGARIAN = 9 -const val LANGUAGE_TURKISH_Q = 10 -const val LANGUAGE_LITHUANIAN = 11 -const val LANGUAGE_BENGALI = 12 -const val LANGUAGE_GREEK = 13 +enum class Language(@StringRes private val stringRes: Int, private val layout: Int) { + ENGLISH_QWERTY( + R.string.translation_english, R.xml.keys_letters_english_qwerty + ), + RUSSIAN( + R.string.translation_russian, R.xml.keys_letters_russian + ), + FRENCH( + R.string.translation_french, R.xml.keys_letters_french + ), + ENGLISH_QWERTZ( + R.string.translation_english, R.xml.keys_letters_english_qwertz + ), + SPANISH( + R.string.translation_spanish, R.string.translation_spanish + ), + GERMAN( + R.string.translation_german, R.xml.keys_letters_german + ), + ENGLISH_DVORAK( + R.string.translation_english, R.xml.keys_letters_english_dvorak + ), + ROMANIAN( + R.string.translation_romanian, R.xml.keys_letters_romanian + ), + SLOVENIAN( + R.string.translation_slovenian, R.xml.keys_letters_slovenian + ), + BULGARIAN( + R.string.translation_bulgarian, R.xml.keys_letters_bulgarian + ), + TURKISH_Q( + R.string.translation_turkish, R.xml.keys_letters_turkish_q + ), + LITHUANIAN( + R.string.translation_lithuanian, R.xml.keys_letters_lithuanian + ), + BENGALI( + R.string.translation_bengali, R.xml.keys_letters_bengali + ), + GREEK( + R.string.translation_greek, R.xml.keys_letters_greek + ); + + fun getName(context: Context): String { + with(context) { + return when (val language = this@Language) { + ENGLISH_DVORAK -> "${getString(language.stringRes)} (DVORAK)" + ENGLISH_QWERTY -> "${getString(language.stringRes)} (QWERTY)" + ENGLISH_QWERTZ -> "${getString(language.stringRes)} (QWERTZ)" + else -> getString(language.stringRes) + } + } + } + + companion object { + fun getKeyboardLayout(keyboardLanguage: Int): Int { + return Language.values().getOrElse(keyboardLanguage) { ENGLISH_QWERTY }.layout + } + + fun getKeyboardName(context: Context, language: Int): String { + return Language.values().getOrElse(language) { ENGLISH_QWERTY }.getName(context) + } + } + +} // keyboard height multiplier options const val KEYBOARD_HEIGHT_MULTIPLIER_SMALL = 1 diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index 8e1192e..1aad86d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -270,24 +270,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL } } - private fun getKeyboardLayoutXML(): Int { - return when (baseContext.config.keyboardLanguage) { - LANGUAGE_BENGALI -> R.xml.keys_letters_bengali - LANGUAGE_BULGARIAN -> R.xml.keys_letters_bulgarian - LANGUAGE_ENGLISH_DVORAK -> R.xml.keys_letters_english_dvorak - LANGUAGE_ENGLISH_QWERTZ -> R.xml.keys_letters_english_qwertz - LANGUAGE_FRENCH -> R.xml.keys_letters_french - LANGUAGE_GERMAN -> R.xml.keys_letters_german - LANGUAGE_GREEK -> R.xml.keys_letters_greek - LANGUAGE_LITHUANIAN -> R.xml.keys_letters_lithuanian - LANGUAGE_ROMANIAN -> R.xml.keys_letters_romanian - LANGUAGE_RUSSIAN -> R.xml.keys_letters_russian - LANGUAGE_SLOVENIAN -> R.xml.keys_letters_slovenian - LANGUAGE_SPANISH -> R.xml.keys_letters_spanish_qwerty - LANGUAGE_TURKISH_Q -> R.xml.keys_letters_turkish_q - else -> R.xml.keys_letters_english_qwerty - } - } + private fun getKeyboardLayoutXML() = Language.getKeyboardLayout(baseContext.config.keyboardLanguage) override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { keyboardView?.setupKeyboard() From ec7dd289e97d1615a999318a06cce7f492cd3edb Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 22 May 2023 13:15:56 +1000 Subject: [PATCH 2/7] Extracted languages enum to the Language.kt file --- .../keyboard/helpers/Constants.kt | 67 ----------------- .../keyboard/helpers/Language.kt | 72 +++++++++++++++++++ 2 files changed, 72 insertions(+), 67 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt index a52e400..cc93269 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt @@ -25,73 +25,6 @@ const val SHOW_NUMBERS_ROW = "show_numbers_row" const val ITEM_SECTION_LABEL = 0 const val ITEM_CLIP = 1 -enum class Language(@StringRes private val stringRes: Int, private val layout: Int) { - ENGLISH_QWERTY( - R.string.translation_english, R.xml.keys_letters_english_qwerty - ), - RUSSIAN( - R.string.translation_russian, R.xml.keys_letters_russian - ), - FRENCH( - R.string.translation_french, R.xml.keys_letters_french - ), - ENGLISH_QWERTZ( - R.string.translation_english, R.xml.keys_letters_english_qwertz - ), - SPANISH( - R.string.translation_spanish, R.string.translation_spanish - ), - GERMAN( - R.string.translation_german, R.xml.keys_letters_german - ), - ENGLISH_DVORAK( - R.string.translation_english, R.xml.keys_letters_english_dvorak - ), - ROMANIAN( - R.string.translation_romanian, R.xml.keys_letters_romanian - ), - SLOVENIAN( - R.string.translation_slovenian, R.xml.keys_letters_slovenian - ), - BULGARIAN( - R.string.translation_bulgarian, R.xml.keys_letters_bulgarian - ), - TURKISH_Q( - R.string.translation_turkish, R.xml.keys_letters_turkish_q - ), - LITHUANIAN( - R.string.translation_lithuanian, R.xml.keys_letters_lithuanian - ), - BENGALI( - R.string.translation_bengali, R.xml.keys_letters_bengali - ), - GREEK( - R.string.translation_greek, R.xml.keys_letters_greek - ); - - fun getName(context: Context): String { - with(context) { - return when (val language = this@Language) { - ENGLISH_DVORAK -> "${getString(language.stringRes)} (DVORAK)" - ENGLISH_QWERTY -> "${getString(language.stringRes)} (QWERTY)" - ENGLISH_QWERTZ -> "${getString(language.stringRes)} (QWERTZ)" - else -> getString(language.stringRes) - } - } - } - - companion object { - fun getKeyboardLayout(keyboardLanguage: Int): Int { - return Language.values().getOrElse(keyboardLanguage) { ENGLISH_QWERTY }.layout - } - - fun getKeyboardName(context: Context, language: Int): String { - return Language.values().getOrElse(language) { ENGLISH_QWERTY }.getName(context) - } - } - -} - // keyboard height multiplier options const val KEYBOARD_HEIGHT_MULTIPLIER_SMALL = 1 const val KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM = 2 diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt new file mode 100644 index 0000000..9fe9d87 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt @@ -0,0 +1,72 @@ +package com.simplemobiletools.keyboard.helpers + +import android.content.Context +import androidx.annotation.StringRes +import com.simplemobiletools.keyboard.R + +enum class Language(@StringRes private val stringRes: Int, private val layout: Int) { + ENGLISH_QWERTY( + R.string.translation_english, R.xml.keys_letters_english_qwerty + ), + RUSSIAN( + R.string.translation_russian, R.xml.keys_letters_russian + ), + FRENCH( + R.string.translation_french, R.xml.keys_letters_french + ), + ENGLISH_QWERTZ( + R.string.translation_english, R.xml.keys_letters_english_qwertz + ), + SPANISH( + R.string.translation_spanish, R.string.translation_spanish + ), + GERMAN( + R.string.translation_german, R.xml.keys_letters_german + ), + ENGLISH_DVORAK( + R.string.translation_english, R.xml.keys_letters_english_dvorak + ), + ROMANIAN( + R.string.translation_romanian, R.xml.keys_letters_romanian + ), + SLOVENIAN( + R.string.translation_slovenian, R.xml.keys_letters_slovenian + ), + BULGARIAN( + R.string.translation_bulgarian, R.xml.keys_letters_bulgarian + ), + TURKISH_Q( + R.string.translation_turkish, R.xml.keys_letters_turkish_q + ), + LITHUANIAN( + R.string.translation_lithuanian, R.xml.keys_letters_lithuanian + ), + BENGALI( + R.string.translation_bengali, R.xml.keys_letters_bengali + ), + GREEK( + R.string.translation_greek, R.xml.keys_letters_greek + ); + + fun getName(context: Context): String { + with(context) { + return when (val language = this@Language) { + ENGLISH_DVORAK -> "${getString(language.stringRes)} (DVORAK)" + ENGLISH_QWERTY -> "${getString(language.stringRes)} (QWERTY)" + ENGLISH_QWERTZ -> "${getString(language.stringRes)} (QWERTZ)" + else -> getString(language.stringRes) + } + } + } + + companion object { + fun getKeyboardLayout(keyboardLanguage: Int): Int { + return Language.values().getOrElse(keyboardLanguage) { ENGLISH_QWERTY }.layout + } + + fun getKeyboardName(context: Context, language: Int): String { + return Language.values().getOrElse(language) { ENGLISH_QWERTY }.getName(context) + } + } + +} From a85d9247eee863dfe78cbc8ae302260dc182dfd9 Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 22 May 2023 22:36:38 +1000 Subject: [PATCH 3/7] Added norwegian, danish and swedish keyboard layouts --- .../keyboard/helpers/Language.kt | 9 + app/src/main/res/xml/keys_letters_danish.xml | 213 ++++++++++++++++++ .../main/res/xml/keys_letters_norwegian.xml | 213 ++++++++++++++++++ app/src/main/res/xml/keys_letters_swedish.xml | 212 +++++++++++++++++ 4 files changed, 647 insertions(+) create mode 100644 app/src/main/res/xml/keys_letters_danish.xml create mode 100644 app/src/main/res/xml/keys_letters_norwegian.xml create mode 100644 app/src/main/res/xml/keys_letters_swedish.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt index 9fe9d87..e48a655 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt @@ -46,6 +46,15 @@ enum class Language(@StringRes private val stringRes: Int, private val layout: I ), GREEK( R.string.translation_greek, R.xml.keys_letters_greek + ), + Norwegian( + R.string.translation_norwegian, R.xml.keys_letters_norwegian + ), + Swedish( + R.string.translation_swedish, R.xml.keys_letters_swedish + ), + Danish( + R.string.translation_danish, R.xml.keys_letters_danish ); fun getName(context: Context): String { diff --git a/app/src/main/res/xml/keys_letters_danish.xml b/app/src/main/res/xml/keys_letters_danish.xml new file mode 100644 index 0000000..f421e68 --- /dev/null +++ b/app/src/main/res/xml/keys_letters_danish.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/keys_letters_norwegian.xml b/app/src/main/res/xml/keys_letters_norwegian.xml new file mode 100644 index 0000000..8db27c8 --- /dev/null +++ b/app/src/main/res/xml/keys_letters_norwegian.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/keys_letters_swedish.xml b/app/src/main/res/xml/keys_letters_swedish.xml new file mode 100644 index 0000000..7c6f246 --- /dev/null +++ b/app/src/main/res/xml/keys_letters_swedish.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 5738029991e06deb09e21d25ae8af28c5aec2aef Mon Sep 17 00:00:00 2001 From: merkost Date: Thu, 25 May 2023 23:19:53 +1000 Subject: [PATCH 4/7] Language.kt - added sorted function --- .../kotlin/com/simplemobiletools/keyboard/extensions/Context.kt | 2 +- .../kotlin/com/simplemobiletools/keyboard/helpers/Language.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 8b842be..75e8aa8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -149,7 +149,7 @@ fun Context.setupKeyboardDialogStuff( } fun Context.getKeyboardLanguages(): ArrayList { - val languages = Language.values().map { RadioItem(it.ordinal, it.getName(this)) } + val languages = Language.sorted(this).map { RadioItem(it.ordinal, it.getName(this)) } return ArrayList(languages) } diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt index 9fe9d87..dd6be24 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt @@ -60,6 +60,8 @@ enum class Language(@StringRes private val stringRes: Int, private val layout: I } companion object { + fun sorted(context: Context) = Language.values().sortedBy { context.getString(it.stringRes) } + fun getKeyboardLayout(keyboardLanguage: Int): Int { return Language.values().getOrElse(keyboardLanguage) { ENGLISH_QWERTY }.layout } From 326772789b67793ace75ed3a4cd719497150f8b2 Mon Sep 17 00:00:00 2001 From: merkost Date: Fri, 26 May 2023 08:57:59 +1000 Subject: [PATCH 5/7] Language.kt - languages sorted inside enum --- .../keyboard/helpers/Language.kt | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt index c90dee3..5656b79 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt @@ -5,56 +5,56 @@ import androidx.annotation.StringRes import com.simplemobiletools.keyboard.R enum class Language(@StringRes private val stringRes: Int, private val layout: Int) { - ENGLISH_QWERTY( - R.string.translation_english, R.xml.keys_letters_english_qwerty - ), - RUSSIAN( - R.string.translation_russian, R.xml.keys_letters_russian - ), - FRENCH( - R.string.translation_french, R.xml.keys_letters_french - ), - ENGLISH_QWERTZ( - R.string.translation_english, R.xml.keys_letters_english_qwertz - ), - SPANISH( - R.string.translation_spanish, R.string.translation_spanish - ), - GERMAN( - R.string.translation_german, R.xml.keys_letters_german - ), - ENGLISH_DVORAK( - R.string.translation_english, R.xml.keys_letters_english_dvorak - ), - ROMANIAN( - R.string.translation_romanian, R.xml.keys_letters_romanian - ), - SLOVENIAN( - R.string.translation_slovenian, R.xml.keys_letters_slovenian + BENGALI( + R.string.translation_bengali, R.xml.keys_letters_bengali ), BULGARIAN( R.string.translation_bulgarian, R.xml.keys_letters_bulgarian ), - TURKISH_Q( - R.string.translation_turkish, R.xml.keys_letters_turkish_q + DANISH( + R.string.translation_danish, R.xml.keys_letters_danish ), - LITHUANIAN( - R.string.translation_lithuanian, R.xml.keys_letters_lithuanian + ENGLISH_DVORAK( + R.string.translation_english, R.xml.keys_letters_english_dvorak ), - BENGALI( - R.string.translation_bengali, R.xml.keys_letters_bengali + ENGLISH_QWERTY( + R.string.translation_english, R.xml.keys_letters_english_qwerty + ), + ENGLISH_QWERTZ( + R.string.translation_english, R.xml.keys_letters_english_qwertz + ), + FRENCH( + R.string.translation_french, R.xml.keys_letters_french + ), + GERMAN( + R.string.translation_german, R.xml.keys_letters_german ), GREEK( R.string.translation_greek, R.xml.keys_letters_greek ), - Norwegian( + LITHUANIAN( + R.string.translation_lithuanian, R.xml.keys_letters_lithuanian + ), + NORWEGIAN( R.string.translation_norwegian, R.xml.keys_letters_norwegian ), - Swedish( + ROMANIAN( + R.string.translation_romanian, R.xml.keys_letters_romanian + ), + RUSSIAN( + R.string.translation_russian, R.xml.keys_letters_russian + ), + SLOVENIAN( + R.string.translation_slovenian, R.xml.keys_letters_slovenian + ), + SPANISH( + R.string.translation_spanish, R.string.translation_spanish + ), + SWEDISH( R.string.translation_swedish, R.xml.keys_letters_swedish ), - Danish( - R.string.translation_danish, R.xml.keys_letters_danish + TURKISH_Q( + R.string.translation_turkish, R.xml.keys_letters_turkish_q ); fun getName(context: Context): String { From 88c4bb5ebb03f9fe7a49f7aef18705693fc27603 Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 29 May 2023 17:18:35 +1000 Subject: [PATCH 6/7] Removed languages refactoring (Language.kt enum) --- .../keyboard/extensions/Context.kt | 50 +++++++++-- .../keyboard/helpers/Config.kt | 4 +- .../keyboard/helpers/Constants.kt | 18 ++++ .../keyboard/helpers/Language.kt | 83 ------------------- .../keyboard/services/SimpleKeyboardIME.kt | 22 ++++- 5 files changed, 83 insertions(+), 94 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 75e8aa8..7a62833 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -4,11 +4,7 @@ import android.content.ClipboardManager import android.content.Context import android.graphics.Color import android.os.IBinder -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.view.Window -import android.view.WindowManager +import android.view.* import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.core.content.res.ResourcesCompat @@ -149,9 +145,47 @@ fun Context.setupKeyboardDialogStuff( } fun Context.getKeyboardLanguages(): ArrayList { - val languages = Language.sorted(this).map { RadioItem(it.ordinal, it.getName(this)) } - return ArrayList(languages) + return arrayListOf( + RadioItem(LANGUAGE_BENGALI, getKeyboardLanguageText(LANGUAGE_BENGALI)), + RadioItem(LANGUAGE_BULGARIAN, getKeyboardLanguageText(LANGUAGE_BULGARIAN)), + RadioItem(LANGUAGE_DANISH, getKeyboardLanguageText(LANGUAGE_DANISH)), + RadioItem(LANGUAGE_ENGLISH_QWERTY, getKeyboardLanguageText(LANGUAGE_ENGLISH_QWERTY)), + RadioItem(LANGUAGE_ENGLISH_QWERTZ, getKeyboardLanguageText(LANGUAGE_ENGLISH_QWERTZ)), + RadioItem(LANGUAGE_ENGLISH_DVORAK, getKeyboardLanguageText(LANGUAGE_ENGLISH_DVORAK)), + RadioItem(LANGUAGE_FRENCH, getKeyboardLanguageText(LANGUAGE_FRENCH)), + RadioItem(LANGUAGE_GERMAN, getKeyboardLanguageText(LANGUAGE_GERMAN)), + RadioItem(LANGUAGE_GREEK, getKeyboardLanguageText(LANGUAGE_GREEK)), + RadioItem(LANGUAGE_LITHUANIAN, getKeyboardLanguageText(LANGUAGE_LITHUANIAN)), + RadioItem(LANGUAGE_NORWEGIAN, getKeyboardLanguageText(LANGUAGE_NORWEGIAN)), + RadioItem(LANGUAGE_ROMANIAN, getKeyboardLanguageText(LANGUAGE_ROMANIAN)), + RadioItem(LANGUAGE_RUSSIAN, getKeyboardLanguageText(LANGUAGE_RUSSIAN)), + RadioItem(LANGUAGE_SLOVENIAN, getKeyboardLanguageText(LANGUAGE_SLOVENIAN)), + RadioItem(LANGUAGE_SPANISH, getKeyboardLanguageText(LANGUAGE_SPANISH)), + RadioItem(LANGUAGE_SWEDISH, getKeyboardLanguageText(LANGUAGE_SWEDISH)), + RadioItem(LANGUAGE_TURKISH_Q, getKeyboardLanguageText(LANGUAGE_TURKISH_Q)), + ) +} + +fun Context.getKeyboardLanguageText(language: Int): String { + return when (language) { + LANGUAGE_BENGALI -> getString(R.string.translation_bengali) + LANGUAGE_BULGARIAN -> getString(R.string.translation_bulgarian) + LANGUAGE_DANISH -> getString(R.string.translation_danish) + LANGUAGE_ENGLISH_DVORAK -> "${getString(R.string.translation_english)} (DVORAK)" + LANGUAGE_ENGLISH_QWERTZ -> "${getString(R.string.translation_english)} (QWERTZ)" + LANGUAGE_FRENCH -> getString(R.string.translation_french) + LANGUAGE_GERMAN -> getString(R.string.translation_german) + LANGUAGE_GREEK -> getString(R.string.translation_greek) + LANGUAGE_LITHUANIAN -> getString(R.string.translation_lithuanian) + LANGUAGE_NORWEGIAN -> getString(R.string.translation_norwegian) + LANGUAGE_ROMANIAN -> getString(R.string.translation_romanian) + LANGUAGE_RUSSIAN -> getString(R.string.translation_russian) + LANGUAGE_SLOVENIAN -> getString(R.string.translation_slovenian) + LANGUAGE_SPANISH -> getString(R.string.translation_spanish) + LANGUAGE_SWEDISH -> getString(R.string.translation_swedish) + LANGUAGE_TURKISH_Q -> "${getString(R.string.translation_turkish)} (Q)" + else -> "${getString(R.string.translation_english)} (QWERTY)" + } } -fun Context.getKeyboardLanguageText(language: Int) = Language.getKeyboardName(this, language) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt index 06cb020..c612e27 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt @@ -48,9 +48,9 @@ class Config(context: Context) : BaseConfig(context) { private fun getDefaultLanguage(): Int { val conf = context.resources.configuration return if (conf.locale.toString().toLowerCase(Locale.getDefault()).startsWith("ru_")) { - Language.RUSSIAN.ordinal + LANGUAGE_RUSSIAN } else { - Language.ENGLISH_QWERTY.ordinal + LANGUAGE_ENGLISH_QWERTY } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt index a49ebf8..3045fde 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt @@ -75,6 +75,24 @@ const val SHOW_NUMBERS_ROW = "show_numbers_row" const val ITEM_SECTION_LABEL = 0 const val ITEM_CLIP = 1 +const val LANGUAGE_ENGLISH_QWERTY = 0 +const val LANGUAGE_RUSSIAN = 1 +const val LANGUAGE_FRENCH = 2 +const val LANGUAGE_ENGLISH_QWERTZ = 3 +const val LANGUAGE_SPANISH = 4 +const val LANGUAGE_GERMAN = 5 +const val LANGUAGE_ENGLISH_DVORAK = 6 +const val LANGUAGE_ROMANIAN = 7 +const val LANGUAGE_SLOVENIAN = 8 +const val LANGUAGE_BULGARIAN = 9 +const val LANGUAGE_TURKISH_Q = 10 +const val LANGUAGE_LITHUANIAN = 11 +const val LANGUAGE_BENGALI = 12 +const val LANGUAGE_GREEK = 13 +const val LANGUAGE_NORWEGIAN = 14 +const val LANGUAGE_SWEDISH = 15 +const val LANGUAGE_DANISH = 16 + // keyboard height multiplier options const val KEYBOARD_HEIGHT_MULTIPLIER_SMALL = 1 const val KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM = 2 diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt deleted file mode 100644 index 5656b79..0000000 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Language.kt +++ /dev/null @@ -1,83 +0,0 @@ -package com.simplemobiletools.keyboard.helpers - -import android.content.Context -import androidx.annotation.StringRes -import com.simplemobiletools.keyboard.R - -enum class Language(@StringRes private val stringRes: Int, private val layout: Int) { - BENGALI( - R.string.translation_bengali, R.xml.keys_letters_bengali - ), - BULGARIAN( - R.string.translation_bulgarian, R.xml.keys_letters_bulgarian - ), - DANISH( - R.string.translation_danish, R.xml.keys_letters_danish - ), - ENGLISH_DVORAK( - R.string.translation_english, R.xml.keys_letters_english_dvorak - ), - ENGLISH_QWERTY( - R.string.translation_english, R.xml.keys_letters_english_qwerty - ), - ENGLISH_QWERTZ( - R.string.translation_english, R.xml.keys_letters_english_qwertz - ), - FRENCH( - R.string.translation_french, R.xml.keys_letters_french - ), - GERMAN( - R.string.translation_german, R.xml.keys_letters_german - ), - GREEK( - R.string.translation_greek, R.xml.keys_letters_greek - ), - LITHUANIAN( - R.string.translation_lithuanian, R.xml.keys_letters_lithuanian - ), - NORWEGIAN( - R.string.translation_norwegian, R.xml.keys_letters_norwegian - ), - ROMANIAN( - R.string.translation_romanian, R.xml.keys_letters_romanian - ), - RUSSIAN( - R.string.translation_russian, R.xml.keys_letters_russian - ), - SLOVENIAN( - R.string.translation_slovenian, R.xml.keys_letters_slovenian - ), - SPANISH( - R.string.translation_spanish, R.string.translation_spanish - ), - SWEDISH( - R.string.translation_swedish, R.xml.keys_letters_swedish - ), - TURKISH_Q( - R.string.translation_turkish, R.xml.keys_letters_turkish_q - ); - - fun getName(context: Context): String { - with(context) { - return when (val language = this@Language) { - ENGLISH_DVORAK -> "${getString(language.stringRes)} (DVORAK)" - ENGLISH_QWERTY -> "${getString(language.stringRes)} (QWERTY)" - ENGLISH_QWERTZ -> "${getString(language.stringRes)} (QWERTZ)" - else -> getString(language.stringRes) - } - } - } - - companion object { - fun sorted(context: Context) = Language.values().sortedBy { context.getString(it.stringRes) } - - fun getKeyboardLayout(keyboardLanguage: Int): Int { - return Language.values().getOrElse(keyboardLanguage) { ENGLISH_QWERTY }.layout - } - - fun getKeyboardName(context: Context, language: Int): String { - return Language.values().getOrElse(language) { ENGLISH_QWERTY }.getName(context) - } - } - -} diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index 2c6faa8..fc6c529 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -294,7 +294,27 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL } } - private fun getKeyboardLayoutXML() = Language.getKeyboardLayout(baseContext.config.keyboardLanguage) + private fun getKeyboardLayoutXML(): Int { + return when (baseContext.config.keyboardLanguage) { + LANGUAGE_BENGALI -> R.xml.keys_letters_bengali + LANGUAGE_BULGARIAN -> R.xml.keys_letters_bulgarian + LANGUAGE_DANISH -> R.xml.keys_letters_danish + LANGUAGE_ENGLISH_DVORAK -> R.xml.keys_letters_english_dvorak + LANGUAGE_ENGLISH_QWERTZ -> R.xml.keys_letters_english_qwertz + LANGUAGE_FRENCH -> R.xml.keys_letters_french + LANGUAGE_GERMAN -> R.xml.keys_letters_german + LANGUAGE_GREEK -> R.xml.keys_letters_greek + LANGUAGE_LITHUANIAN -> R.xml.keys_letters_lithuanian + LANGUAGE_NORWEGIAN -> R.xml.keys_letters_norwegian + LANGUAGE_ROMANIAN -> R.xml.keys_letters_romanian + LANGUAGE_RUSSIAN -> R.xml.keys_letters_russian + LANGUAGE_SLOVENIAN -> R.xml.keys_letters_slovenian + LANGUAGE_SWEDISH -> R.xml.keys_letters_swedish + LANGUAGE_SPANISH -> R.xml.keys_letters_spanish_qwerty + LANGUAGE_TURKISH_Q -> R.xml.keys_letters_turkish_q + else -> R.xml.keys_letters_english_qwerty + } + } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { keyboardView?.setupKeyboard() From f9cdecdb32dc5db102e7796688b9e29a9c56bf5e Mon Sep 17 00:00:00 2001 From: merkost Date: Tue, 30 May 2023 16:41:54 +1000 Subject: [PATCH 7/7] Languages xml refactored and fixed numbers popup --- app/src/main/res/xml/keys_letters_danish.xml | 8 ++++---- app/src/main/res/xml/keys_letters_lithuanian.xml | 10 +++++----- app/src/main/res/xml/keys_letters_norwegian.xml | 8 ++++---- app/src/main/res/xml/keys_letters_swedish.xml | 8 ++++---- app/src/main/res/xml/keys_letters_turkish_q.xml | 12 ++++++------ 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/src/main/res/xml/keys_letters_danish.xml b/app/src/main/res/xml/keys_letters_danish.xml index f421e68..f0639a5 100644 --- a/app/src/main/res/xml/keys_letters_danish.xml +++ b/app/src/main/res/xml/keys_letters_danish.xml @@ -81,13 +81,13 @@ + app:popupKeyboard="@xml/keyboard_popup_template" /> + app:popupKeyboard="@xml/keyboard_popup_template" /> diff --git a/app/src/main/res/xml/keys_letters_lithuanian.xml b/app/src/main/res/xml/keys_letters_lithuanian.xml index 6ac6345..f27a032 100644 --- a/app/src/main/res/xml/keys_letters_lithuanian.xml +++ b/app/src/main/res/xml/keys_letters_lithuanian.xml @@ -73,7 +73,7 @@ app:topSmallNumber="7" /> + app:keyWidth="10%p" + app:secondaryKeyIcon="@drawable/ic_language_outlined" /> + app:popupKeyboard="@xml/keyboard_popup_template" /> + app:popupKeyboard="@xml/keyboard_popup_template" /> + app:popupKeyboard="@xml/keyboard_popup_template" /> diff --git a/app/src/main/res/xml/keys_letters_swedish.xml b/app/src/main/res/xml/keys_letters_swedish.xml index 7c6f246..8b2c74c 100644 --- a/app/src/main/res/xml/keys_letters_swedish.xml +++ b/app/src/main/res/xml/keys_letters_swedish.xml @@ -81,13 +81,13 @@ + app:popupKeyboard="@xml/keyboard_popup_template" /> + app:popupKeyboard="@xml/keyboard_popup_template" /> + app:keyWidth="10%p" + app:secondaryKeyIcon="@drawable/ic_language_outlined" /> + app:popupKeyboard="@xml/keyboard_popup_template" />