mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-24 08:36:26 +00:00
remove unused / unneeded code
This commit is contained in:
parent
d6769f6d65
commit
58ddee786e
11 changed files with 14 additions and 409 deletions
|
@ -4,7 +4,7 @@
|
|||
-->
|
||||
<resources>
|
||||
<string name="english_ime_name" translatable="false">OpenBoard debug</string>
|
||||
<string name="spell_checker_service_name">OpenBoard debug Spell Checker</string>
|
||||
<string name="ime_settings">OpenBoard debug Settings</string>
|
||||
<string name="spell_checker_service_name" translatable="false">OpenBoard debug Spell Checker</string>
|
||||
<string name="ime_settings" translatable="false">OpenBoard debug Settings</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
package org.dslul.openboard.inputmethod.latin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.dslul.openboard.inputmethod.latin.makedict.DictionaryHeader;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.DictionaryInfoUtils;
|
||||
|
||||
|
@ -25,25 +25,17 @@ import java.util.Locale;
|
|||
* Factory for dictionary instances.
|
||||
*/
|
||||
public final class DictionaryFactory {
|
||||
private static final String TAG = DictionaryFactory.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Initializes a main dictionary collection from a dictionary pack, with explicit flags.
|
||||
*
|
||||
* <p>
|
||||
* This searches for a content provider providing a dictionary pack for the specified
|
||||
* locale. If none is found, it falls back to the built-in dictionary - if any.
|
||||
* @param context application context for reading resources
|
||||
* @param locale the locale for which to create the dictionary
|
||||
* @return an initialized instance of DictionaryCollection
|
||||
*/
|
||||
public static DictionaryCollection createMainDictionaryFromManager(final Context context,
|
||||
final Locale locale) {
|
||||
if (null == locale) {
|
||||
Log.e(TAG, "No locale defined for dictionary");
|
||||
return new DictionaryCollection(Dictionary.TYPE_MAIN, locale,
|
||||
createReadOnlyBinaryDictionary(context, locale));
|
||||
}
|
||||
|
||||
public static DictionaryCollection createMainDictionaryFromManager(final Context context, @NonNull final Locale locale) {
|
||||
final LinkedList<Dictionary> dictList = new LinkedList<>();
|
||||
ArrayList<AssetFileAddress> assetFileList =
|
||||
BinaryDictionaryGetter.getDictionaryFiles(locale, context, false);
|
||||
|
@ -104,45 +96,4 @@ public final class DictionaryFactory {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a read-only binary dictionary from a raw resource file
|
||||
* @param context application context for reading resources
|
||||
* @param locale the locale to use for the resource
|
||||
* @return an initialized instance of ReadOnlyBinaryDictionary
|
||||
*/
|
||||
private static ReadOnlyBinaryDictionary createReadOnlyBinaryDictionary(final Context context,
|
||||
final Locale locale) {
|
||||
AssetFileDescriptor afd = null;
|
||||
try {
|
||||
final int resId = DictionaryInfoUtils.getMainDictionaryResourceIdIfAvailableForLocale(
|
||||
context.getResources(), locale);
|
||||
if (0 == resId) return null;
|
||||
afd = context.getResources().openRawResourceFd(resId);
|
||||
if (afd == null) {
|
||||
Log.e(TAG, "Found the resource but it is compressed. resId=" + resId);
|
||||
return null;
|
||||
}
|
||||
final String sourceDir = context.getApplicationInfo().sourceDir;
|
||||
final File packagePath = new File(sourceDir);
|
||||
// TODO: Come up with a way to handle a directory.
|
||||
if (!packagePath.isFile()) {
|
||||
Log.e(TAG, "sourceDir is not a file: " + sourceDir);
|
||||
return null;
|
||||
}
|
||||
return new ReadOnlyBinaryDictionary(sourceDir, afd.getStartOffset(), afd.getLength(),
|
||||
false /* useFullEditDistance */, locale, Dictionary.TYPE_MAIN);
|
||||
} catch (android.content.res.Resources.NotFoundException e) {
|
||||
Log.e(TAG, "Could not find the resource");
|
||||
return null;
|
||||
} finally {
|
||||
if (null != afd) {
|
||||
try {
|
||||
afd.close();
|
||||
} catch (java.io.IOException e) {
|
||||
/* IOException on close ? What am I supposed to do ? */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ import org.dslul.openboard.inputmethod.latin.settings.SettingsValues;
|
|||
import org.dslul.openboard.inputmethod.latin.suggestions.SuggestionStripView;
|
||||
import org.dslul.openboard.inputmethod.latin.suggestions.SuggestionStripViewAccessor;
|
||||
import org.dslul.openboard.inputmethod.latin.touchinputconsumer.GestureConsumer;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.ApplicationUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.ColorUtilKt;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.InlineAutofillUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.InputMethodPickerKt;
|
||||
|
@ -2008,8 +2007,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
|
||||
final Printer p = new PrintWriterPrinter(fout);
|
||||
p.println("LatinIME state :");
|
||||
p.println(" VersionCode = " + ApplicationUtils.getVersionCode(this));
|
||||
p.println(" VersionName = " + ApplicationUtils.getVersionName(this));
|
||||
p.println(" VersionCode = " + BuildConfig.VERSION_CODE);
|
||||
p.println(" VersionName = " + BuildConfig.VERSION_NAME);
|
||||
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
||||
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
|
||||
p.println(" Keyboard mode = " + keyboardMode);
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.dslul.openboard.inputmethod.latin.BuildConfig;
|
|||
import org.dslul.openboard.inputmethod.latin.DictionaryDumpBroadcastReceiver;
|
||||
import org.dslul.openboard.inputmethod.latin.DictionaryFacilitatorImpl;
|
||||
import org.dslul.openboard.inputmethod.latin.R;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.ApplicationUtils;
|
||||
|
||||
/**
|
||||
* "Debug mode" settings sub screen.
|
||||
|
@ -109,7 +108,7 @@ public final class DebugSettingsFragment extends SubScreenFragment
|
|||
}
|
||||
|
||||
private void updateDebugMode() {
|
||||
final String version = getString(R.string.version_text, ApplicationUtils.getVersionName(getActivity()));
|
||||
final String version = getString(R.string.version_text, BuildConfig.VERSION_NAME);
|
||||
mDebugMode.setSummary(version);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,7 @@ package org.dslul.openboard.inputmethod.latin.settings;
|
|||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
|
@ -22,13 +20,11 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import org.dslul.openboard.inputmethod.latin.BuildConfig;
|
||||
import org.dslul.openboard.inputmethod.latin.R;
|
||||
import org.dslul.openboard.inputmethod.latin.common.FileUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.define.DebugFlags;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.ApplicationUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.DictionaryUtilsKt;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.ExecutorUtils;
|
||||
|
@ -57,11 +53,9 @@ public final class SettingsFragment extends PreferenceFragmentCompat {
|
|||
@Override
|
||||
public void onCreatePreferences(@Nullable Bundle bundle, @Nullable String s) {
|
||||
addPreferencesFromResource(R.xml.prefs);
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
preferenceScreen.setTitle(ApplicationUtils.getActivityTitleResId(getActivity(), SettingsActivity.class));
|
||||
if (!JniUtils.sHaveGestureLib) {
|
||||
final Preference gesturePreference = findPreference(Settings.SCREEN_GESTURE);
|
||||
preferenceScreen.removePreference(gesturePreference);
|
||||
getPreferenceScreen().removePreference(gesturePreference);
|
||||
}
|
||||
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD)
|
||||
.execute(() -> DictionaryUtilsKt.cleanUnusedMainDicts(requireContext()));
|
||||
|
@ -89,13 +83,6 @@ public final class SettingsFragment extends PreferenceFragmentCompat {
|
|||
askAboutCrashReports();
|
||||
}
|
||||
|
||||
private static boolean isUserSetupComplete(final Activity activity) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
return true;
|
||||
}
|
||||
return Secure.getInt(activity.getContentResolver(), "user_setup_complete", 0) != 0;
|
||||
}
|
||||
|
||||
private String getEnabledSubtypesLabel() {
|
||||
final List<InputMethodSubtype> subtypes = SubtypeSettingsKt.getEnabledSubtypes(DeviceProtectedUtils.getSharedPreferences(getActivity()), true);
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
|
|
@ -15,11 +15,7 @@ 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.ApplicationUtils;
|
||||
|
||||
import static org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager.get;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreferenceCompat;
|
||||
|
||||
/**
|
||||
|
@ -35,21 +31,13 @@ public final class SpellCheckerSettingsFragment extends SubScreenFragment
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.spell_checker_settings);
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
preferenceScreen.setTitle(ApplicationUtils.getActivityTitleResId(getActivity(), SpellCheckerSettingsActivity.class));
|
||||
|
||||
mLookupContactsPreference = (SwitchPreferenceCompat) findPreference(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY);
|
||||
turnOffLookupContactsIfNoPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (!TextUtils.equals(key, AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sharedPreferences.getBoolean(key, false)) {
|
||||
// don't care if the preference is turned off.
|
||||
if (!TextUtils.equals(key, AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY) || sharedPreferences.getBoolean(key, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -58,7 +46,7 @@ public final class SpellCheckerSettingsFragment extends SubScreenFragment
|
|||
return; // all permissions granted, no need to request permissions.
|
||||
}
|
||||
|
||||
get(requireContext()).requestPermissions(this, getActivity(), Manifest.permission.READ_CONTACTS);
|
||||
PermissionsManager.get(requireContext()).requestPermissions(this, getActivity(), Manifest.permission.READ_CONTACTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2013 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 android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.Log;
|
||||
|
||||
public final class ApplicationUtils {
|
||||
private static final String TAG = ApplicationUtils.class.getSimpleName();
|
||||
|
||||
private ApplicationUtils() {
|
||||
// This utility class is not publicly instantiable.
|
||||
}
|
||||
|
||||
public static int getActivityTitleResId(final Context context,
|
||||
final Class<? extends Activity> cls) {
|
||||
final ComponentName cn = new ComponentName(context, cls);
|
||||
try {
|
||||
final ActivityInfo ai = context.getPackageManager().getActivityInfo(cn, 0);
|
||||
if (ai != null) {
|
||||
return ai.labelRes;
|
||||
}
|
||||
} catch (final NameNotFoundException e) {
|
||||
Log.e(TAG, "Failed to get settings activity title res id.", e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility method to get the application's PackageInfo.versionName
|
||||
* @return the application's PackageInfo.versionName
|
||||
*/
|
||||
public static String getVersionName(final Context context) {
|
||||
try {
|
||||
if (context == null) {
|
||||
return "";
|
||||
}
|
||||
final String packageName = context.getPackageName();
|
||||
final PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
|
||||
return info.versionName;
|
||||
} catch (final NameNotFoundException e) {
|
||||
Log.e(TAG, "Could not find version info.", e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility method to get the application's PackageInfo.versionCode
|
||||
* @return the application's PackageInfo.versionCode
|
||||
*/
|
||||
public static int getVersionCode(final Context context) {
|
||||
try {
|
||||
if (context == null) {
|
||||
return 0;
|
||||
}
|
||||
final String packageName = context.getPackageName();
|
||||
final PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
|
||||
return info.versionCode;
|
||||
} catch (final NameNotFoundException e) {
|
||||
Log.e(TAG, "Could not find version info.", e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
package org.dslul.openboard.inputmethod.latin.utils;
|
||||
|
||||
import org.dslul.openboard.inputmethod.latin.utils.Log;
|
||||
|
||||
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
|
||||
|
||||
import org.dslul.openboard.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||
|
|
|
@ -7,10 +7,7 @@
|
|||
package org.dslul.openboard.inputmethod.latin.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.text.TextUtils;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -18,11 +15,7 @@ import androidx.annotation.Nullable;
|
|||
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
|
||||
|
||||
import org.dslul.openboard.inputmethod.annotations.UsedForTesting;
|
||||
import org.dslul.openboard.inputmethod.latin.AssetFileAddress;
|
||||
import org.dslul.openboard.inputmethod.latin.BinaryDictionaryGetter;
|
||||
import org.dslul.openboard.inputmethod.latin.R;
|
||||
import org.dslul.openboard.inputmethod.latin.RichInputMethodManager;
|
||||
import org.dslul.openboard.inputmethod.latin.common.LocaleUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.define.DecoderSpecificConstants;
|
||||
import org.dslul.openboard.inputmethod.latin.makedict.DictionaryHeader;
|
||||
import org.dslul.openboard.inputmethod.latin.makedict.UnsupportedFormatException;
|
||||
|
@ -30,9 +23,6 @@ import org.dslul.openboard.inputmethod.latin.settings.SpacingAndPunctuations;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
@ -40,43 +30,12 @@ import java.util.Locale;
|
|||
*/
|
||||
public class DictionaryInfoUtils {
|
||||
private static final String TAG = DictionaryInfoUtils.class.getSimpleName();
|
||||
public static final String RESOURCE_PACKAGE_NAME = R.class.getPackage().getName();
|
||||
public static final String DEFAULT_MAIN_DICT = "main";
|
||||
public static final String MAIN_DICT_PREFIX = DEFAULT_MAIN_DICT + "_";
|
||||
private static final String DICTIONARY_CATEGORY_SEPARATOR_EXPRESSION = "[" + BinaryDictionaryGetter.ID_CATEGORY_SEPARATOR + "_]";
|
||||
private static final String DECODER_DICT_SUFFIX = DecoderSpecificConstants.DECODER_DICT_SUFFIX;
|
||||
// 6 digits - unicode is limited to 21 bits
|
||||
private static final int MAX_HEX_DIGITS_FOR_CODEPOINT = 6;
|
||||
|
||||
public static class DictionaryInfo {
|
||||
@NonNull public final String mId;
|
||||
@NonNull public final Locale mLocale;
|
||||
@Nullable public final String mDescription;
|
||||
@Nullable public final String mFilename;
|
||||
public final long mFilesize;
|
||||
public final long mModifiedTimeMillis;
|
||||
public final int mVersion;
|
||||
|
||||
public DictionaryInfo(@NonNull String id, @NonNull Locale locale,
|
||||
@Nullable String description, @Nullable String filename,
|
||||
long filesize, long modifiedTimeMillis, int version) {
|
||||
mId = id;
|
||||
mLocale = locale;
|
||||
mDescription = description;
|
||||
mFilename = filename;
|
||||
mFilesize = filesize;
|
||||
mModifiedTimeMillis = modifiedTimeMillis;
|
||||
mVersion = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DictionaryInfo : Id = '" + mId
|
||||
+ "' : Locale=" + mLocale
|
||||
+ " : Version=" + mVersion;
|
||||
}
|
||||
}
|
||||
|
||||
private DictionaryInfoUtils() {
|
||||
// Private constructor to forbid instantation of this helper class.
|
||||
}
|
||||
|
@ -124,13 +83,6 @@ public class DictionaryInfoUtils {
|
|||
return context.getFilesDir() + File.separator + "dicts";
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the top level cache directory.
|
||||
*/
|
||||
public static String getWordListStagingDirectory(final Context context) {
|
||||
return context.getFilesDir() + File.separator + "staging";
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the top level temp directory.
|
||||
*/
|
||||
|
@ -167,10 +119,6 @@ public class DictionaryInfoUtils {
|
|||
return new File(DictionaryInfoUtils.getWordListCacheDirectory(context)).listFiles();
|
||||
}
|
||||
|
||||
public static File[] getStagingDirectoryList(final Context context) {
|
||||
return new File(DictionaryInfoUtils.getWordListStagingDirectory(context)).listFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the category for a given file name.
|
||||
* <p>
|
||||
|
@ -219,60 +167,6 @@ public class DictionaryInfoUtils {
|
|||
return BinaryDictionaryGetter.MAIN_DICTIONARY_CATEGORY.equals(idArray[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out whether a dictionary is available for this locale.
|
||||
* @param context the context on which to check resources.
|
||||
* @param locale the locale to check for.
|
||||
* @return whether a (non-placeholder) dictionary is available or not.
|
||||
*/
|
||||
public static boolean isDictionaryAvailable(final Context context, final Locale locale) {
|
||||
final Resources res = context.getResources();
|
||||
return 0 != getMainDictionaryResourceIdIfAvailableForLocale(res, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to return a dictionary res id for a locale, or 0 if none.
|
||||
* @param res resources for the app
|
||||
* @param locale dictionary locale
|
||||
* @return main dictionary resource id
|
||||
*/
|
||||
public static int getMainDictionaryResourceIdIfAvailableForLocale(final Resources res,
|
||||
final Locale locale) {
|
||||
int resId;
|
||||
// Try to find main_language_country dictionary.
|
||||
if (!locale.getCountry().isEmpty()) {
|
||||
final String dictLanguageCountry = MAIN_DICT_PREFIX
|
||||
+ locale.toString().toLowerCase(Locale.ROOT) + DECODER_DICT_SUFFIX;
|
||||
if ((resId = res.getIdentifier(dictLanguageCountry, "raw", RESOURCE_PACKAGE_NAME)) != 0) {
|
||||
return resId;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to find main_language dictionary.
|
||||
final String dictLanguage = MAIN_DICT_PREFIX + locale.getLanguage() + DECODER_DICT_SUFFIX;
|
||||
if ((resId = res.getIdentifier(dictLanguage, "raw", RESOURCE_PACKAGE_NAME)) != 0) {
|
||||
return resId;
|
||||
}
|
||||
|
||||
// Not found, return 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a main dictionary resource id
|
||||
* @param res resources for the app
|
||||
* @param locale dictionary locale
|
||||
* @return main dictionary resource id
|
||||
*/
|
||||
public static int getMainDictionaryResourceId(final Resources res, final Locale locale) {
|
||||
int resourceId = getMainDictionaryResourceIdIfAvailableForLocale(res, locale);
|
||||
if (0 != resourceId) {
|
||||
return resourceId;
|
||||
}
|
||||
return res.getIdentifier(DEFAULT_MAIN_DICT + DecoderSpecificConstants.DECODER_DICT_SUFFIX,
|
||||
"raw", RESOURCE_PACKAGE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id associated with the main word list for a specified locale.
|
||||
* <p>
|
||||
|
@ -308,145 +202,6 @@ public class DictionaryInfoUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information of the dictionary.
|
||||
*
|
||||
* @param fileAddress the asset dictionary file address.
|
||||
* @param locale Locale for this file.
|
||||
* @return information of the specified dictionary.
|
||||
*/
|
||||
private static DictionaryInfo createDictionaryInfoFromFileAddress(
|
||||
@NonNull final AssetFileAddress fileAddress, final Locale locale) {
|
||||
final String id = getMainDictId(locale);
|
||||
final int version = DictionaryHeaderUtils.getContentVersion(fileAddress);
|
||||
final String description = SubtypeLocaleUtils
|
||||
.getSubtypeLocaleDisplayName(locale.toString());
|
||||
// Do not store the filename on db as it will try to move the filename from db to the
|
||||
// cached directory. If the filename is already in cached directory, this is not
|
||||
// necessary.
|
||||
final String filenameToStoreOnDb = null;
|
||||
return new DictionaryInfo(id, locale, description, filenameToStoreOnDb,
|
||||
fileAddress.mLength, new File(fileAddress.mFilename).lastModified(), version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the information of the dictionary for the given {@link AssetFileAddress}.
|
||||
* If the file is corrupted or a pre-fava file, then the file gets deleted and the null
|
||||
* value is returned.
|
||||
*/
|
||||
@Nullable
|
||||
private static DictionaryInfo createDictionaryInfoForUnCachedFile(
|
||||
@NonNull final AssetFileAddress fileAddress, final Locale locale) {
|
||||
final String id = getMainDictId(locale);
|
||||
final int version = DictionaryHeaderUtils.getContentVersion(fileAddress);
|
||||
|
||||
if (version == -1) {
|
||||
// Purge the pre-fava/corrupted unused dictionaires.
|
||||
fileAddress.deleteUnderlyingFile();
|
||||
return null;
|
||||
}
|
||||
|
||||
final String description = SubtypeLocaleUtils
|
||||
.getSubtypeLocaleDisplayName(locale.toString());
|
||||
|
||||
final File unCachedFile = new File(fileAddress.mFilename);
|
||||
// Store just the filename and not the full path.
|
||||
final String filenameToStoreOnDb = unCachedFile.getName();
|
||||
return new DictionaryInfo(id, locale, description, filenameToStoreOnDb, fileAddress.mLength,
|
||||
unCachedFile.lastModified(), version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns dictionary information for the given locale.
|
||||
*/
|
||||
private static DictionaryInfo createDictionaryInfoFromLocale(Locale locale) {
|
||||
final String id = getMainDictId(locale);
|
||||
final int version = -1;
|
||||
final String description = SubtypeLocaleUtils
|
||||
.getSubtypeLocaleDisplayName(locale.toString());
|
||||
return new DictionaryInfo(id, locale, description, null, 0L, 0L, version);
|
||||
}
|
||||
|
||||
private static void addOrUpdateDictInfo(final ArrayList<DictionaryInfo> dictList,
|
||||
final DictionaryInfo newElement) {
|
||||
final Iterator<DictionaryInfo> iter = dictList.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final DictionaryInfo thisDictInfo = iter.next();
|
||||
if (thisDictInfo.mLocale.equals(newElement.mLocale)) {
|
||||
if (newElement.mVersion <= thisDictInfo.mVersion) {
|
||||
return;
|
||||
}
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
dictList.add(newElement);
|
||||
}
|
||||
|
||||
public static ArrayList<DictionaryInfo> getCurrentDictionaryFileNameAndVersionInfo(final Context context) {
|
||||
final ArrayList<DictionaryInfo> dictList = new ArrayList<>();
|
||||
|
||||
// Retrieve downloaded dictionaries from cached directories
|
||||
final File[] directoryList = getCachedDirectoryList(context);
|
||||
if (null != directoryList) {
|
||||
for (final File directory : directoryList) {
|
||||
final String localeString = getWordListIdFromFileName(directory.getName());
|
||||
final File[] dicts = BinaryDictionaryGetter.getCachedWordLists(
|
||||
localeString, context, false);
|
||||
for (final File dict : dicts) {
|
||||
final String wordListId = getWordListIdFromFileName(dict.getName());
|
||||
if (!DictionaryInfoUtils.isMainWordListId(wordListId)) {
|
||||
continue;
|
||||
}
|
||||
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
|
||||
final AssetFileAddress fileAddress = AssetFileAddress.makeFromFile(dict);
|
||||
final DictionaryInfo dictionaryInfo = createDictionaryInfoFromFileAddress(fileAddress, locale);
|
||||
// Protect against cases of a less-specific dictionary being found, like an
|
||||
// en dictionary being used for an en_US locale. In this case, the en dictionary
|
||||
// should be used for en_US but discounted for listing purposes.
|
||||
if (dictionaryInfo == null || !dictionaryInfo.mLocale.equals(locale)) {
|
||||
continue;
|
||||
}
|
||||
addOrUpdateDictInfo(dictList, dictionaryInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve files from assets
|
||||
final Resources resources = context.getResources();
|
||||
final AssetManager assets = resources.getAssets();
|
||||
for (final String localeString : assets.getLocales()) {
|
||||
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
|
||||
final int resourceId =
|
||||
DictionaryInfoUtils.getMainDictionaryResourceIdIfAvailableForLocale(context.getResources(), locale);
|
||||
if (0 == resourceId) {
|
||||
continue;
|
||||
}
|
||||
final AssetFileAddress fileAddress = BinaryDictionaryGetter.loadFallbackResource(context, resourceId);
|
||||
final DictionaryInfo dictionaryInfo = createDictionaryInfoFromFileAddress(fileAddress, locale);
|
||||
// Protect against cases of a less-specific dictionary being found, like an
|
||||
// en dictionary being used for an en_US locale. In this case, the en dictionary
|
||||
// should be used for en_US but discounted for listing purposes.
|
||||
// TODO: Remove dictionaryInfo == null when the static LMs have the headers.
|
||||
if (dictionaryInfo == null || !dictionaryInfo.mLocale.equals(locale)) {
|
||||
continue;
|
||||
}
|
||||
addOrUpdateDictInfo(dictList, dictionaryInfo);
|
||||
}
|
||||
|
||||
// Generate the dictionary information from the enabled subtypes. This will not
|
||||
// overwrite the real records.
|
||||
RichInputMethodManager.init(context);
|
||||
List<InputMethodSubtype> enabledSubtypes = RichInputMethodManager
|
||||
.getInstance().getMyEnabledInputMethodSubtypeList(true);
|
||||
for (InputMethodSubtype subtype : enabledSubtypes) {
|
||||
Locale locale = LocaleUtils.constructLocaleFromString(subtype.getLocale());
|
||||
DictionaryInfo dictionaryInfo = createDictionaryInfoFromLocale(locale);
|
||||
addOrUpdateDictInfo(dictList, dictionaryInfo);
|
||||
}
|
||||
|
||||
return dictList;
|
||||
}
|
||||
|
||||
@UsedForTesting
|
||||
public static boolean looksValidForDictionaryInsertion(final CharSequence text,
|
||||
final SpacingAndPunctuations spacingAndPunctuations) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
||||
-->
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:key="english_ime_settings">
|
||||
android:title="@string/ime_settings">
|
||||
<PreferenceScreen
|
||||
android:fragment="org.dslul.openboard.inputmethod.latin.settings.LanguageSettingsFragment"
|
||||
android:title="@string/language_selection_title"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
-->
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/android_spell_checker_settings"
|
||||
>
|
||||
<SwitchPreferenceCompat
|
||||
android:key="pref_spellcheck_use_contacts"
|
||||
|
|
Loading…
Add table
Reference in a new issue