]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Arrows in UI to display HtmlEntry on Tokens.
authorthadh <thadh@dhcp-192-168-28-174.mtv.corp.google.com>
Mon, 10 Sep 2012 22:03:58 +0000 (15:03 -0700)
committerthadh <thadh@dhcp-192-168-28-174.mtv.corp.google.com>
Mon, 10 Sep 2012 22:03:58 +0000 (15:03 -0700)
res/drawable/ic_menu_forward.png [new file with mode: 0644]
res/layout/html_display_activity.xml
res/values-de/languages.xml
res/values/languages.xml
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/HtmlDisplayActivity.java
src/com/hughes/android/dictionary/MyWebView.java [new file with mode: 0644]
src/com/hughes/android/dictionary/engine/HtmlEntry.java
src/com/hughes/android/dictionary/engine/Language.java
src/com/hughes/android/dictionary/engine/TokenRow.java

diff --git a/res/drawable/ic_menu_forward.png b/res/drawable/ic_menu_forward.png
new file mode 100644 (file)
index 0000000..4a0b6ef
Binary files /dev/null and b/res/drawable/ic_menu_forward.png differ
index a9ac9a26f88f41018e4cf4f4499c4d51bc7a2bda..0e226263c1275965819ee6440d635a9143e17ab4 100644 (file)
@@ -4,7 +4,7 @@
     android:layout_height="match_parent"
     android:orientation="vertical" >
     
-  <WebView
+  <com.hughes.android.dictionary.MyWebView
       android:id="@+id/webView"
       android:layout_width="match_parent"
       android:layout_height="0dip"
index e86a1fe262ca8f1b8fad7bd2fb0589099e473781..4cc31011c3d56ef82ef551d35c6fda9cef3e9ff2 100644 (file)
@@ -9,10 +9,12 @@
   <string name="BN">Bengali</string>
   <string name="BS">Bosnisch</string>
   <string name="BG">Bulgarisch</string>
+  <string name="MY">Burmesisch</string>
   <string name="CA">Katalanisch</string>
   <string name="HR">Kroatisch</string>
   <string name="CS">Tschechisch</string>
-  <string name="ZH">Chinesisch (Mandarin, Kantonesisch)</string>
+  <string name="yue">Kantonesisch</string>
+  <string name="ZH">Chinesisch (Mandarin)</string>
   <string name="DA">Dänisch</string>
   <string name="NL">Niederländisch</string>
   <string name="EN">Englisch</string>
@@ -23,6 +25,7 @@
   <string name="GD">Schottisch-Gälisch</string>
   <string name="DE">Deutsch</string>
   <string name="EL">Griechisch</string>
+  <string name="grc">Altgriechischmymymymymymymymy</string>
   <string name="haw">Hawaiian</string>
   <string name="HE">Hebräisch</string>
   <string name="HI">Hindi</string>
index 07245f9eaa6e81d410d98a1fc3c11c3df12b4823..d8dabf213a23c7926f297921f48538dbb5e52496 100644 (file)
@@ -9,10 +9,12 @@
   <string name="BN">Bengali</string>
   <string name="BS">Bosnian</string>
   <string name="BG">Bulgarian</string>
+  <string name="MY">Burmese</string>
+  <string name="yue">Cantonese</string>
   <string name="CA">Catalan</string>
   <string name="HR">Croatian</string>
   <string name="CS">Czech</string>
-  <string name="ZH">Chinese (Mandarin, Cantonese)</string>
+  <string name="ZH">Chinese (Mandarin)</string>
   <string name="DA">Danish</string>
   <string name="NL">Dutch</string>
   <string name="EN">English</string>
@@ -23,6 +25,7 @@
   <string name="GD">Scottish Gaelic</string>
   <string name="DE">German</string>
   <string name="EL">Greek</string>
+  <string name="grc">Ancient Greek</string>
   <string name="haw">Hawaiian</string>
   <string name="HE">Hebrew</string>
   <string name="HI">Hindi</string>
