From da55b878cfd6c5f7b042c5ef0d0ce7a5d35431b7 Mon Sep 17 00:00:00 2001 From: thadh Date: Tue, 31 Jul 2012 08:39:18 -0700 Subject: [PATCH] Switching to HtmlDisplayActivity. --- ...activity.xml => html_display_activity.xml} | 0 .../dictionary/DictionaryActivity.java | 40 +++++++++++++++++++ .../dictionary/HtmlDisplayActivity.java | 18 ++++++++- .../android/dictionary/engine/HtmlEntry.java | 4 +- 4 files changed, 59 insertions(+), 3 deletions(-) rename res/layout/{help_activity.xml => html_display_activity.xml} (100%) diff --git a/res/layout/help_activity.xml b/res/layout/html_display_activity.xml similarity index 100% rename from res/layout/help_activity.xml rename to res/layout/html_display_activity.xml diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index f526cb9..84238e9 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -64,8 +64,10 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; +import android.webkit.WebView; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.BaseAdapter; @@ -83,6 +85,7 @@ import android.widget.Toast; import com.hughes.android.dictionary.DictionaryInfo.IndexInfo; import com.hughes.android.dictionary.engine.Dictionary; import com.hughes.android.dictionary.engine.EntrySource; +import com.hughes.android.dictionary.engine.HtmlEntry; import com.hughes.android.dictionary.engine.Index; import com.hughes.android.dictionary.engine.Index.IndexEntry; import com.hughes.android.dictionary.engine.PairEntry; @@ -929,6 +932,9 @@ public class DictionaryActivity extends ListActivity { // -------------------------------------------------------------------------- // IndexAdapter // -------------------------------------------------------------------------- + + static ViewGroup.LayoutParams WEIGHT_1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0f); + static ViewGroup.LayoutParams WEIGHT_0 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0f); final class IndexAdapter extends BaseAdapter { @@ -977,6 +983,8 @@ public class DictionaryActivity extends ListActivity { return getView(position, (PairEntry.Row) row, parent, result); } else if (row instanceof TokenRow) { return getView((TokenRow) row, parent, result); + } else if (row instanceof HtmlEntry.Row) { + return getView((HtmlEntry.Row) row, parent, result); } else { throw new IllegalArgumentException("Unsupported Row type: " + row.getClass()); } @@ -1071,7 +1079,39 @@ 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("%s", htmlEntry.html))); + } + }); + + return result; + } + private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) { final Context context = parent.getContext(); final TextView textView = new TextView(context); diff --git a/src/com/hughes/android/dictionary/HtmlDisplayActivity.java b/src/com/hughes/android/dictionary/HtmlDisplayActivity.java index 265f470..24e0a6e 100644 --- a/src/com/hughes/android/dictionary/HtmlDisplayActivity.java +++ b/src/com/hughes/android/dictionary/HtmlDisplayActivity.java @@ -27,6 +27,7 @@ import com.hughes.util.StringUtil; public final class HtmlDisplayActivity extends Activity { static final String HTML_RES = "html_res"; + static final String HTML = "html"; public static Intent getHelpLaunchIntent() { final Intent intent = new Intent(); @@ -42,15 +43,28 @@ public final class HtmlDisplayActivity extends Activity { return intent; } + public static Intent getHtmlIntent(final String html) { + final Intent intent = new Intent(); + intent.setClassName(HtmlDisplayActivity.class.getPackage().getName(), HtmlDisplayActivity.class.getName()); + intent.putExtra(HTML, html); + return intent; + } + /** Called when the activity is first created. */ @Override public void onCreate(final Bundle savedInstanceState) { setTheme(((DictionaryApplication)getApplication()).getSelectedTheme().themeId); super.onCreate(savedInstanceState); - setContentView(R.layout.help_activity); + setContentView(R.layout.html_display_activity); + final int htmlRes = getIntent().getIntExtra(HTML_RES, -1); - final String html = StringUtil.readToString(getResources().openRawResource(htmlRes)); + final String html; + if (htmlRes != -1) { + html = StringUtil.readToString(getResources().openRawResource(htmlRes)); + } else { + html = getIntent().getStringExtra(HTML); + } final WebView webView = (WebView) findViewById(R.id.webView); webView.loadData(html, "text/html", "utf-8"); diff --git a/src/com/hughes/android/dictionary/engine/HtmlEntry.java b/src/com/hughes/android/dictionary/engine/HtmlEntry.java index af9651f..fe3fd1d 100644 --- a/src/com/hughes/android/dictionary/engine/HtmlEntry.java +++ b/src/com/hughes/android/dictionary/engine/HtmlEntry.java @@ -13,7 +13,7 @@ import com.ibm.icu.text.Transliterator; public class HtmlEntry extends AbstractEntry implements RAFSerializable, Comparable { - final String title; + public final String title; public String html; @@ -89,6 +89,8 @@ public class HtmlEntry extends AbstractEntry implements RAFSerializable