mirror of
https://github.com/SimpleMobileTools/Simple-Keyboard.git
synced 2025-02-27 00:57:40 +01:00
Merge pull request #70 from jacobkapitein/main
Add functionality to set keyboard height
This commit is contained in:
commit
f681cf986a
@ -31,6 +31,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
setupVibrateOnKeypress()
|
setupVibrateOnKeypress()
|
||||||
setupShowPopupOnKeypress()
|
setupShowPopupOnKeypress()
|
||||||
setupKeyboardLanguage()
|
setupKeyboardLanguage()
|
||||||
|
setupKeyboardHeightMultiplier()
|
||||||
|
|
||||||
updateTextColors(settings_nested_scrollview)
|
updateTextColors(settings_nested_scrollview)
|
||||||
|
|
||||||
@ -137,4 +138,29 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
else -> "${getString(R.string.translation_english)} (QWERTY)"
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,11 @@ 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
|
||||||
|
get() = prefs.getInt(HEIGHT_MULTIPLIER, 1)
|
||||||
|
set(keyboardHeightMultiplier) = prefs.edit().putInt(HEIGHT_MULTIPLIER, keyboardHeightMultiplier).apply()
|
||||||
|
|
||||||
|
|
||||||
private fun getDefaultLanguage(): Int {
|
private fun getDefaultLanguage(): Int {
|
||||||
val conf = context.resources.configuration
|
val conf = context.resources.configuration
|
||||||
return if (conf.locale.toString().toLowerCase(Locale.getDefault()).startsWith("ru_")) {
|
return if (conf.locale.toString().toLowerCase(Locale.getDefault()).startsWith("ru_")) {
|
||||||
|
@ -12,6 +12,7 @@ const val VIBRATE_ON_KEYPRESS = "vibrate_on_keypress"
|
|||||||
const val SHOW_POPUP_ON_KEYPRESS = "show_popup_on_keypress"
|
const val SHOW_POPUP_ON_KEYPRESS = "show_popup_on_keypress"
|
||||||
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"
|
||||||
|
|
||||||
// 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
|
||||||
@ -27,5 +28,9 @@ const val LANGUAGE_ENGLISH_DVORAK = 6
|
|||||||
const val LANGUAGE_ROMANIAN = 7
|
const val LANGUAGE_ROMANIAN = 7
|
||||||
const val LANGUAGE_SLOVENIAN = 8
|
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"
|
const val EMOJI_SPEC_FILE_PATH = "media/emoji_spec.txt"
|
||||||
|
@ -12,6 +12,8 @@ import android.view.inputmethod.EditorInfo
|
|||||||
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
|
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
|
||||||
import androidx.annotation.XmlRes
|
import androidx.annotation.XmlRes
|
||||||
import com.simplemobiletools.keyboard.R
|
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.
|
* 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 */
|
/** Default key height */
|
||||||
private var mDefaultHeight = 0
|
private var mDefaultHeight = 0
|
||||||
|
|
||||||
|
/** Multiplier for the keyboard height */
|
||||||
|
var mKeyboardHeightMultiplier: Float = 1F
|
||||||
|
|
||||||
/** Is the keyboard in the shifted state */
|
/** Is the keyboard in the shifted state */
|
||||||
var mShiftState = SHIFT_OFF
|
var mShiftState = SHIFT_OFF
|
||||||
|
|
||||||
@ -100,7 +105,7 @@ class MyKeyboard {
|
|||||||
this.parent = parent
|
this.parent = parent
|
||||||
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
val a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard)
|
||||||
defaultWidth = getDimensionOrFraction(a, R.styleable.MyKeyboard_keyWidth, parent.mDisplayWidth, parent.mDefaultWidth)
|
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)
|
defaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, parent.mDisplayWidth, parent.mDefaultHorizontalGap)
|
||||||
a.recycle()
|
a.recycle()
|
||||||
}
|
}
|
||||||
@ -244,6 +249,7 @@ class MyKeyboard {
|
|||||||
mDefaultHorizontalGap = 0
|
mDefaultHorizontalGap = 0
|
||||||
mDefaultWidth = mDisplayWidth / 10
|
mDefaultWidth = mDisplayWidth / 10
|
||||||
mDefaultHeight = mDefaultWidth
|
mDefaultHeight = mDefaultWidth
|
||||||
|
mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier);
|
||||||
mKeys = ArrayList()
|
mKeys = ArrayList()
|
||||||
mEnterKeyType = enterKeyType
|
mEnterKeyType = enterKeyType
|
||||||
loadKeyboard(context, context.resources.getXml(xmlLayoutResId))
|
loadKeyboard(context, context.resources.getXml(xmlLayoutResId))
|
||||||
@ -267,6 +273,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);
|
||||||
|
|
||||||
characters.forEachIndexed { index, character ->
|
characters.forEachIndexed { index, character ->
|
||||||
val key = Key(row)
|
val key = Key(row)
|
||||||
@ -377,4 +384,13 @@ class MyKeyboard {
|
|||||||
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, mDisplayWidth, 0)
|
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.MyKeyboard_horizontalGap, mDisplayWidth, 0)
|
||||||
a.recycle()
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,6 +185,30 @@
|
|||||||
tools:text="@string/translation_english" />
|
tools:text="@string/translation_english" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</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>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
@ -38,4 +38,4 @@
|
|||||||
Haven't found some strings? There's more at
|
Haven't found some strings? There's more at
|
||||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||||
-->
|
-->
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user