From 2c06585263ee1735b578ad5909f53671be4f410e Mon Sep 17 00:00:00 2001 From: thadh Date: Tue, 25 Sep 2012 08:41:39 -0700 Subject: [PATCH] UI fixes. --- res/values-de/strings.xml | 1 + res/values-it/strings.xml | 1 + res/values/strings.xml | 1 + .../dictionary/DictionaryActivity.java | 40 +++++++++++++------ .../dictionary/HtmlDisplayActivity.java | 23 +++++++---- .../android/dictionary/engine/HtmlEntry.java | 2 +- 6 files changed, 47 insertions(+), 21 deletions(-) diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index 110a49f..3f36142 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -40,6 +40,7 @@ Über Wörterbuch… Random Wort Font failure: %s + vgl.: %s diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml index ac8e3f0..44224f6 100644 --- a/res/values-it/strings.xml +++ b/res/values-it/strings.xml @@ -35,6 +35,7 @@ Rilevato problema di font (comune su apparecchi Sony Ericsson), ritorno a font d About dictionary… Parola a caso Problema di Font: %s +Vedi anche: %s File: %s Dimenzione: %,d bytes diff --git a/res/values/strings.xml b/res/values/strings.xml index 9023625..86e5b9c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -41,6 +41,7 @@ About dictionary… Random word Font failure: %s + See also: %s diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 0193355..158c1fc 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -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); @@ -1161,30 +1167,33 @@ public class DictionaryActivity extends ListActivity { return result; } - private TableLayout getView(HtmlEntry.Row row, ViewGroup parent, final TableLayout result) { - final HtmlEntry htmlEntry = row.getEntry(); - return getPossibleHtmlEntryView(htmlEntry.title, false, Collections.singletonList(htmlEntry), parent, result); - } - - private TableLayout getPossibleHtmlEntryView(final String text, final boolean hasMainEntry, final List htmlEntries, ViewGroup parent, final TableLayout result) { + private TableLayout getPossibleHtmlEntryView(final boolean isTokenRow, final String text, final boolean hasMainEntry, final List htmlEntries, final String htmlTextToHighlight, ViewGroup parent, final TableLayout result) { final Context context = parent.getContext(); final TableRow tableRow = new TableRow(result.getContext()); 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 TextView textView = new TextView(context); 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); @@ -1197,7 +1206,7 @@ public class DictionaryActivity extends ListActivity { public void onClick(View v) { final String html = HtmlEntry.htmlBody(htmlEntries); startActivity(HtmlDisplayActivity.getHtmlIntent(String.format( - "%s", html), text)); + "%s", html), htmlTextToHighlight, false)); } }); tableRow.addView(button); @@ -1212,9 +1221,16 @@ public class DictionaryActivity extends ListActivity { private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) { final IndexEntry indexEntry = row.getIndexEntry(); - return getPossibleHtmlEntryView(indexEntry.token, row.hasMainEntry, indexEntry.htmlEntries, parent, result); + 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); } + } diff --git a/src/com/hughes/android/dictionary/HtmlDisplayActivity.java b/src/com/hughes/android/dictionary/HtmlDisplayActivity.java index f4bc8ce..a987f5d 100644 --- a/src/com/hughes/android/dictionary/HtmlDisplayActivity.java +++ b/src/com/hughes/android/dictionary/HtmlDisplayActivity.java @@ -17,23 +17,23 @@ package com.hughes.android.dictionary; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.view.ContextMenu; -import android.view.ContextMenu.ContextMenuInfo; -import android.view.MenuItem; -import android.view.MenuItem.OnMenuItemClickListener; +import android.util.Log; import android.view.View; import android.view.View.OnClickListener; -import android.view.View.OnCreateContextMenuListener; import android.webkit.WebView; import android.widget.Button; import com.hughes.util.StringUtil; public final class HtmlDisplayActivity extends Activity { + + static final String LOG = "QuickDic"; + static final String HTML_RES = "html_res"; static final String HTML = "html"; static final String TEXT_TO_HIGHLIGHT = "textToHighlight"; + static final String SHOW_OK_BUTTON = "showOKButton"; public static Intent getHelpLaunchIntent() { final Intent intent = new Intent(); @@ -49,11 +49,12 @@ public final class HtmlDisplayActivity extends Activity { return intent; } - public static Intent getHtmlIntent(final String html, final String textToHighlight) { + public static Intent getHtmlIntent(final String html, final String textToHighlight, final boolean showOkButton) { final Intent intent = new Intent(); intent.setClassName(HtmlDisplayActivity.class.getPackage().getName(), HtmlDisplayActivity.class.getName()); intent.putExtra(HTML, html); intent.putExtra(TEXT_TO_HIGHLIGHT, textToHighlight); + intent.putExtra(SHOW_OK_BUTTON, showOkButton); return intent; } @@ -76,8 +77,11 @@ public final class HtmlDisplayActivity extends Activity { webView.loadData(html, "text/html", "utf-8"); final String textToHighlight = getIntent().getStringExtra(TEXT_TO_HIGHLIGHT); - if (textToHighlight != null && "".equals(textToHighlight)) { - webView.findAllAsync(textToHighlight); + if (textToHighlight != null && !"".equals(textToHighlight)) { + Log.d(LOG, "Highlighting text: " + textToHighlight); + // This isn't working: + webView.findAll(textToHighlight); + //webView.showFindDialog(textToHighlight, false); } final Button okButton = (Button) findViewById(R.id.okButton); @@ -87,6 +91,9 @@ public final class HtmlDisplayActivity extends Activity { finish(); } }); + if (!getIntent().getBooleanExtra(SHOW_OK_BUTTON, true)) { + okButton.setVisibility(View.INVISIBLE); + } } } diff --git a/src/com/hughes/android/dictionary/engine/HtmlEntry.java b/src/com/hughes/android/dictionary/engine/HtmlEntry.java index 8ff40e3..dc5437b 100644 --- a/src/com/hughes/android/dictionary/engine/HtmlEntry.java +++ b/src/com/hughes/android/dictionary/engine/HtmlEntry.java @@ -141,7 +141,7 @@ public class HtmlEntry extends AbstractEntry implements RAFSerializable htmlEntries) { final StringBuilder result = new StringBuilder(); for (final HtmlEntry htmlEntry : htmlEntries) { - result.append(String.format("

%s

%s\n", htmlEntry.title, htmlEntry.html)); + result.append(String.format("

%s

%s\n", htmlEntry.title, htmlEntry.title, htmlEntry.html)); } return result.toString(); } -- 2.43.0