]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/PreferenceActivity.java
Run automated code cleanup.
[Dictionary.git] / src / com / hughes / android / dictionary / PreferenceActivity.java
index 2d66bf945235b48375e5730005a689c89906a5fb..add2141e05da764b5b7502ed60403f49f2310796 100644 (file)
@@ -33,9 +33,10 @@ 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);
         if (prefs.getString(getString(R.string.quickdicDirectoryKey), "").equals("")) {
             prefs.edit().putString(getString(R.string.quickdicDirectoryKey), application.getDictDir().getAbsolutePath()).commit();
@@ -52,14 +53,13 @@ public class PreferenceActivity extends android.preference.PreferenceActivity
         super.onCreate(savedInstanceState);
         addPreferencesFromResource(R.xml.preferences);
         ListPreference defaultDic = (ListPreference) findPreference(getResources().getString(
-                R.string.defaultDicKey));
+                                        R.string.defaultDicKey));
         List<DictionaryInfo> dicts = application.getDictionariesOnDevice(null);
 
         final CharSequence[] entries = new CharSequence[dicts.size()];
         final CharSequence[] entryvalues = new CharSequence[dicts.size()];
 
-        for (int i = 0; i < entries.length; ++i)
-        {
+        for (int i = 0; i < entries.length; ++i) {
             entries[i] = dicts.get(i).dictInfo;
             entryvalues[i] = dicts.get(i).uncompressedFilename;
         }
@@ -89,10 +89,11 @@ public class PreferenceActivity extends android.preference.PreferenceActivity
 
     @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)) {
+                !DictionaryApplication.checkFileCreate(dictDir)) {
             String dirs = "";
             String externalDir = Environment.getExternalStorageDirectory().getAbsolutePath();
             if (new File(externalDir).canWrite())
@@ -104,16 +105,23 @@ public class PreferenceActivity extends android.preference.PreferenceActivity
                         dirs += "\n" + f.getAbsolutePath();
                 }
             } else {
-                File efd = getApplicationContext().getExternalFilesDir(null);
+                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();
             new AlertDialog.Builder(this).setTitle(getString(R.string.error))
-                .setMessage(getString(R.string.chosenNotWritable) + dirs)
-                    .setNeutralButton("Close", null).show();
+            .setMessage(getString(R.string.chosenNotWritable) + dirs)
+            .setNeutralButton("Close", null).show();
         }
     }
 }