remove some unused code and todos

This commit is contained in:
Helium314 2023-10-20 09:43:14 +02:00
parent 6fd6113271
commit d183baf401
9 changed files with 17 additions and 101 deletions

View file

@ -46,10 +46,6 @@ android {
} }
ndkVersion '25.2.9519653' 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 { packagingOptions {
jniLibs { jniLibs {

View file

@ -236,11 +236,6 @@ final class EmojiCategory {
return mCurrentCategoryPageId; return mCurrentCategoryPageId;
} }
public void saveLastTypedCategoryPage() {
Settings.writeLastTypedEmojiCategoryPageId(
mPrefs, mCurrentCategoryId, mCurrentCategoryPageId);
}
public boolean isInRecentTab() { public boolean isInRecentTab() {
return mCurrentCategoryId == EmojiCategory.ID_RECENTS; return mCurrentCategoryId == EmojiCategory.ID_RECENTS;
} }

View file

@ -353,7 +353,6 @@ public final class EmojiPalettesView extends LinearLayout
@Override @Override
public void onReleaseKey(final Key key) { public void onReleaseKey(final Key key) {
mEmojiPalettesAdapter.addRecentKey(key); mEmojiPalettesAdapter.addRecentKey(key);
mEmojiCategory.saveLastTypedCategoryPage();
final int code = key.getCode(); final int code = key.getCode();
if (code == Constants.CODE_OUTPUT_TEXT) { if (code == Constants.CODE_OUTPUT_TEXT) {
mKeyboardActionListener.onTextInput(key.getOutputText()); mKeyboardActionListener.onTextInput(key.getOutputText());

View file

@ -17,7 +17,6 @@ import org.dslul.openboard.inputmethod.latin.makedict.DictionaryHeader;
import org.dslul.openboard.inputmethod.latin.utils.DictionaryInfoUtils; import org.dslul.openboard.inputmethod.latin.utils.DictionaryInfoUtils;
import java.io.File; import java.io.File;
import java.text.Normalizer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Locale; import java.util.Locale;
@ -97,10 +96,8 @@ public final class DictionaryFactory {
public static void killDictionary(final Context context, final AssetFileAddress f) { public static void killDictionary(final Context context, final AssetFileAddress f) {
if (f.pointsToPhysicalFile()) { if (f.pointsToPhysicalFile()) {
f.deleteUnderlyingFile(); f.deleteUnderlyingFile();
// notify the user // notify the user if possible (toast not showing up on Android 13+)
// todo: use an alertDialog to avoid the toast not showing up on Android 13+ // but not that important, as the not working dictionary should be obvious
// 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
final String wordlistId = DictionaryInfoUtils.getWordListIdFromFileName(new File(f.mFilename).getName()); final String wordlistId = DictionaryInfoUtils.getWordListIdFromFileName(new File(f.mFilename).getName());
new Handler(Looper.getMainLooper()).post(() -> new Handler(Looper.getMainLooper()).post(() ->
Toast.makeText(context, "dictionary "+wordlistId+" is invalid, deleting", Toast.LENGTH_LONG).show() Toast.makeText(context, "dictionary "+wordlistId+" is invalid, deleting", Toast.LENGTH_LONG).show()

View file

@ -297,8 +297,8 @@ public final class RichInputConnection implements PrivateCommandPerformer {
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug(); if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
mCommittedTextBeforeComposingText.append(text); mCommittedTextBeforeComposingText.append(text);
// TODO: the following is exceedingly error-prone. Right now when the cursor is in the // 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 // 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. // that is before the cursor, so this actually works, but it's terribly confusing. Fix this.
mExpectedSelStart += text.length() - mComposingText.length(); mExpectedSelStart += text.length() - mComposingText.length();
mExpectedSelEnd = mExpectedSelStart; mExpectedSelEnd = mExpectedSelStart;
mComposingText.setLength(0); mComposingText.setLength(0);
@ -368,10 +368,10 @@ public final class RichInputConnection implements PrivateCommandPerformer {
return TextUtils.CAP_MODE_CHARACTERS & inputType; return TextUtils.CAP_MODE_CHARACTERS & inputType;
} }
// TODO: this will generally work, but there may be cases where the buffer contains SOME // 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 // 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. // 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 // getCapsMode should be updated to be able to return a "not enough info" result so that
// we can get more context only when needed. // we can get more context only when needed.
if (TextUtils.isEmpty(mCommittedTextBeforeComposingText) && 0 != mExpectedSelStart) { if (TextUtils.isEmpty(mCommittedTextBeforeComposingText) && 0 != mExpectedSelStart) {
if (!reloadTextCache()) { if (!reloadTextCache()) {
Log.w(TAG, "Unable to connect to the editor. " 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 // This never calls InputConnection#getCapsMode - in fact, it's a static method that
// never blocks or initiates IPC. // never blocks or initiates IPC.
// TODO: don't call #toString() here. Instead, all accesses to // 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, return CapsModeUtils.getCapsMode(mCommittedTextBeforeComposingText.toString(), inputType,
spacingAndPunctuations, hasSpaceBefore); 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 CharSequence text = mComposingText.length() == 0 ? mCommittedTextBeforeComposingText : mComposingText;
final int length = text.length(); final int length = text.length();
if (length < 1) return Constants.NOT_A_CODE; if (length < 1) return Constants.NOT_A_CODE;
return Character.codePointBefore(text, length); 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); if (mComposingText.length() >= 2) return mComposingText.charAt(mComposingText.length() - 2);
final int length = mCommittedTextBeforeComposingText.length(); final int length = mCommittedTextBeforeComposingText.length();
if (mComposingText.length() == 1) return mCommittedTextBeforeComposingText.charAt(length - 1); 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) { public void deleteTextBeforeCursor(final int beforeLength) {
if (DEBUG_BATCH_NESTING) checkBatchEdit(); if (DEBUG_BATCH_NESTING) checkBatchEdit();
// TODO: the following is incorrect if the cursor is not immediately after the composition. // 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 // 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. // come here in this case, but we need to fix this.
final int remainingChars = mComposingText.length() - beforeLength; final int remainingChars = mComposingText.length() - beforeLength;
if (remainingChars >= 0) { if (remainingChars >= 0) {
mComposingText.setLength(remainingChars); mComposingText.setLength(remainingChars);
@ -591,7 +591,7 @@ public final class RichInputConnection implements PrivateCommandPerformer {
mComposingText.setLength(0); mComposingText.setLength(0);
mComposingText.append(text); mComposingText.append(text);
// TODO: support values of newCursorPosition != 1. At this time, this is never called with // TODO: support values of newCursorPosition != 1. At this time, this is never called with
// newCursorPosition != 1. // newCursorPosition != 1.
if (isConnected()) { if (isConnected()) {
mIC.setComposingText(text, newCursorPosition); mIC.setComposingText(text, newCursorPosition);
} }
@ -671,8 +671,8 @@ public final class RichInputConnection implements PrivateCommandPerformer {
final String reference = prev.length() <= checkLength ? prev.toString() final String reference = prev.length() <= checkLength ? prev.toString()
: prev.subSequence(prev.length() - checkLength, prev.length()).toString(); : prev.subSequence(prev.length() - checkLength, prev.length()).toString();
// TODO: right now the following works because mComposingText holds the part of the // 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 // composing text that is before the cursor, but this is very confusing. We should
// fix it. // fix it.
final StringBuilder internal = new StringBuilder() final StringBuilder internal = new StringBuilder()
.append(mCommittedTextBeforeComposingText).append(mComposingText); .append(mCommittedTextBeforeComposingText).append(mComposingText);
if (internal.length() > checkLength) { if (internal.length() > checkLength) {

View file

@ -47,8 +47,6 @@ class Colors (
val adjustedKeyText: Int val adjustedKeyText: Int
val spaceBarText: 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 backgroundFilter: ColorFilter
val adjustedBackgroundFilter: ColorFilter val adjustedBackgroundFilter: ColorFilter
val keyBackgroundFilter: ColorFilter val keyBackgroundFilter: ColorFilter
@ -83,7 +81,7 @@ class Colors (
spaceBarText = keyHintText 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)) 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)) fun stateList(pressed: Int, normal: Int) = ColorStateList(states, intArrayOf(pressed, normal))
// todo (idea): make better use of the states? // todo (idea): make better use of the states?

View file

@ -29,7 +29,6 @@ import org.dslul.openboard.inputmethod.latin.InputAttributes;
import org.dslul.openboard.inputmethod.latin.R; import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.common.Colors; import org.dslul.openboard.inputmethod.latin.common.Colors;
import org.dslul.openboard.inputmethod.latin.common.LocaleUtils; 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.AdditionalSubtypeUtils;
import org.dslul.openboard.inputmethod.latin.utils.ColorUtilKt; import org.dslul.openboard.inputmethod.latin.utils.ColorUtilKt;
import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
public final class Settings implements SharedPreferences.OnSharedPreferenceChangeListener { 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_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "pref_dont_show_missing_dict_dialog";
public static final String PREF_PINNED_KEYS = "pref_pinned_keys"; 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 // Emoji
public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys"; 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_ID = "last_shown_emoji_category_id";
public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID = "last_shown_emoji_category_page_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)); 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) { public static boolean readClipboardHistoryEnabled(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_ENABLE_CLIPBOARD_HISTORY, true); return prefs.getBoolean(PREF_ENABLE_CLIPBOARD_HISTORY, true);
} }
@ -423,37 +399,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
&& conf.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_YES; && 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<String> corpusHandles) {
mPrefs.edit().putStringSet(PREF_CORPUS_HANDLES_FOR_PERSONALIZATION, corpusHandles).apply();
}
public Set<String> readCorpusHandlesForPersonalization() {
final Set<String> emptySet = Collections.emptySet();
return mPrefs.getStringSet(PREF_CORPUS_HANDLES_FOR_PERSONALIZATION, emptySet);
}
public static void writeEmojiRecentKeys(final SharedPreferences prefs, String str) { public static void writeEmojiRecentKeys(final SharedPreferences prefs, String str) {
prefs.edit().putString(PREF_EMOJI_RECENT_KEYS, str).apply(); 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, ""); 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( public static void writeLastShownEmojiCategoryId(
final SharedPreferences prefs, final int categoryId) { final SharedPreferences prefs, final int categoryId) {
prefs.edit().putInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, categoryId).apply(); 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: case PREF_COLOR_ACCENT_SUFFIX:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { 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 // 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 Context wrapper = new ContextThemeWrapper(context, android.R.style.Theme_DeviceDefault);
final TypedValue value = new TypedValue(); final TypedValue value = new TypedValue();
if (wrapper.getTheme().resolveAttribute(android.R.attr.colorAccent, value, true)) if (wrapper.getTheme().resolveAttribute(android.R.attr.colorAccent, value, true))

View file

@ -1 +0,0 @@
<EFBFBD><EFBFBD>:<3A>

Binary file not shown.