]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
Fix corner-case where search icon would not be hidden.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index cd238f355eb3a64d04794cc7b24b2f879cb2b4d5..fa00dfdf2fc61d5069243a5f46d9e5f374754b60 100644 (file)
@@ -143,7 +143,7 @@ public class DictionaryActivity extends ActionBarActivity {
     volatile boolean ttsReady;
 
     Typeface typeface;
-    C.Theme theme = C.Theme.LIGHT;
+    DictionaryApplication.Theme theme = DictionaryApplication.Theme.LIGHT;
     int textColorFg = Color.BLACK;
     int fontSizeSp;
 
@@ -187,11 +187,9 @@ public class DictionaryActivity extends ActionBarActivity {
     public DictionaryActivity() {
     }
 
-    public static Intent getLaunchIntent(final File dictFile, final String indexShortName,
+    public static Intent getLaunchIntent(Context c, final File dictFile, final String indexShortName,
             final String searchToken) {
-        final Intent intent = new Intent();
-        intent.setClassName(DictionaryActivity.class.getPackage().getName(),
-                DictionaryActivity.class.getName());
+        final Intent intent = new Intent(c, DictionaryActivity.class);
         intent.putExtra(C.DICT_FILE, dictFile.getPath());
         intent.putExtra(C.INDEX_SHORT_NAME, indexShortName);
         intent.putExtra(C.SEARCH_TOKEN, searchToken);
@@ -206,13 +204,6 @@ public class DictionaryActivity extends ActionBarActivity {
         outState.putString(C.SEARCH_TOKEN, searchView.getQuery().toString());
     }
 
-    @Override
-    protected void onRestoreInstanceState(final Bundle savedInstanceState) {
-        super.onRestoreInstanceState(savedInstanceState);
-        Log.d(LOG, "onRestoreInstanceState: " + savedInstanceState.getString(C.SEARCH_TOKEN));
-        onCreate(savedInstanceState);
-    }
-
     @Override
     public void onCreate(Bundle savedInstanceState) {
         // This needs to be before super.onCreate, otherwise ActionbarSherlock
@@ -228,6 +219,7 @@ public class DictionaryActivity extends ActionBarActivity {
         // Don't auto-launch if this fails.
         prefs.edit().remove(C.DICT_FILE).commit();
 
+        setContentView(R.layout.dictionary_activity);
 
         application = (DictionaryApplication) getApplication();
         theme = application.getSelectedTheme();
@@ -321,7 +313,7 @@ public class DictionaryActivity extends ActionBarActivity {
         if (dictFilename == null)
         {
             Toast.makeText(this, getString(R.string.no_dict_file), Toast.LENGTH_LONG).show();
-            startActivity(DictionaryManagerActivity.getLaunchIntent());
+            startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
             finish();
             return;
         }
@@ -354,7 +346,7 @@ public class DictionaryActivity extends ActionBarActivity {
             }
             Toast.makeText(this, getString(R.string.invalidDictionary, "", e.getMessage()),
                     Toast.LENGTH_LONG).show();
-            startActivity(DictionaryManagerActivity.getLaunchIntent());
+            startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
             finish();
             return;
         }
@@ -406,10 +398,19 @@ public class DictionaryActivity extends ActionBarActivity {
             }
         }).start();
 
-        String fontName = prefs.getString(getString(R.string.fontKey), "FreeSerif.ttf.jpg");
+        String fontName = prefs.getString(getString(R.string.fontKey), "FreeSerif.otf.jpg");
         if ("SYSTEM".equals(fontName)) {
             typeface = Typeface.DEFAULT;
+       } else if ("SERIF".equals(fontName)) {
+            typeface = Typeface.SERIF;
+       } else if ("SANS_SERIF".equals(fontName)) {
+            typeface = Typeface.SANS_SERIF;
+       } else if ("MONOSPACE".equals(fontName)) {
+            typeface = Typeface.MONOSPACE;
         } else {
+            if ("FreeSerif.ttf.jpg".equals(fontName)) {
+                fontName = "FreeSerif.otf.jpg";
+            }
             try {
                 typeface = Typeface.createFromAsset(getAssets(), fontName);
             } catch (Exception e) {
@@ -429,8 +430,6 @@ public class DictionaryActivity extends ActionBarActivity {
             fontSizeSp = 14;
         }
 
-        setContentView(R.layout.dictionary_activity);
-
         // ContextMenu.
         registerForContextMenu(getListView());
 
@@ -475,7 +474,7 @@ public class DictionaryActivity extends ActionBarActivity {
         final int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300,
                 getResources().getDisplayMetrics());
         final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
-                width, ViewGroup.LayoutParams.WRAP_CONTENT);
+                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
         customSearchView.setLayoutParams(layoutParams);
 
         listView.setOnItemClickListener(new OnItemClickListener() {
@@ -689,7 +688,7 @@ public class DictionaryActivity extends ActionBarActivity {
         final String name = getString(R.string.dictionaryManager);
         button.setText(name);
         final IntentLauncher intentLauncher = new IntentLauncher(listView.getContext(),
-                DictionaryManagerActivity.getLaunchIntent()) {
+                DictionaryManagerActivity.getLaunchIntent(getApplicationContext())) {
             @Override
             protected void onGo() {
                 dialog.dismiss();
@@ -711,7 +710,7 @@ public class DictionaryActivity extends ActionBarActivity {
                     final View button = application.createButton(parent.getContext(),
                             dictionaryInfo, indexInfo);
                     final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(),
-                            getLaunchIntent(
+                            getLaunchIntent(getApplicationContext(),
                                     application.getPath(dictionaryInfo.uncompressedFilename),
                                     indexInfo.shortName, searchView.getQuery().toString())) {
                         @Override
@@ -824,7 +823,7 @@ public class DictionaryActivity extends ActionBarActivity {
             MenuItemCompat.setShowAsAction(dictionaryManager, MenuItem.SHOW_AS_ACTION_NEVER);
             dictionaryManager.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                 public boolean onMenuItemClick(final MenuItem menuItem) {
-                    startActivity(DictionaryManagerActivity.getLaunchIntent());
+                    startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
                     finish();
                     return false;
                 }
@@ -1101,6 +1100,11 @@ public class DictionaryActivity extends ActionBarActivity {
         searchView.setQuery(text, false);
         moveCursorToRight();
         searchView.setOnQueryTextListener(onQueryTextListener);
+
+        // Hide search icon once text is entered
+        searchView.setIconifiedByDefault(text.length() > 0);
+        searchView.setIconified(false);
+
         if (triggerSearch) {
             onQueryTextListener.onQueryTextChange(text);
         }
@@ -1473,7 +1477,7 @@ public class DictionaryActivity extends ActionBarActivity {
                         String html = HtmlEntry.htmlBody(htmlEntries, index.shortName);
                         // Log.d(LOG, "html=" + html);
                         startActivityForResult(
-                                HtmlDisplayActivity.getHtmlIntent(String.format(
+                                HtmlDisplayActivity.getHtmlIntent(getApplicationContext(), String.format(
                                         "<html><head></head><body>%s</body></html>", html),
                                         htmlTextToHighlight, false),
                                 0);
@@ -1576,6 +1580,11 @@ public class DictionaryActivity extends ActionBarActivity {
             Log.d(LOG, "searchText changed during shutdown, doing nothing.");
             return;
         }
+
+        // Hide search icon once text is entered
+        searchView.setIconifiedByDefault(text.length() > 0);
+        searchView.setIconified(false);
+
         // if (!searchView.hasFocus()) {
         // Log.d(LOG, "searchText changed without focus, doing nothing.");
         // return;