+ final MenuItem help = menu.add(c.getString(R.string.help));
+ MenuItemCompat.setShowAsAction(help, MenuItem.SHOW_AS_ACTION_NEVER);
+ help.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ public boolean onMenuItemClick(final MenuItem menuItem) {
+ context.startActivity(HtmlDisplayActivity.getHelpLaunchIntent(c));
+ return false;
+ }
+ });
+
+ final MenuItem reportIssue = menu.add(c.getString(R.string.reportIssue));
+ MenuItemCompat.setShowAsAction(reportIssue, MenuItem.SHOW_AS_ACTION_NEVER);
+ reportIssue.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ public boolean onMenuItemClick(final MenuItem menuItem) {
+ final Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(Uri
+ .parse("https://github.com/rdoeffinger/Dictionary/issues"));
+ context.startActivity(intent);
+ return false;
+ }
+ });
+
+ final MenuItem about = menu.add(c.getString(R.string.about));
+ MenuItemCompat.setShowAsAction(about, MenuItem.SHOW_AS_ACTION_NEVER);
+ about.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ public boolean onMenuItemClick(final MenuItem menuItem) {
+ final Intent intent = new Intent(c, AboutActivity.class);
+ context.startActivity(intent);
+ return false;
+ }
+ });
+ }
+
+ private String selectDefaultDir() {
+ final File defaultDictDir = new File(Environment.getExternalStorageDirectory(), "quickDic");
+ String dir = defaultDictDir.getAbsolutePath();
+ File dictDir = new File(dir);
+ String[] fileList = dictDir.isDirectory() ? dictDir.list() : null;
+ if (fileList != null && fileList.length > 0) {
+ return dir;
+ }
+ File efd = null;
+ try {
+ efd = appContext.getExternalFilesDir(null);
+ } catch (Exception e) {
+ }
+ if (efd != null) {
+ efd.mkdirs();
+ if (!dictDir.isDirectory() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ appContext.getExternalFilesDirs(null);
+ }
+ if (efd.isDirectory() && efd.canWrite() && checkFileCreate(efd)) {
+ return efd.getAbsolutePath();
+ }
+ }
+ if (!dictDir.isDirectory() && !dictDir.mkdirs()) {
+ return appContext.getFilesDir().getAbsolutePath();
+ }
+ return dir;
+ }
+
+ public synchronized File getDictDir() {
+ // This metaphor doesn't work, because we've already reset
+ // prefsMightHaveChanged.
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
+ String dir = prefs.getString(appContext.getString(R.string.quickdicDirectoryKey), "");
+ if (dir.isEmpty()) {
+ dir = selectDefaultDir();
+ }
+ 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) {
+ boolean res = false;
+ File testfile = new File(dir, "quickdic_writetest");
+ try {
+ testfile.delete();
+ res = testfile.createNewFile() & testfile.delete();
+ } catch (Exception e) {
+ }
+ return res;
+ }
+
+ public File getWordListFile() {
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
+ String file = prefs.getString(appContext.getString(R.string.wordListFileKey), "");
+ if (file.isEmpty()) {
+ return new File(getDictDir(), "wordList.txt");
+ }
+ return new File(file);
+ }
+
+ public Theme getSelectedTheme() {
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
+ final String theme = prefs.getString(appContext.getString(R.string.themeKey), "themeLight");
+ if (theme.equals("themeLight")) {
+ return Theme.LIGHT;
+ } else {
+ return Theme.DEFAULT;
+ }
+ }
+
+ public File getPath(String uncompressedFilename) {
+ return new File(getDictDir(), uncompressedFilename);
+ }
+
+ String defaultLangISO2 = Locale.getDefault().getLanguage().toLowerCase();
+ String defaultLangName = null;
+ final Map<String, String> fileToNameCache = new HashMap<String, String>();
+
+ 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);
+ ListUtil.swap(result, 0, 1);
+ return result;
+ }
+ return indexInfos;
+ }
+
+ public synchronized String getDictionaryName(final String uncompressedFilename) {
+ final String currentLocale = Locale.getDefault().getLanguage().toLowerCase();
+ if (!currentLocale.equals(defaultLangISO2)) {
+ defaultLangISO2 = currentLocale;
+ fileToNameCache.clear();
+ defaultLangName = null;
+ }
+ if (defaultLangName == null) {
+ defaultLangName = IsoUtils.INSTANCE.isoCodeToLocalizedLanguageName(appContext, defaultLangISO2);
+ }
+
+ String name = fileToNameCache.get(uncompressedFilename);
+ if (name != null) {
+ return name;
+ }
+
+ final DictionaryInfo dictionaryInfo = DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO
+ .get(uncompressedFilename);