allow toggling between russian and english keyboard language

This commit is contained in:
tibbi 2022-02-02 17:30:05 +01:00
parent 0bad827830
commit 078a9ca753
6 changed files with 72 additions and 10 deletions

View File

@ -64,7 +64,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:49c2c3da51'
implementation 'com.github.SimpleMobileTools:Simple-Commons:81809a9339'
kapt 'androidx.room:room-compiler:2.3.0'
implementation 'androidx.room:room-runtime:2.3.0'

View File

@ -3,9 +3,13 @@ package com.simplemobiletools.keyboard.activities
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.helpers.LANGUAGE_ENGLISH
import com.simplemobiletools.keyboard.helpers.LANGUAGE_RUSSIAN
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*
import kotlin.system.exitProcess
@ -26,6 +30,7 @@ class SettingsActivity : SimpleActivity() {
setupManageClipboardItems()
setupVibrateOnKeypress()
setupShowPopupOnKeypress()
setupKeyboardLanguage()
updateTextColors(settings_scrollview)
@ -101,4 +106,26 @@ class SettingsActivity : SimpleActivity() {
config.showPopupOnKeypress = settings_show_popup_on_keypress.isChecked
}
}
private fun setupKeyboardLanguage() {
settings_keyboard_language.text = getKeyboardLanguageText()
settings_keyboard_language_holder.setOnClickListener {
val items = arrayListOf(
RadioItem(LANGUAGE_ENGLISH, getString(R.string.translation_english)),
RadioItem(LANGUAGE_RUSSIAN, getString(R.string.translation_russian))
)
RadioGroupDialog(this@SettingsActivity, items, config.keyboardLanguage) {
config.keyboardLanguage = it as Int
settings_keyboard_language.text = getKeyboardLanguageText()
}
}
}
fun getKeyboardLanguageText() = getString(
when (config.keyboardLanguage) {
LANGUAGE_RUSSIAN -> R.string.translation_russian
else -> R.string.translation_english
}
)
}

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.keyboard.helpers
import android.content.Context
import com.simplemobiletools.commons.helpers.BaseConfig
import java.util.*
class Config(context: Context) : BaseConfig(context) {
companion object {
@ -20,7 +21,16 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getString(LAST_EXPORTED_CLIPS_FOLDER, "")!!
set(lastExportedClipsFolder) = prefs.edit().putString(LAST_EXPORTED_CLIPS_FOLDER, lastExportedClipsFolder).apply()
var keyboardLanguage: String
get() = prefs.getString(KEYBOARD_LANGUAGE, "en")!!
set(keyboardLanguage) = prefs.edit().putString(KEYBOARD_LANGUAGE, keyboardLanguage).apply()
var keyboardLanguage: Int
get() = prefs.getInt(KEYBOARD_LANGUAGE, getDefaultLanguage())
set(keyboardLanguage) = prefs.edit().putInt(KEYBOARD_LANGUAGE, keyboardLanguage).apply()
private fun getDefaultLanguage(): Int {
val conf = context.resources.configuration
return if (conf.locale.toString().toLowerCase(Locale.getDefault()).startsWith("ru_")) {
LANGUAGE_RUSSIAN
} else {
LANGUAGE_ENGLISH
}
}
}

View File

@ -16,3 +16,6 @@ const val KEYBOARD_LANGUAGE = "keyboard_language"
// differentiate current and pinned clips at the keyboards' Clipboard section
const val ITEM_SECTION_LABEL = 0
const val ITEM_CLIP = 1
const val LANGUAGE_ENGLISH = 0
const val LANGUAGE_RUSSIAN = 1

View File

@ -10,10 +10,7 @@ import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import android.view.inputmethod.ExtractedTextRequest
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.helpers.MyKeyboard
import com.simplemobiletools.keyboard.helpers.SHIFT_OFF
import com.simplemobiletools.keyboard.helpers.SHIFT_ON_ONE_CHAR
import com.simplemobiletools.keyboard.helpers.SHIFT_ON_PERMANENT
import com.simplemobiletools.keyboard.helpers.*
import com.simplemobiletools.keyboard.views.MyKeyboardView
import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.*
@ -216,7 +213,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
private fun getKeyboardLayoutXML(): Int {
return when (baseContext.config.keyboardLanguage) {
"ru" -> R.xml.keys_letters_russian
LANGUAGE_RUSSIAN -> R.xml.keys_letters_russian
else -> R.xml.keys_letters_english
}
}

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/settings_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -126,7 +127,7 @@
style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_bottom_corners">
android:background="@drawable/ripple_background">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_show_popup_on_keypress"
@ -136,6 +137,30 @@
android:text="@string/show_popup" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_keyboard_language_holder"
style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_bottom_corners">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_keyboard_language_label"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/keyboard_language" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_keyboard_language"
style="@style/SettingsTextValueStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/settings_keyboard_language_label"
tools:text="@string/translation_english" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>