some fixes

This commit is contained in:
Helium314 2024-01-31 19:49:50 +01:00
parent a91a90bfbd
commit 40f39a70d0
6 changed files with 24 additions and 21 deletions

View file

@ -7,7 +7,7 @@ android {
buildToolsVersion = '34.0.0' buildToolsVersion = '34.0.0'
defaultConfig { defaultConfig {
applicationId "helium314.keyboard.latin" applicationId "helium314.keyboard"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 34 targetSdkVersion 34
versionCode 1000 versionCode 1000

View file

@ -1,17 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 The Android Open Source Project <!--
Copyright (C) 2012 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License"); modified
you may not use this file except in compliance with the License. SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--> -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">

View file

@ -204,10 +204,10 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
val layoutName = Settings.readSymbolsLayoutName(context, params.mId.locale) val layoutName = Settings.readSymbolsLayoutName(context, params.mId.locale)
val layout = if (layoutName.startsWith(CUSTOM_LAYOUT_PREFIX)) { val layout = if (layoutName.startsWith(CUSTOM_LAYOUT_PREFIX)) {
val parser = if (layoutName.endsWith("json")) JsonKeyboardParser(params, context) val parser = if (layoutName.endsWith("json")) JsonKeyboardParser(params, context)
else SimpleKeyboardParser(params, context) else SimpleKeyboardParser(params, context, false)
parser.parseCoreLayout(getLayoutFile(layoutName, context).readText()) parser.parseCoreLayout(getLayoutFile(layoutName, context).readText())
} else { } else {
SimpleKeyboardParser(params, context).parseCoreLayout(context.readAssetsFile("layouts/$layoutName.txt")) SimpleKeyboardParser(params, context, false).parseCoreLayout(context.readAssetsFile("layouts/$layoutName.txt"))
} }
layout.forEachIndexed { i, row -> layout.forEachIndexed { i, row ->
val baseRow = baseKeys.getOrNull(i) ?: return@forEachIndexed val baseRow = baseKeys.getOrNull(i) ?: return@forEachIndexed

View file

@ -13,9 +13,11 @@ import helium314.keyboard.latin.common.splitOnWhitespace
* for alphabet, 3 keys for symbols and 4 keys for shift symbols. MoreKeys on period and comma get * for alphabet, 3 keys for symbols and 4 keys for shift symbols. MoreKeys on period and comma get
* merged with defaults. * merged with defaults.
*/ */
class SimpleKeyboardParser(private val params: KeyboardParams, private val context: Context) : KeyboardParser(params, context) { class SimpleKeyboardParser(
private val addExtraKeys = params.mId.mSubtype.keyboardLayoutSetName.endsWith("+") private val params: KeyboardParams,
context: Context,
private val addExtraKeys: Boolean = params.mId.mSubtype.keyboardLayoutSetName.endsWith("+") && params.mId.isAlphabetKeyboard
) : KeyboardParser(params, context) {
override fun parseCoreLayout(layoutContent: String): MutableList<List<KeyData>> { override fun parseCoreLayout(layoutContent: String): MutableList<List<KeyData>> {
val rowStrings = layoutContent.replace("\r\n", "\n").split("\\n\\s*\\n".toRegex()) val rowStrings = layoutContent.replace("\r\n", "\n").split("\\n\\s*\\n".toRegex())
return rowStrings.mapIndexedNotNullTo(mutableListOf()) { i, row -> return rowStrings.mapIndexedNotNullTo(mutableListOf()) { i, row ->

View file

@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
package helium314.keyboard.latin package helium314.keyboard.latin
import android.app.Application import android.app.Application
@ -9,6 +10,7 @@ import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX
import helium314.keyboard.latin.utils.DeviceProtectedUtils import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.DictionaryInfoUtils import helium314.keyboard.latin.utils.DictionaryInfoUtils
import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.upgradeToolbarPref import helium314.keyboard.latin.utils.upgradeToolbarPref
import java.io.File import java.io.File
@ -33,6 +35,7 @@ class App : Application() {
fun checkVersionUpgrade(context: Context) { fun checkVersionUpgrade(context: Context) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context) val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val oldVersion = prefs.getInt(Settings.PREF_VERSION_CODE, 0) val oldVersion = prefs.getInt(Settings.PREF_VERSION_CODE, 0)
Log.d("test", "old v $oldVersion, current ${BuildConfig.VERSION_CODE}")
if (oldVersion == BuildConfig.VERSION_CODE) if (oldVersion == BuildConfig.VERSION_CODE)
return return
upgradeToolbarPref(prefs) upgradeToolbarPref(prefs)
@ -85,6 +88,7 @@ private fun upgradesWhenComingFromOldAppName(context: Context) {
} }
prefs.all.toMap().forEach { prefs.all.toMap().forEach {
if (it.key.startsWith("pref_key_") && it.key != "pref_key_longpress_timeout") { if (it.key.startsWith("pref_key_") && it.key != "pref_key_longpress_timeout") {
Log.d("test", "adjusting ${it.key}")
var remove = true var remove = true
when (val value = it.value) { when (val value = it.value) {
is Boolean -> prefs.edit().putBoolean(it.key.substringAfter("pref_key_"), value).apply() is Boolean -> prefs.edit().putBoolean(it.key.substringAfter("pref_key_"), value).apply()
@ -97,6 +101,7 @@ private fun upgradesWhenComingFromOldAppName(context: Context) {
if (remove) if (remove)
prefs.edit().remove(it.key).apply() prefs.edit().remove(it.key).apply()
} else if (it.key.startsWith("pref_")) { } else if (it.key.startsWith("pref_")) {
Log.d("test", "adjusting ${it.key}")
var remove = true var remove = true
when (val value = it.value) { when (val value = it.value) {
is Boolean -> prefs.edit().putBoolean(it.key.substringAfter("pref_"), value).apply() is Boolean -> prefs.edit().putBoolean(it.key.substringAfter("pref_"), value).apply()
@ -108,19 +113,24 @@ private fun upgradesWhenComingFromOldAppName(context: Context) {
} }
if (remove) if (remove)
prefs.edit().remove(it.key).apply() prefs.edit().remove(it.key).apply()
} else {
Log.d("test", "keeping ${it.key}")
} }
} }
// change more_keys to popup_keys // change more_keys to popup_keys
if (prefs.contains("more_keys_order")) { if (prefs.contains("more_keys_order")) {
Log.d("test", "more_keys_order")
prefs.edit().putString(Settings.PREF_POPUP_KEYS_ORDER, prefs.getString("more_keys_order", "")).apply() prefs.edit().putString(Settings.PREF_POPUP_KEYS_ORDER, prefs.getString("more_keys_order", "")).apply()
prefs.edit().remove("more_keys_order").apply() prefs.edit().remove("more_keys_order").apply()
} }
if (prefs.contains("more_keys_labels_order")) { if (prefs.contains("more_keys_labels_order")) {
Log.d("test", "more_keys_labels_order")
prefs.edit().putString(Settings.PREF_POPUP_KEYS_LABELS_ORDER, prefs.getString("more_keys_labels_order", "")).apply() prefs.edit().putString(Settings.PREF_POPUP_KEYS_LABELS_ORDER, prefs.getString("more_keys_labels_order", "")).apply()
prefs.edit().remove("more_keys_labels_order").apply() prefs.edit().remove("more_keys_labels_order").apply()
} }
if (prefs.contains("more_more_keys")) { if (prefs.contains("more_more_keys")) {
prefs.edit().putString(Settings.PREF_POPUP_KEYS_ORDER, prefs.getString("more_more_keys", "")).apply() Log.d("test", "more_more_keys")
prefs.edit().putString(Settings.PREF_MORE_POPUP_KEYS, prefs.getString("more_more_keys", "")).apply()
prefs.edit().remove("more_more_keys").apply() prefs.edit().remove("more_more_keys").apply()
} }
// upgrade additional subtype locale strings // upgrade additional subtype locale strings

View file

@ -27,7 +27,7 @@ object ShadowLocaleManagerCompat {
class ShadowInputMethodManager2 : ShadowInputMethodManager() { class ShadowInputMethodManager2 : ShadowInputMethodManager() {
@Implementation @Implementation
override fun getInputMethodList() = listOf( override fun getInputMethodList() = listOf(
InputMethodInfo("helium314.keyboard.latin.debug", "LatinIME", "openboard debug", null), InputMethodInfo("helium314.keyboard.debug", "LatinIME", "openboard debug", null),
) )
@Implementation @Implementation
fun getShortcutInputMethodsAndSubtypes() = emptyMap<InputMethodInfo, List<InputMethodSubtype>>() fun getShortcutInputMethodsAndSubtypes() = emptyMap<InputMethodInfo, List<InputMethodSubtype>>()