From 6b8d93c656bd93ad26fa57a5f3a07cfb481d4e7d Mon Sep 17 00:00:00 2001 From: thadh Date: Mon, 10 Sep 2012 15:03:58 -0700 Subject: [PATCH] Arrows in UI to display HtmlEntry on Tokens. --- res/drawable/ic_menu_forward.png | Bin 0 -> 769 bytes res/layout/html_display_activity.xml | 2 +- res/values-de/languages.xml | 5 +- res/values/languages.xml | 5 +- .../dictionary/DictionaryActivity.java | 72 +++++++++++++----- .../dictionary/HtmlDisplayActivity.java | 5 ++ .../hughes/android/dictionary/MyWebView.java | 24 ++++++ .../android/dictionary/engine/HtmlEntry.java | 9 +++ .../android/dictionary/engine/Language.java | 3 + .../android/dictionary/engine/TokenRow.java | 7 +- 10 files changed, 107 insertions(+), 25 deletions(-) create mode 100644 res/drawable/ic_menu_forward.png create mode 100644 src/com/hughes/android/dictionary/MyWebView.java diff --git a/res/drawable/ic_menu_forward.png b/res/drawable/ic_menu_forward.png new file mode 100644 index 0000000000000000000000000000000000000000..4a0b6ef68b4dd16bca545dd14b227fdd61d64651 GIT binary patch literal 769 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE0wix1Z>k4UOiAAEE)4(M`_JqL@;D1TB8!2v z2N=7Z%(epwmK8Xr18D^?ZvQoBE>Ih%r;B5V$MK_6ef@<4McVEcr~h&_4e(B~Z_Dys zBdO@7V7P1Hj>2S~+?c7GKJjn(n(y(*ZJWg1jA)OJ&iaEbtnW$`4L4|Ux3~Ds-1&W% z#?~9>_AVB9yt8}e(aQOj^7+r0{#*B4;3*TdY4n@_eC2^9hM8`EgIc=#q!u!A94L?v z&+2jBaVc2G<-p)7Y(D+ifz^-B`owewY6ZkJ-%@vFIf97gUsNh>elCt~jN^*5_bihV}2NBMc6Qk1MieE_f@Gb6>+h zWvA|PnvN`ev$>kJz*SY`d)Y=eJ zYvbY+-R+w`%V~J5yXho(pOZ;-^}SQ)f2LRc_gy!e(Q(m~)%lrEcgc6Tm~8yA&fxjW zCs_?FPduNWerCus*G5H&P3!9PYg(5q&i_pa66(~rYZlD$wYzG - Bengali Bosnisch Bulgarisch + Burmesisch Katalanisch Kroatisch Tschechisch - Chinesisch (Mandarin, Kantonesisch) + Kantonesisch + Chinesisch (Mandarin) Dänisch Niederländisch Englisch @@ -23,6 +25,7 @@ Schottisch-Gälisch Deutsch Griechisch + Altgriechischmymymymymymymymy Hawaiian Hebräisch Hindi diff --git a/res/values/languages.xml b/res/values/languages.xml index 07245f9..d8dabf2 100644 --- a/res/values/languages.xml +++ b/res/values/languages.xml @@ -9,10 +9,12 @@ Bengali Bosnian Bulgarian + Burmese + Cantonese Catalan Croatian Czech - Chinese (Mandarin, Cantonese) + Chinese (Mandarin) Danish Dutch English @@ -23,6 +25,7 @@ Scottish Gaelic German Greek + Ancient Greek Hawaiian Hebrew Hindi diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 8afa61a..279451b 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -14,20 +14,6 @@ package com.hughes.android.dictionary; -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; -import com.hughes.android.dictionary.engine.PairEntry.Pair; -import com.hughes.android.dictionary.engine.RowBase; -import com.hughes.android.dictionary.engine.TokenRow; -import com.hughes.android.dictionary.engine.TransliteratorManager; -import com.hughes.android.util.IntentLauncher; -import com.hughes.android.util.NonLinkClickableSpan; - import android.app.Dialog; import android.app.ListActivity; import android.content.Context; @@ -62,9 +48,11 @@ import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; +import android.widget.LinearLayout.LayoutParams; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListAdapter; @@ -74,6 +62,20 @@ import android.widget.TableRow; import android.widget.TextView; 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; +import com.hughes.android.dictionary.engine.PairEntry.Pair; +import com.hughes.android.dictionary.engine.RowBase; +import com.hughes.android.dictionary.engine.TokenRow; +import com.hughes.android.dictionary.engine.TransliteratorManager; +import com.hughes.android.util.IntentLauncher; +import com.hughes.android.util.NonLinkClickableSpan; + import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -1187,20 +1189,48 @@ public class DictionaryActivity extends ListActivity { private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) { final Context context = parent.getContext(); + + final TableRow tableRow = new TableRow(result.getContext()); + tableRow.setBackgroundResource(row.hasMainEntry ? theme.tokenRowMainBg + : theme.tokenRowOtherBg); + tableRow.setPadding(mPaddingDefault, mPaddingDefault, mPaddingDefault, 0); + result.addView(tableRow); + + final IndexEntry indexEntry = row.getIndexEntry(); + final TextView textView = new TextView(context); - textView.setText(row.getToken()); + textView.setText(indexEntry.token); // 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); - - final TableRow tableRow = new TableRow(result.getContext()); + TableRow.LayoutParams lp = new TableRow.LayoutParams(0); + lp.weight = 1.0f; + textView.setLayoutParams(lp); tableRow.addView(textView); - tableRow.setBackgroundResource(row.hasMainEntry ? theme.tokenRowMainBg - : theme.tokenRowOtherBg); - tableRow.setPadding(mPaddingDefault, mPaddingDefault, mPaddingDefault, 0); - result.addView(tableRow); + + + if (!indexEntry.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); + startActivity(HtmlDisplayActivity.getHtmlIntent(String.format( + "%s", html))); + } + }); + tableRow.addView(button); + lp = new TableRow.LayoutParams(1); + lp.weight = 0.0f; + button.setLayoutParams(lp); + //result.setColumnStretchable(0, true); + //result.setColumnStretchable(1, false); + } + + return result; } diff --git a/src/com/hughes/android/dictionary/HtmlDisplayActivity.java b/src/com/hughes/android/dictionary/HtmlDisplayActivity.java index 24e0a6e..4e12ebf 100644 --- a/src/com/hughes/android/dictionary/HtmlDisplayActivity.java +++ b/src/com/hughes/android/dictionary/HtmlDisplayActivity.java @@ -17,8 +17,13 @@ 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.view.View; import android.view.View.OnClickListener; +import android.view.View.OnCreateContextMenuListener; import android.webkit.WebView; import android.widget.Button; diff --git a/src/com/hughes/android/dictionary/MyWebView.java b/src/com/hughes/android/dictionary/MyWebView.java new file mode 100644 index 0000000..5f39697 --- /dev/null +++ b/src/com/hughes/android/dictionary/MyWebView.java @@ -0,0 +1,24 @@ +package com.hughes.android.dictionary; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.ContextMenu; +import android.webkit.WebView; + +public class MyWebView extends WebView { + + public MyWebView(Context context) { + super(context); + } + + public MyWebView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + + @Override + public void onCreateContextMenu(ContextMenu menu) { + super.onCreateContextMenu(menu); + } + +} diff --git a/src/com/hughes/android/dictionary/engine/HtmlEntry.java b/src/com/hughes/android/dictionary/engine/HtmlEntry.java index 404bc6a..d5fbebf 100644 --- a/src/com/hughes/android/dictionary/engine/HtmlEntry.java +++ b/src/com/hughes/android/dictionary/engine/HtmlEntry.java @@ -12,6 +12,7 @@ import java.util.regex.Pattern; public class HtmlEntry extends AbstractEntry implements RAFSerializable, Comparable { + // Both are HTML escaped already. public final String title; public String html; @@ -137,4 +138,12 @@ 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)); + } + return result.toString(); + } + } diff --git a/src/com/hughes/android/dictionary/engine/Language.java b/src/com/hughes/android/dictionary/engine/Language.java index 802fd0a..deeda18 100644 --- a/src/com/hughes/android/dictionary/engine/Language.java +++ b/src/com/hughes/android/dictionary/engine/Language.java @@ -51,6 +51,8 @@ public class Language { isoCodeToResources.put("BN", new LanguageResources("Bengali", R.string.BN)); isoCodeToResources.put("BS", new LanguageResources("Bosnian", R.string.BS)); isoCodeToResources.put("BG", new LanguageResources("Bulgarian", R.string.BG)); + isoCodeToResources.put("MY", new LanguageResources("Burmese", R.string.MY)); + isoCodeToResources.put("yue", new LanguageResources("Cantonese", R.string.yue)); isoCodeToResources.put("CA", new LanguageResources("Catalan", R.string.CA)); isoCodeToResources.put("HR", new LanguageResources("Croatian", R.string.HR)); isoCodeToResources.put("CS", new LanguageResources("Czech", R.string.CS)); @@ -64,6 +66,7 @@ public class Language { isoCodeToResources.put("FR", new LanguageResources("French", R.string.FR)); isoCodeToResources.put("DE", new LanguageResources("German", R.string.DE)); isoCodeToResources.put("EL", new LanguageResources("Greek", R.string.EL)); + isoCodeToResources.put("grc", new LanguageResources("Ancient Greek", R.string.grc)); isoCodeToResources.put("haw", new LanguageResources("Hawaiian", R.string.haw)); isoCodeToResources.put("HE", new LanguageResources("Hebrew", R.string.HE)); isoCodeToResources.put("HI", new LanguageResources("Hindi", R.string.HI)); diff --git a/src/com/hughes/android/dictionary/engine/TokenRow.java b/src/com/hughes/android/dictionary/engine/TokenRow.java index 956044a..96842e9 100644 --- a/src/com/hughes/android/dictionary/engine/TokenRow.java +++ b/src/com/hughes/android/dictionary/engine/TokenRow.java @@ -20,6 +20,7 @@ import java.io.RandomAccessFile; import java.util.List; import java.util.regex.Pattern; +import com.hughes.android.dictionary.engine.Index.IndexEntry; import com.ibm.icu.text.Transliterator; public class TokenRow extends RowBase { @@ -51,7 +52,11 @@ public class TokenRow extends RowBase { } public String getToken() { - return index.sortedIndexEntries.get(referenceIndex).token; + return getIndexEntry().token; + } + + public IndexEntry getIndexEntry() { + return index.sortedIndexEntries.get(referenceIndex); } @Override -- 2.43.0