]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
UI fixes.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index beed7aeb00bd4066ae0f594a3e50b46669544432..158c1fcb326b5e46533fd53edb1049c20dfb5a04 100644 (file)
@@ -386,6 +386,7 @@ public class DictionaryActivity extends ListActivity {
 
     @Override
     protected void onResume() {
+        Log.d(LOG, "onResume");
         super.onResume();
         if (PreferenceActivity.prefsMightHaveChanged) {
             PreferenceActivity.prefsMightHaveChanged = false;
@@ -395,6 +396,7 @@ public class DictionaryActivity extends ListActivity {
         if (initialSearchText != null) {
             setSearchText(initialSearchText, true);
         }
+        showKeyboard();
     }
 
     @Override
@@ -444,6 +446,10 @@ public class DictionaryActivity extends ListActivity {
 
     private void onClearSearchTextButton() {
         setSearchText("", true);
+        showKeyboard();
+    }
+
+    private void showKeyboard() {
         Log.d(LOG, "Trying to show soft keyboard.");
         final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
         manager.showSoftInput(searchText, InputMethodManager.SHOW_IMPLICIT);
@@ -529,6 +535,12 @@ public class DictionaryActivity extends ListActivity {
                     layoutParams.weight = 1.0f;
                     button.setLayoutParams(layoutParams);
                     result.addView(button);
+                    
+                    if (i > 0) {
+                        final TextView dash = new TextView(parent.getContext());
+                        dash.setText("-");
+                        result.addView(dash);
+                    }
                 }
                 return result;
             }
@@ -1155,73 +1167,46 @@ public class DictionaryActivity extends ListActivity {
             return result;
         }
 
-        private TableLayout getView(HtmlEntry.Row row, ViewGroup parent, final TableLayout result) {
-            final Context context = parent.getContext();
-
-            final HtmlEntry htmlEntry = row.getEntry();
-
-            // final TableRow tableRow = new TableRow(context);
-            final LinearLayout tableRow = new LinearLayout(context);
-            result.addView(tableRow);
-
-            // Text.
-            final TextView textView = new TextView(context);
-            textView.setText(htmlEntry.title);
-            textView.setLayoutParams(new LinearLayout.LayoutParams(0,
-                    ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
-            tableRow.addView(textView);
-
-            // Button.
-            final Button button = new Button(context);
-            button.setText("open");
-            button.setLayoutParams(new LinearLayout.LayoutParams(
-                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0.0f));
-            tableRow.addView(button);
-
-            button.setOnClickListener(new OnClickListener() {
-                @Override
-                public void onClick(View v) {
-                    startActivity(HtmlDisplayActivity.getHtmlIntent(String.format(
-                            "<html><head></head><body>%s</body></html>", htmlEntry.html)));
-                }
-            });
-
-            return result;
-        }
-
-        private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) {
+        private TableLayout getPossibleHtmlEntryView(final boolean isTokenRow, final String text, final boolean hasMainEntry, final List<HtmlEntry> htmlEntries, final String htmlTextToHighlight, ViewGroup parent, final TableLayout result) {
             final Context context = parent.getContext();
             
             final TableRow tableRow = new TableRow(result.getContext());
-            tableRow.setBackgroundResource(row.hasMainEntry ? theme.tokenRowMainBg
+            tableRow.setBackgroundResource(hasMainEntry ? theme.tokenRowMainBg
                     : theme.tokenRowOtherBg);
-            tableRow.setPadding(mPaddingDefault, mPaddingDefault, mPaddingDefault, 0);
+            if (isTokenRow) {
+                tableRow.setPadding(mPaddingDefault, mPaddingDefault, mPaddingDefault, 0);
+            } else {
+                tableRow.setPadding(mPaddingLarge, mPaddingDefault, mPaddingDefault, 0);
+            }
             result.addView(tableRow);
-            
-            final IndexEntry indexEntry = row.getIndexEntry();
 
             final TextView textView = new TextView(context);
-            textView.setText(indexEntry.token);
+            textView.setText(text);
             // Doesn't work:
             // textView.setTextColor(android.R.color.secondary_text_light);
-            textView.setTextAppearance(context, theme.tokenRowFg);
             textView.setTypeface(typeface);
-            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 5 * fontSizeSp / 4);
             TableRow.LayoutParams lp = new TableRow.LayoutParams(0);
+            if (isTokenRow) {
+                textView.setTextAppearance(context, theme.tokenRowFg);
+                textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 4 * fontSizeSp / 3);
+            } else {
+                textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);
+            }
             lp.weight = 1.0f;
+            
             textView.setLayoutParams(lp);
             tableRow.addView(textView);
 
             
-            if (!indexEntry.htmlEntries.isEmpty()) {
+            if (!htmlEntries.isEmpty()) {
                 final ImageButton button = new ImageButton(context);
                 button.setImageResource(R.drawable.ic_menu_forward);
                 button.setOnClickListener(new OnClickListener() {
                     @Override
                     public void onClick(View v) {
-                        final String html = HtmlEntry.htmlBody(indexEntry.htmlEntries);
+                        final String html = HtmlEntry.htmlBody(htmlEntries);
                         startActivity(HtmlDisplayActivity.getHtmlIntent(String.format(
-                                "<html><head></head><body>%s</body></html>", html)));
+                                "<html><head></head><body>%s</body></html>", html), htmlTextToHighlight, false));
                     }
                 });
                 tableRow.addView(button);
@@ -1231,12 +1216,24 @@ public class DictionaryActivity extends ListActivity {
                 //result.setColumnStretchable(0, true);
                 //result.setColumnStretchable(1, false);
             }
-            
-            
             return result;
         }
+        
+        private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) {
+            final IndexEntry indexEntry = row.getIndexEntry();
+            return getPossibleHtmlEntryView(true, indexEntry.token, row.hasMainEntry, indexEntry.htmlEntries, null, parent, result);
+        }
+        
+        private TableLayout getView(HtmlEntry.Row row, ViewGroup parent, final TableLayout result) {
+            final HtmlEntry htmlEntry = row.getEntry();
+            final TokenRow tokenRow = row.getTokenRow(true);
+            return getPossibleHtmlEntryView(false, getString(R.string.seeAlso, htmlEntry.title), false, Collections.singletonList(htmlEntry), tokenRow.getToken(), parent, result);
+        }
+
 
     }
+    
+
 
     static final Pattern CHAR_DASH = Pattern.compile("['\\p{L}\\p{M}\\p{N}]+");
 
@@ -1351,15 +1348,15 @@ public class DictionaryActivity extends ListActivity {
     }
 
     void setFiltered(final SearchOperation searchOperation) {
-        ((Button) findViewById(R.id.UpButton)).setEnabled(false);
-        ((Button) findViewById(R.id.DownButton)).setEnabled(false);
+        ((ImageButton) findViewById(R.id.UpButton)).setEnabled(false);
+        ((ImageButton) findViewById(R.id.DownButton)).setEnabled(false);
         rowsToShow = searchOperation.multiWordSearchResult;
         setListAdapter(new IndexAdapter(index, rowsToShow, searchOperation.searchTokens));
     }
 
     void clearFiltered() {
-        ((Button) findViewById(R.id.UpButton)).setEnabled(true);
-        ((Button) findViewById(R.id.DownButton)).setEnabled(true);
+        ((ImageButton) findViewById(R.id.UpButton)).setEnabled(true);
+        ((ImageButton) findViewById(R.id.DownButton)).setEnabled(true);
         setListAdapter(new IndexAdapter(index));
         rowsToShow = null;
     }