]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryApplication.java
Make updating the dictionary list more robust.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryApplication.java
index d63553825430153b01bec1c25e6a34e13cf2d486..b8022cebe827e08c9fe5ed7edc68dffbbe0724a2 100644 (file)
@@ -33,6 +33,7 @@ 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.DictionaryInfo.IndexInfo;
@@ -61,6 +62,14 @@ public class DictionaryApplication extends Application {
 
     static final String LOG = "QuickDicApp";
 
+    // If set to false, avoid use of ICU collator
+    // Works well enough for most european languages,
+    // gives faster startup and avoids crashes on some
+    // devices due to Dalvik bugs (e.g. ARMv6, S5570i, CM11).
+    // 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, determined by resources (and locale).
     // Unordered.
     static Map<String, DictionaryInfo> DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = null;
@@ -517,10 +526,7 @@ public class DictionaryApplication extends Application {
             button.setScaleType(ScaleType.FIT_CENTER);
             result = button;
         }
-        result.setMinimumWidth(languageButtonPixels);
-        result.setMinimumHeight(languageButtonPixels * 2 / 3);
-        // result.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
-        // LayoutParams.WRAP_CONTENT));
+        result.setLayoutParams(new LinearLayout.LayoutParams(languageButtonPixels, LinearLayout.LayoutParams.MATCH_PARENT));
         return result;
     }
 
@@ -539,7 +545,7 @@ public class DictionaryApplication extends Application {
         PersistentObjectCache.getInstance().write(C.DICTIONARY_CONFIGS, dictionaryConfig);
     }
 
-    final Collator collator = Collator.getInstance();
+    final Comparator collator = USE_COLLATOR ? Collator.getInstance() : String.CASE_INSENSITIVE_ORDER;
     final Comparator<String> uncompressedFilenameComparator = new Comparator<String>() {
         @Override
         public int compare(String uncompressedFilename1, String uncompressedFilename2) {
@@ -628,8 +634,13 @@ public class DictionaryApplication extends Application {
                     newDictionaryConfig.dictionaryFilesOrdered.addAll(toAddSorted);
                 }
 
-                PersistentObjectCache.getInstance()
-                        .write(C.DICTIONARY_CONFIGS, newDictionaryConfig);
+                try {
+                    PersistentObjectCache.getInstance()
+                                 .write(C.DICTIONARY_CONFIGS, newDictionaryConfig);
+                } catch (Exception e) {
+                    Log.e(LOG, "Failed persisting dictionary configs", e);
+                }
+
                 synchronized (this) {
                     dictionaryConfig = newDictionaryConfig;
                 }