From d183baf401c34c969f8641998e83345bfa0a3a22 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Fri, 20 Oct 2023 09:43:14 +0200 Subject: [PATCH] remove some unused code and todos --- app/build.gradle | 4 -- .../keyboard/emoji/EmojiCategory.java | 5 -- .../keyboard/emoji/EmojiPalettesView.java | 1 - .../inputmethod/latin/DictionaryFactory.java | 7 +- .../latin/RichInputConnection.java | 28 ++++---- .../inputmethod/latin/common/Colors.kt | 4 +- .../inputmethod/latin/settings/Settings.java | 68 ------------------ app/src/main/res/raw/empty.dict | 1 - app/src/main/res/raw/main.dict | Bin 34 -> 0 bytes 9 files changed, 17 insertions(+), 101 deletions(-) delete mode 100644 app/src/main/res/raw/empty.dict delete mode 100644 app/src/main/res/raw/main.dict diff --git a/app/build.gradle b/app/build.gradle index dd90b87b2..71d6841c3 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,10 +46,6 @@ android { } ndkVersion '25.2.9519653' - androidResources { // todo: check, probably both can be removed (together with searching dicts in res/raw) - noCompress 'main.dict' - noCompress 'empty.dict' - } packagingOptions { jniLibs { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiCategory.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiCategory.java index c1d1dab94..7d54f64ae 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiCategory.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiCategory.java @@ -236,11 +236,6 @@ final class EmojiCategory { return mCurrentCategoryPageId; } - public void saveLastTypedCategoryPage() { - Settings.writeLastTypedEmojiCategoryPageId( - mPrefs, mCurrentCategoryId, mCurrentCategoryPageId); - } - public boolean isInRecentTab() { return mCurrentCategoryId == EmojiCategory.ID_RECENTS; } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiPalettesView.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiPalettesView.java index 07971a365..7a4d8bed7 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiPalettesView.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiPalettesView.java @@ -353,7 +353,6 @@ public final class EmojiPalettesView extends LinearLayout @Override public void onReleaseKey(final Key key) { mEmojiPalettesAdapter.addRecentKey(key); - mEmojiCategory.saveLastTypedCategoryPage(); final int code = key.getCode(); if (code == Constants.CODE_OUTPUT_TEXT) { mKeyboardActionListener.onTextInput(key.getOutputText()); diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFactory.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFactory.java index 8edae9873..387e01ffa 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFactory.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFactory.java @@ -17,7 +17,6 @@ import org.dslul.openboard.inputmethod.latin.makedict.DictionaryHeader; import org.dslul.openboard.inputmethod.latin.utils.DictionaryInfoUtils; import java.io.File; -import java.text.Normalizer; import java.util.ArrayList; import java.util.LinkedList; import java.util.Locale; @@ -97,10 +96,8 @@ public final class DictionaryFactory { public static void killDictionary(final Context context, final AssetFileAddress f) { if (f.pointsToPhysicalFile()) { f.deleteUnderlyingFile(); - // notify the user - // todo: use an alertDialog to avoid the toast not showing up on Android 13+ - // but asyncTask doesn't work because android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? - // https://stackoverflow.com/questions/7199014/show-an-alertdialog-from-a-background-thread-with-the-appcontext + // notify the user if possible (toast not showing up on Android 13+) + // but not that important, as the not working dictionary should be obvious final String wordlistId = DictionaryInfoUtils.getWordListIdFromFileName(new File(f.mFilename).getName()); new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, "dictionary "+wordlistId+" is invalid, deleting", Toast.LENGTH_LONG).show() diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/RichInputConnection.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/RichInputConnection.java index 1c79e50df..22059e539 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/RichInputConnection.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/RichInputConnection.java @@ -297,8 +297,8 @@ public final class RichInputConnection implements PrivateCommandPerformer { if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug(); mCommittedTextBeforeComposingText.append(text); // TODO: the following is exceedingly error-prone. Right now when the cursor is in the - // middle of the composing word mComposingText only holds the part of the composing text - // that is before the cursor, so this actually works, but it's terribly confusing. Fix this. + // middle of the composing word mComposingText only holds the part of the composing text + // that is before the cursor, so this actually works, but it's terribly confusing. Fix this. mExpectedSelStart += text.length() - mComposingText.length(); mExpectedSelEnd = mExpectedSelStart; mComposingText.setLength(0); @@ -368,10 +368,10 @@ public final class RichInputConnection implements PrivateCommandPerformer { return TextUtils.CAP_MODE_CHARACTERS & inputType; } // TODO: this will generally work, but there may be cases where the buffer contains SOME - // information but not enough to determine the caps mode accurately. This may happen after - // heavy pressing of delete, for example DEFAULT_TEXT_CACHE_SIZE - 5 times or so. - // getCapsMode should be updated to be able to return a "not enough info" result so that - // we can get more context only when needed. + // information but not enough to determine the caps mode accurately. This may happen after + // heavy pressing of delete, for example DEFAULT_TEXT_CACHE_SIZE - 5 times or so. + // getCapsMode should be updated to be able to return a "not enough info" result so that + // we can get more context only when needed. if (TextUtils.isEmpty(mCommittedTextBeforeComposingText) && 0 != mExpectedSelStart) { if (!reloadTextCache()) { Log.w(TAG, "Unable to connect to the editor. " @@ -381,19 +381,19 @@ public final class RichInputConnection implements PrivateCommandPerformer { // This never calls InputConnection#getCapsMode - in fact, it's a static method that // never blocks or initiates IPC. // TODO: don't call #toString() here. Instead, all accesses to - // mCommittedTextBeforeComposingText should be done on the main thread. + // mCommittedTextBeforeComposingText should be done on the main thread. return CapsModeUtils.getCapsMode(mCommittedTextBeforeComposingText.toString(), inputType, spacingAndPunctuations, hasSpaceBefore); } - public int getCodePointBeforeCursor() { // todo: behavior still correct? also should do this to getCharBeforeBeforeCursor + public int getCodePointBeforeCursor() { final CharSequence text = mComposingText.length() == 0 ? mCommittedTextBeforeComposingText : mComposingText; final int length = text.length(); if (length < 1) return Constants.NOT_A_CODE; return Character.codePointBefore(text, length); } - public int getCharBeforeBeforeCursor() { // todo: behavior still correct? + public int getCharBeforeBeforeCursor() { if (mComposingText.length() >= 2) return mComposingText.charAt(mComposingText.length() - 2); final int length = mCommittedTextBeforeComposingText.length(); if (mComposingText.length() == 1) return mCommittedTextBeforeComposingText.charAt(length - 1); @@ -474,8 +474,8 @@ public final class RichInputConnection implements PrivateCommandPerformer { public void deleteTextBeforeCursor(final int beforeLength) { if (DEBUG_BATCH_NESTING) checkBatchEdit(); // TODO: the following is incorrect if the cursor is not immediately after the composition. - // Right now we never come here in this case because we reset the composing state before we - // come here in this case, but we need to fix this. + // Right now we never come here in this case because we reset the composing state before we + // come here in this case, but we need to fix this. final int remainingChars = mComposingText.length() - beforeLength; if (remainingChars >= 0) { mComposingText.setLength(remainingChars); @@ -591,7 +591,7 @@ public final class RichInputConnection implements PrivateCommandPerformer { mComposingText.setLength(0); mComposingText.append(text); // TODO: support values of newCursorPosition != 1. At this time, this is never called with - // newCursorPosition != 1. + // newCursorPosition != 1. if (isConnected()) { mIC.setComposingText(text, newCursorPosition); } @@ -671,8 +671,8 @@ public final class RichInputConnection implements PrivateCommandPerformer { final String reference = prev.length() <= checkLength ? prev.toString() : prev.subSequence(prev.length() - checkLength, prev.length()).toString(); // TODO: right now the following works because mComposingText holds the part of the - // composing text that is before the cursor, but this is very confusing. We should - // fix it. + // composing text that is before the cursor, but this is very confusing. We should + // fix it. final StringBuilder internal = new StringBuilder() .append(mCommittedTextBeforeComposingText).append(mComposingText); if (internal.length() > checkLength) { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.kt index 710385c8c..f4019c502 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.kt @@ -47,8 +47,6 @@ class Colors ( val adjustedKeyText: Int val spaceBarText: Int - // todo (later): evaluate which colors, colorFilters and colorStateLists are actually necessary - // also, ideally the color filters would be private and chosen internally depending on type val backgroundFilter: ColorFilter val adjustedBackgroundFilter: ColorFilter val keyBackgroundFilter: ColorFilter @@ -83,7 +81,7 @@ class Colors ( spaceBarText = keyHintText } - // create color filters, todo: maybe better / simplify + // create color filters val states = arrayOf(intArrayOf(android.R.attr.state_pressed), intArrayOf(-android.R.attr.state_pressed)) fun stateList(pressed: Int, normal: Int) = ColorStateList(states, intArrayOf(pressed, normal)) // todo (idea): make better use of the states? diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java index 0dc7744f0..c39f8a9d2 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java @@ -29,7 +29,6 @@ import org.dslul.openboard.inputmethod.latin.InputAttributes; import org.dslul.openboard.inputmethod.latin.R; import org.dslul.openboard.inputmethod.latin.common.Colors; import org.dslul.openboard.inputmethod.latin.common.LocaleUtils; -import org.dslul.openboard.inputmethod.latin.common.StringUtils; import org.dslul.openboard.inputmethod.latin.utils.AdditionalSubtypeUtils; import org.dslul.openboard.inputmethod.latin.utils.ColorUtilKt; import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils; @@ -40,11 +39,9 @@ import org.dslul.openboard.inputmethod.latin.utils.StatsUtils; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; -import java.util.Set; import java.util.concurrent.locks.ReentrantLock; public final class Settings implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -126,17 +123,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "pref_dont_show_missing_dict_dialog"; public static final String PREF_PINNED_KEYS = "pref_pinned_keys"; - - private static final String PREF_LAST_USED_PERSONALIZATION_TOKEN = - "pref_last_used_personalization_token"; - private static final String PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME = - "pref_last_used_personalization_dict_wiped_time"; - private static final String PREF_CORPUS_HANDLES_FOR_PERSONALIZATION = - "pref_corpus_handles_for_personalization"; - // Emoji public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys"; - public static final String PREF_EMOJI_CATEGORY_LAST_TYPED_ID = "emoji_category_last_typed_id"; public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_ID = "last_shown_emoji_category_id"; public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID = "last_shown_emoji_category_page_id"; @@ -334,18 +322,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang R.array.keypress_vibration_durations, DEFAULT_KEYPRESS_VIBRATION_DURATION)); } - public static float readKeyPreviewAnimationScale(final SharedPreferences prefs, - final String prefKey, final float defaultValue) { - final float fraction = prefs.getFloat(prefKey, UNDEFINED_PREFERENCE_VALUE_FLOAT); - return (fraction != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? fraction : defaultValue; - } - - public static int readKeyPreviewAnimationDuration(final SharedPreferences prefs, - final String prefKey, final int defaultValue) { - final int milliseconds = prefs.getInt(prefKey, UNDEFINED_PREFERENCE_VALUE_INT); - return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds : defaultValue; - } - public static boolean readClipboardHistoryEnabled(final SharedPreferences prefs) { return prefs.getBoolean(PREF_ENABLE_CLIPBOARD_HISTORY, true); } @@ -423,37 +399,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang && conf.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_YES; } - public void writeLastUsedPersonalizationToken(byte[] token) { - if (token == null) { - mPrefs.edit().remove(PREF_LAST_USED_PERSONALIZATION_TOKEN).apply(); - } else { - final String tokenStr = StringUtils.byteArrayToHexString(token); - mPrefs.edit().putString(PREF_LAST_USED_PERSONALIZATION_TOKEN, tokenStr).apply(); - } - } - - public byte[] readLastUsedPersonalizationToken() { - final String tokenStr = mPrefs.getString(PREF_LAST_USED_PERSONALIZATION_TOKEN, null); - return StringUtils.hexStringToByteArray(tokenStr); - } - - public void writeLastPersonalizationDictWipedTime(final long timestamp) { - mPrefs.edit().putLong(PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME, timestamp).apply(); - } - - public long readLastPersonalizationDictGeneratedTime() { - return mPrefs.getLong(PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME, 0); - } - - public void writeCorpusHandlesForPersonalization(final Set corpusHandles) { - mPrefs.edit().putStringSet(PREF_CORPUS_HANDLES_FOR_PERSONALIZATION, corpusHandles).apply(); - } - - public Set readCorpusHandlesForPersonalization() { - final Set emptySet = Collections.emptySet(); - return mPrefs.getStringSet(PREF_CORPUS_HANDLES_FOR_PERSONALIZATION, emptySet); - } - public static void writeEmojiRecentKeys(final SharedPreferences prefs, String str) { prefs.edit().putString(PREF_EMOJI_RECENT_KEYS, str).apply(); } @@ -462,18 +407,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang return prefs.getString(PREF_EMOJI_RECENT_KEYS, ""); } - public static void writeLastTypedEmojiCategoryPageId( - final SharedPreferences prefs, final int categoryId, final int categoryPageId) { - final String key = PREF_EMOJI_CATEGORY_LAST_TYPED_ID + categoryId; - prefs.edit().putInt(key, categoryPageId).apply(); - } - - public static int readLastTypedEmojiCategoryPageId( - final SharedPreferences prefs, final int categoryId) { - final String key = PREF_EMOJI_CATEGORY_LAST_TYPED_ID + categoryId; - return prefs.getInt(key, 0); - } - public static void writeLastShownEmojiCategoryId( final SharedPreferences prefs, final int categoryId) { prefs.edit().putInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, categoryId).apply(); @@ -566,7 +499,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang case PREF_COLOR_ACCENT_SUFFIX: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { // try determining accent color on Android 10 & 11, accent is not available in resources - // todo: test whether this actually works final Context wrapper = new ContextThemeWrapper(context, android.R.style.Theme_DeviceDefault); final TypedValue value = new TypedValue(); if (wrapper.getTheme().resolveAttribute(android.R.attr.colorAccent, value, true)) diff --git a/app/src/main/res/raw/empty.dict b/app/src/main/res/raw/empty.dict deleted file mode 100644 index 80ce06699..000000000 --- a/app/src/main/res/raw/empty.dict +++ /dev/null @@ -1 +0,0 @@ -›Á:þ \ No newline at end of file diff --git a/app/src/main/res/raw/main.dict b/app/src/main/res/raw/main.dict deleted file mode 100644 index a456cf3d39e5bdca3e04ba6b90a6c24d0be0aeca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 34 pcmZQ{bYNg*%yVGiVoY&h;AbpyU=U%