index 8afa61a8a0e08cebb4c038103bf5700072954ff0..279451b1dc40b03065d3a93ad4c4896ad610caf9 100644 (file)
 
 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(
+                                "<html><head></head><body>%s</body></html>", 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;
         }
 
index 24e0a6e20274154dd8ca32c62dfd48693860f443..4e12ebf284529d61eafe0eb551a430dcb64c3081 100644 (file)
@@ -17,8 +17,13 @@ package com.hughes.android.dictionary;
 import android.app.Activity;\r
 import android.content.Intent;\r
 import android.os.Bundle;\r
+import android.view.ContextMenu;\r
+import android.view.ContextMenu.ContextMenuInfo;\r
+import android.view.MenuItem;\r
+import android.view.MenuItem.OnMenuItemClickListener;\r
 import android.view.View;\r
 import android.view.View.OnClickListener;\r
+import android.view.View.OnCreateContextMenuListener;\r
 import android.webkit.WebView;\r
 import android.widget.Button;\r
 \r
diff --git a/src/com/hughes/android/dictionary/MyWebView.java b/src/com/hughes/android/dictionary/MyWebView.java
new file mode 100644 (file)
index 0000000..5f39697
--- /dev/null
@@ -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);
+    }
+
+}
index 404bc6a28f21713dbd8a2ddf7031d3ff28805fca..d5fbebf97fc37fb948a789eeaa5a0c45f5241776 100644 (file)
@@ -12,6 +12,7 @@ import java.util.regex.Pattern;
 
 public class HtmlEntry extends AbstractEntry implements RAFSerializable<HtmlEntry>, Comparable<HtmlEntry> {
   
+  // Both are HTML escaped already.
   public final String title;
   public String html;
   
@@ -137,4 +138,12 @@ public class HtmlEntry extends AbstractEntry implements RAFSerializable<HtmlEntr
     
   }
 
+    public static String htmlBody(final List<HtmlEntry> htmlEntries) {
+        final StringBuilder result = new StringBuilder();
+        for (final HtmlEntry htmlEntry : htmlEntries) {
+            result.append(String.format("<h1>%s</h1>%s\n", htmlEntry.title, htmlEntry.html));
+        }
+        return result.toString();
+    }
+
 }
index 802fd0ac2b134cc087797a2281d9cb743c155efe..deeda18b245658724089eb753bcd68b31ed68a01 100644 (file)
@@ -51,6 +51,8 @@ public class Language {
     isoCodeToResources.put("BN", new LanguageResources("Bengali", R.string.BN));\r
     isoCodeToResources.put("BS", new LanguageResources("Bosnian", R.string.BS));\r
     isoCodeToResources.put("BG", new LanguageResources("Bulgarian", R.string.BG));\r
+    isoCodeToResources.put("MY", new LanguageResources("Burmese", R.string.MY));\r
+    isoCodeToResources.put("yue", new LanguageResources("Cantonese", R.string.yue));\r
     isoCodeToResources.put("CA", new LanguageResources("Catalan", R.string.CA));\r
     isoCodeToResources.put("HR", new LanguageResources("Croatian", R.string.HR));\r
     isoCodeToResources.put("CS", new LanguageResources("Czech", R.string.CS));\r
@@ -64,6 +66,7 @@ public class Language {
     isoCodeToResources.put("FR", new LanguageResources("French", R.string.FR));\r
     isoCodeToResources.put("DE", new LanguageResources("German", R.string.DE));\r
     isoCodeToResources.put("EL", new LanguageResources("Greek", R.string.EL));\r
+    isoCodeToResources.put("grc", new LanguageResources("Ancient Greek", R.string.grc));\r
     isoCodeToResources.put("haw", new LanguageResources("Hawaiian", R.string.haw));\r
     isoCodeToResources.put("HE", new LanguageResources("Hebrew", R.string.HE));\r
     isoCodeToResources.put("HI", new LanguageResources("Hindi", R.string.HI));\r
index 956044afe3a715f1dd6b6e1e80417399d6749c7e..96842e985bda925558f8451661f0fb1bff9f22d0 100644 (file)
@@ -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