mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 15:02:48 +00:00
determine symbols from symbols layout instead of putting the keys on each keyboard layout separately
This commit is contained in:
parent
c5c42bc5d7
commit
2c03623b8a
22 changed files with 461 additions and 435 deletions
|
@ -77,9 +77,6 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
|
|||
// does glide typing work with multiple letters on one key? if not, users should be notified
|
||||
// maybe allow users to define their own symbol and shift-symbol layouts
|
||||
// allow users to import layouts, which essentially just fills the text from a file
|
||||
// add setting to use moreKeys from symbol layout (always, never, only if none defined)
|
||||
// should also have sth related to hint, because hint and start morekey maybe should stay
|
||||
// option to add language extra keys for all layouts?
|
||||
|
||||
// labelFlags should be set correctly
|
||||
// alignHintLabelToBottom: on lxx and rounded themes, but did not find what it actually does...
|
||||
|
@ -120,7 +117,8 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
|
|||
val sv = Settings.getInstance().current
|
||||
addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMoreMoreKeys)
|
||||
mParams.mMoreKeyTypes.addAll(sv.mMoreKeyTypes)
|
||||
mParams.mMoreKeyLabelSources.addAll(sv.mMoreKeyLabelSources)
|
||||
// add label source only if moreKey type enabled
|
||||
sv.mMoreKeyLabelSources.forEach { if (it in sv.mMoreKeyTypes) mParams.mMoreKeyLabelSources.add(it) }
|
||||
keysInRows = KeyboardParser.parseFromAssets(mParams, mContext)
|
||||
determineAbsoluteValues()
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -24,6 +24,8 @@ import org.dslul.openboard.inputmethod.latin.define.DebugFlags
|
|||
import org.dslul.openboard.inputmethod.latin.settings.Settings
|
||||
import org.dslul.openboard.inputmethod.latin.spellcheck.AndroidSpellCheckerService
|
||||
import org.dslul.openboard.inputmethod.latin.utils.InputTypeUtils
|
||||
import org.dslul.openboard.inputmethod.latin.utils.MORE_KEYS_LAYOUT
|
||||
import org.dslul.openboard.inputmethod.latin.utils.MORE_KEYS_NUMBER
|
||||
import org.dslul.openboard.inputmethod.latin.utils.RunInLocale
|
||||
import org.dslul.openboard.inputmethod.latin.utils.ScriptUtils
|
||||
import org.dslul.openboard.inputmethod.latin.utils.sumOf
|
||||
|
@ -44,9 +46,9 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
|||
Key.LABEL_FLAGS_DISABLE_HINT_LABEL // reproduce the no-hints in symbol layouts, todo: add setting
|
||||
else 0
|
||||
|
||||
protected abstract fun getLayoutFromAssets(layoutName: String): String
|
||||
abstract fun getLayoutFromAssets(layoutName: String): String
|
||||
|
||||
protected abstract fun parseCoreLayout(layoutContent: String): MutableList<List<KeyData>>
|
||||
abstract fun parseCoreLayout(layoutContent: String): MutableList<List<KeyData>>
|
||||
|
||||
fun parseLayoutFromAssets(layoutName: String): ArrayList<ArrayList<KeyParams>> =
|
||||
parseLayoutString(getLayoutFromAssets(layoutName))
|
||||
|
@ -87,11 +89,22 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
|||
// replace first symbols row with number row
|
||||
baseKeys[0] = params.mLocaleKeyTexts.getNumberRow()
|
||||
} else if (!params.mId.mNumberRowEnabled && params.mId.isAlphabetKeyboard
|
||||
&& params.mId.locale.language != "ko"
|
||||
// todo: move this decision to some other place!
|
||||
&& !(params.mId.locale.language == "ko" && baseKeys.size == 4)
|
||||
&& params.mId.locale.language != "th"
|
||||
&& params.mId.locale.language != "lo"
|
||||
&& params.mId.mSubtype.keyboardLayoutSetName != "pcqwerty"
|
||||
) {
|
||||
if (baseKeys[0].any { it.popup.main != null || !it.popup.relevant.isNullOrEmpty() } // first row of baseKeys has any layout more key
|
||||
&& params.mMoreKeyLabelSources.let {
|
||||
val layout = it.indexOf(MORE_KEYS_LAYOUT)
|
||||
val number = it.indexOf(MORE_KEYS_NUMBER)
|
||||
layout != -1 && layout < number // layout before number label
|
||||
}
|
||||
) {
|
||||
// remove number from labels, to avoid awkward mix of numbers and others caused by layout more keys
|
||||
params.mMoreKeyLabelSources.remove(MORE_KEYS_NUMBER)
|
||||
}
|
||||
// add number to the first 10 keys in first row
|
||||
// setting the correct moreKeys is handled in PopupSet
|
||||
// not for korean/lao/thai layouts, todo: should be decided in the layout / layoutInfos, not in the parser
|
||||
|
@ -103,6 +116,20 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
|||
}
|
||||
}
|
||||
|
||||
if (params.mId.isAlphabetKeyboard) {
|
||||
// fill popup symbols
|
||||
val symbolsLayoutName = if (ScriptUtils.getScriptFromSpellCheckerLocale(params.mId.locale) == ScriptUtils.SCRIPT_ARABIC)
|
||||
"symbols_arabic"
|
||||
else "symbols"
|
||||
val p = SimpleKeyboardParser(params, context)
|
||||
p.parseCoreLayout(p.getLayoutFromAssets(symbolsLayoutName)).forEachIndexed { i, row ->
|
||||
val baseRow = baseKeys.getOrNull(i) ?: return@forEachIndexed
|
||||
row.forEachIndexed { j, key ->
|
||||
baseRow.getOrNull(j)?.popup?.symbol = key.label
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val keysInRows = ArrayList<ArrayList<KeyParams>>()
|
||||
val functionalKeysReversed = parseFunctionalKeys(R.string.key_def_functional).reversed()
|
||||
val functionalKeysTop = parseFunctionalKeys(R.string.key_def_functional_top_row)
|
||||
|
@ -815,6 +842,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
|||
|
||||
}
|
||||
|
||||
// todo: actually this should be in some separate file, or maybe part of an (extended) key texts
|
||||
data class LayoutInfos(
|
||||
val defaultLabelFlags: Int = 0,
|
||||
// disabled by default, but enabled for all alphabet layouts
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.dslul.openboard.inputmethod.keyboard.internal.KeySpecParser
|
||||
import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardParams
|
||||
|
||||
// taken from FlorisBoard, considerably modified
|
||||
|
@ -19,13 +20,14 @@ open class PopupSet<T : AbstractKeyData>(
|
|||
open fun getPopupKeyLabels(params: KeyboardParams): Collection<String>? {
|
||||
if (main == null && relevant == null) return null
|
||||
val moreKeys = mutableListOf<String>()
|
||||
main?.getLabel(params)?.let { moreKeys.add(it) }
|
||||
relevant?.let { moreKeys.addAll(it.map { it.getLabel(params) }) }
|
||||
main?.getLabel(params)?.let { moreKeys.add(KeySpecParser.getLabel(it)!!) }
|
||||
relevant?.let { moreKeys.addAll(it.map { KeySpecParser.getLabel(it.getLabel(params))!! }) }
|
||||
if (moreKeys.isEmpty()) return null
|
||||
return moreKeys
|
||||
}
|
||||
|
||||
var numberIndex: Int? = null
|
||||
var symbol: String? = null // maybe list of keys?
|
||||
}
|
||||
|
||||
class SimplePopups(val moreKeys: Collection<String>?) : PopupSet<AbstractKeyData>() {
|
||||
|
|
|
@ -18,35 +18,41 @@ import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardParams
|
|||
import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris.PopupSet
|
||||
import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.rtlLabel
|
||||
import org.dslul.openboard.inputmethod.latin.R
|
||||
import org.dslul.openboard.inputmethod.latin.settings.Settings
|
||||
import java.util.Collections
|
||||
|
||||
private const val MORE_KEYS_NUMBER = "more_keys_number"
|
||||
const val MORE_KEYS_NUMBER = "more_keys_number"
|
||||
private const val MORE_KEYS_LANGUAGE_PRIORITY = "more_keys_language_priority"
|
||||
private const val MORE_KEYS_LAYOUT = "more_keys_layout"
|
||||
const val MORE_KEYS_LAYOUT = "more_keys_layout"
|
||||
private const val MORE_KEYS_SYMBOLS = "more_keys_symbols"
|
||||
private const val MORE_KEYS_LANGUAGE = "more_keys_language"
|
||||
const val MORE_KEYS_LABEL_DEFAULT = "$MORE_KEYS_NUMBER,true;$MORE_KEYS_LANGUAGE_PRIORITY,false;$MORE_KEYS_LAYOUT,true;$MORE_KEYS_SYMBOLS,true;$MORE_KEYS_LANGUAGE,false"
|
||||
const val MORE_KEYS_ORDER_DEFAULT = "$MORE_KEYS_LANGUAGE_PRIORITY,true;$MORE_KEYS_NUMBER,true;$MORE_KEYS_SYMBOLS,true;$MORE_KEYS_LAYOUT,true;$MORE_KEYS_LANGUAGE,true"
|
||||
|
||||
// todo:
|
||||
// take moreKeys from symbols layout (in a separate commit)
|
||||
// maybe also add a (simple) parser cache... or cache the layout somewhere else?
|
||||
// that might be annoying with base and full layout (functional keys and spacers)
|
||||
// because base layout not available later... put it to keyParams?
|
||||
// or create symbol moreKeys in the parser? that should work best, there we have proper access to layouts
|
||||
// could be done later:
|
||||
// some way to allow hint labels in symbols layout
|
||||
// remove duplicate symbol moreKeys
|
||||
// in remove_symbol_duplicates.patch
|
||||
// issues, see comments
|
||||
// maybe put "language" moreKeys into a different category when not using alphabet layout
|
||||
// because disabling language moreKeys will remove e.g. quote moreKeys
|
||||
|
||||
fun createMoreKeysArray(popupSet: PopupSet<*>?, params: KeyboardParams, label: String): Array<String>? {
|
||||
val moreKeys = mutableSetOf<String>()
|
||||
// often moreKeys are empty, so we want to avoid unnecessarily creating sets
|
||||
val moreKeysDelegate = lazy { mutableSetOf<String>() }
|
||||
val moreKeys by moreKeysDelegate
|
||||
params.mMoreKeyTypes.forEach { type ->
|
||||
when (type) {
|
||||
MORE_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { moreKeys.add(it) }
|
||||
MORE_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { moreKeys.addAll(it) }
|
||||
MORE_KEYS_SYMBOLS -> {} // todo
|
||||
MORE_KEYS_SYMBOLS -> popupSet?.symbol?.let { moreKeys.add(it) }
|
||||
MORE_KEYS_LANGUAGE -> params.mLocaleKeyTexts.getMoreKeys(label)?.let { moreKeys.addAll(it) }
|
||||
MORE_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyTexts.getPriorityMoreKeys(label)?.let { moreKeys.addAll(it) }
|
||||
}
|
||||
}
|
||||
if (moreKeys.isEmpty()) return null
|
||||
if (!moreKeysDelegate.isInitialized() || moreKeys.isEmpty())
|
||||
return null
|
||||
val fco = moreKeys.firstOrNull { it.startsWith(Key.MORE_KEYS_FIXED_COLUMN_ORDER) }
|
||||
if (fco != null && fco.substringAfter(Key.MORE_KEYS_FIXED_COLUMN_ORDER).toIntOrNull() != moreKeys.size - 1) {
|
||||
moreKeys.remove(fco) // maybe rather adjust the number instead of remove?
|
||||
|
@ -66,16 +72,17 @@ fun getHintLabel(popupSet: PopupSet<*>?, params: KeyboardParams, label: String):
|
|||
when (type) {
|
||||
MORE_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { hintLabel = it }
|
||||
MORE_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { hintLabel = it.firstOrNull() }
|
||||
MORE_KEYS_SYMBOLS -> {} // todo
|
||||
MORE_KEYS_SYMBOLS -> popupSet?.symbol?.let { hintLabel = it }
|
||||
MORE_KEYS_LANGUAGE -> params.mLocaleKeyTexts.getMoreKeys(label)?.let { hintLabel = it.firstOrNull() }
|
||||
MORE_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyTexts.getPriorityMoreKeys(label)?.let { hintLabel = it.firstOrNull() }
|
||||
}
|
||||
if (hintLabel != null) break
|
||||
}
|
||||
|
||||
// avoid e.g. !autoColumnOrder! as label
|
||||
// this will avoid having labels on comma and period keys
|
||||
return hintLabel?.let { transformLabel(it, params) }
|
||||
// don't do the rtl transform, hint label is only the label
|
||||
return hintLabel?.let { if (it == "$$$") transformLabel(it, params) else it }
|
||||
// avoid e.g. !autoColumnOrder! as label
|
||||
// this will avoid having labels on comma and period keys
|
||||
?.takeIf { !it.startsWith("!") || it == "!" }
|
||||
}
|
||||
|
||||
|
@ -115,12 +122,6 @@ fun reorderMoreKeysDialog(context: Context, key: String, defaultSetting: String,
|
|||
val adapter = object : ListAdapter<Pair<String, Boolean>, RecyclerView.ViewHolder>(callback) {
|
||||
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): RecyclerView.ViewHolder {
|
||||
val b = LayoutInflater.from(context).inflate(R.layout.morekeys_list_item, rv, false)
|
||||
// wtf? this results in transparent background, but when the background is set in xml it's fine?
|
||||
// but of course when setting in xml i need to duplicate the entire thing except for background because of api things
|
||||
// why tf is it so complicated to just use the dialog's background?
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// b.setBackgroundColor(android.R.attr.colorBackgroundFloating)
|
||||
// }
|
||||
return object : RecyclerView.ViewHolder(b) { }
|
||||
}
|
||||
override fun onBindViewHolder(p0: RecyclerView.ViewHolder, p1: Int) {
|
||||
|
@ -130,6 +131,7 @@ fun reorderMoreKeysDialog(context: Context, key: String, defaultSetting: String,
|
|||
p0.itemView.findViewById<TextView>(R.id.morekeys_type)?.text = displayText
|
||||
val switch = p0.itemView.findViewById<SwitchCompat>(R.id.morekeys_switch)
|
||||
switch?.isChecked = wasChecked
|
||||
switch?.isEnabled = !(key.contains(Settings.PREF_MORE_KEYS_ORDER) && text == MORE_KEYS_LAYOUT) // layout can't be disabled
|
||||
switch?.setOnCheckedChangeListener { _, isChecked ->
|
||||
val position = orderedItems.indexOfFirst { it.first == text }
|
||||
orderedItems[position] = text to isChecked
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue