Add keyboard height percentage options

This commit is contained in:
Ensar Sarajčić 2023-07-06 08:59:45 +02:00
parent e41c6c0817
commit 6b07eeddbc
4 changed files with 36 additions and 36 deletions

View File

@ -11,9 +11,7 @@ import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.extensions.getKeyboardLanguageText import com.simplemobiletools.keyboard.extensions.getKeyboardLanguageText
import com.simplemobiletools.keyboard.extensions.getKeyboardLanguages import com.simplemobiletools.keyboard.extensions.getKeyboardLanguages
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_LARGE import com.simplemobiletools.keyboard.helpers.*
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_SMALL
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
@ -130,29 +128,30 @@ class SettingsActivity : SimpleActivity() {
} }
private fun setupKeyboardHeightMultiplier() { private fun setupKeyboardHeightMultiplier() {
settings_keyboard_height_multiplier.text = getKeyboardHeightMultiplierText(config.keyboardHeightMultiplier) settings_keyboard_height_multiplier.text = getKeyboardHeightPercentageText(config.keyboardHeightPercentage)
settings_keyboard_height_multiplier_holder.setOnClickListener { settings_keyboard_height_multiplier_holder.setOnClickListener {
val items = arrayListOf( val items = arrayListOf(
RadioItem(KEYBOARD_HEIGHT_MULTIPLIER_SMALL, getKeyboardHeightMultiplierText(KEYBOARD_HEIGHT_MULTIPLIER_SMALL)), RadioItem(KEYBOARD_HEIGHT_50_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_50_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM, getKeyboardHeightMultiplierText(KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM)), RadioItem(KEYBOARD_HEIGHT_60_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_60_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_MULTIPLIER_LARGE, getKeyboardHeightMultiplierText(KEYBOARD_HEIGHT_MULTIPLIER_LARGE)), RadioItem(KEYBOARD_HEIGHT_75_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_75_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_90_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_90_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_100_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_100_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_125_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_125_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_150_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_150_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_175_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_175_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_200_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_200_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_250_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_250_PERCENT)),
RadioItem(KEYBOARD_HEIGHT_300_PERCENT, getKeyboardHeightPercentageText(KEYBOARD_HEIGHT_300_PERCENT))
) )
RadioGroupDialog(this@SettingsActivity, items, config.keyboardHeightMultiplier) { RadioGroupDialog(this@SettingsActivity, items, config.keyboardHeightPercentage) {
config.keyboardHeightMultiplier = it as Int config.keyboardHeightPercentage = it as Int
settings_keyboard_height_multiplier.text = getKeyboardHeightMultiplierText(config.keyboardHeightMultiplier) settings_keyboard_height_multiplier.text = getKeyboardHeightPercentageText(config.keyboardHeightPercentage)
} }
} }
} }
private fun getKeyboardHeightMultiplierText(multiplier: Int): String { private fun getKeyboardHeightPercentageText(keyboardHeightPercentage: Int): String = "$keyboardHeightPercentage%"
return when (multiplier) {
KEYBOARD_HEIGHT_MULTIPLIER_SMALL -> getString(R.string.small)
KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM -> getString(R.string.medium)
KEYBOARD_HEIGHT_MULTIPLIER_LARGE -> getString(R.string.large)
else -> getString(R.string.small)
}
}
private fun setupShowClipboardContent() { private fun setupShowClipboardContent() {
settings_show_clipboard_content.isChecked = config.showClipboardContent settings_show_clipboard_content.isChecked = config.showClipboardContent

View File

@ -35,9 +35,9 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getInt(KEYBOARD_LANGUAGE, getDefaultLanguage()) get() = prefs.getInt(KEYBOARD_LANGUAGE, getDefaultLanguage())
set(keyboardLanguage) = prefs.edit().putInt(KEYBOARD_LANGUAGE, keyboardLanguage).apply() set(keyboardLanguage) = prefs.edit().putInt(KEYBOARD_LANGUAGE, keyboardLanguage).apply()
var keyboardHeightMultiplier: Int var keyboardHeightPercentage: Int
get() = prefs.getInt(HEIGHT_MULTIPLIER, 1) get() = prefs.getInt(HEIGHT_PERCENTAGE, 100)
set(keyboardHeightMultiplier) = prefs.edit().putInt(HEIGHT_MULTIPLIER, keyboardHeightMultiplier).apply() set(keyboardHeightMultiplier) = prefs.edit().putInt(HEIGHT_PERCENTAGE, keyboardHeightMultiplier).apply()
var showClipboardContent: Boolean var showClipboardContent: Boolean
get() = prefs.getBoolean(SHOW_CLIPBOARD_CONTENT, true) get() = prefs.getBoolean(SHOW_CLIPBOARD_CONTENT, true)

View File

@ -17,7 +17,7 @@ const val SHOW_KEY_BORDERS = "show_key_borders"
const val SENTENCES_CAPITALIZATION = "sentences_capitalization" const val SENTENCES_CAPITALIZATION = "sentences_capitalization"
const val LAST_EXPORTED_CLIPS_FOLDER = "last_exported_clips_folder" const val LAST_EXPORTED_CLIPS_FOLDER = "last_exported_clips_folder"
const val KEYBOARD_LANGUAGE = "keyboard_language" const val KEYBOARD_LANGUAGE = "keyboard_language"
const val HEIGHT_MULTIPLIER = "height_multiplier" const val HEIGHT_PERCENTAGE = "height_percentage"
const val SHOW_CLIPBOARD_CONTENT = "show_clipboard_content" const val SHOW_CLIPBOARD_CONTENT = "show_clipboard_content"
const val SHOW_NUMBERS_ROW = "show_numbers_row" const val SHOW_NUMBERS_ROW = "show_numbers_row"
@ -45,10 +45,18 @@ const val LANGUAGE_DANISH = 16
const val LANGUAGE_FRENCH_BEPO = 17 const val LANGUAGE_FRENCH_BEPO = 17
const val LANGUAGE_VIETNAMESE_TELEX = 18 const val LANGUAGE_VIETNAMESE_TELEX = 18
// keyboard height multiplier options // keyboard height percentage options
const val KEYBOARD_HEIGHT_MULTIPLIER_SMALL = 1 const val KEYBOARD_HEIGHT_50_PERCENT = 50
const val KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM = 2 const val KEYBOARD_HEIGHT_60_PERCENT = 60
const val KEYBOARD_HEIGHT_MULTIPLIER_LARGE = 3 const val KEYBOARD_HEIGHT_75_PERCENT = 75
const val KEYBOARD_HEIGHT_90_PERCENT = 90
const val KEYBOARD_HEIGHT_100_PERCENT = 100
const val KEYBOARD_HEIGHT_125_PERCENT = 125
const val KEYBOARD_HEIGHT_150_PERCENT = 150
const val KEYBOARD_HEIGHT_175_PERCENT = 175
const val KEYBOARD_HEIGHT_200_PERCENT = 200
const val KEYBOARD_HEIGHT_250_PERCENT = 250
const val KEYBOARD_HEIGHT_300_PERCENT = 300
const val EMOJI_SPEC_FILE_PATH = "media/emoji_spec.txt" const val EMOJI_SPEC_FILE_PATH = "media/emoji_spec.txt"
const val LANGUAGE_VN_TELEX = "language/extension.json" const val LANGUAGE_VN_TELEX = "language/extension.json"

View File

@ -273,7 +273,7 @@ class MyKeyboard {
mDefaultHorizontalGap = 0 mDefaultHorizontalGap = 0
mDefaultWidth = mDisplayWidth / 10 mDefaultWidth = mDisplayWidth / 10
mDefaultHeight = mDefaultWidth mDefaultHeight = mDefaultWidth
mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier) mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightPercentage)
mKeys = ArrayList() mKeys = ArrayList()
mEnterKeyType = enterKeyType mEnterKeyType = enterKeyType
loadKeyboard(context, context.resources.getXml(xmlLayoutResId)) loadKeyboard(context, context.resources.getXml(xmlLayoutResId))
@ -296,7 +296,7 @@ class MyKeyboard {
row.defaultHeight = mDefaultHeight row.defaultHeight = mDefaultHeight
row.defaultWidth = keyWidth row.defaultWidth = keyWidth
row.defaultHorizontalGap = mDefaultHorizontalGap row.defaultHorizontalGap = mDefaultHorizontalGap
mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier) mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightPercentage)
characters.forEachIndexed { index, character -> characters.forEachIndexed { index, character ->
val key = Key(row) val key = Key(row)
@ -425,12 +425,5 @@ class MyKeyboard {
a.recycle() a.recycle()
} }
private fun getKeyboardHeightMultiplier(multiplierType: Int): Float { private fun getKeyboardHeightMultiplier(percentage: Int): Float = percentage / 100.0F
return when (multiplierType) {
KEYBOARD_HEIGHT_MULTIPLIER_SMALL -> 1.0F
KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM -> 1.2F
KEYBOARD_HEIGHT_MULTIPLIER_LARGE -> 1.4F
else -> 1.0F
}
}
} }