Merge pull request #70 from jacobkapitein/main

Add functionality to set keyboard height
This commit is contained in:
Tibor Kaputa 2022-08-15 22:35:13 +02:00 committed by GitHub
commit f681cf986a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 2 deletions

View File

@ -31,6 +31,7 @@ class SettingsActivity : SimpleActivity() {
setupVibrateOnKeypress()
setupShowPopupOnKeypress()
setupKeyboardLanguage()
setupKeyboardHeightMultiplier()
updateTextColors(settings_nested_scrollview)
@ -137,4 +138,29 @@ class SettingsActivity : SimpleActivity() {
else -> "${getString(R.string.translation_english)} (QWERTY)"
}
}
private fun setupKeyboardHeightMultiplier() {
settings_height_multiplier.text = getKeyboardHeightMultiplierText(config.keyboardHeightMultiplier)
settings_keyboard_height_multiplier_holder.setOnClickListener {
val items = arrayListOf(
RadioItem(KEYBOARD_HEIGHT_MULTIPLIER_SMALL, getKeyboardHeightMultiplierText(KEYBOARD_HEIGHT_MULTIPLIER_SMALL)),
RadioItem(KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM, getKeyboardHeightMultiplierText(KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM)),
RadioItem(KEYBOARD_HEIGHT_MULTIPLIER_LARGE, getKeyboardHeightMultiplierText(KEYBOARD_HEIGHT_MULTIPLIER_LARGE)),
)
RadioGroupDialog(this@SettingsActivity, items, config.keyboardHeightMultiplier) {
config.keyboardHeightMultiplier = it as Int
settings_height_multiplier.text = getKeyboardHeightMultiplierText(config.keyboardHeightMultiplier)
}
}
}
private fun getKeyboardHeightMultiplierText(multiplier: Int): String {
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)
}
}
}

View File

@ -25,6 +25,11 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getInt(KEYBOARD_LANGUAGE, getDefaultLanguage())
set(keyboardLanguage) = prefs.edit().putInt(KEYBOARD_LANGUAGE, keyboardLanguage).apply()
var keyboardHeightMultiplier: Int
get() = prefs.getInt(HEIGHT_MULTIPLIER, 1)
set(keyboardHeightMultiplier) = prefs.edit().putInt(HEIGHT_MULTIPLIER, keyboardHeightMultiplier).apply()
private fun getDefaultLanguage(): Int {
val conf = context.resources.configuration
return if (conf.locale.toString().toLowerCase(Locale.getDefault()).startsWith("ru_")) {

View File

@ -12,6 +12,7 @@ const val VIBRATE_ON_KEYPRESS = "vibrate_on_keypress"
const val SHOW_POPUP_ON_KEYPRESS = "show_popup_on_keypress"
const val LAST_EXPORTED_CLIPS_FOLDER = "last_exported_clips_folder"
const val KEYBOARD_LANGUAGE = "keyboard_language"
const val HEIGHT_MULTIPLIER = "height_multiplier"
// differentiate current and pinned clips at the keyboards' Clipboard section
const val ITEM_SECTION_LABEL = 0
@ -27,5 +28,9 @@ const val LANGUAGE_ENGLISH_DVORAK = 6
const val LANGUAGE_ROMANIAN = 7
const val LANGUAGE_SLOVENIAN = 8
// keyboard height multiplier options
const val KEYBOARD_HEIGHT_MULTIPLIER_SMALL = 1
const val KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM = 2
const val KEYBOARD_HEIGHT_MULTIPLIER_LARGE = 3
const val EMOJI_SPEC_FILE_PATH = "media/emoji_spec.txt"

View File

@ -12,6 +12,8 @@ import android.view.inputmethod.EditorInfo
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import androidx.annotation.XmlRes
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config
import kotlin.math.roundToInt
/**
* Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard consists of rows of keys.
@ -28,6 +30,9 @@ class MyKeyboard {
/** Default key height */
private var mDefaultHeight = 0
/** Multiplier for the keyboard height */
var mKeyboardHeightMultiplier: Float = 1F
/** Is the keyboard in the shifted state */
var mShiftState = SHIFT_OFF
@ -100,7 +105,7 @@ class MyKeyboard {
this.parent = parent
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
defaultHeight = res.getDimension(R.dimen.key_height).toInt()
defaultHeight = (res.getDimension(R.dimen.key_height) * this.parent.mKeyboardHeightMultiplier).roundToInt()
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
a.recycle()
}
@ -244,6 +249,7 @@ class MyKeyboard {
mDefaultHorizontalGap = 0
mDefaultWidth = mDisplayWidth / 10
mDefaultHeight = mDefaultWidth
mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier);
mKeys = ArrayList()
mEnterKeyType = enterKeyType
loadKeyboard(context, context.resources.getXml(xmlLayoutResId))
@ -267,6 +273,7 @@ class MyKeyboard {
row.defaultHeight = mDefaultHeight
row.defaultWidth = keyWidth
row.defaultHorizontalGap = mDefaultHorizontalGap
mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier);
characters.forEachIndexed { index, character ->
val key = Key(row)
@ -377,4 +384,13 @@ class MyKeyboard {
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, mDisplayWidth, 0)
a.recycle()
}
private fun getKeyboardHeightMultiplier(multiplierType: Int): Float {
return when(multiplierType) {
KEYBOARD_HEIGHT_MULTIPLIER_SMALL -> 1.0F
KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM -> 1.2F
KEYBOARD_HEIGHT_MULTIPLIER_LARGE -> 1.4F
else -> 1.0F
}
}
}

View File

@ -185,6 +185,30 @@
tools:text="@string/translation_english" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_keyboard_height_multiplier_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_height_multiplier_label"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/keyboard_height" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_height_multiplier"
style="@style/SettingsTextValueStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/settings_keyboard_height_multiplier_label"
tools:text="@string/small" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -38,4 +38,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>