mirror of
https://github.com/SimpleMobileTools/Simple-Keyboard.git
synced 2025-04-08 23:51:29 +02:00
allow toggling between russian and english keyboard language
This commit is contained in:
parent
0bad827830
commit
078a9ca753
@ -64,7 +64,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:49c2c3da51'
|
implementation 'com.github.SimpleMobileTools:Simple-Commons:81809a9339'
|
||||||
|
|
||||||
kapt 'androidx.room:room-compiler:2.3.0'
|
kapt 'androidx.room:room-compiler:2.3.0'
|
||||||
implementation 'androidx.room:room-runtime:2.3.0'
|
implementation 'androidx.room:room-runtime:2.3.0'
|
||||||
|
@ -3,9 +3,13 @@ package com.simplemobiletools.keyboard.activities
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.keyboard.R
|
import com.simplemobiletools.keyboard.R
|
||||||
import com.simplemobiletools.keyboard.extensions.config
|
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 kotlinx.android.synthetic.main.activity_settings.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
@ -26,6 +30,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
setupManageClipboardItems()
|
setupManageClipboardItems()
|
||||||
setupVibrateOnKeypress()
|
setupVibrateOnKeypress()
|
||||||
setupShowPopupOnKeypress()
|
setupShowPopupOnKeypress()
|
||||||
|
setupKeyboardLanguage()
|
||||||
|
|
||||||
updateTextColors(settings_scrollview)
|
updateTextColors(settings_scrollview)
|
||||||
|
|
||||||
@ -101,4 +106,26 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
config.showPopupOnKeypress = settings_show_popup_on_keypress.isChecked
|
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
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.keyboard.helpers
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class Config(context: Context) : BaseConfig(context) {
|
class Config(context: Context) : BaseConfig(context) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -20,7 +21,16 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
get() = prefs.getString(LAST_EXPORTED_CLIPS_FOLDER, "")!!
|
get() = prefs.getString(LAST_EXPORTED_CLIPS_FOLDER, "")!!
|
||||||
set(lastExportedClipsFolder) = prefs.edit().putString(LAST_EXPORTED_CLIPS_FOLDER, lastExportedClipsFolder).apply()
|
set(lastExportedClipsFolder) = prefs.edit().putString(LAST_EXPORTED_CLIPS_FOLDER, lastExportedClipsFolder).apply()
|
||||||
|
|
||||||
var keyboardLanguage: String
|
var keyboardLanguage: Int
|
||||||
get() = prefs.getString(KEYBOARD_LANGUAGE, "en")!!
|
get() = prefs.getInt(KEYBOARD_LANGUAGE, getDefaultLanguage())
|
||||||
set(keyboardLanguage) = prefs.edit().putString(KEYBOARD_LANGUAGE, keyboardLanguage).apply()
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,3 +16,6 @@ const val KEYBOARD_LANGUAGE = "keyboard_language"
|
|||||||
// differentiate current and pinned clips at the keyboards' Clipboard section
|
// differentiate current and pinned clips at the keyboards' Clipboard section
|
||||||
const val ITEM_SECTION_LABEL = 0
|
const val ITEM_SECTION_LABEL = 0
|
||||||
const val ITEM_CLIP = 1
|
const val ITEM_CLIP = 1
|
||||||
|
|
||||||
|
const val LANGUAGE_ENGLISH = 0
|
||||||
|
const val LANGUAGE_RUSSIAN = 1
|
||||||
|
@ -10,10 +10,7 @@ import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
|
|||||||
import android.view.inputmethod.ExtractedTextRequest
|
import android.view.inputmethod.ExtractedTextRequest
|
||||||
import com.simplemobiletools.keyboard.R
|
import com.simplemobiletools.keyboard.R
|
||||||
import com.simplemobiletools.keyboard.extensions.config
|
import com.simplemobiletools.keyboard.extensions.config
|
||||||
import com.simplemobiletools.keyboard.helpers.MyKeyboard
|
import com.simplemobiletools.keyboard.helpers.*
|
||||||
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.views.MyKeyboardView
|
import com.simplemobiletools.keyboard.views.MyKeyboardView
|
||||||
import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.*
|
import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.*
|
||||||
|
|
||||||
@ -216,7 +213,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
|||||||
|
|
||||||
private fun getKeyboardLayoutXML(): Int {
|
private fun getKeyboardLayoutXML(): Int {
|
||||||
return when (baseContext.config.keyboardLanguage) {
|
return when (baseContext.config.keyboardLanguage) {
|
||||||
"ru" -> R.xml.keys_letters_russian
|
LANGUAGE_RUSSIAN -> R.xml.keys_letters_russian
|
||||||
else -> R.xml.keys_letters_english
|
else -> R.xml.keys_letters_english
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/settings_scrollview"
|
android:id="@+id/settings_scrollview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
@ -126,7 +127,7 @@
|
|||||||
style="@style/SettingsHolderCheckboxStyle"
|
style="@style/SettingsHolderCheckboxStyle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/ripple_bottom_corners">
|
android:background="@drawable/ripple_background">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
android:id="@+id/settings_show_popup_on_keypress"
|
android:id="@+id/settings_show_popup_on_keypress"
|
||||||
@ -136,6 +137,30 @@
|
|||||||
android:text="@string/show_popup" />
|
android:text="@string/show_popup" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</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>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user