X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2FPreferenceActivity.java;h=d8ded038fd4d08ba50ffc0607e300bfcb1ac7c3b;hb=f8a245b0a2461fb922b72fd137f2a44662c9c760;hp=78223848f297f78a15086dc786748823ecaeed38;hpb=9cb5a8e2d7acacc8e01e5133e50a225550eb0501;p=Dictionary.git diff --git a/src/com/hughes/android/dictionary/PreferenceActivity.java b/src/com/hughes/android/dictionary/PreferenceActivity.java index 7822384..d8ded03 100644 --- a/src/com/hughes/android/dictionary/PreferenceActivity.java +++ b/src/com/hughes/android/dictionary/PreferenceActivity.java @@ -33,7 +33,8 @@ public class PreferenceActivity extends android.preference.PreferenceActivity @SuppressWarnings("deprecation") @Override public void onCreate(Bundle savedInstanceState) { - final DictionaryApplication application = (DictionaryApplication) getApplication(); + DictionaryApplication.INSTANCE.init(getApplicationContext()); + final DictionaryApplication application = DictionaryApplication.INSTANCE; setTheme(application.getSelectedTheme().themeId); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -44,8 +45,8 @@ public class PreferenceActivity extends android.preference.PreferenceActivity prefs.edit().putString(getString(R.string.wordListFileKey), application.getWordListFile().getAbsolutePath()).commit(); } - /** - * @author Dominik Köppl Preference: select default dictionary As this + /* + @author Dominik Köppl Preference: select default dictionary As this * list is dynamically generated, we have to do it in this * fashion */ @@ -81,42 +82,55 @@ public class PreferenceActivity extends android.preference.PreferenceActivity prefs.registerOnSharedPreferenceChangeListener(this); } - @Override - public void onContentChanged() { - super.onContentChanged(); + private String suggestedPaths(String suffix) { + String dirs = ""; + String externalDir = Environment.getExternalStorageDirectory().getAbsolutePath(); + if (new File(externalDir).canWrite()) + dirs += "\n" + externalDir + "/quickDic" + suffix; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + File[] files = getApplicationContext().getExternalFilesDirs(null); + for (File f : files) { + if (f.canWrite()) + dirs += "\n" + f.getAbsolutePath() + suffix; + } + } else { + File efd = null; + try { + efd = getApplicationContext().getExternalFilesDir(null); + } catch (Exception ignored) { + } + if (efd != null) { + String externalFilesDir = efd.getAbsolutePath(); + if (new File(externalFilesDir).canWrite()) + dirs += "\n" + externalFilesDir + suffix; + } + } + File fd = getApplicationContext().getFilesDir(); + if (fd.canWrite()) + dirs += "\n" + fd.getAbsolutePath() + suffix; + return dirs; } @Override public void onSharedPreferenceChanged(SharedPreferences p, String v) { - final DictionaryApplication application = (DictionaryApplication)getApplication(); + DictionaryApplication.INSTANCE.init(getApplicationContext()); + final DictionaryApplication application = DictionaryApplication.INSTANCE; File dictDir = application.getDictDir(); if (!dictDir.isDirectory() || !dictDir.canWrite() || - !application.checkFileCreate(dictDir)) { - String dirs = ""; - String externalDir = Environment.getExternalStorageDirectory().getAbsolutePath(); - if (new File(externalDir).canWrite()) - dirs += "\n" + externalDir + "/quickDic"; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - File[] files = getApplicationContext().getExternalFilesDirs(null); - for (File f : files) { - if (f.canWrite()) - dirs += "\n" + f.getAbsolutePath(); - } - } else { - File efd = null; - try { - efd = getApplicationContext().getExternalFilesDir(null); - } catch (Exception e) { - } - if (efd != null) { - String externalFilesDir = efd.getAbsolutePath(); - if (new File(externalFilesDir).canWrite()) - dirs += "\n" + externalFilesDir; - } - } - File fd = getApplicationContext().getFilesDir(); - if (fd.canWrite()) - dirs += "\n" + fd.getAbsolutePath(); + !DictionaryApplication.checkFileCreate(dictDir)) { + String dirs = suggestedPaths(""); + new AlertDialog.Builder(this).setTitle(getString(R.string.error)) + .setMessage(getString(R.string.chosenNotWritable) + dirs) + .setNeutralButton("Close", null).show(); + } + File wordlist = application.getWordListFile(); + boolean ok = false; + try { + ok = wordlist.canWrite() || wordlist.createNewFile(); + } catch (Exception ignored) { + } + if (!ok) { + String dirs = suggestedPaths("/wordList.txt"); new AlertDialog.Builder(this).setTitle(getString(R.string.error)) .setMessage(getString(R.string.chosenNotWritable) + dirs) .setNeutralButton("Close", null).show();