diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java index 088824448..f4b5630a1 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java @@ -601,13 +601,12 @@ public class KeyboardView extends View { if (key.isAccentColored()) { icon.setColorFilter(mColors.getActionKeyIconColorFilter()); } else if (key.isShift() && keyboard != null) { - // todo: switch to multiply after changing keyboard symbols to white icons if (keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED ) - icon.setColorFilter(mColors.getAccent(), PorterDuff.Mode.SRC_ATOP); // accent if shifted, needs SRC_ATOP because of underlying drawable + icon.setColorFilter(mColors.getAccent(), PorterDuff.Mode.SRC_ATOP); // todo: switch to accentColorFilter after changing keyboard symbols to white icons else icon.setColorFilter(mColors.getKeyTextFilter()); // key text if not shifted } else if (key.getBackgroundType() != Key.BACKGROUND_TYPE_NORMAL) { 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 7b627fbf3..e59223c93 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 @@ -273,7 +273,7 @@ public final class EmojiPalettesView extends LinearLayout colors.setBackgroundColor(mAlphabetKeyLeft.getBackground(), BackgroundType.FUNCTIONAL); colors.setBackgroundColor(mDeleteKey.getBackground(), BackgroundType.FUNCTIONAL); colors.setBackgroundColor(mSpacebar.getBackground(), BackgroundType.SPACE); - colors.setKeyboardBackground(this); // todo: color on top appears a little darker than on normal keyboard, what is wrong? + colors.setKeyboardBackground(this); mEmojiCategoryPageIndicatorView.setColors(colors.getAccent(), colors.getAdjustedBackground()); } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/BinaryDictionaryGetter.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/BinaryDictionaryGetter.java index c5771e4b3..2b50ecd19 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/BinaryDictionaryGetter.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/BinaryDictionaryGetter.java @@ -187,7 +187,7 @@ final public class BinaryDictionaryGetter { DictionaryInfoUtils.getCategoryFromFileName(wordList.getName()); final FileAndMatchLevel currentBestMatch = cacheFiles.get(category); if (null == currentBestMatch || currentBestMatch.mMatchLevel <= matchLevel) { - // todo: not nice, related to getDictionaryFiles todo + // todo: not nice, related to todo in getDictionaryFiles // this is so user-added main dict has priority over internal main dict // actually any user-added dict has priority, but there aren't any other built-in types if (wordList.getName().endsWith(USER_DICTIONARY_SUFFIX) || currentBestMatch == null) @@ -206,30 +206,6 @@ final public class BinaryDictionaryGetter { return result; } - // ## HACK ## we prevent usage of a dictionary before version 18. The reason for this is, since - // those do not include whitelist entries, the new code with an old version of the dictionary - // would lose whitelist functionality. - private static boolean hackCanUseDictionaryFile(final File file) { - if (!SHOULD_USE_DICT_VERSION) { - return true; - } - - try { - // Read the version of the file - final DictionaryHeader header = BinaryDictionaryUtils.getHeader(file); - final String version = header.mDictionaryOptions.mAttributes.get(VERSION_KEY); - if (null == version) { - // No version in the options : the format is unexpected - return false; - } - // Version 18 is the first one to include the whitelist - // Obviously this is a big ## HACK ## - return Integer.parseInt(version) >= 18; - } catch (IOException | NumberFormatException | BufferUnderflowException | UnsupportedFormatException e) { - return false; - } - } - /** * Returns a list of file addresses for a given locale, trying relevant methods in order. * @@ -245,7 +221,7 @@ final public class BinaryDictionaryGetter { // todo: the way of using assets and cached lists should be improved, so that the assets file // doesn't need to be in cached dir just for checking whether it's a good match public static ArrayList getDictionaryFiles(final Locale locale, - final Context context, boolean notifyDictionaryPackForUpdates, final boolean weakMatchAcceptable) { + final Context context, final boolean weakMatchAcceptable) { loadDictionaryFromAssets(locale.toString(), context, weakMatchAcceptable); // will copy dict to cached word lists if not existing final File[] cachedWordLists = getCachedWordLists(locale.toString(), context, weakMatchAcceptable); final String mainDictId = DictionaryInfoUtils.getMainDictId(locale); @@ -256,10 +232,7 @@ final public class BinaryDictionaryGetter { // cachedWordLists may not be null, see doc for getCachedDictionaryList for (final File f : cachedWordLists) { final String wordListId = DictionaryInfoUtils.getWordListIdFromFileName(f.getName()); - // remove the hack that requires version 18 - // danger of getting an old version is rather low, and user-added dictionaries - // will usually not work as they will likely start at version 1 - final boolean canUse = f.canRead(); // && hackCanUseDictionaryFile(f); + final boolean canUse = f.canRead(); if (canUse && DictionaryInfoUtils.isMainWordListId(wordListId)) { foundMainDict = true; } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFacilitatorImpl.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFacilitatorImpl.java index 4fa2e0799..3479f705e 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFacilitatorImpl.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFacilitatorImpl.java @@ -100,7 +100,13 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator { // todo: these caches are never even set, as the corresponding functions are not called... // and even if they were set, one is only written, but never read, and the other one - // is only read and thus empty and useless -> why? seems they are not needed anyway + // is only read and thus empty and useless -> why? + // anyway, we could just set the same cache using the set functions + // but before doing this, check the potential performance gains + // i.e. how long does a "isValidWord" check take -> on S4 mini 300 µs per dict if ok, but + // sometimes it can also be a few ms + // os if the spell checker is enabled, it's definitely reasonable to cache the results + // but this needs to be done internally, as it should be by language private LruCache mValidSpellingWordReadCache; private LruCache mValidSpellingWordWriteCache; 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 d9ca4048f..9f8764c4c 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 @@ -45,6 +45,11 @@ public final class DictionaryFactory { * @param locale the locale for which to create the dictionary * @return an initialized instance of DictionaryCollection */ + // todo: this should be adjusted + // ONE call to getDictionaryFiles + // should return AssetFileAddress and locale (and maybe match level) + // this should consider the he/iw mess-up + // only if compressed dict needs to be used it should be extracted public static DictionaryCollection createMainDictionaryFromManager(final Context context, final Locale locale) { if (null == locale) { @@ -55,7 +60,7 @@ public final class DictionaryFactory { final LinkedList dictList = new LinkedList<>(); ArrayList assetFileList = - BinaryDictionaryGetter.getDictionaryFiles(locale, context, true, false); + BinaryDictionaryGetter.getDictionaryFiles(locale, context, false); boolean mainFound = false; for (AssetFileAddress fileAddress : assetFileList) { @@ -65,7 +70,7 @@ public final class DictionaryFactory { } } if (!mainFound) // try again and allow weaker match - assetFileList = BinaryDictionaryGetter.getDictionaryFiles(locale, context, true, true); + assetFileList = BinaryDictionaryGetter.getDictionaryFiles(locale, context, true); for (final AssetFileAddress f : assetFileList) { final ReadOnlyBinaryDictionary readOnlyBinaryDictionary = diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/RichInputMethodManager.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/RichInputMethodManager.java index e36ba6edd..cafe7b2c6 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/RichInputMethodManager.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/RichInputMethodManager.java @@ -116,7 +116,7 @@ public class RichInputMethodManager { public @Nullable InputMethodSubtype getNextSubtypeInThisIme(final boolean onlyCurrentIme) { final InputMethodSubtype currentSubtype = getCurrentSubtype().getRawSubtype(); final List enabledSubtypes = getMyEnabledInputMethodSubtypeList(true); - final int currentIndex = getSubtypeIndexInList(currentSubtype, enabledSubtypes); + final int currentIndex = enabledSubtypes.indexOf(currentSubtype); if (currentIndex == INDEX_NOT_FOUND) { Log.w(TAG, "Can't find current subtype in enabled subtypes: subtype=" + SubtypeLocaleUtils.getSubtypeNameForLogging(currentSubtype)); @@ -195,38 +195,17 @@ public class RichInputMethodManager { } public boolean checkIfSubtypeBelongsToThisImeAndEnabled(final InputMethodSubtype subtype) { - return checkIfSubtypeBelongsToList(subtype, - getEnabledInputMethodSubtypeList( - getInputMethodInfoOfThisIme(), - true /* allowsImplicitlySelectedSubtypes */)); + return getEnabledInputMethodSubtypeList(getInputMethodInfoOfThisIme(), true) + .contains(subtype); } - public boolean checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled( - final InputMethodSubtype subtype) { + public boolean checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(final InputMethodSubtype subtype) { final boolean subtypeEnabled = checkIfSubtypeBelongsToThisImeAndEnabled(subtype); - final boolean subtypeExplicitlyEnabled = checkIfSubtypeBelongsToList(subtype, - getMyEnabledInputMethodSubtypeList(false /* allowsImplicitlySelectedSubtypes */)); + final boolean subtypeExplicitlyEnabled = getMyEnabledInputMethodSubtypeList(false) + .contains(subtype); return subtypeEnabled && !subtypeExplicitlyEnabled; } - private static boolean checkIfSubtypeBelongsToList(final InputMethodSubtype subtype, - final List subtypes) { - return getSubtypeIndexInList(subtype, subtypes) != INDEX_NOT_FOUND; - } - - private static int getSubtypeIndexInList(final InputMethodSubtype subtype, - final List subtypes) { - // todo: why not simply subtypes.indexOf(subtype)? should do exactly the same, even return the same value -1 if not found - final int count = subtypes.size(); - for (int index = 0; index < count; index++) { - final InputMethodSubtype ims = subtypes.get(index); - if (ims.equals(subtype)) { - return index; - } - } - return INDEX_NOT_FOUND; - } - public void onSubtypeChanged(@NonNull final InputMethodSubtype newSubtype) { updateCurrentSubtype(newSubtype); updateShortcutIme(); 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 37311c7e0..f8e0f9e65 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 @@ -39,10 +39,6 @@ class Colors ( // 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 - // workaround for error in ClipboardHistoryRecyclerView - // java.lang.IllegalAccessError: Field 'org.dslul.openboard.inputmethod.latin.common.Colors.backgroundFilter' is inaccessible to class 'org.dslul.openboard.inputmethod.keyboard.clipboard.ClipboardHistoryRecyclerView$BottomDividerItemDecoration' - // this should not happen, maybe it's a bug in kotlin? because it also doesn't recognize if the filter is accessed there, and wants to set it private - fun getThatBackgroundFilter() = backgroundFilter val adjustedBackgroundFilter: ColorFilter val keyBackgroundFilter: ColorFilter val functionalKeyBackgroundFilter: ColorFilter 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 e791d93ac..3cf10fda1 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 @@ -62,14 +62,6 @@ public class DictionaryInfoUtils { private static final int MAX_HEX_DIGITS_FOR_CODEPOINT = 6; public static class DictionaryInfo { - private static final String LOCALE_COLUMN = "locale"; - private static final String WORDLISTID_COLUMN = "id"; - private static final String LOCAL_FILENAME_COLUMN = "filename"; - private static final String DESCRIPTION_COLUMN = "description"; - private static final String DATE_COLUMN = "date"; - private static final String FILESIZE_COLUMN = "filesize"; - private static final String VERSION_COLUMN = "version"; - @NonNull public final String mId; @NonNull public final Locale mLocale; @Nullable public final String mDescription; @@ -90,18 +82,6 @@ public class DictionaryInfoUtils { mVersion = version; } - public ContentValues toContentValues() { - final ContentValues values = new ContentValues(); - values.put(WORDLISTID_COLUMN, mId); - values.put(LOCALE_COLUMN, mLocale.toString()); - values.put(DESCRIPTION_COLUMN, mDescription); - values.put(LOCAL_FILENAME_COLUMN, mFilename != null ? mFilename : ""); - values.put(DATE_COLUMN, TimeUnit.MILLISECONDS.toSeconds(mModifiedTimeMillis)); - values.put(FILESIZE_COLUMN, mFilesize); - values.put(VERSION_COLUMN, mVersion); - return values; - } - @Override public String toString() { return "DictionaryInfo : Id = '" + mId diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 010c63eba..5926d88ed 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -1,6 +1,7 @@ + #FFF #BBB #666 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index a3c9c8236..8c117d8ab 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -97,7 +97,7 @@ #FFCCCCCC - ?android:colorForeground + #000 #555 #AAA #1A73E8