package com.hughes.android.dictionary;
-import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
-import android.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceManager;
import android.support.v4.view.MenuItemCompat;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
-import android.view.View;
-import android.widget.Button;
-import android.widget.ImageButton;
-import android.widget.ImageView.ScaleType;
-import android.widget.LinearLayout;
-import android.widget.Toast;
-
-import com.hughes.android.dictionary.CollatorWrapper;
+
import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
import com.hughes.android.dictionary.engine.Dictionary;
-import com.hughes.android.dictionary.engine.Language;
-import com.hughes.android.dictionary.engine.Language.LanguageResources;
import com.hughes.android.dictionary.engine.TransliteratorManager;
import com.hughes.android.util.PersistentObjectCache;
import com.hughes.util.ListUtil;
// Leave it enabled by default for correctness except
// for my known broken development/performance test device config.
//static public final boolean USE_COLLATOR = !android.os.Build.FINGERPRINT.equals("Samsung/cm_tassve/tassve:4.4.4/KTU84Q/20150211:userdebug/release-keys");
- static public final boolean USE_COLLATOR = true;
+ public static final boolean USE_COLLATOR = true;
- static public final TransliteratorManager.ThreadSetup threadBackground = new TransliteratorManager.ThreadSetup() {
+ public static final TransliteratorManager.ThreadSetup threadBackground = new TransliteratorManager.ThreadSetup() {
@Override
public void onThreadStart() {
// THREAD_PRIORITY_BACKGROUND seemed like a good idea, but it
private static final long serialVersionUID = -1444177164708201263L;
// User-ordered list, persisted, just the ones that are/have been
// present.
- final List<String> dictionaryFilesOrdered = new ArrayList<String>();
+ final List<String> dictionaryFilesOrdered = new ArrayList<>();
- final Map<String, DictionaryInfo> uncompressedFilenameToDictionaryInfo = new HashMap<String, DictionaryInfo>();
+ final Map<String, DictionaryInfo> uncompressedFilenameToDictionaryInfo = new HashMap<>();
/**
* Sometimes a deserialized version of this data structure isn't valid.
- * @return
*/
+ @SuppressWarnings("ConstantConditions")
boolean isValid() {
return uncompressedFilenameToDictionaryInfo != null && dictionaryFilesOrdered != null;
}
if (DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO != null) {
return;
}
- DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = new HashMap<String, DictionaryInfo>();
+ DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = new HashMap<>();
final BufferedReader reader = new BufferedReader(
new InputStreamReader(context.getResources().openRawResource(R.raw.dictionary_info)));
try {
}
try {
reader.close();
- } catch (IOException e) {}
+ } catch (IOException ignored) {}
}
- private File dictDir;
-
public synchronized void init(Context c) {
if (appContext != null) {
assert c == appContext;
File efd = null;
try {
efd = appContext.getExternalFilesDir(null);
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
if (efd != null) {
efd.mkdirs();
if (dir.isEmpty()) {
dir = selectDefaultDir();
}
- dictDir = new File(dir);
+ File dictDir = new File(dir);
dictDir.mkdirs();
if (!dictDir.isDirectory() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
appContext.getExternalFilesDirs(null);
return dictDir;
}
- static public boolean checkFileCreate(File dir) {
+ public static boolean checkFileCreate(File dir) {
boolean res = false;
File testfile = new File(dir, "quickdic_writetest");
try {
testfile.delete();
res = testfile.createNewFile() & testfile.delete();
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
return res;
}
public Theme getSelectedTheme() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
- final String theme = prefs.getString(appContext.getString(R.string.themeKey), "themeLight");
+ final String theme = prefs.getString(appContext.getString(R.string.themeKey), "themeSystem");
if (theme.equals("themeLight")) {
return Theme.LIGHT;
+ } else if (theme.equals("themeSystem")) {
+ int mode = (appContext.getResources().getConfiguration().uiMode &
+ Configuration.UI_MODE_NIGHT_MASK);
+ return ((mode == Configuration.UI_MODE_NIGHT_NO) ?
+ Theme.LIGHT:
+ Theme.DEFAULT);
} else {
return Theme.DEFAULT;
}
String defaultLangISO2 = Locale.getDefault().getLanguage().toLowerCase();
String defaultLangName = null;
- final Map<String, String> fileToNameCache = new HashMap<String, String>();
+ final Map<String, String> fileToNameCache = new HashMap<>();
public List<IndexInfo> sortedIndexInfos(List<IndexInfo> indexInfos) {
// Hack to put the default locale first in the name.
if (indexInfos.size() > 1 &&
indexInfos.get(1).shortName.toLowerCase().equals(defaultLangISO2)) {
- List<IndexInfo> result = new ArrayList<DictionaryInfo.IndexInfo>(indexInfos);
+ List<IndexInfo> result = new ArrayList<>(indexInfos);
ListUtil.swap(result, 0, 1);
return result;
}
PersistentObjectCache.getInstance().write(C.DICTIONARY_CONFIGS, dictionaryConfig);
}
- final Comparator collator = USE_COLLATOR ? CollatorWrapper.getInstance() : String.CASE_INSENSITIVE_ORDER;
+ final Comparator<Object> collator = USE_COLLATOR ? CollatorWrapper.getInstance() : null;
final Comparator<String> uncompressedFilenameComparator = new Comparator<String>() {
@Override
public int compare(String uncompressedFilename1, String uncompressedFilename2) {
&& !name2.startsWith(defaultLangName + "-")) {
return -1;
} else if (name2.startsWith(defaultLangName + "-")
- && !name1.startsWith(defaultLangName + "-")) {
+ && !name1.startsWith(defaultLangName + "-")) {
return 1;
}
}
- return collator.compare(name1, name2);
+ return collator != null ? collator.compare(name1, name2) : name1.compareToIgnoreCase(name2);
}
};
final Comparator<DictionaryInfo> dictionaryInfoComparator = new Comparator<DictionaryInfo>() {
// Are there dictionaries on the device that we didn't know
// about already?
// Pick them up and put them at the end of the list.
- final List<String> toAddSorted = new ArrayList<String>();
+ final List<String> toAddSorted = new ArrayList<>();
final File[] dictDirFiles = getDictDir().listFiles();
if (dictDirFiles != null) {
for (final File file : dictDirFiles) {
}).start();
}
- public boolean matchesFilters(final DictionaryInfo dictionaryInfo, final String[] filters) {
+ private boolean matchesFilters(final DictionaryInfo dictionaryInfo, final String[] filters) {
if (filters == null) {
return true;
}
}
public synchronized List<DictionaryInfo> getDictionariesOnDevice(String[] filters) {
- final List<DictionaryInfo> result = new ArrayList<DictionaryInfo>(
- dictionaryConfig.dictionaryFilesOrdered.size());
+ final List<DictionaryInfo> result = new ArrayList<>(
+ dictionaryConfig.dictionaryFilesOrdered.size());
for (final String uncompressedFilename : dictionaryConfig.dictionaryFilesOrdered) {
final DictionaryInfo dictionaryInfo = dictionaryConfig.uncompressedFilenameToDictionaryInfo
.get(uncompressedFilename);
}
public List<DictionaryInfo> getDownloadableDictionaries(String[] filters) {
- final List<DictionaryInfo> result = new ArrayList<DictionaryInfo>(
- dictionaryConfig.dictionaryFilesOrdered.size());
+ final List<DictionaryInfo> result = new ArrayList<>(
+ dictionaryConfig.dictionaryFilesOrdered.size());
- final Map<String, DictionaryInfo> remaining = new HashMap<String, DictionaryInfo>(
- DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO);
+ final Map<String, DictionaryInfo> remaining = new HashMap<>(
+ DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO);
remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered);
for (final DictionaryInfo dictionaryInfo : remaining.values()) {
if (matchesFilters(dictionaryInfo, filters)) {
return result;
}
- public synchronized boolean isDictionaryOnDevice(String uncompressedFilename) {
- return dictionaryConfig.uncompressedFilenameToDictionaryInfo.get(uncompressedFilename) != null;
- }
-
public boolean updateAvailable(final DictionaryInfo dictionaryInfo) {
final DictionaryInfo downloadable =
DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.get(
}
public DictionaryInfo getDownloadable(final String uncompressedFilename) {
- final DictionaryInfo downloadable = DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO
- .get(uncompressedFilename);
- return downloadable;
+ return DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.get(uncompressedFilename);
}
}