]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
Try to fix DictionaryActivity leaks.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index 01d0a3cb094ef51647934dc6d629ff99856df915..b02eb7d4fddd1d31a7fbdd72c71333b373d5cd0a 100644 (file)
@@ -108,6 +108,7 @@ import java.util.Locale;
 import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -135,7 +136,7 @@ public class DictionaryActivity extends ActionBarActivity {
 
     final Handler uiHandler = new Handler();
 
-    private final Executor searchExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
+    private final ExecutorService searchExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
         @Override
         public Thread newThread(Runnable r) {
             return new Thread(r, "searchExecutor");
@@ -198,6 +199,7 @@ public class DictionaryActivity extends ActionBarActivity {
         intent.putExtra(C.DICT_FILE, dictFile.getPath());
         intent.putExtra(C.INDEX_SHORT_NAME, indexShortName);
         intent.putExtra(C.SEARCH_TOKEN, searchToken);
+        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
         return intent;
     }
 
@@ -332,7 +334,7 @@ public class DictionaryActivity extends ActionBarActivity {
         /**
          * @author Dominik Köppl If no dictionary is chosen, use the default
          *         dictionary specified in the preferences If this step does
-         *         fail (no default directory specified), show a toast and
+         *         fail (no default dictionary specified), show a toast and
          *         abort.
          */
         if (intent.getStringExtra(C.DICT_FILE) == null)
@@ -353,26 +355,35 @@ public class DictionaryActivity extends ActionBarActivity {
             for (int i = 0; dictFilename == null && i < dics.size(); ++i)
             {
                 try {
-                    final String fname = dics.get(i).uncompressedFilename;
-                    Dictionary dic = new Dictionary(new RandomAccessFile(new File(fname), "r"));
+                    Log.d(LOG, "Checking dictionary " + dics.get(i).uncompressedFilename);
+                    final File dictfile = application.getPath(dics.get(i).uncompressedFilename);
+                    Dictionary dic = new Dictionary(new RandomAccessFile(dictfile, "r"));
                     for (int j = 0; j < dic.indices.size(); ++j) {
                         Index idx = dic.indices.get(j);
+                        Log.d(LOG, "Checking index " + idx.shortName);
                         if (idx.findExact(search) != null)
                         {
-                            dictFilename = fname;
+                            Log.d(LOG, "Found exact match");
+                            dictFilename = dictfile.toString();
                             intent.putExtra(C.INDEX_SHORT_NAME, idx.shortName);
                             break;
                         }
                         int matchLen = getMatchLen(search, idx.findInsertionPoint(search, dummy));
+                        Log.d(LOG, "Found partial match length " + matchLen);
                         if (matchLen > bestMatchLen)
                         {
-                            dictFilename = fname;
-                            intent.putExtra(C.INDEX_SHORT_NAME, idx.shortName);
+                            bestFname = dictfile.toString();
+                            bestIndex = idx.shortName;
                             bestMatchLen = matchLen;
                         }
                     }
                 } catch (Exception e) {}
             }
+            if (dictFilename == null && bestFname != null)
+            {
+                dictFilename = bestFname;
+                intent.putExtra(C.INDEX_SHORT_NAME, bestIndex);
+            }
         }
 
         if (dictFilename == null)
@@ -692,6 +703,7 @@ public class DictionaryActivity extends ActionBarActivity {
             currentSearchOperation = null;
             searchOperation.interrupted.set(true);
         }
+        searchExecutor.shutdownNow();
 
         try {
             Log.d(LOG, "Closing RAF.");
@@ -1475,6 +1487,11 @@ public class DictionaryActivity extends ActionBarActivity {
 
                 final TextView col1 = new TextView(tableRow.getContext());
                 final TextView col2 = new TextView(tableRow.getContext());
+                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
+                {
+                    col1.setTextIsSelectable(true);
+                    col2.setTextIsSelectable(true);
+                }
 
                 // Set the columns in the table.
                 if (r > 0) {