]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Tried to fix launch last used bug.
authorThad Hughes <thad.hughes@gmail.com>
Wed, 15 Feb 2012 23:35:47 +0000 (15:35 -0800)
committerThad Hughes <thad.hughes@gmail.com>
Wed, 15 Feb 2012 23:35:47 +0000 (15:35 -0800)
res/raw/whats_new.html
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/DictionaryManagerActivity.java

index a11ed322126056edf5d6e381aa4c40341c6e40d4..8aff685262a32bec14155d1ab6dce55a0c566518 100644 (file)
@@ -9,12 +9,11 @@
 </head>
 <body>
 <!-- Don't use links in the text below, it crashes the app. -->
-Thanks for updating to QuickDic 3.1.
+Thanks for updating to QuickDic 3.2.
 <p>New features:</p>
 <ul>
-<li>Search for multiple words at once (separated by spaces).</li>
-<li>All words are hyperlinks: long-press any word in a dictionary
-to lookup that word.</li>
+<li>Go straight to last-used dictionary on launch.</li>
+
 <li>Easier dictionary switching: long-press the switch-language
 button.</li>
 <li>New English dictionaries: Azeri, Basque, Breton, Burmese,
index ac828e6092a8633db7b2a47b3931d093e7ad80b6..2ecaf3738615785f7f876a837c3e47d92f7d7259 100644 (file)
@@ -176,9 +176,6 @@ public class DictionaryActivity extends ListActivity {
 \r
     application = (DictionaryApplication) getApplication();\r
     theme = application.getSelectedTheme();\r
-\r
-    // Clear them so that if something goes wrong, we won't relaunch.\r
-    clearDictionaryPrefs(this);\r
     \r
     final Intent intent = getIntent();\r
     dictFile = new File(intent.getStringExtra(C.DICT_FILE));\r
@@ -372,15 +369,6 @@ public class DictionaryActivity extends ListActivity {
     prefs.commit();\r
   }\r
 \r
-  private static void clearDictionaryPrefs(final Context context) {\r
-    final SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(context).edit();\r
-    prefs.remove(C.DICT_FILE);\r
-    prefs.remove(C.INDEX_INDEX);\r
-    prefs.remove(C.SEARCH_TOKEN);\r
-    prefs.commit();\r
-  }\r
-\r
-\r
   @Override\r
   protected void onDestroy() {\r
     super.onDestroy();\r
@@ -523,7 +511,10 @@ public class DictionaryActivity extends ListActivity {
     Log.d(LOG, "onUpDownButton, destIndexEntry=" + dest.token);\r
     searchText.removeTextChangedListener(searchTextWatcher);\r
     searchText.setText(dest.token);\r
-    Selection.moveToRightEdge(searchText.getText(), searchText.getLayout());\r
+    if (searchText.getLayout() != null) {\r
+      // Surprising, but this can otherwise crash sometimes...\r
+      Selection.moveToRightEdge(searchText.getText(), searchText.getLayout());\r
+    }\r
     jumpToRow(index.sortedIndexEntries.get(destIndexEntry).startRow);\r
     searchText.addTextChangedListener(searchTextWatcher);\r
   }\r
@@ -730,7 +721,8 @@ public class DictionaryActivity extends ListActivity {
     }\r
     if (keyCode == KeyEvent.KEYCODE_BACK) {\r
       Log.d(LOG, "Clearing dictionary prefs.");\r
-      DictionaryActivity.clearDictionaryPrefs(this);\r
+      // Pretend that we just autolaunched so that we won't do it again.\r
+      DictionaryManagerActivity.lastAutoLaunchMillis = System.currentTimeMillis();\r
     }\r
     if (keyCode == KeyEvent.KEYCODE_ENTER) {\r
       Log.d(LOG, "Trying to hide soft keyboard.");\r
index ba56163f9aa01f20e0cd7191e795eaf131425a22..260fb1dc4540953ab68c8663e21756036c0b158f 100644 (file)
@@ -52,7 +52,9 @@ import com.hughes.util.StringUtil;
 public class DictionaryManagerActivity extends ListActivity {
 
   static final String LOG = "QuickDic";
-  static boolean canAutoLaunch = true;
+  static final long AUTO_LAUNCH_WAIT_MILLIS = 20 * 1000;
+  static long lastAutoLaunchMillis = -1;
+  static boolean blockAutoLaunch = false;
 
   DictionaryApplication application;
   Adapter adapter;
@@ -91,10 +93,11 @@ public class DictionaryManagerActivity extends ListActivity {
     // ContextMenu.
     registerForContextMenu(getListView());
 
+    blockAutoLaunch = false;
     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
     final String thanksForUpdatingLatestVersion = getString(R.string.thanksForUpdatingVersion);
     if (!prefs.getString(C.THANKS_FOR_UPDATING_VERSION, "").equals(thanksForUpdatingLatestVersion)) {
-      canAutoLaunch = false;
+      blockAutoLaunch = true;
       final AlertDialog.Builder builder = new AlertDialog.Builder(this);
       builder.setCancelable(false);
       final WebView webView = new WebView(getApplicationContext());
@@ -114,10 +117,6 @@ public class DictionaryManagerActivity extends ListActivity {
       alert.getWindow().setAttributes(layoutParams);
       prefs.edit().putString(C.THANKS_FOR_UPDATING_VERSION, thanksForUpdatingLatestVersion).commit();
     }
-    
-    if (!getIntent().getBooleanExtra(C.CAN_AUTO_LAUNCH_DICT, true)) {
-      canAutoLaunch = false;
-    }
   }
   
   @Override
@@ -154,11 +153,16 @@ public class DictionaryManagerActivity extends ListActivity {
       startActivity(getIntent());
     }
     
+    final long now = System.currentTimeMillis();
     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
-    if (canAutoLaunch && prefs.contains(C.DICT_FILE) && prefs.contains(C.INDEX_INDEX)) {
-      canAutoLaunch = false;  // Only autolaunch once per-process, on startup.
+    if (now - lastAutoLaunchMillis > AUTO_LAUNCH_WAIT_MILLIS &&
+        getIntent().getBooleanExtra(C.CAN_AUTO_LAUNCH_DICT, true) &&
+        prefs.contains(C.DICT_FILE) && 
+        prefs.contains(C.INDEX_INDEX) &&
+        !blockAutoLaunch) {
       Log.d(LOG, "Skipping Dictionary List, going straight to dictionary.");
       startActivity(DictionaryActivity.getLaunchIntent(new File(prefs.getString(C.DICT_FILE, "")), prefs.getInt(C.INDEX_INDEX, 0), prefs.getString(C.SEARCH_TOKEN, "")));
+      lastAutoLaunchMillis = now;
       // Don't finish, so that user can hit back and get here.
       //finish();
       return;