From 2f5e3230d0de0b066d6e14ff24ff2d6b9a4f3f13 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Mon, 29 Jan 2024 14:32:51 +0100 Subject: [PATCH] some adjustments / lint / unused code --- .github/PULL_REQUEST_TEMPLATE.md | 1 + README.md | 26 ++++++-- .../inputmethod/keyboard/ProximityInfo.java | 3 +- .../keyboard/clipboard/ClipboardAdapter.kt | 7 ++- .../dslul/openboard/inputmethod/latin/App.kt | 4 +- .../inputmethod/latin/AssetFileAddress.java | 60 ------------------- .../settings/CorrectionSettingsFragment.java | 4 +- .../SpellCheckerSettingsFragment.java | 6 +- .../latin/utils/DictionaryHeaderUtils.java | 21 ------- .../latin/utils/DictionaryInfoUtils.java | 2 +- .../latin/utils/DictionaryUtils.kt | 17 +++--- app/src/main/proguard.flags | 1 - .../res/layout/language_search_filter.xml | 6 +- .../main/res/xml/prefs_screen_advanced.xml | 16 ++--- .../main/res/xml/prefs_screen_appearance.xml | 10 ++-- .../main/res/xml/prefs_screen_correction.xml | 24 ++++---- app/src/main/res/xml/prefs_screen_debug.xml | 10 ++-- app/src/main/res/xml/prefs_screen_gesture.xml | 8 +-- .../main/res/xml/prefs_screen_preferences.xml | 18 +++--- .../main/res/xml/spell_checker_settings.xml | 2 +- settings.gradle | 1 - 21 files changed, 91 insertions(+), 156 deletions(-) delete mode 100644 app/src/main/java/org/dslul/openboard/inputmethod/latin/AssetFileAddress.java delete mode 100644 app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryHeaderUtils.java diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 9d645a6f3..b169918b0 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,4 +3,5 @@ IMPORTANT: The package will be renamed soon. To avoid merge conflicts, please do * Please bescribe briefly what your pull request proposes to fix or improve. * If it's not completely obvious, describe what the PR does to achieve the desired result. * If you use someone else's code, please mention or better link to the source. +* See the contributing section in the readme for more detailed guidelines --> diff --git a/README.md b/README.md index f95d66b9b..49187c3e7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,18 @@ # OpenBoard upgrade, WIP IMPORTANT: The package will be renamed soon. To avoid merge conflicts, please do not submit any PRs until the renaming is done. +## Table of contents + +- [Features](#features) + * [Hidden functionality](#hidden-functionality) +- [Contributing](#contributing-) + * [Reporting issues](#reporting-issues) + * [Translation](#translation) + * [Dictionary creation](#dictionary-creation) + * [Code contribution](#code-contribution) +- [License](#license) +- [Credits](#credits) + ## Plan for actual release The plans for major changes are completed, and most features appear to be stable enough for a proper release. So what comes next: @@ -57,7 +69,7 @@ Features that may go unnoticed, and further potentially useful information # Contributing ❤ -## Issue reporting +## Reporting issues Whether you encountered a bug, or want to see a new feature in OpenBoard, you can contribute to the project by opening a new issue [here](https://github.com/openboard-team/openboard/issues). Your help is always welcome! @@ -78,16 +90,22 @@ IMPORTANT: The package will be renamed soon. To avoid merge conflicts, please do ### Getting started -OpenBoard project is based on Gradle and Android Gradle Plugin. To get started, you'll just need to install [Android Studio](https://developer.android.com/studio), and import project 'from Version Control / Git / Github' by providing this git repository [URL](https://github.com/Helium314/openboard) (or git SSH [URL](git@github.com:Helium314/openboard.git)). +OpenBoard project is based on Gradle and Android Gradle Plugin. To get started, you can install [Android Studio](https://developer.android.com/studio), and import project 'from Version Control / Git / Github' by providing this git repository [URL](https://github.com/Helium314/openboard) (or git SSH [URL](git@github.com:Helium314/openboard.git)). +Of course you can also use any other compatible IDE, or work with text editor and command line. -Once everything got setted up correctly, you're ready to go! +Once everything is up correctly, you're ready to go! ### Guidelines OpenBoard 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. +If there is no issue related to your intended contribution, it's a good idea to open a new one 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 contributions into a single PR is hard to review and can get messy. +- **Has a proper description**. What your coutribution does is usually less obvious to reviewers than for yourself. A good description helps a lot for understanding what is going on, and for separating wanted from unintended changes in behavior. - **Uses already in-place mechanism and take advantage of them**. In other terms, does not reinvent the wheel or uses shortcuts that could alter the consistency of the existing code. -- **Has the lowest footprint possible**. OpenBoard code has been written by android experts (AOSP/Google engineers). It has been tested and runned on millions of devices. Thus, **existing code will always be safer than new code**. The less we alter existing code, the more OpenBoard will stay stable. Especially in the input logic scope. +- **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. - **Complies with the user privacy principle OpenBoard follows**. In addition to previous elements, OpenBoard must stick to [F-Droid inclusion guidelines](https://f-droid.org/docs/Inclusion_Policy/). diff --git a/app/src/main/java/com/android/inputmethod/keyboard/ProximityInfo.java b/app/src/main/java/com/android/inputmethod/keyboard/ProximityInfo.java index c61ba9cf3..4cc819d33 100644 --- a/app/src/main/java/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/app/src/main/java/com/android/inputmethod/keyboard/ProximityInfo.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Locale; public class ProximityInfo { private static final String TAG = ProximityInfo.class.getSimpleName(); @@ -192,7 +193,7 @@ public class ProximityInfo { touchPositionCorrection.getRadius(row) * hitBoxDiagonal; } if (DEBUG) { - Log.d(TAG, String.format( + Log.d(TAG, String.format(Locale.US, " [%2d] row=%d x/y/r=%7.2f/%7.2f/%5.2f %s code=%s", infoIndex, row, sweetSpotCenterXs[infoIndex], sweetSpotCenterYs[infoIndex], sweetSpotRadii[infoIndex], (row < rows ? "correct" : "default"), diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/clipboard/ClipboardAdapter.kt b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/clipboard/ClipboardAdapter.kt index 730c7b88b..83535d685 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/clipboard/ClipboardAdapter.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/clipboard/ClipboardAdapter.kt @@ -2,6 +2,7 @@ package org.dslul.openboard.inputmethod.keyboard.clipboard +import android.annotation.SuppressLint import android.graphics.Typeface import android.util.TypedValue import android.view.LayoutInflater @@ -79,11 +80,11 @@ class ClipboardAdapter( pinnedIconView.visibility = if (historyEntry?.isPinned == true) View.VISIBLE else View.GONE } + @SuppressLint("ClickableViewAccessibility") override fun onTouch(view: View, event: MotionEvent): Boolean { - if (event.actionMasked != MotionEvent.ACTION_DOWN) { - return false + if (event.actionMasked == MotionEvent.ACTION_DOWN) { + keyEventListener.onKeyDown(view.tag as Long) } - keyEventListener.onKeyDown(view.tag as Long) return false } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/App.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/App.kt index 7fec1f27e..45db31fc5 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/App.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/App.kt @@ -9,7 +9,6 @@ import org.dslul.openboard.inputmethod.latin.settings.Settings import org.dslul.openboard.inputmethod.latin.settings.USER_DICTIONARY_SUFFIX import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils import org.dslul.openboard.inputmethod.latin.utils.DictionaryInfoUtils -import org.dslul.openboard.inputmethod.latin.utils.Log import org.dslul.openboard.inputmethod.latin.utils.upgradeToolbarPref import java.io.File @@ -34,12 +33,11 @@ class App : Application() { fun checkVersionUpgrade(context: Context) { val prefs = DeviceProtectedUtils.getSharedPreferences(context) val oldVersion = prefs.getInt(Settings.PREF_VERSION_CODE, 0) - Log.i("test", "old version $oldVersion") if (oldVersion == BuildConfig.VERSION_CODE) return upgradeToolbarPref(prefs) // clear extracted dictionaries, in case updated version contains newer ones - DictionaryInfoUtils.getCachedDirectoryList(context).forEach { + DictionaryInfoUtils.getCachedDirectoryList(context)?.forEach { if (!it.isDirectory) return@forEach val files = it.listFiles() ?: return@forEach for (file in files) { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/AssetFileAddress.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/AssetFileAddress.java deleted file mode 100644 index a7d31dab5..000000000 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/AssetFileAddress.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * modified - * SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only - */ - -package org.dslul.openboard.inputmethod.latin; - -import org.dslul.openboard.inputmethod.latin.common.FileUtils; - -import java.io.File; - -/** - * Immutable class to hold the address of an asset. - * As opposed to a normal file, an asset is usually represented as a contiguous byte array in - * the package file. Open it correctly thus requires the name of the package it is in, but - * also the offset in the file and the length of this data. This class encapsulates these three. - */ -public final class AssetFileAddress { - public final String mFilename; - public final long mOffset; - public final long mLength; - - public AssetFileAddress(final String filename, final long offset, final long length) { - mFilename = filename; - mOffset = offset; - mLength = length; - } - - public static AssetFileAddress makeFromFile(final File file) { - if (!file.isFile()) return null; - return new AssetFileAddress(file.getAbsolutePath(), 0L, file.length()); - } - - public static AssetFileAddress makeFromFileName(final String filename) { - if (null == filename) return null; - return makeFromFile(new File(filename)); - } - - public static AssetFileAddress makeFromFileNameAndOffset(final String filename, - final long offset, final long length) { - if (null == filename) return null; - final File f = new File(filename); - if (!f.isFile()) return null; - return new AssetFileAddress(filename, offset, length); - } - - public boolean pointsToPhysicalFile() { - return 0 == mOffset; - } - - public void deleteUnderlyingFile() { - FileUtils.deleteRecursively(new File(mFilename)); - } - - @Override - public String toString() { - return String.format("%s (offset=%d, length=%d)", mFilename, mOffset, mLength); - } -} diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java index 9451a70b4..2ca74006d 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java @@ -13,7 +13,7 @@ import android.content.SharedPreferences; import android.os.Bundle; import androidx.appcompat.app.AlertDialog; -import androidx.preference.SwitchPreferenceCompat; +import androidx.preference.SwitchPreference; import androidx.preference.TwoStatePreference; import org.dslul.openboard.inputmethod.latin.R; @@ -25,7 +25,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment implements SharedPreferences.OnSharedPreferenceChangeListener, PermissionsManager.PermissionsResultCallback { - private SwitchPreferenceCompat mLookupContactsPreference; + private SwitchPreference mLookupContactsPreference; @Override public void onCreate(final Bundle icicle) { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java index f0a92070a..28ed22689 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java @@ -11,14 +11,14 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.text.TextUtils; +import androidx.preference.SwitchPreference; + import org.dslul.openboard.inputmethod.latin.R; import org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager; import org.dslul.openboard.inputmethod.latin.permissions.PermissionsUtil; import org.dslul.openboard.inputmethod.latin.settings.SubScreenFragment; import org.dslul.openboard.inputmethod.latin.utils.ActivityThemeUtils; -import androidx.preference.SwitchPreferenceCompat; - /** * Preference screen. */ @@ -26,7 +26,7 @@ public final class SpellCheckerSettingsFragment extends SubScreenFragment implements SharedPreferences.OnSharedPreferenceChangeListener, PermissionsManager.PermissionsResultCallback { - private SwitchPreferenceCompat mLookupContactsPreference; + private SwitchPreference mLookupContactsPreference; @Override public void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryHeaderUtils.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryHeaderUtils.java deleted file mode 100644 index 1b66a21a5..000000000 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryHeaderUtils.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * modified - * SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only - */ - -package org.dslul.openboard.inputmethod.latin.utils; - -import org.dslul.openboard.inputmethod.latin.AssetFileAddress; -import org.dslul.openboard.inputmethod.latin.makedict.DictionaryHeader; - -import java.io.File; - -public class DictionaryHeaderUtils { - - public static int getContentVersion(AssetFileAddress fileAddress) { - final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull( - new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength); - return Integer.parseInt(header.mVersionString); - } -} diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryInfoUtils.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryInfoUtils.java index 5a9e43794..301ae371a 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryInfoUtils.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryInfoUtils.java @@ -110,7 +110,7 @@ public class DictionaryInfoUtils { /** * Helper method to the list of cache directories, one for each distinct locale. */ - public static File[] getCachedDirectoryList(final Context context) { + @Nullable public static File[] getCachedDirectoryList(final Context context) { return new File(DictionaryInfoUtils.getWordListCacheDirectory(context)).listFiles(); } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryUtils.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryUtils.kt index 320a551d2..c3d091ca0 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryUtils.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/DictionaryUtils.kt @@ -19,14 +19,11 @@ fun getDictionaryLocales(context: Context): MutableSet { val locales = HashSet() // get cached dictionaries: extracted or user-added dictionaries - val cachedDirectoryList = DictionaryInfoUtils.getCachedDirectoryList(context) - if (cachedDirectoryList != null) { - for (directory in cachedDirectoryList) { - if (!directory.isDirectory) continue - if (!hasAnythingOtherThanExtractedMainDictionary(directory)) continue - val locale = DictionaryInfoUtils.getWordListIdFromFileName(directory.name).constructLocale() - locales.add(locale) - } + DictionaryInfoUtils.getCachedDirectoryList(context)?.forEach { directory -> + if (!directory.isDirectory) return@forEach + if (!hasAnythingOtherThanExtractedMainDictionary(directory)) return@forEach + val locale = DictionaryInfoUtils.getWordListIdFromFileName(directory.name).constructLocale() + locales.add(locale) } // get assets dictionaries val assetsDictionaryList = DictionaryInfoUtils.getAssetsDictionaryList(context) @@ -70,8 +67,8 @@ fun cleanUnusedMainDicts(context: Context) { val dirs = dictionaryDir.listFiles() ?: return val prefs = DeviceProtectedUtils.getSharedPreferences(context) val usedLocaleLanguageTags = hashSetOf() - getEnabledSubtypes(prefs).forEach { - val locale = it.locale() + getEnabledSubtypes(prefs).forEach { subtype -> + val locale = subtype.locale() usedLocaleLanguageTags.add(locale.toLanguageTag()) Settings.getSecondaryLocales(prefs, locale).forEach { usedLocaleLanguageTags.add(it.toLanguageTag()) } } diff --git a/app/src/main/proguard.flags b/app/src/main/proguard.flags index dccefd9e1..f3c85204b 100644 --- a/app/src/main/proguard.flags +++ b/app/src/main/proguard.flags @@ -17,7 +17,6 @@ # Keep classes that are used as a parameter type of methods that are also marked as keep # to preserve changing those methods' signature. --keep class org.dslul.openboard.inputmethod.latin.AssetFileAddress -keep class org.dslul.openboard.inputmethod.latin.Dictionary -keep class org.dslul.openboard.inputmethod.latin.NgramContext -keep class org.dslul.openboard.inputmethod.latin.makedict.ProbabilityInfo diff --git a/app/src/main/res/layout/language_search_filter.xml b/app/src/main/res/layout/language_search_filter.xml index d0041af04..c44c86ffe 100644 --- a/app/src/main/res/layout/language_search_filter.xml +++ b/app/src/main/res/layout/language_search_filter.xml @@ -18,7 +18,8 @@ app:tint="@color/foreground" android:layout_gravity="center_vertical" android:layout_width="40dp" - android:layout_height="40dp" /> + android:layout_height="40dp" + android:contentDescription="@string/label_search_key" /> + android:layout_height="wrap_content" + android:autofillHints="language" /> - - - - - - - - - - - @@ -57,7 +57,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -