From da8827efc398596d7c6b27832867b05237b967c7 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 19 Jan 2025 18:15:58 +0100 Subject: [PATCH 01/14] migrate build.gradle to kts --- app/build.gradle | 117 ----------------------------- app/build.gradle.kts | 117 +++++++++++++++++++++++++++++ build.gradle | 33 -------- build.gradle.kts | 24 ++++++ tools/make-emoji-keys/build.gradle | 4 +- 5 files changed, 142 insertions(+), 153 deletions(-) delete mode 100755 app/build.gradle create mode 100755 app/build.gradle.kts delete mode 100755 build.gradle create mode 100755 build.gradle.kts diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100755 index 4ece57b5..00000000 --- a/app/build.gradle +++ /dev/null @@ -1,117 +0,0 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlinx-serialization' - -android { - compileSdk 34 - buildToolsVersion = '34.0.0' - - defaultConfig { - applicationId "helium314.keyboard" - minSdkVersion 21 - targetSdkVersion 34 - versionCode 2301 - versionName '2.3' - ndk { - abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' - } - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - - buildTypes { - release { - minifyEnabled true - shrinkResources false - debuggable false - jniDebuggable false - renderscriptDebuggable false - } - nouserlib { // same as release, but does not allow the user to provide a library - minifyEnabled true - shrinkResources false - debuggable false - jniDebuggable false - renderscriptDebuggable false - } - debug { - minifyEnabled true - jniDebuggable false - applicationIdSuffix ".debug" - } - runTests { // build variant for running tests on CI that skips tests known to fail - minifyEnabled true - jniDebuggable false - } - archivesBaseName = "HeliBoard_" + defaultConfig.versionName - } - - buildFeatures { - viewBinding true - buildConfig true - } - - externalNativeBuild { - ndkBuild { - path 'src/main/jni/Android.mk' - } - } - - - ndkVersion '26.2.11394342' - - packagingOptions { - jniLibs { - // shrinks APK by 3 MB, zipped size unchanged - useLegacyPackaging true - } - } - - testOptions { - unitTests { - includeAndroidResources = true - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } - - kotlinOptions { - jvmTarget = JavaVersion.VERSION_17.toString() - } - - // see https://github.com/Helium314/HeliBoard/issues/477 - dependenciesInfo { - includeInApk = false - includeInBundle = false - } - - namespace "helium314.keyboard.latin" - lint { - abortOnError true - } -} - -dependencies { - // androidx - implementation 'androidx.core:core-ktx:1.13.1' - implementation 'androidx.appcompat:appcompat:1.7.0' - implementation 'androidx.preference:preference:1.2.1' - implementation 'androidx.recyclerview:recyclerview:1.3.2' - implementation 'androidx.autofill:autofill:1.1.0' - - // kotlin - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3" - - // color picker for user-defined colors - implementation 'com.github.martin-stone:hsv-alpha-color-picker-android:3.1.0' - - // test - testImplementation 'junit:junit:4.13.2' - testImplementation 'org.mockito:mockito-core:5.14.2' - testImplementation 'org.robolectric:robolectric:4.12.1' - testImplementation 'androidx.test:runner:1.6.2' - testImplementation 'androidx.test:core:1.6.1' -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100755 index 00000000..b2a0d518 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,117 @@ +plugins { + id("com.android.application") + kotlin("android") + kotlin("plugin.serialization") version "2.0.21" +} + +android { + compileSdk = 34 + buildToolsVersion = "34.0.0" + + defaultConfig { + applicationId = "helium314.keyboard" + minSdk = 21 + targetSdk = 34 + versionCode = 2301 + versionName = "2.3" + ndk { + abiFilters.clear() + abiFilters.addAll(listOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64")) + } + proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = true + isShrinkResources = false + isDebuggable = false + isJniDebuggable = false + } + create("nouserlib") { // same as release, but does not allow the user to provide a library + isMinifyEnabled = true + isShrinkResources = false + isDebuggable = false + isJniDebuggable = false + } + debug { + isMinifyEnabled = true + isJniDebuggable = false + applicationIdSuffix = ".debug" + } + create("runTests") { // build variant for running tests on CI that skips tests known to fail + isMinifyEnabled = true + isJniDebuggable = false + } + base.archivesBaseName = "HeliBoard_" + defaultConfig.versionName + } + + buildFeatures { + viewBinding = true + buildConfig = true + } + + externalNativeBuild { + ndkBuild { + path = File("src/main/jni/Android.mk") + } + } + + + ndkVersion = "26.2.11394342" + + packagingOptions { + jniLibs { + // shrinks APK by 3 MB, zipped size unchanged + useLegacyPackaging = true + } + } + + testOptions { + unitTests { + isIncludeAndroidResources = true + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_17.toString() + } + + // see https://github.com/Helium314/HeliBoard/issues/477 + dependenciesInfo { + includeInApk = false + includeInBundle = false + } + + namespace = "helium314.keyboard.latin" + lint { + abortOnError = true + } +} + +dependencies { + // androidx + implementation("androidx.core:core-ktx:1.13.1") + implementation("androidx.appcompat:appcompat:1.7.0") + implementation("androidx.preference:preference:1.2.1") + implementation("androidx.recyclerview:recyclerview:1.3.2") + implementation("androidx.autofill:autofill:1.1.0") + + // kotlin + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0") + + // color picker for user-defined colors + implementation("com.github.martin-stone:hsv-alpha-color-picker-android:3.1.0") + + // test + testImplementation("junit:junit:4.13.2") + testImplementation("org.mockito:mockito-core:5.15.2") + testImplementation("org.robolectric:robolectric:4.12.1") + testImplementation("androidx.test:runner:1.6.2") + testImplementation("androidx.test:core:1.6.1") +} diff --git a/build.gradle b/build.gradle deleted file mode 100755 index f43362f6..00000000 --- a/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - ext.kotlin_version = '2.0.21' - repositories { - mavenCentral() - google() - } - dependencies { - classpath 'com.android.tools.build:gradle:8.7.2' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -plugins { - id 'org.jetbrains.kotlin.plugin.serialization' version "$kotlin_version" -} - -allprojects { - repositories { - google() - mavenCentral() - maven { url "https://jitpack.io" } - } -} - -tasks.register('clean', Delete) { - delete rootProject.layout.buildDirectory -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100755 index 00000000..63075526 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,24 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + val kotlinVersion = "2.0.21" + repositories { + mavenCentral() + google() + } + dependencies { + classpath("com.android.tools.build:gradle:8.7.2") + classpath(kotlin("gradle-plugin", version = kotlinVersion)) + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + mavenCentral() + maven { url = uri("https://jitpack.io") } + } +} diff --git a/tools/make-emoji-keys/build.gradle b/tools/make-emoji-keys/build.gradle index a21e766a..dde20660 100644 --- a/tools/make-emoji-keys/build.gradle +++ b/tools/make-emoji-keys/build.gradle @@ -25,11 +25,9 @@ task makeEmoji(type: JavaExec, dependsOn: ['jar']) { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib:2.0.21" } - - java { sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 From df8c0c6c59da6c861e9aa01f3e6a36514914d732 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 19 Jan 2025 18:27:31 +0100 Subject: [PATCH 02/14] switch tests from junit to kotlin.test (mostly) --- app/build.gradle.kts | 1 + .../helium314/keyboard/KeySpecParserTest.kt | 4 ++-- .../helium314/keyboard/KeyboardParserTest.kt | 18 +++++++++--------- .../helium314/keyboard/latin/InputLogicTest.kt | 9 +++++---- .../keyboard/latin/LocaleUtilsTest.kt | 4 ++-- .../keyboard/latin/ScriptUtilsTest.kt | 4 ++-- .../keyboard/latin/StringUtilsTest.kt | 4 ++-- .../helium314/keyboard/latin/SuggestTest.kt | 6 +++--- 8 files changed, 26 insertions(+), 24 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b2a0d518..7d6bc1be 100755 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -109,6 +109,7 @@ dependencies { implementation("com.github.martin-stone:hsv-alpha-color-picker-android:3.1.0") // test + testImplementation(kotlin("test")) testImplementation("junit:junit:4.13.2") testImplementation("org.mockito:mockito-core:5.15.2") testImplementation("org.robolectric:robolectric:4.12.1") diff --git a/app/src/test/java/helium314/keyboard/KeySpecParserTest.kt b/app/src/test/java/helium314/keyboard/KeySpecParserTest.kt index 5212984e..cc6b1fc9 100644 --- a/app/src/test/java/helium314/keyboard/KeySpecParserTest.kt +++ b/app/src/test/java/helium314/keyboard/KeySpecParserTest.kt @@ -2,8 +2,8 @@ package helium314.keyboard import helium314.keyboard.keyboard.internal.KeySpecParser import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode -import org.junit.Assert.assertEquals -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals class KeySpecParserTest { @Test fun label() { diff --git a/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt b/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt index 197d127c..42b261f9 100644 --- a/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt +++ b/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt @@ -9,6 +9,7 @@ import helium314.keyboard.keyboard.Keyboard import helium314.keyboard.keyboard.KeyboardId import helium314.keyboard.keyboard.KeyboardLayoutSet import helium314.keyboard.keyboard.internal.KeySpecParser +import helium314.keyboard.keyboard.internal.KeySpecParser.KeySpecParserError import helium314.keyboard.keyboard.internal.KeyboardBuilder import helium314.keyboard.keyboard.internal.KeyboardParams import helium314.keyboard.keyboard.internal.TouchPositionCorrection @@ -22,11 +23,6 @@ import helium314.keyboard.latin.RichInputMethodSubtype import helium314.keyboard.latin.utils.AdditionalSubtypeUtils.createEmojiCapableAdditionalSubtype import helium314.keyboard.latin.utils.POPUP_KEYS_LAYOUT import helium314.keyboard.latin.utils.checkKeys -import org.junit.Assert.assertEquals -import org.junit.Assert.assertThrows -import org.junit.Assert.assertTrue -import org.junit.Before -import org.junit.Test import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner @@ -35,6 +31,11 @@ import org.robolectric.annotation.Implementation import org.robolectric.annotation.Implements import org.robolectric.shadows.ShadowLog import java.util.Locale +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith +import kotlin.test.assertTrue @RunWith(RobolectricTestRunner::class) @Config(shadows = [ @@ -45,8 +46,7 @@ class ParserTest { private lateinit var latinIME: LatinIME private lateinit var params: KeyboardParams - @Before - fun setUp() { + @BeforeTest fun setUp() { latinIME = Robolectric.setupService(LatinIME::class.java) ShadowLog.setupLogging() ShadowLog.stream = System.out @@ -320,7 +320,7 @@ f""", // no newline at the end } @Test fun invalidKeys() { - assertThrows(KeySpecParser.KeySpecParserError::class.java) { + assertFailsWith { RawKeyboardParser.parseJsonString("""[[{ "label": "!icon/clipboard_action_key" }]]""").map { it.mapNotNull { it.compute(params)?.toKeyParams(params) } } } } @@ -402,7 +402,7 @@ f""", // no newline at the end } @Test fun invalidPopupKeys() { - assertThrows(KeySpecParser.KeySpecParserError::class.java) { + assertFailsWith { RawKeyboardParser.parseJsonString("""[[{ "label": "a", "popup": { "main": { "label": "!icon/clipboard_action_key" } } }]]""").map { it.mapNotNull { it.compute(params)?.toKeyParams(params) } } diff --git a/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt b/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt index 07f90492..08cf13fd 100644 --- a/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt @@ -24,9 +24,6 @@ import helium314.keyboard.latin.inputlogic.SpaceState import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.utils.DeviceProtectedUtils import helium314.keyboard.latin.utils.ScriptUtils -import org.junit.Assert.assertEquals -import org.junit.Before -import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito import org.robolectric.Robolectric @@ -37,6 +34,9 @@ import org.robolectric.annotation.Implements import org.robolectric.shadows.ShadowLog import java.util.* import kotlin.math.min +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertEquals @RunWith(RobolectricTestRunner::class) @Config(shadows = [ @@ -61,7 +61,8 @@ class InputLogicTest { private val composingReader = RichInputConnection::class.java.getDeclaredField("mComposingText").apply { isAccessible = true } private val connectionComposingText get() = (composingReader.get(connection) as CharSequence).toString() - @Before fun setUp() { + @BeforeTest + fun setUp() { latinIME = Robolectric.setupService(LatinIME::class.java) // start logging only after latinIME is created, avoids showing the stack traces if library is not found ShadowLog.setupLogging() diff --git a/app/src/test/java/helium314/keyboard/latin/LocaleUtilsTest.kt b/app/src/test/java/helium314/keyboard/latin/LocaleUtilsTest.kt index b549e04e..9fb7eaaf 100644 --- a/app/src/test/java/helium314/keyboard/latin/LocaleUtilsTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/LocaleUtilsTest.kt @@ -2,8 +2,8 @@ package helium314.keyboard.latin import helium314.keyboard.latin.common.LocaleUtils.constructLocale -import org.junit.Assert.assertEquals -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals class LocaleUtilsTest { @Test fun createLocales() { diff --git a/app/src/test/java/helium314/keyboard/latin/ScriptUtilsTest.kt b/app/src/test/java/helium314/keyboard/latin/ScriptUtilsTest.kt index d9a04186..9134a587 100644 --- a/app/src/test/java/helium314/keyboard/latin/ScriptUtilsTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/ScriptUtilsTest.kt @@ -6,8 +6,8 @@ import helium314.keyboard.latin.utils.ScriptUtils.SCRIPT_CYRILLIC import helium314.keyboard.latin.utils.ScriptUtils.SCRIPT_DEVANAGARI import helium314.keyboard.latin.utils.ScriptUtils.SCRIPT_LATIN import helium314.keyboard.latin.utils.ScriptUtils.script -import org.junit.Assert.assertEquals -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals class ScriptUtilsTest { @Test fun defaultScript() { diff --git a/app/src/test/java/helium314/keyboard/latin/StringUtilsTest.kt b/app/src/test/java/helium314/keyboard/latin/StringUtilsTest.kt index cb5f0d9b..518b6ffe 100644 --- a/app/src/test/java/helium314/keyboard/latin/StringUtilsTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/StringUtilsTest.kt @@ -3,8 +3,8 @@ package helium314.keyboard.latin import helium314.keyboard.latin.common.StringUtils import helium314.keyboard.latin.common.getFullEmojiAtEnd -import org.junit.Assert.assertEquals -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals // todo: actually this test could/should be significantly expanded... class StringUtilsTest { diff --git a/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt b/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt index baafd255..c37b4392 100644 --- a/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt @@ -15,8 +15,6 @@ import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.SettingsValuesForSuggestion import helium314.keyboard.latin.utils.DeviceProtectedUtils import helium314.keyboard.latin.utils.SuggestionResults -import org.junit.Before -import org.junit.Test import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner @@ -25,6 +23,8 @@ import org.robolectric.annotation.Implementation import org.robolectric.annotation.Implements import org.robolectric.shadows.ShadowLog import java.util.* +import kotlin.test.BeforeTest +import kotlin.test.Test @Suppress("NonAsciiCharacters") @RunWith(RobolectricTestRunner::class) @@ -43,7 +43,7 @@ class SuggestTest { private val thresholdAggressive = "1" private val thresholdVeryAggressive = "2" - @Before fun setUp() { + @BeforeTest fun setUp() { latinIME = Robolectric.setupService(LatinIME::class.java) // start logging only after latinIME is created, avoids showing the stack traces if library is not found ShadowLog.setupLogging() From 35e0fe6be3c2baf458446f293b5dfdf30bd00ebc Mon Sep 17 00:00:00 2001 From: Helium314 Date: Mon, 20 Jan 2025 21:28:12 +0100 Subject: [PATCH 03/14] add TLD information to LocaleKeyboardInfos preparation for #492 --- CONTRIBUTING.md | 2 +- app/src/main/assets/locale_key_texts/af.txt | 3 ++ app/src/main/assets/locale_key_texts/ar.txt | 3 ++ app/src/main/assets/locale_key_texts/bg.txt | 3 ++ app/src/main/assets/locale_key_texts/ca.txt | 3 ++ app/src/main/assets/locale_key_texts/cs.txt | 3 ++ app/src/main/assets/locale_key_texts/da.txt | 3 ++ app/src/main/assets/locale_key_texts/de.txt | 3 ++ app/src/main/assets/locale_key_texts/el.txt | 3 ++ app/src/main/assets/locale_key_texts/es.txt | 3 ++ app/src/main/assets/locale_key_texts/et.txt | 3 ++ app/src/main/assets/locale_key_texts/fa.txt | 3 ++ app/src/main/assets/locale_key_texts/fi.txt | 3 ++ app/src/main/assets/locale_key_texts/fr.txt | 3 ++ .../main/assets/locale_key_texts/hi-Latn.txt | 2 + app/src/main/assets/locale_key_texts/hi.txt | 3 ++ app/src/main/assets/locale_key_texts/hr.txt | 3 ++ app/src/main/assets/locale_key_texts/hu.txt | 3 ++ app/src/main/assets/locale_key_texts/hy.txt | 3 ++ app/src/main/assets/locale_key_texts/is.txt | 3 ++ app/src/main/assets/locale_key_texts/it.txt | 3 ++ app/src/main/assets/locale_key_texts/iw.txt | 3 ++ app/src/main/assets/locale_key_texts/kab.txt | 2 + app/src/main/assets/locale_key_texts/ko.txt | 3 ++ app/src/main/assets/locale_key_texts/lt.txt | 3 ++ app/src/main/assets/locale_key_texts/lv.txt | 3 ++ app/src/main/assets/locale_key_texts/nb.txt | 3 ++ app/src/main/assets/locale_key_texts/pl.txt | 3 ++ app/src/main/assets/locale_key_texts/ro.txt | 3 ++ app/src/main/assets/locale_key_texts/ru.txt | 3 ++ app/src/main/assets/locale_key_texts/sk.txt | 3 ++ app/src/main/assets/locale_key_texts/sl.txt | 3 ++ .../main/assets/locale_key_texts/sr-Latn.txt | 3 ++ app/src/main/assets/locale_key_texts/sr.txt | 3 ++ app/src/main/assets/locale_key_texts/sv.txt | 3 ++ app/src/main/assets/locale_key_texts/tr.txt | 3 ++ app/src/main/assets/locale_key_texts/uk.txt | 3 ++ app/src/main/assets/locale_key_texts/vi.txt | 3 ++ .../keyboard_parser/LocaleKeyboardInfos.kt | 38 +++++++++++++++++++ 39 files changed, 148 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dcb63d11..5e0fbaef 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ If you have difficulties implementing some functionality, you're welcome to ask # Guidelines HeliBoard is a complex application, when contributing, you must take a step back and make sure your contribution: -- **Is actually wanted**. Best check related open issues before you start working on a PR. Issues with "PR" and "contributor needed" labels are accepted, but still it would be good if you announced that you are working on it, so we can discuss how changes are best implemented. +- **Is actually wanted**. Best check related open issues before you start working on a PR. Issues with [_PR_](https://github.com/Helium314/HeliBoard/labels/PR) and [_contributor needed_](https://github.com/Helium314/HeliBoard/issues?q=label%3A%22contributor%20needed%22) [labels](https://github.com/Helium314/HeliBoard/labels) are accepted, but still it would be good if you announced that you are working on it, so we can discuss how changes are best implemented. If there is no accepted issue related to your intended contribution, it's a good idea to open a new one (and of course getting one of "PR" or "contributor needed" labels) to avoid disappointment of the contribution not being accepted. For small changes or fixing obvious bugs this step is not necessary. - **Is only about a single thing**. Mixing unrelated or semi-related contributions into a single PR is hard to review and can get messy. - **Is finished or a draft**. When you keep changing the PR without reviewer's feedback, any attempt to review it is doomed and a waste of time. Better mark it as a draft in this case. diff --git a/app/src/main/assets/locale_key_texts/af.txt b/app/src/main/assets/locale_key_texts/af.txt index de2685f2..556e2290 100644 --- a/app/src/main/assets/locale_key_texts/af.txt +++ b/app/src/main/assets/locale_key_texts/af.txt @@ -6,3 +6,6 @@ o ó ô ö ò õ œ ø ō u ú û ü ù ū n ñ ń y ý ij + +[tlds] +za diff --git a/app/src/main/assets/locale_key_texts/ar.txt b/app/src/main/assets/locale_key_texts/ar.txt index 88497618..5c4b3c00 100644 --- a/app/src/main/assets/locale_key_texts/ar.txt +++ b/app/src/main/assets/locale_key_texts/ar.txt @@ -24,3 +24,6 @@ question: ؟ [number_row] ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩ ٠ + +[tlds] +sa diff --git a/app/src/main/assets/locale_key_texts/bg.txt b/app/src/main/assets/locale_key_texts/bg.txt index a0d8740f..40924464 100644 --- a/app/src/main/assets/locale_key_texts/bg.txt +++ b/app/src/main/assets/locale_key_texts/bg.txt @@ -3,3 +3,6 @@ [labels] alphabet: АБВ + +[tlds] +bg diff --git a/app/src/main/assets/locale_key_texts/ca.txt b/app/src/main/assets/locale_key_texts/ca.txt index d386f760..619481bc 100644 --- a/app/src/main/assets/locale_key_texts/ca.txt +++ b/app/src/main/assets/locale_key_texts/ca.txt @@ -10,3 +10,6 @@ punctuation !autoColumnOrder!9 \, ? ! · # ) ( / ; ' @ : - " + \% & [extra_keys] 2: ç + +[tlds] +cat es diff --git a/app/src/main/assets/locale_key_texts/cs.txt b/app/src/main/assets/locale_key_texts/cs.txt index 83e844e6..a34abb41 100644 --- a/app/src/main/assets/locale_key_texts/cs.txt +++ b/app/src/main/assets/locale_key_texts/cs.txt @@ -14,3 +14,6 @@ y ý z ž ' ’ ‚ ‘ › ‹ " ” „ “ » « + +[tlds] +cz diff --git a/app/src/main/assets/locale_key_texts/da.txt b/app/src/main/assets/locale_key_texts/da.txt index b12cd416..17094de2 100644 --- a/app/src/main/assets/locale_key_texts/da.txt +++ b/app/src/main/assets/locale_key_texts/da.txt @@ -9,3 +9,6 @@ o ø 1: å 2: æ ä 2: ø ö + +[tlds] +dk diff --git a/app/src/main/assets/locale_key_texts/de.txt b/app/src/main/assets/locale_key_texts/de.txt index d51c37f2..0cc11904 100644 --- a/app/src/main/assets/locale_key_texts/de.txt +++ b/app/src/main/assets/locale_key_texts/de.txt @@ -5,3 +5,6 @@ u ü s ß ' ’ ‚ ‘ › ‹ " ” „ “ » « + +[tlds] +de at ch diff --git a/app/src/main/assets/locale_key_texts/el.txt b/app/src/main/assets/locale_key_texts/el.txt index 6372cd78..0dd59534 100644 --- a/app/src/main/assets/locale_key_texts/el.txt +++ b/app/src/main/assets/locale_key_texts/el.txt @@ -9,3 +9,6 @@ [labels] alphabet: ΑΒΓ + +[tlds] +gr diff --git a/app/src/main/assets/locale_key_texts/es.txt b/app/src/main/assets/locale_key_texts/es.txt index 5e66d981..bfaa35a9 100644 --- a/app/src/main/assets/locale_key_texts/es.txt +++ b/app/src/main/assets/locale_key_texts/es.txt @@ -10,3 +10,6 @@ punctuation !autoColumnOrder!9 \, ? ! # ) ( / ; ¡ ' @ : - " + \% & ¿ [extra_keys] 2: ñ + +[tlds] +es com.es diff --git a/app/src/main/assets/locale_key_texts/et.txt b/app/src/main/assets/locale_key_texts/et.txt index 0ad69c23..2ee735f5 100644 --- a/app/src/main/assets/locale_key_texts/et.txt +++ b/app/src/main/assets/locale_key_texts/et.txt @@ -12,3 +12,6 @@ z ž 2: ö õ 2: ä 3: õ + +[tlds] +ee diff --git a/app/src/main/assets/locale_key_texts/fa.txt b/app/src/main/assets/locale_key_texts/fa.txt index 1fce5e71..3ce747ec 100644 --- a/app/src/main/assets/locale_key_texts/fa.txt +++ b/app/src/main/assets/locale_key_texts/fa.txt @@ -17,3 +17,6 @@ question: ؟ [number_row] ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹ ۰ + +[tlds] +ir diff --git a/app/src/main/assets/locale_key_texts/fi.txt b/app/src/main/assets/locale_key_texts/fi.txt index bfb58732..287d329f 100644 --- a/app/src/main/assets/locale_key_texts/fi.txt +++ b/app/src/main/assets/locale_key_texts/fi.txt @@ -8,3 +8,6 @@ z ž 1: å 2: ö ø 2: ä æ + +[tlds] +fi diff --git a/app/src/main/assets/locale_key_texts/fr.txt b/app/src/main/assets/locale_key_texts/fr.txt index 4311b091..02772665 100644 --- a/app/src/main/assets/locale_key_texts/fr.txt +++ b/app/src/main/assets/locale_key_texts/fr.txt @@ -11,3 +11,6 @@ y ÿ 1: è ü 2: é ö 2: à ä + +[tlds] +fr diff --git a/app/src/main/assets/locale_key_texts/hi-Latn.txt b/app/src/main/assets/locale_key_texts/hi-Latn.txt index e69de29b..b77e1c87 100644 --- a/app/src/main/assets/locale_key_texts/hi-Latn.txt +++ b/app/src/main/assets/locale_key_texts/hi-Latn.txt @@ -0,0 +1,2 @@ +[tlds] +in diff --git a/app/src/main/assets/locale_key_texts/hi.txt b/app/src/main/assets/locale_key_texts/hi.txt index e6947823..c30631dc 100644 --- a/app/src/main/assets/locale_key_texts/hi.txt +++ b/app/src/main/assets/locale_key_texts/hi.txt @@ -73,3 +73,6 @@ period: । [number_row] १ २ ३ ४ ५ ६ ७ ८ ९ ० + +[tlds] +in diff --git a/app/src/main/assets/locale_key_texts/hr.txt b/app/src/main/assets/locale_key_texts/hr.txt index 2f20257a..dbe04049 100644 --- a/app/src/main/assets/locale_key_texts/hr.txt +++ b/app/src/main/assets/locale_key_texts/hr.txt @@ -5,3 +5,6 @@ c č ć d đ ' ‘ ‚ ’ › ‹ " “ „ ” » « + +[tlds] +hr diff --git a/app/src/main/assets/locale_key_texts/hu.txt b/app/src/main/assets/locale_key_texts/hu.txt index f973343a..423b4514 100644 --- a/app/src/main/assets/locale_key_texts/hu.txt +++ b/app/src/main/assets/locale_key_texts/hu.txt @@ -6,3 +6,6 @@ o ó ö ő u ú ü ű ' ‘ ‚ ’ › ‹ " “ „ ” » « + +[tlds] +hu gov.hu diff --git a/app/src/main/assets/locale_key_texts/hy.txt b/app/src/main/assets/locale_key_texts/hy.txt index 4808e31b..66b3f344 100644 --- a/app/src/main/assets/locale_key_texts/hy.txt +++ b/app/src/main/assets/locale_key_texts/hy.txt @@ -6,3 +6,6 @@ punctuation !autoColumnOrder!8 \, ՞ ՜ ․ … ' = / ՝ ՛ ֊ » « ― ) ( [labels] alphabet: ԱԲԳ period: ։ + +[tlds] +am diff --git a/app/src/main/assets/locale_key_texts/is.txt b/app/src/main/assets/locale_key_texts/is.txt index b8380b2e..4474bc16 100644 --- a/app/src/main/assets/locale_key_texts/is.txt +++ b/app/src/main/assets/locale_key_texts/is.txt @@ -9,3 +9,6 @@ y ý t þ ' ’ ‚ ‘ " ” „ “ + +[tlds] +is diff --git a/app/src/main/assets/locale_key_texts/it.txt b/app/src/main/assets/locale_key_texts/it.txt index 305127e2..8ee569cf 100644 --- a/app/src/main/assets/locale_key_texts/it.txt +++ b/app/src/main/assets/locale_key_texts/it.txt @@ -4,3 +4,6 @@ e è é ə i ì o ò ó º u ù + +[tlds] +it gov.it edu.it diff --git a/app/src/main/assets/locale_key_texts/iw.txt b/app/src/main/assets/locale_key_texts/iw.txt index 70f5f0a2..781fe76b 100644 --- a/app/src/main/assets/locale_key_texts/iw.txt +++ b/app/src/main/assets/locale_key_texts/iw.txt @@ -10,3 +10,6 @@ [labels] alphabet: אבג + +[tlds] +il co.il gov.il diff --git a/app/src/main/assets/locale_key_texts/kab.txt b/app/src/main/assets/locale_key_texts/kab.txt index 47a02ff2..34df7212 100644 --- a/app/src/main/assets/locale_key_texts/kab.txt +++ b/app/src/main/assets/locale_key_texts/kab.txt @@ -14,3 +14,5 @@ b p [labels] alphabet: AƐΓ +[tlds] +dz fr diff --git a/app/src/main/assets/locale_key_texts/ko.txt b/app/src/main/assets/locale_key_texts/ko.txt index 10535b9a..9f7c4e37 100644 --- a/app/src/main/assets/locale_key_texts/ko.txt +++ b/app/src/main/assets/locale_key_texts/ko.txt @@ -1,2 +1,5 @@ [labels] alphabet: ㄱㄴㄷ + +[tlds] +kr diff --git a/app/src/main/assets/locale_key_texts/lt.txt b/app/src/main/assets/locale_key_texts/lt.txt index a55b1603..d017e381 100644 --- a/app/src/main/assets/locale_key_texts/lt.txt +++ b/app/src/main/assets/locale_key_texts/lt.txt @@ -8,3 +8,6 @@ u ū ų z ž ' ’ ‚ ‘ " ” „ “ + +[tlds] +lt diff --git a/app/src/main/assets/locale_key_texts/lv.txt b/app/src/main/assets/locale_key_texts/lv.txt index cf6f5365..de243b16 100644 --- a/app/src/main/assets/locale_key_texts/lv.txt +++ b/app/src/main/assets/locale_key_texts/lv.txt @@ -13,3 +13,6 @@ u ū z ž ' ’ ‚ ‘ " ” „ “ + +[tlds] +lv diff --git a/app/src/main/assets/locale_key_texts/nb.txt b/app/src/main/assets/locale_key_texts/nb.txt index 05c9c877..5b75b95c 100644 --- a/app/src/main/assets/locale_key_texts/nb.txt +++ b/app/src/main/assets/locale_key_texts/nb.txt @@ -9,3 +9,6 @@ o ø 1: å 2: ø ö 2: æ ä + +[tlds] +no diff --git a/app/src/main/assets/locale_key_texts/pl.txt b/app/src/main/assets/locale_key_texts/pl.txt index a92ce9c4..91baf0d3 100644 --- a/app/src/main/assets/locale_key_texts/pl.txt +++ b/app/src/main/assets/locale_key_texts/pl.txt @@ -9,3 +9,6 @@ z ż ź l ł ' ‘ ‚ ’ " “ „ ” + +[tlds] +pl diff --git a/app/src/main/assets/locale_key_texts/ro.txt b/app/src/main/assets/locale_key_texts/ro.txt index 49b4c2ef..988644ef 100644 --- a/app/src/main/assets/locale_key_texts/ro.txt +++ b/app/src/main/assets/locale_key_texts/ro.txt @@ -5,3 +5,6 @@ s ș t ț ' ‘ ‚ ’ " “ „ ” + +[tlds] +ro diff --git a/app/src/main/assets/locale_key_texts/ru.txt b/app/src/main/assets/locale_key_texts/ru.txt index f6062fb5..bbb9a247 100644 --- a/app/src/main/assets/locale_key_texts/ru.txt +++ b/app/src/main/assets/locale_key_texts/ru.txt @@ -6,3 +6,6 @@ [labels] alphabet: АБВ + +[tlds] +ru diff --git a/app/src/main/assets/locale_key_texts/sk.txt b/app/src/main/assets/locale_key_texts/sk.txt index 36ec252b..b699ff6b 100644 --- a/app/src/main/assets/locale_key_texts/sk.txt +++ b/app/src/main/assets/locale_key_texts/sk.txt @@ -15,3 +15,6 @@ z ž l ľ ĺ ' ’ ‚ ‘ › ‹ " ” „ “ » « + +[tlds] +sk diff --git a/app/src/main/assets/locale_key_texts/sl.txt b/app/src/main/assets/locale_key_texts/sl.txt index 1a7c5ebe..beb84143 100644 --- a/app/src/main/assets/locale_key_texts/sl.txt +++ b/app/src/main/assets/locale_key_texts/sl.txt @@ -4,3 +4,6 @@ c č ć z ž ' ’ ‚ ‘ › ‹ " ” „ “ » « + +[tlds] +si diff --git a/app/src/main/assets/locale_key_texts/sr-Latn.txt b/app/src/main/assets/locale_key_texts/sr-Latn.txt index ecce81e4..7f0b254d 100644 --- a/app/src/main/assets/locale_key_texts/sr-Latn.txt +++ b/app/src/main/assets/locale_key_texts/sr-Latn.txt @@ -10,3 +10,6 @@ d đ 2: ć 3: đ 3: ž + +[tlds] +rs diff --git a/app/src/main/assets/locale_key_texts/sr.txt b/app/src/main/assets/locale_key_texts/sr.txt index 89e06672..039e1f48 100644 --- a/app/src/main/assets/locale_key_texts/sr.txt +++ b/app/src/main/assets/locale_key_texts/sr.txt @@ -6,3 +6,6 @@ [labels] alphabet: АБВ + +[tlds] +rs diff --git a/app/src/main/assets/locale_key_texts/sv.txt b/app/src/main/assets/locale_key_texts/sv.txt index 0425538d..233e02c3 100644 --- a/app/src/main/assets/locale_key_texts/sv.txt +++ b/app/src/main/assets/locale_key_texts/sv.txt @@ -8,3 +8,6 @@ o ö 1: å 2: ö 2: ä + +[tlds] +sv diff --git a/app/src/main/assets/locale_key_texts/tr.txt b/app/src/main/assets/locale_key_texts/tr.txt index a729bd4d..e2f1771b 100644 --- a/app/src/main/assets/locale_key_texts/tr.txt +++ b/app/src/main/assets/locale_key_texts/tr.txt @@ -7,3 +7,6 @@ u ü û s ş g ğ c ç + +[tlds] +tr gov.tr edu.tr com.tr diff --git a/app/src/main/assets/locale_key_texts/uk.txt b/app/src/main/assets/locale_key_texts/uk.txt index 851c7280..9ee926c9 100644 --- a/app/src/main/assets/locale_key_texts/uk.txt +++ b/app/src/main/assets/locale_key_texts/uk.txt @@ -7,3 +7,6 @@ [labels] alphabet: АБВ + +[tlds] +ua diff --git a/app/src/main/assets/locale_key_texts/vi.txt b/app/src/main/assets/locale_key_texts/vi.txt index 8f8fb9d7..83db93bb 100644 --- a/app/src/main/assets/locale_key_texts/vi.txt +++ b/app/src/main/assets/locale_key_texts/vi.txt @@ -6,3 +6,6 @@ o ò ó ỏ õ ọ ô ồ ố ổ ỗ ộ ơ ờ ớ ở ỡ ợ u ù ú ủ ũ ụ ư ừ ứ ử ữ ự y ỳ ý ỷ ỹ ỵ d đ + +[tlds] +vn diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt index bd7f8064..722fb822 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt @@ -43,6 +43,7 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) { "mns" -> Key.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO else -> 0 } + val tlds = getLocaleTlds(locale) // todo: USE IT init { readStream(dataStream, false, true) @@ -74,17 +75,25 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) { "[extra_keys]" -> { mode = READER_MODE_EXTRA_KEYS; return@forEachLine } "[labels]" -> { mode = READER_MODE_LABELS; return@forEachLine } "[number_row]" -> { mode = READER_MODE_NUMBER_ROW; return@forEachLine } + "[tlds]" -> { mode = READER_MODE_TLD; return@forEachLine } } when (mode) { READER_MODE_POPUP_KEYS -> addPopupKeys(line, priority) READER_MODE_EXTRA_KEYS -> if (!onlyPopupKeys) addExtraKey(line.split(colonSpaceRegex, 2)) READER_MODE_LABELS -> if (!onlyPopupKeys) addLabel(line.split(colonSpaceRegex, 2)) READER_MODE_NUMBER_ROW -> localizedNumberKeys = line.splitOnWhitespace() + READER_MODE_TLD -> line.splitOnWhitespace().forEach { tlds.add(".$it") } } } } } + fun addDefaultTlds(locale: Locale) { + if ((locale.language != "en" && euroLocales.matches(locale.language)) || euroCountries.matches(locale.country)) + tlds.add(".eu") + tlds.addAll(defaultTlds.splitOnWhitespace()) + } + /** Pair(extraKeysLeft, extraKeysRight) */ fun getTabletExtraKeys(elementId: Int): Pair, List> { val flags = Key.LABEL_FLAGS_FONT_DEFAULT @@ -192,6 +201,7 @@ private fun createLocaleKeyTexts(context: Context, params: KeyboardParams, popup if (locale == params.mId.locale) return@forEach lkt.addFile(getStreamForLocale(locale, context), true) } + lkt.addDefaultTlds(params.mId.locale) when (popupKeysSetting) { POPUP_KEYS_MAIN -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_main.txt"), false) POPUP_KEYS_MORE -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_more.txt"), false) @@ -212,6 +222,20 @@ private fun getStreamForLocale(locale: Locale, context: Context) = } } +private fun getLocaleTlds(locale: Locale): LinkedHashSet { + val ccLower = locale.country.lowercase() + val tlds = LinkedHashSet() + if (ccLower.isEmpty() || ccLower == "zz") + return tlds + specialCountryTlds.forEach { + if (ccLower != it.first) return@forEach + tlds.addAll(it.second.splitOnWhitespace()) + return tlds + } + tlds.add(".$ccLower") + return tlds +} + fun clearCache() = localeKeyboardInfosCache.clear() // cache the texts, so they don't need to be read over and over @@ -222,6 +246,7 @@ private const val READER_MODE_POPUP_KEYS = 1 private const val READER_MODE_EXTRA_KEYS = 2 private const val READER_MODE_LABELS = 3 private const val READER_MODE_NUMBER_ROW = 4 +private const val READER_MODE_TLD = 5 // probably could be improved and extended, currently this is what's done in key_styles_currency.xml private fun getCurrencyKey(locale: Locale): Pair> { @@ -294,3 +319,16 @@ const val POPUP_KEYS_MAIN = 3 const val POPUP_KEYS_NORMAL = 0 private const val LOCALE_TEXTS_FOLDER = "locale_key_texts" + +// either tld is not lowecase ISO 3166-1 code, or there are multiple according to some list +private val specialCountryTlds = listOf( + "bd" to ".bd .com.bd", + "bq" to ".bq .an .nl", + "bl" to ".bl .gp .fr", + "sx" to ".sx .an", + "gb" to ".uk .co.uk", + "eh" to ".eh .ma", + "mf" to ".mf .gp .fr", + "tl" to ".tl .tp", +) +private const val defaultTlds = ".com .gov .edu .org .net" From 05816e44368a43335ee023fc8426a90c5523980c Mon Sep 17 00:00:00 2001 From: zyachel Date: Wed, 22 Jan 2025 16:35:32 +0000 Subject: [PATCH 04/14] fix link to license file in about screen (#1315) --- app/src/main/res/xml/prefs_screen_about.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/xml/prefs_screen_about.xml b/app/src/main/res/xml/prefs_screen_about.xml index 9314227a..94430c96 100644 --- a/app/src/main/res/xml/prefs_screen_about.xml +++ b/app/src/main/res/xml/prefs_screen_about.xml @@ -24,7 +24,7 @@ android:summary="@string/gnu_gpl" android:icon="@drawable/ic_settings_about_license"> + android:data="https://github.com/Helium314/HeliBoard/blob/main/LICENSE" /> Date: Thu, 23 Jan 2025 00:54:09 +0100 Subject: [PATCH 05/14] fix typo, add short text to contributing about app size --- CONTRIBUTING.md | 3 ++- .../keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5e0fbaef..93ed9feb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ If you have difficulties implementing some functionality, you're welcome to ask # Guidelines HeliBoard is a complex application, when contributing, you must take a step back and make sure your contribution: -- **Is actually wanted**. Best check related open issues before you start working on a PR. Issues with [_PR_](https://github.com/Helium314/HeliBoard/labels/PR) and [_contributor needed_](https://github.com/Helium314/HeliBoard/issues?q=label%3A%22contributor%20needed%22) [labels](https://github.com/Helium314/HeliBoard/labels) are accepted, but still it would be good if you announced that you are working on it, so we can discuss how changes are best implemented. +- **Is actually wanted**. Best check related open issues before you start working on a PR. Issues with the [labels](https://github.com/Helium314/HeliBoard/labels) [_PR_](https://github.com/Helium314/HeliBoard/labels/PR) and [_contributor needed_](https://github.com/Helium314/HeliBoard/issues?q=label%3A%22contributor%20needed%22) (even closed ones) are accepted, but still it would be good if you announced that you are working on it, so we can discuss how changes are best implemented. If there is no accepted issue related to your intended contribution, it's a good idea to open a new one (and of course getting one of "PR" or "contributor needed" labels) to avoid disappointment of the contribution not being accepted. For small changes or fixing obvious bugs this step is not necessary. - **Is only about a single thing**. Mixing unrelated or semi-related contributions into a single PR is hard to review and can get messy. - **Is finished or a draft**. When you keep changing the PR without reviewer's feedback, any attempt to review it is doomed and a waste of time. Better mark it as a draft in this case. @@ -18,6 +18,7 @@ HeliBoard is a complex application, when contributing, you must take a step back - **Has a low footprint**. Some parts of the code are executed very frequently, and the keyboard should stay responsive even on older devices. - **Does not bring any non-free code or proprietary binary blobs**. This also applies to code/binaries with unknown licenses. Make sure you do not introduce any closed-source library from Google. If your contribution contains code that is not your own, provide a link to the source. +- **Does not increase app size too much**. Just code changes or adding icons is not in issue, but e.g. large dependencies or adding more default dictionaries will not be accepted. - **Complies with the user privacy principle HeliBoard follows**. A good description and small scope ("single thing") massively help with reviewing. Don't be surprised when your PR gets closes if you clearly / repeatedly violate these parts of the guidelines. diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt index 722fb822..70f696c9 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt @@ -320,7 +320,7 @@ const val POPUP_KEYS_NORMAL = 0 private const val LOCALE_TEXTS_FOLDER = "locale_key_texts" -// either tld is not lowecase ISO 3166-1 code, or there are multiple according to some list +// either tld is not simply lowercase ISO 3166-1 code, or there are multiple according to some list private val specialCountryTlds = listOf( "bd" to ".bd .com.bd", "bq" to ".bq .an .nl", From fc12877795e1079bf67257e7446098fcf730c712 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Thu, 23 Jan 2025 16:53:26 +0100 Subject: [PATCH 06/14] fix additional subtypes being removed when upgrading from 2.2 beta or older --- app/src/main/java/helium314/keyboard/latin/App.kt | 6 ++---- layouts.md | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/App.kt b/app/src/main/java/helium314/keyboard/latin/App.kt index 089f8ebc..c265bd78 100644 --- a/app/src/main/java/helium314/keyboard/latin/App.kt +++ b/app/src/main/java/helium314/keyboard/latin/App.kt @@ -111,19 +111,17 @@ fun checkVersionUpgrade(context: Context) { if (additionalSubtypeString.contains(".")) { // means there are custom layouts val subtypeStrings = additionalSubtypeString.split(";") val newSubtypeStrings = subtypeStrings.mapNotNull { + if ("." !in it) // not a custom subtype, nothing to do + return@mapNotNull it val split = it.split(":").toMutableList() - Log.i("test", "0: $it") if (split.size < 2) return@mapNotNull null // should never happen val oldName = split[1] val newName = oldName.substringBeforeLast(".") + "." if (oldName == newName) return@mapNotNull split.joinToString(":") // should never happen val oldFile = getCustomLayoutFile(oldName, context) val newFile = getCustomLayoutFile(newName, context) - Log.i("test", "1") if (!oldFile.exists()) return@mapNotNull null // should never happen - Log.i("test", "2") if (newFile.exists()) newFile.delete() // should never happen - Log.i("test", "3") oldFile.renameTo(newFile) val enabledSubtypes = prefs.getString(Settings.PREF_ENABLED_SUBTYPES, "")!! if (enabledSubtypes.contains(oldName)) diff --git a/layouts.md b/layouts.md index 58755e49..f5811941 100644 --- a/layouts.md +++ b/layouts.md @@ -37,7 +37,7 @@ If the layout has exactly 2 keys in the bottom row, these keys will replace comm * `shift_state_selector`: keys for `unshifted`, `shifted`, `shiftedManual`, `shiftedAutomatic`, `capsLock`, `manualOrLocked`, `default` (all optional) * `variation_selector`: keys for input types `datetime`, `time`, `date`, `password`, `normal`, `uri`, `email`, `default` (all optional) * `keyboard_state_selector`: keys for `emojiKeyEnabled`, `languageKeyEnabled`, `symbols`, `moreSymbols`, `alphabet`, `default` (all optional) - * the `keyEnabled` keys will be used if the corresponding setting is enabled, `symbols`, `moreSymbols`, `alphabet` will be used when the said keyboard view is active + * the `KeyEnabled` keys will be used if the corresponding setting is enabled, `symbols`, `moreSymbols`, `alphabet` will be used when the said keyboard view is active * `layout_direction_selector`: keys for `ltr` and `rtl` (both mandatory) ### Properties * A (non-selector) key can have the following properties: From f45f69f8a2639d91992bce6aa7c16a2d4b59f4c8 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 26 Jan 2025 09:10:07 +0100 Subject: [PATCH 07/14] add setting for adjusting bottom padding in landscape mode fixes some issue I can't currently find slight issue: will remove the bottom padding on large tables (sw768-land), users need to get it back by switching to 100% --- .../keyboard/latin/settings/AppearanceSettingsFragment.kt | 1 + .../java/helium314/keyboard/latin/settings/Settings.java | 7 +++++++ .../helium314/keyboard/latin/settings/SettingsValues.java | 2 +- app/src/main/res/values-land/config.xml | 2 +- app/src/main/res/values-sw600dp-land/config.xml | 2 +- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/prefs_screen_appearance.xml | 7 +++++++ 7 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/settings/AppearanceSettingsFragment.kt b/app/src/main/java/helium314/keyboard/latin/settings/AppearanceSettingsFragment.kt index 93d3b0f5..fa9614f3 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/AppearanceSettingsFragment.kt +++ b/app/src/main/java/helium314/keyboard/latin/settings/AppearanceSettingsFragment.kt @@ -105,6 +105,7 @@ class AppearanceSettingsFragment : SubScreenFragment() { setupScalePrefs(Settings.PREF_KEYBOARD_HEIGHT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE) setupScalePrefs(Settings.PREF_BOTTOM_PADDING_SCALE, SettingsValues.DEFAULT_SIZE_SCALE) + setupScalePrefs(Settings.PREF_BOTTOM_PADDING_SCALE_LANDSCAPE, 0f) if (splitScalePref != null) { setupScalePrefs(Settings.PREF_SPLIT_SPACER_SCALE, SettingsValues.DEFAULT_SIZE_SCALE) splitScalePref?.isVisible = splitPref?.isChecked == true diff --git a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java index 446a3f0c..8f67ddc1 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java @@ -112,6 +112,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_SPLIT_SPACER_SCALE = "split_spacer_scale"; public static final String PREF_KEYBOARD_HEIGHT_SCALE = "keyboard_height_scale"; public static final String PREF_BOTTOM_PADDING_SCALE = "bottom_padding_scale"; + public static final String PREF_BOTTOM_PADDING_SCALE_LANDSCAPE = "bottom_padding_scale_landscape"; public static final String PREF_SPACE_HORIZONTAL_SWIPE = "horizontal_space_swipe"; public static final String PREF_SPACE_VERTICAL_SWIPE = "vertical_space_swipe"; public static final String PREF_DELETE_SWIPE = "delete_swipe"; @@ -499,6 +500,12 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang (getCurrent().mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), gravity).apply(); } + public static float readBottomPaddingScale(final SharedPreferences prefs, final boolean landscape) { + if (landscape) + return prefs.getFloat(PREF_BOTTOM_PADDING_SCALE_LANDSCAPE, 0f); + return prefs.getFloat(PREF_BOTTOM_PADDING_SCALE, SettingsValues.DEFAULT_SIZE_SCALE); + } + public static boolean readHasHardwareKeyboard(final Configuration conf) { // The standard way of finding out whether we have a hardware keyboard. This code is taken // from InputMethodService#onEvaluateInputShown, which canonically determines this. diff --git a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java index eae7b375..0a312633 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java @@ -262,7 +262,7 @@ public class SettingsValues { prefs.getBoolean(Settings.PREF_GESTURE_SPACE_AWARE, false) ); mSpacingAndPunctuations = new SpacingAndPunctuations(res, mUrlDetectionEnabled); - mBottomPaddingScale = prefs.getFloat(Settings.PREF_BOTTOM_PADDING_SCALE, DEFAULT_SIZE_SCALE); + mBottomPaddingScale = Settings.readBottomPaddingScale(prefs, mDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE); mLongPressSymbolsForNumpad = prefs.getBoolean(Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, false); mAutoShowToolbar = prefs.getBoolean(Settings.PREF_AUTO_SHOW_TOOLBAR, false); mAutoHideToolbar = readSuggestionsEnabled(prefs) && prefs.getBoolean(Settings.PREF_AUTO_HIDE_TOOLBAR, false); diff --git a/app/src/main/res/values-land/config.xml b/app/src/main/res/values-land/config.xml index cde49ee1..e1d90984 100644 --- a/app/src/main/res/values-land/config.xml +++ b/app/src/main/res/values-land/config.xml @@ -21,7 +21,7 @@ 53.76dp 2.727%p - 0.0%p + 2.5%p 5.368%p 1.020%p 4.85%p diff --git a/app/src/main/res/values-sw600dp-land/config.xml b/app/src/main/res/values-sw600dp-land/config.xml index 9d00149e..448b73c0 100644 --- a/app/src/main/res/values-sw600dp-land/config.xml +++ b/app/src/main/res/values-sw600dp-land/config.xml @@ -15,7 +15,7 @@ 81.9dp 2.727%p - 0.0%p + 2.0%p 4.5%p 0.9%p 4.5%p diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 322cadd7..a5c94bdf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -311,6 +311,8 @@ Keyboard height scale Bottom padding scale + + Bottom padding scale (landscape) Custom text on space bar diff --git a/app/src/main/res/xml/prefs_screen_appearance.xml b/app/src/main/res/xml/prefs_screen_appearance.xml index e02f3702..1590619c 100644 --- a/app/src/main/res/xml/prefs_screen_appearance.xml +++ b/app/src/main/res/xml/prefs_screen_appearance.xml @@ -111,6 +111,13 @@ latin:minValue="0" latin:maxValue="500" /> + + Date: Sun, 26 Jan 2025 09:27:48 +0100 Subject: [PATCH 08/14] add font scale setting (separat for emoji view, because here it feels different) fixes #1149 --- .../helium314/keyboard/keyboard/KeyboardView.java | 10 +++++++--- .../keyboard/keyboard/MainKeyboardView.java | 3 ++- .../keyboard/keyboard/internal/KeyPreviewView.java | 4 ++-- .../latin/settings/AppearanceSettingsFragment.kt | 2 ++ .../helium314/keyboard/latin/settings/Settings.java | 2 ++ .../keyboard/latin/settings/SettingsValues.java | 4 ++++ app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/xml/prefs_screen_appearance.xml | 12 ++++++++++++ 8 files changed, 35 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java index 5e39d166..d374dac6 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java @@ -65,6 +65,7 @@ public class KeyboardView extends View { private static final float KET_TEXT_SHADOW_RADIUS_DISABLED = -1.0f; private final Colors mColors; private float mKeyScaleForText; + protected float mFontSizeMultiplier; // The maximum key label width in the proportion to the key width. private static final float MAX_LABEL_RATIO = 0.90f; @@ -189,6 +190,9 @@ public class KeyboardView extends View { mKeyDrawParams.updateParams(scaledKeyHeight, keyboard.mKeyVisualAttributes); invalidateAllKeys(); requestLayout(); + mFontSizeMultiplier = mKeyboard.mId.isEmojiKeyboard() + ? Settings.getInstance().getCurrent().mFontSizeMultiplierEmoji + : Settings.getInstance().getCurrent().mFontSizeMultiplier; } /** @@ -384,7 +388,7 @@ public class KeyboardView extends View { final String label = key.getLabel(); if (label != null) { paint.setTypeface(mTypeface == null ? key.selectTypeface(params) : mTypeface); - paint.setTextSize(key.selectTextSize(params)); + paint.setTextSize(key.selectTextSize(params) * mFontSizeMultiplier); final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint); final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint); @@ -446,7 +450,7 @@ public class KeyboardView extends View { // Draw hint label. final String hintLabel = key.getHintLabel(); if (hintLabel != null && mShowsHints) { - paint.setTextSize(key.selectHintTextSize(params)); + paint.setTextSize(key.selectHintTextSize(params) * mFontSizeMultiplier); // maybe take sqrt to not have such extreme changes? paint.setColor(key.selectHintTextColor(params)); // TODO: Should add a way to specify type face for hint letters paint.setTypeface(Typeface.DEFAULT_BOLD); @@ -561,7 +565,7 @@ public class KeyboardView extends View { } else { paint.setColor(key.selectTextColor(mKeyDrawParams)); paint.setTypeface(key.selectTypeface(mKeyDrawParams)); - paint.setTextSize(key.selectTextSize(mKeyDrawParams)); + paint.setTextSize(key.selectTextSize(mKeyDrawParams) * mFontSizeMultiplier); } return paint; } diff --git a/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java index c004822b..fddc64d5 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java @@ -164,7 +164,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy mBackgroundDimAlphaPaint.setColor(Color.BLACK); mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha); mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction( - R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f); + R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f) + * Settings.getInstance().getCurrent().mFontSizeMultiplier; final Colors colors = Settings.getInstance().getCurrent().mColors; mLanguageOnSpacebarTextColor = colors.get(ColorType.SPACE_BAR_TEXT); mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat( diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyPreviewView.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyPreviewView.java index f1d75986..94ad2cc5 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyPreviewView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyPreviewView.java @@ -57,8 +57,8 @@ public class KeyPreviewView extends AppCompatTextView { setCompoundDrawables(null, null, null, null); setTextColor(drawParams.mPreviewTextColor); - setTextSize(TypedValue.COMPLEX_UNIT_PX, key.selectPreviewTextSize(drawParams)); - // wie hier machen? + setTextSize(TypedValue.COMPLEX_UNIT_PX, key.selectPreviewTextSize(drawParams) + * Settings.getInstance().getCurrent().mFontSizeMultiplier); setTypeface(mTypeface == null ? key.selectPreviewTypeface(drawParams) : mTypeface); // TODO Should take care of temporaryShiftLabel here. setTextAndScaleX(key.getPreviewLabel()); diff --git a/app/src/main/java/helium314/keyboard/latin/settings/AppearanceSettingsFragment.kt b/app/src/main/java/helium314/keyboard/latin/settings/AppearanceSettingsFragment.kt index fa9614f3..aa990648 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/AppearanceSettingsFragment.kt +++ b/app/src/main/java/helium314/keyboard/latin/settings/AppearanceSettingsFragment.kt @@ -106,6 +106,8 @@ class AppearanceSettingsFragment : SubScreenFragment() { setupScalePrefs(Settings.PREF_KEYBOARD_HEIGHT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE) setupScalePrefs(Settings.PREF_BOTTOM_PADDING_SCALE, SettingsValues.DEFAULT_SIZE_SCALE) setupScalePrefs(Settings.PREF_BOTTOM_PADDING_SCALE_LANDSCAPE, 0f) + setupScalePrefs(Settings.PREF_FONT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE) + setupScalePrefs(Settings.PREF_EMOJI_FONT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE) if (splitScalePref != null) { setupScalePrefs(Settings.PREF_SPLIT_SPACER_SCALE, SettingsValues.DEFAULT_SIZE_SCALE) splitScalePref?.isVisible = splitPref?.isChecked == true diff --git a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java index 8f67ddc1..0db33ad1 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java @@ -113,6 +113,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_KEYBOARD_HEIGHT_SCALE = "keyboard_height_scale"; public static final String PREF_BOTTOM_PADDING_SCALE = "bottom_padding_scale"; public static final String PREF_BOTTOM_PADDING_SCALE_LANDSCAPE = "bottom_padding_scale_landscape"; + public static final String PREF_FONT_SCALE = "font_scale"; + public static final String PREF_EMOJI_FONT_SCALE = "emoji_font_scale"; public static final String PREF_SPACE_HORIZONTAL_SWIPE = "horizontal_space_swipe"; public static final String PREF_SPACE_VERTICAL_SWIPE = "vertical_space_swipe"; public static final String PREF_DELETE_SWIPE = "delete_swipe"; diff --git a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java index 0a312633..c8976165 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java @@ -120,6 +120,8 @@ public class SettingsValues { public final boolean mAlphaAfterSymbolAndSpace; public final boolean mRemoveRedundantPopups; public final String mSpaceBarText; + public final float mFontSizeMultiplier; + public final float mFontSizeMultiplierEmoji; // From the input box @NonNull @@ -273,6 +275,8 @@ public class SettingsValues { mRemoveRedundantPopups = prefs.getBoolean(Settings.PREF_REMOVE_REDUNDANT_POPUPS, false); mSpaceBarText = prefs.getString(Settings.PREF_SPACE_BAR_TEXT, ""); mEmojiMaxSdk = prefs.getInt(Settings.PREF_EMOJI_MAX_SDK, Build.VERSION.SDK_INT); + mFontSizeMultiplier = prefs.getFloat(Settings.PREF_FONT_SCALE, DEFAULT_SIZE_SCALE); + mFontSizeMultiplierEmoji = prefs.getFloat(Settings.PREF_EMOJI_FONT_SCALE, DEFAULT_SIZE_SCALE); } public boolean isApplicationSpecifiedCompletionsOn() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a5c94bdf..43b0a351 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -313,6 +313,10 @@ Bottom padding scale Bottom padding scale (landscape) + + Keyboard font scale + + Emoji view font scale Custom text on space bar diff --git a/app/src/main/res/xml/prefs_screen_appearance.xml b/app/src/main/res/xml/prefs_screen_appearance.xml index 1590619c..d30b97ae 100644 --- a/app/src/main/res/xml/prefs_screen_appearance.xml +++ b/app/src/main/res/xml/prefs_screen_appearance.xml @@ -130,6 +130,18 @@ android:defaultValue="" android:persistent="true" /> + + + + From 5afb1e3a0c0aa4d9b4d3f915df8f1f6a2417c1a7 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 26 Jan 2025 09:31:32 +0100 Subject: [PATCH 09/14] use custom font also for hint labels, fixes #1323 --- app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java index d374dac6..ffcb9e2d 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java @@ -453,7 +453,7 @@ public class KeyboardView extends View { paint.setTextSize(key.selectHintTextSize(params) * mFontSizeMultiplier); // maybe take sqrt to not have such extreme changes? paint.setColor(key.selectHintTextColor(params)); // TODO: Should add a way to specify type face for hint letters - paint.setTypeface(Typeface.DEFAULT_BOLD); + paint.setTypeface(mTypeface == null ? Typeface.DEFAULT_BOLD : mTypeface); blendAlpha(paint, params.mAnimAlpha); final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint); final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint); From 419c0d847b4ce6943cace7150c4db3b7f54eaa34 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 26 Jan 2025 09:48:21 +0100 Subject: [PATCH 10/14] switch from start / stop one-handed mode key codes to a toggle code mainly so there is no awkward state-dependent key code on the toolbar key --- .../keyboard/keyboard/internal/KeyboardCodesSet.java | 10 ++++++---- .../keyboard/keyboard/internal/KeyboardState.java | 6 ++---- .../internal/keyboard_parser/floris/KeyCode.kt | 7 ++++--- .../internal/keyboard_parser/floris/TextKeyData.kt | 2 +- .../helium314/keyboard/latin/KeyboardWrapperView.kt | 5 ++--- .../helium314/keyboard/latin/common/Constants.java | 3 +-- .../keyboard/latin/inputlogic/InputLogic.java | 2 +- .../helium314/keyboard/latin/utils/ToolbarUtils.kt | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardCodesSet.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardCodesSet.java index 7c21f154..7671784e 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardCodesSet.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardCodesSet.java @@ -52,8 +52,9 @@ public final class KeyboardCodesSet { "key_emoji", "key_unspecified", "key_clipboard", - "key_start_onehanded", - "key_stop_onehanded", + "key_toggle_onehanded", + "key_start_onehanded", // keep name to avoid breaking custom layouts + "key_stop_onehanded", // keep name to avoid breaking custom layouts "key_switch_onehanded" }; @@ -77,8 +78,9 @@ public final class KeyboardCodesSet { KeyCode.EMOJI, KeyCode.NOT_SPECIFIED, KeyCode.CLIPBOARD, - KeyCode.START_ONE_HANDED_MODE, - KeyCode.STOP_ONE_HANDED_MODE, + KeyCode.TOGGLE_ONE_HANDED_MODE, + KeyCode.TOGGLE_ONE_HANDED_MODE, + KeyCode.TOGGLE_ONE_HANDED_MODE, KeyCode.SWITCH_ONE_HANDED_MODE }; diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java index 6eae4b15..ded17bdc 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java @@ -808,10 +808,8 @@ public final class KeyboardState { toggleNumpad(false, autoCapsFlags, recapitalizeMode, false, true); } else if (code == KeyCode.SYMBOL) { setSymbolsKeyboard(); - } else if (code == KeyCode.START_ONE_HANDED_MODE) { - setOneHandedModeEnabled(true); - } else if (code == KeyCode.STOP_ONE_HANDED_MODE) { - setOneHandedModeEnabled(false); + } else if (code == KeyCode.TOGGLE_ONE_HANDED_MODE) { + setOneHandedModeEnabled(!Settings.getInstance().getCurrent().mOneHandedModeEnabled); } else if (code == KeyCode.SWITCH_ONE_HANDED_MODE) { switchOneHandedMode(); } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyCode.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyCode.kt index 8f39a39c..55250513 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyCode.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyCode.kt @@ -125,8 +125,8 @@ object KeyCode { // heliboard only codes const val SYMBOL_ALPHA = -10001 - const val START_ONE_HANDED_MODE = -10002 - const val STOP_ONE_HANDED_MODE = -10003 + const val TOGGLE_ONE_HANDED_MODE = -10002 + const val TOGGLE_ONE_HANDED_MODE_2 = -10003 // does the same as TOGGLE_ONE_HANDED_MODE (used to be start & stop) const val SWITCH_ONE_HANDED_MODE = -10004 const val SHIFT_ENTER = -10005 const val ACTION_NEXT = -10006 @@ -179,7 +179,7 @@ object KeyCode { FN, CLIPBOARD_CLEAR_HISTORY, NUMPAD, // heliboard only - SYMBOL_ALPHA, START_ONE_HANDED_MODE, STOP_ONE_HANDED_MODE, SWITCH_ONE_HANDED_MODE, SHIFT_ENTER, + SYMBOL_ALPHA, TOGGLE_ONE_HANDED_MODE, SWITCH_ONE_HANDED_MODE, SHIFT_ENTER, ACTION_NEXT, ACTION_PREVIOUS, NOT_SPECIFIED, CLIPBOARD_COPY_ALL, WORD_LEFT, WORD_RIGHT, PAGE_UP, PAGE_DOWN, META, TAB, ESCAPE, INSERT, SLEEP, MEDIA_PLAY, MEDIA_PAUSE, MEDIA_PLAY_PAUSE, MEDIA_NEXT, MEDIA_PREVIOUS, VOL_UP, VOL_DOWN, MUTE, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, BACK @@ -189,6 +189,7 @@ object KeyCode { IME_UI_MODE_TEXT -> ALPHA VIEW_PHONE -> ALPHA // phone keyboard is treated like alphabet, just with different layout VIEW_PHONE2 -> SYMBOL + TOGGLE_ONE_HANDED_MODE_2 -> TOGGLE_ONE_HANDED_MODE else -> throw IllegalStateException("key code $this not yet supported") } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt index b26d3a08..d22cf4c2 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt @@ -127,7 +127,7 @@ sealed interface KeyData : AbstractKeyData { if (!params.mId.mLanguageSwitchKeyEnabled && !params.mId.isNumberLayout && RichInputMethodManager.canSwitchLanguage()) keys.add("!icon/language_switch_key|!code/key_language_switch") if (!params.mId.mOneHandedModeEnabled) - keys.add("!icon/start_onehanded_mode_key|!code/key_start_onehanded") + keys.add("!icon/start_onehanded_mode_key|!code/key_toggle_onehanded") if (!params.mId.mDeviceLocked) keys.add("!icon/settings_key|!code/key_settings") return keys diff --git a/app/src/main/java/helium314/keyboard/latin/KeyboardWrapperView.kt b/app/src/main/java/helium314/keyboard/latin/KeyboardWrapperView.kt index 8393e21e..1ffbfadf 100644 --- a/app/src/main/java/helium314/keyboard/latin/KeyboardWrapperView.kt +++ b/app/src/main/java/helium314/keyboard/latin/KeyboardWrapperView.kt @@ -84,8 +84,7 @@ class KeyboardWrapperView @JvmOverloads constructor( if (newScale == oldScale) return@setOnTouchListener true Settings.getInstance().writeOneHandedModeScale(newScale) oneHandedModeEnabled = false // intentionally putting wrong value, so KeyboardSwitcher.setOneHandedModeEnabled does actually reload - keyboardActionListener?.onCodeInput(KeyCode.START_ONE_HANDED_MODE, - Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false) + KeyboardSwitcher.getInstance().setOneHandedModeEnabled(true) } else -> x = 0f } @@ -119,7 +118,7 @@ class KeyboardWrapperView @JvmOverloads constructor( override fun onClick(view: View) { if (view === stopOneHandedModeBtn) { - keyboardActionListener?.onCodeInput(KeyCode.STOP_ONE_HANDED_MODE, + keyboardActionListener?.onCodeInput(KeyCode.TOGGLE_ONE_HANDED_MODE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false /* isKeyRepeat */) } else if (view === switchOneHandedModeBtn) { diff --git a/app/src/main/java/helium314/keyboard/latin/common/Constants.java b/app/src/main/java/helium314/keyboard/latin/common/Constants.java index 07685cd1..ff8ef330 100644 --- a/app/src/main/java/helium314/keyboard/latin/common/Constants.java +++ b/app/src/main/java/helium314/keyboard/latin/common/Constants.java @@ -224,8 +224,7 @@ public final class Constants { case CODE_TAB: return "tab"; case CODE_ENTER: return "enter"; case CODE_SPACE: return "space"; - case KeyCode.START_ONE_HANDED_MODE: return "startOneHandedMode"; - case KeyCode.STOP_ONE_HANDED_MODE: return "stopOneHandedMode"; + case KeyCode.TOGGLE_ONE_HANDED_MODE: return "toggleOneHandedMode"; case KeyCode.SWITCH_ONE_HANDED_MODE: return "switchOneHandedMode"; case KeyCode.NUMPAD: return "numpad"; default: diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java index d3239187..ff782ebd 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -779,7 +779,7 @@ public final class InputLogic { // We need to switch to the shortcut IME. This is handled by LatinIME since the // input logic has no business with IME switching. case KeyCode.CAPS_LOCK, KeyCode.SYMBOL_ALPHA, KeyCode.ALPHA, KeyCode.SYMBOL, KeyCode.NUMPAD, KeyCode.EMOJI, - KeyCode.START_ONE_HANDED_MODE, KeyCode.STOP_ONE_HANDED_MODE, KeyCode.SWITCH_ONE_HANDED_MODE, + KeyCode.TOGGLE_ONE_HANDED_MODE, KeyCode.SWITCH_ONE_HANDED_MODE, KeyCode.CTRL, KeyCode.ALT, KeyCode.FN, KeyCode.META: break; default: diff --git a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt index 6cb94ff7..ee4126e8 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt @@ -60,7 +60,7 @@ fun getCodeForToolbarKey(key: ToolbarKey) = Settings.getInstance().getCustomTool COPY -> KeyCode.CLIPBOARD_COPY CUT -> KeyCode.CLIPBOARD_CUT PASTE -> KeyCode.CLIPBOARD_PASTE - ONE_HANDED -> if (Settings.getInstance().current.mOneHandedModeEnabled) KeyCode.STOP_ONE_HANDED_MODE else KeyCode.START_ONE_HANDED_MODE + ONE_HANDED -> KeyCode.TOGGLE_ONE_HANDED_MODE INCOGNITO -> KeyCode.TOGGLE_INCOGNITO_MODE AUTOCORRECT -> KeyCode.TOGGLE_AUTOCORRECT CLEAR_CLIPBOARD -> KeyCode.CLIPBOARD_CLEAR_HISTORY From 54f222c0ee7d46b47519896392b704229f83f137 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 26 Jan 2025 11:25:50 +0100 Subject: [PATCH 11/14] fix weird issue with toolbar keys having wrong color for their state and remove related semi-workaround --- .../keyboard/keyboard/clipboard/ClipboardHistoryView.kt | 7 +++---- .../main/java/helium314/keyboard/latin/common/Colors.kt | 6 +++--- .../java/helium314/keyboard/latin/utils/ToolbarUtils.kt | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt index 188ed3c5..98c70f61 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt @@ -65,10 +65,6 @@ class ClipboardHistoryView @JvmOverloads constructor( keyBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_keyBackground, 0) keyboardViewAttr.recycle() val keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle, R.style.SuggestionStripView) - // todo (maybe): setting the correct color only works because the activated state is inverted - // even when state is activated, the not activated color is set - // in suggestionStripView the same thing works correctly, wtf? - // need to properly fix it (and maybe undo the inverted isActivated) when adding a toggle key getEnabledClipboardToolbarKeys(DeviceProtectedUtils.getSharedPreferences(context)) .forEach { toolbarKeys.add(createToolbarKey(context, KeyboardIconsSet.instance, it)) } keyboardAttr.recycle() @@ -169,6 +165,9 @@ class ClipboardHistoryView @JvmOverloads constructor( adapter = clipboardAdapter layoutParams.width = ResourceUtils.getKeyboardWidth(context, Settings.getInstance().current) } + + // absurd workaround so Android sets the correct color from stateList (depending on "activated") + toolbarKeys.forEach { it.isEnabled = false; it.isEnabled = true } } fun stopClipboardHistory() { diff --git a/app/src/main/java/helium314/keyboard/latin/common/Colors.kt b/app/src/main/java/helium314/keyboard/latin/common/Colors.kt index 6876823c..154cff3c 100644 --- a/app/src/main/java/helium314/keyboard/latin/common/Colors.kt +++ b/app/src/main/java/helium314/keyboard/latin/common/Colors.kt @@ -626,9 +626,9 @@ private fun stateList(pressed: Int, normal: Int): ColorStateList { return ColorStateList(states, intArrayOf(pressed, normal)) } -private fun activatedStateList(normal: Int, activated: Int): ColorStateList { - val states = arrayOf(intArrayOf(-android.R.attr.state_activated), intArrayOf(android.R.attr.state_activated)) - return ColorStateList(states, intArrayOf(normal, activated)) +private fun activatedStateList(activated: Int, normal: Int): ColorStateList { + val states = arrayOf(intArrayOf(android.R.attr.state_activated), intArrayOf(-android.R.attr.state_activated)) + return ColorStateList(states, intArrayOf(activated, normal)) } enum class ColorType { diff --git a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt index ee4126e8..76626534 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt @@ -26,7 +26,6 @@ import helium314.keyboard.latin.R import helium314.keyboard.latin.databinding.ReorderDialogItemBinding import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.utils.ToolbarKey.* -import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import java.util.EnumMap import java.util.Locale @@ -38,7 +37,7 @@ fun createToolbarKey(context: Context, iconsSet: KeyboardIconsSet, key: ToolbarK val contentDescriptionId = context.resources.getIdentifier(key.name.lowercase(), "string", context.packageName) if (contentDescriptionId != 0) button.contentDescription = context.getString(contentDescriptionId) - button.isActivated = !when (key) { + button.isActivated = when (key) { INCOGNITO -> Settings.readAlwaysIncognitoMode(DeviceProtectedUtils.getSharedPreferences(context)) ONE_HANDED -> Settings.getInstance().current.mOneHandedModeEnabled AUTOCORRECT -> Settings.getInstance().current.mAutoCorrectionEnabledPerUserSettings From 833aa321b9ac5de4324b3355e576a225d42bc866 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 26 Jan 2025 11:27:40 +0100 Subject: [PATCH 12/14] rename stateList to pressedStateList for clarification --- .../helium314/keyboard/latin/common/Colors.kt | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/common/Colors.kt b/app/src/main/java/helium314/keyboard/latin/common/Colors.kt index 154cff3c..e5bf3d66 100644 --- a/app/src/main/java/helium314/keyboard/latin/common/Colors.kt +++ b/app/src/main/java/helium314/keyboard/latin/common/Colors.kt @@ -195,12 +195,12 @@ class DynamicColors(context: Context, override val themeStyle: String, override } adjustedBackgroundStateList = if (themeStyle == STYLE_HOLO) { - stateList(accent, adjustedBackground) + pressedStateList(accent, adjustedBackground) } else if (isNight) { - if (hasKeyBorders) stateList(doubleAdjustedAccent, keyBackground) - else stateList(adjustedAccent, adjustedKeyBackground) + if (hasKeyBorders) pressedStateList(doubleAdjustedAccent, keyBackground) + else pressedStateList(adjustedAccent, adjustedKeyBackground) } else { - stateList(accent, Color.WHITE) + pressedStateList(accent, Color.WHITE) } val stripBackground = if (keyboardBackground == null && !hasKeyBorders) { @@ -210,7 +210,7 @@ class DynamicColors(context: Context, override val themeStyle: String, override } val pressedStripElementBackground = if (keyboardBackground == null) adjustedBackground else if (isDarkColor(background)) 0x22ffffff else 0x11000000 - stripBackgroundList = stateList(pressedStripElementBackground, stripBackground) + stripBackgroundList = pressedStateList(pressedStripElementBackground, stripBackground) adjustedBackgroundFilter = if (themeStyle == STYLE_HOLO) colorFilter(adjustedBackground) @@ -218,47 +218,47 @@ class DynamicColors(context: Context, override val themeStyle: String, override if (hasKeyBorders) { backgroundStateList = - if (!isNight) stateList(adjustedFunctionalKey, background) - else stateList(adjustedKeyBackground, background) + if (!isNight) pressedStateList(adjustedFunctionalKey, background) + else pressedStateList(adjustedKeyBackground, background) keyStateList = - if (!isNight) stateList(adjustedBackground, keyBackground) - else stateList(adjustedKeyBackground, keyBackground) + if (!isNight) pressedStateList(adjustedBackground, keyBackground) + else pressedStateList(adjustedKeyBackground, keyBackground) functionalKeyStateList = - if (!isNight) stateList(doubleAdjustedFunctionalKey, functionalKey) - else stateList(functionalKey, doubleAdjustedKeyBackground) + if (!isNight) pressedStateList(doubleAdjustedFunctionalKey, functionalKey) + else pressedStateList(functionalKey, doubleAdjustedKeyBackground) actionKeyStateList = - if (!isNight) stateList(gesture, accent) - else stateList(doubleAdjustedAccent, accent) + if (!isNight) pressedStateList(gesture, accent) + else pressedStateList(doubleAdjustedAccent, accent) spaceBarStateList = - if (themeStyle == STYLE_HOLO) stateList(spaceBar, spaceBar) + if (themeStyle == STYLE_HOLO) pressedStateList(spaceBar, spaceBar) else keyStateList } else { // need to set color to background if key borders are disabled, or there will be ugly keys backgroundStateList = - if (!isNight) stateList(adjustedFunctionalKey, background) - else stateList(adjustedKeyBackground, background) + if (!isNight) pressedStateList(adjustedFunctionalKey, background) + else pressedStateList(adjustedKeyBackground, background) keyStateList = - if (!isNight) stateList(adjustedFunctionalKey, Color.TRANSPARENT) - else stateList(functionalKey, Color.TRANSPARENT) + if (!isNight) pressedStateList(adjustedFunctionalKey, Color.TRANSPARENT) + else pressedStateList(functionalKey, Color.TRANSPARENT) functionalKeyStateList = - if (themeStyle == STYLE_HOLO) stateList(functionalKey, Color.TRANSPARENT) + if (themeStyle == STYLE_HOLO) pressedStateList(functionalKey, Color.TRANSPARENT) else keyStateList actionKeyStateList = - if (themeStyle == STYLE_HOLO) stateList(accent, Color.TRANSPARENT) - else if (!isNight) stateList(gesture, accent) - else stateList(doubleAdjustedAccent, accent) + if (themeStyle == STYLE_HOLO) pressedStateList(accent, Color.TRANSPARENT) + else if (!isNight) pressedStateList(gesture, accent) + else pressedStateList(doubleAdjustedAccent, accent) spaceBarStateList = - if (!isNight) stateList(gesture, adjustedFunctionalKey) - else stateList(adjustedKeyBackground, spaceBar) + if (!isNight) pressedStateList(gesture, adjustedFunctionalKey) + else pressedStateList(adjustedKeyBackground, spaceBar) } keyTextFilter = colorFilter(keyText) @@ -409,7 +409,7 @@ class DefaultColors ( adjustedBackground = darken(background) doubleAdjustedBackground = darken(adjustedBackground) } - adjustedBackgroundStateList = stateList(doubleAdjustedBackground, adjustedBackground) + adjustedBackgroundStateList = pressedStateList(doubleAdjustedBackground, adjustedBackground) val stripBackground: Int val pressedStripElementBackground: Int @@ -424,7 +424,7 @@ class DefaultColors ( stripBackground = adjustedBackground pressedStripElementBackground = doubleAdjustedBackground } - stripBackgroundList = stateList(pressedStripElementBackground, stripBackground) + stripBackgroundList = pressedStateList(pressedStripElementBackground, stripBackground) if (themeStyle == STYLE_HOLO && keyboardBackground == null) { val darkerBackground = adjustLuminosityAndKeepAlpha(background, -0.2f) @@ -437,22 +437,22 @@ class DefaultColors ( adjustedBackgroundFilter = colorFilter(adjustedBackground) if (hasKeyBorders) { - backgroundStateList = stateList(brightenOrDarken(background, true), background) - keyStateList = if (themeStyle == STYLE_HOLO) stateList(keyBackground, keyBackground) - else stateList(brightenOrDarken(keyBackground, true), keyBackground) - functionalKeyStateList = stateList(brightenOrDarken(functionalKey, true), functionalKey) + backgroundStateList = pressedStateList(brightenOrDarken(background, true), background) + keyStateList = if (themeStyle == STYLE_HOLO) pressedStateList(keyBackground, keyBackground) + else pressedStateList(brightenOrDarken(keyBackground, true), keyBackground) + functionalKeyStateList = pressedStateList(brightenOrDarken(functionalKey, true), functionalKey) actionKeyStateList = if (themeStyle == STYLE_HOLO) functionalKeyStateList - else stateList(brightenOrDarken(accent, true), accent) - spaceBarStateList = if (themeStyle == STYLE_HOLO) stateList(spaceBar, spaceBar) - else stateList(brightenOrDarken(spaceBar, true), spaceBar) + else pressedStateList(brightenOrDarken(accent, true), accent) + spaceBarStateList = if (themeStyle == STYLE_HOLO) pressedStateList(spaceBar, spaceBar) + else pressedStateList(brightenOrDarken(spaceBar, true), spaceBar) } else { // need to set color to background if key borders are disabled, or there will be ugly keys - backgroundStateList = stateList(brightenOrDarken(background, true), background) - keyStateList = stateList(keyBackground, Color.TRANSPARENT) + backgroundStateList = pressedStateList(brightenOrDarken(background, true), background) + keyStateList = pressedStateList(keyBackground, Color.TRANSPARENT) functionalKeyStateList = keyStateList actionKeyStateList = if (themeStyle == STYLE_HOLO) functionalKeyStateList - else stateList(brightenOrDarken(accent, true), accent) - spaceBarStateList = stateList(brightenOrDarken(spaceBar, true), spaceBar) + else pressedStateList(brightenOrDarken(accent, true), accent) + spaceBarStateList = pressedStateList(brightenOrDarken(spaceBar, true), spaceBar) } keyTextFilter = colorFilter(keyText) actionKeyIconColorFilter = when { @@ -556,7 +556,7 @@ class AllColors(private val colorMap: EnumMap, override val them override fun get(color: ColorType): Int = colorMap[color] ?: color.default() override fun setColor(drawable: Drawable, color: ColorType) { - val colorStateList = stateListMap.getOrPut(color) { stateList(brightenOrDarken(get(color), true), get(color)) } + val colorStateList = stateListMap.getOrPut(color) { pressedStateList(brightenOrDarken(get(color), true), get(color)) } DrawableCompat.setTintMode(drawable, PorterDuff.Mode.MULTIPLY) DrawableCompat.setTintList(drawable, colorStateList) } @@ -621,7 +621,7 @@ private fun colorFilter(color: Int, mode: BlendModeCompat = BlendModeCompat.MODU return BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, mode)!! } -private fun stateList(pressed: Int, normal: Int): ColorStateList { +private fun pressedStateList(pressed: Int, normal: Int): ColorStateList { val states = arrayOf(intArrayOf(android.R.attr.state_pressed), intArrayOf(-android.R.attr.state_pressed)) return ColorStateList(states, intArrayOf(pressed, normal)) } From 79c9a85082dc2e3a2e881b7ab31377bd560a29f3 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 26 Jan 2025 11:36:17 +0100 Subject: [PATCH 13/14] better choice of color for deactivated toolbar key --- .../java/helium314/keyboard/latin/common/Colors.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/common/Colors.kt b/app/src/main/java/helium314/keyboard/latin/common/Colors.kt index e5bf3d66..b9790e4a 100644 --- a/app/src/main/java/helium314/keyboard/latin/common/Colors.kt +++ b/app/src/main/java/helium314/keyboard/latin/common/Colors.kt @@ -150,7 +150,11 @@ class DynamicColors(context: Context, override val themeStyle: String, override private val spaceBarStateList: ColorStateList private val adjustedBackgroundStateList: ColorStateList private val stripBackgroundList: ColorStateList - private val toolbarKeyStateList = activatedStateList(keyText, darken(darken(keyText))) + private val toolbarKeyStateList = activatedStateList( + keyText, + if (isBrightColor(keyText)) darken(darken(keyText)) + else brighten(brighten(keyText)) + ) /** darkened variant of [accent] because the accent color is always light for dynamic colors */ private val adjustedAccent: Int = darken(accent) @@ -398,7 +402,11 @@ class DefaultColors ( private val spaceBarStateList: ColorStateList private val adjustedBackgroundStateList: ColorStateList private val stripBackgroundList: ColorStateList - private val toolbarKeyStateList = activatedStateList(suggestionText, darken(darken(suggestionText))) + private val toolbarKeyStateList = activatedStateList( + suggestionText, + if (isBrightColor(suggestionText)) darken(darken(suggestionText)) + else brighten(brighten(suggestionText)) + ) private var backgroundSetupDone = false init { From 635cd5f8dad00fd9a3edb47d53d0b30334ea5c35 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 26 Jan 2025 13:16:13 +0100 Subject: [PATCH 14/14] toolbar key activated state now responds to settings changes --- .../keyboard/keyboard/KeyboardSwitcher.java | 14 +++++++-- .../clipboard/ClipboardHistoryView.kt | 11 +++++-- .../suggestions/SuggestionStripView.java | 15 ++++++---- .../keyboard/latin/utils/ToolbarUtils.kt | 30 ++++++++++++++++--- 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java index e676e014..0ea11475 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java @@ -8,6 +8,7 @@ package helium314.keyboard.keyboard; import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.drawable.Drawable; @@ -40,8 +41,10 @@ import helium314.keyboard.latin.RichInputMethodSubtype; import helium314.keyboard.latin.WordComposer; import helium314.keyboard.latin.settings.Settings; import helium314.keyboard.latin.settings.SettingsValues; +import helium314.keyboard.latin.suggestions.SuggestionStripView; import helium314.keyboard.latin.utils.AdditionalSubtypeUtils; import helium314.keyboard.latin.utils.CapsModeUtils; +import helium314.keyboard.latin.utils.DeviceProtectedUtils; import helium314.keyboard.latin.utils.LanguageOnSpacebarUtils; import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.RecapitalizeStatus; @@ -59,7 +62,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { private View mEmojiTabStripView; private LinearLayout mClipboardStripView; private HorizontalScrollView mClipboardStripScrollView; - private View mSuggestionStripView; + private SuggestionStripView mSuggestionStripView; private ClipboardHistoryView mClipboardHistoryView; private TextView mFakeToastView; private LatinIME mLatinIME; @@ -325,7 +328,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { if (DEBUG_ACTION) { Log.d(TAG, "setEmojiKeyboard"); } - final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET); mMainKeyboardFrame.setVisibility(View.VISIBLE); // The visibility of {@link #mKeyboardView} must be aligned with {@link #MainKeyboardFrame}. // @see #getVisibleKeyboardView() and @@ -346,7 +348,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { if (DEBUG_ACTION) { Log.d(TAG, "setClipboardKeyboard"); } - final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET); mMainKeyboardFrame.setVisibility(View.VISIBLE); // The visibility of {@link #mKeyboardView} must be aligned with {@link #MainKeyboardFrame}. // @see #getVisibleKeyboardView() and @@ -634,6 +635,11 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { mKeyboardView.closing(); } PointerTracker.clearOldViewData(); + final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(displayContext); + if (mSuggestionStripView != null) + prefs.unregisterOnSharedPreferenceChangeListener(mSuggestionStripView); + if (mClipboardHistoryView != null) + prefs.unregisterOnSharedPreferenceChangeListener(mClipboardHistoryView); updateKeyboardThemeAndContextThemeWrapper(displayContext, KeyboardTheme.getKeyboardTheme(displayContext)); mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(R.layout.input_view, null); @@ -656,6 +662,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { mClipboardStripScrollView = mCurrentInputView.findViewById(R.id.clipboard_strip_scroll_view); mSuggestionStripView = mCurrentInputView.findViewById(R.id.suggestion_strip_view); + prefs.registerOnSharedPreferenceChangeListener(mSuggestionStripView); + prefs.registerOnSharedPreferenceChangeListener(mClipboardHistoryView); PointerTracker.switchTo(mKeyboardView); return mCurrentInputView; } diff --git a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt index 98c70f61..73e5959b 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt @@ -4,6 +4,7 @@ package helium314.keyboard.keyboard.clipboard import android.annotation.SuppressLint import android.content.Context +import android.content.SharedPreferences import android.util.AttributeSet import android.util.TypedValue import android.view.View @@ -34,6 +35,7 @@ import helium314.keyboard.latin.utils.createToolbarKey import helium314.keyboard.latin.utils.getCodeForToolbarKey import helium314.keyboard.latin.utils.getCodeForToolbarKeyLongClick import helium314.keyboard.latin.utils.getEnabledClipboardToolbarKeys +import helium314.keyboard.latin.utils.setToolbarButtonsActivatedStateOnPrefChange @SuppressLint("CustomViewStyleable") class ClipboardHistoryView @JvmOverloads constructor( @@ -41,7 +43,8 @@ class ClipboardHistoryView @JvmOverloads constructor( attrs: AttributeSet?, defStyle: Int = R.attr.clipboardHistoryViewStyle ) : LinearLayout(context, attrs, defStyle), View.OnClickListener, - ClipboardHistoryManager.OnHistoryChangeListener, OnKeyEventListener, View.OnLongClickListener { + ClipboardHistoryManager.OnHistoryChangeListener, OnKeyEventListener, + View.OnLongClickListener, SharedPreferences.OnSharedPreferenceChangeListener { private val clipboardLayoutParams = ClipboardLayoutParams(context) private val pinIconId: Int @@ -232,4 +235,8 @@ class ClipboardHistoryView @JvmOverloads constructor( clipboardAdapter.notifyItemChanged(to) if (to < from) clipboardRecyclerView.smoothScrollToPosition(to) } -} \ No newline at end of file + + override fun onSharedPreferenceChanged(prefs: SharedPreferences?, key: String?) { + setToolbarButtonsActivatedStateOnPrefChange(KeyboardSwitcher.getInstance().clipboardStrip, key) + } +} diff --git a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java index 04cc9c4e..ab99a506 100644 --- a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java +++ b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java @@ -70,7 +70,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; public final class SuggestionStripView extends RelativeLayout implements OnClickListener, - OnLongClickListener { + OnLongClickListener, SharedPreferences.OnSharedPreferenceChangeListener { public interface Listener { void pickSuggestionManually(SuggestedWordInfo word); void onCodeInput(int primaryCode, int x, int y, boolean isKeyRepeat); @@ -231,6 +231,12 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick colors.setBackground(this, ColorType.STRIP_BACKGROUND); } + @Override + public void onSharedPreferenceChanged(SharedPreferences prefs, @Nullable String key) { + ToolbarUtilsKt.setToolbarButtonsActivatedStateOnPrefChange(mPinnedKeys, key); + ToolbarUtilsKt.setToolbarButtonsActivatedStateOnPrefChange(mToolbar, key); + } + /** * A connection back to the input method. */ @@ -647,11 +653,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick if (code != KeyCode.UNSPECIFIED) { Log.d(TAG, "click toolbar key "+tag); mListener.onCodeInput(code, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false); - if (tag == ToolbarKey.INCOGNITO || tag == ToolbarKey.AUTOCORRECT || tag == ToolbarKey.ONE_HANDED) { - if (tag == ToolbarKey.INCOGNITO) - updateKeys(); // update icon - view.setActivated(!view.isActivated()); - } + if (tag == ToolbarKey.INCOGNITO) + updateKeys(); // update expand key icon return; } } diff --git a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt index 76626534..a14a5ff6 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt @@ -6,6 +6,7 @@ import android.content.Context import android.content.DialogInterface import android.content.SharedPreferences import android.view.LayoutInflater +import android.view.ViewGroup import android.widget.EditText import android.widget.ImageButton import android.widget.ImageView @@ -16,6 +17,7 @@ import androidx.core.content.ContextCompat import androidx.core.content.edit import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeCompat +import androidx.core.view.forEach import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.core.widget.doAfterTextChanged @@ -26,6 +28,9 @@ import helium314.keyboard.latin.R import helium314.keyboard.latin.databinding.ReorderDialogItemBinding import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.utils.ToolbarKey.* +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import kotlinx.serialization.json.Json import java.util.EnumMap import java.util.Locale @@ -37,14 +42,31 @@ fun createToolbarKey(context: Context, iconsSet: KeyboardIconsSet, key: ToolbarK val contentDescriptionId = context.resources.getIdentifier(key.name.lowercase(), "string", context.packageName) if (contentDescriptionId != 0) button.contentDescription = context.getString(contentDescriptionId) - button.isActivated = when (key) { - INCOGNITO -> Settings.readAlwaysIncognitoMode(DeviceProtectedUtils.getSharedPreferences(context)) + setToolbarButtonActivatedState(button) + button.setImageDrawable(iconsSet.getNewDrawable(key.name, context)) + return button +} + +fun setToolbarButtonsActivatedStateOnPrefChange(buttonsGroup: ViewGroup, key: String?) { + // settings need to be updated when buttons change + if (key != Settings.PREF_AUTO_CORRECTION + && key != Settings.PREF_ALWAYS_INCOGNITO_MODE + && key?.startsWith(Settings.PREF_ONE_HANDED_MODE_PREFIX) == false) + return + + GlobalScope.launch { + delay(10) // need to wait until SettingsValues are reloaded + buttonsGroup.forEach { if (it is ImageButton) setToolbarButtonActivatedState(it) } + } +} + +private fun setToolbarButtonActivatedState(button: ImageButton) { + button.isActivated = when (button.tag) { + INCOGNITO -> Settings.readAlwaysIncognitoMode(DeviceProtectedUtils.getSharedPreferences(button.context)) ONE_HANDED -> Settings.getInstance().current.mOneHandedModeEnabled AUTOCORRECT -> Settings.getInstance().current.mAutoCorrectionEnabledPerUserSettings else -> true } - button.setImageDrawable(iconsSet.getNewDrawable(key.name, context)) - return button } fun getCodeForToolbarKey(key: ToolbarKey) = Settings.getInstance().getCustomToolbarKeyCode(key) ?: when (key) {