]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
addedAboutAndIcons
authorthadh <thadh@THADH-MTV.ad.corp.google.com>
Thu, 16 Apr 2009 16:06:12 +0000 (09:06 -0700)
committerthadh <thadh@THADH-MTV.ad.corp.google.com>
Thu, 16 Apr 2009 16:06:12 +0000 (09:06 -0700)
12 files changed:
AndroidManifest.xml
americanFlag.jpg [new file with mode: 0755]
flags.xcf [new file with mode: 0755]
germanFlag.jpg [new file with mode: 0755]
res/drawable/icon.png
res/layout/about.xml [new file with mode: 0755]
res/layout/main.xml
res/values/strings.xml
src/com/hughes/android/dictionary/AboutActivity.java [new file with mode: 0755]
src/com/hughes/android/dictionary/Dictionary.java
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/R.java

index 577a753b19b425a6efa7f6a23d7088a928584212..479231d7b141119f140350e2eab0692dc8db444d 100755 (executable)
@@ -11,5 +11,7 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-    </application>
+    
+<activity android:name="AboutActivity"></activity>
+</application>
 </manifest> 
\ No newline at end of file
diff --git a/americanFlag.jpg b/americanFlag.jpg
new file mode 100755 (executable)
index 0000000..8d85b25
Binary files /dev/null and b/americanFlag.jpg differ
diff --git a/flags.xcf b/flags.xcf
new file mode 100755 (executable)
index 0000000..b322c28
Binary files /dev/null and b/flags.xcf differ
diff --git a/germanFlag.jpg b/germanFlag.jpg
new file mode 100755 (executable)
index 0000000..b796c87
Binary files /dev/null and b/germanFlag.jpg differ
index 75024841d327c4fbaefef7c8e9c8d0e892895f93..17ccb38b85ef726803b772bbc1ebd0e2d6e28c31 100755 (executable)
Binary files a/res/drawable/icon.png and b/res/drawable/icon.png differ
diff --git a/res/layout/about.xml b/res/layout/about.xml
new file mode 100755 (executable)
index 0000000..d3c130d
--- /dev/null
@@ -0,0 +1,39 @@
+
+<LinearLayout android:id="@+id/LinearLayout01"
+       android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
+       android:orientation="vertical" android:layout_width="fill_parent">
+
+       <LinearLayout android:id="@+id/LinearLayout02"
+               android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal">
+               
+               <ImageView android:id="@+id/ImageView01"
+                       android:layout_width="wrap_content" android:layout_height="wrap_content"
+                       android:layout_gravity="center_horizontal" android:background="@drawable/icon"></ImageView>
+                       
+               <TextView android:text=" Dictionary 1.0" android:id="@+id/title"
+                       android:textAppearance="?android:attr/textAppearanceLarge"
+                       android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|fill_vertical"></TextView>
+                       
+       </LinearLayout>
+
+       
+
+       <TextView android:text=" " android:id="@+id/space1"
+               android:layout_width="wrap_content" android:layout_height="wrap_content"
+               android:layout_gravity="center_horizontal"></TextView>
+
+       <TextView android:text="(c) 2009" android:id="@+id/copyright"
+               android:layout_width="wrap_content" android:layout_height="wrap_content"
+               android:layout_gravity="center_horizontal"></TextView>
+
+       <TextView android:text="by Thad Hughes" android:id="@+id/author"
+               android:layout_width="wrap_content" android:layout_height="wrap_content"
+               android:layout_gravity="center_horizontal"></TextView>
+
+       <TextView android:text="thughes@cs.stanford.edu" android:id="@+id/email"
+               android:layout_width="wrap_content" android:layout_height="wrap_content"
+               android:layout_gravity="center_horizontal" android:autoLink="email"
+               android:clickable="true"></TextView>
+
+
+</LinearLayout>
index e1e4a89481cd31f2bbdd17d79c8592a759c3cc5f..2de3e1aa9898a960e5e811f1e869712489adcaf3 100755 (executable)
@@ -7,7 +7,7 @@
 
 
 </LinearLayout><TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/SearchBarTableLayout" android:stretchColumns="0">
-<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/SearchBarTableRow"><EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/SearchText" android:hint="Search Text"></EditText><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/LangButton" android:text="LANG"></Button><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/DownButton" android:text="v"></Button><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/UpButton" android:text="^"></Button></TableRow>
+<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/SearchBarTableRow"><EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/SearchText" android:hint="Search Text" android:singleLine="true"></EditText><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/LangButton" android:text="LANG"></Button><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/DownButton" android:text="v"></Button><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/UpButton" android:text="^"></Button></TableRow>
 </TableLayout>
 
        <ListView android:id="@id/android:list"
index 61f6cd45e0f3678187fc9d37f096074c29d9223c..158d1cdb9f39bd58e4c23f46e1b22052cdab644a 100755 (executable)
@@ -1,5 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-    <string name="hello">Hello World, Dictionary</string>
+    
     <string name="app_name">Dictionary</string>
+<string name="about_text">Dictionary\nby Thad Hughes</string>
+
 </resources>
diff --git a/src/com/hughes/android/dictionary/AboutActivity.java b/src/com/hughes/android/dictionary/AboutActivity.java
new file mode 100755 (executable)
index 0000000..8317084
--- /dev/null
@@ -0,0 +1,15 @@
+package com.hughes.android.dictionary;\r
+\r
+import android.app.Activity;\r
+import android.os.Bundle;\r
+\r
+public final class AboutActivity extends Activity {\r
+  \r
+  /** Called when the activity is first created. */\r
+  @Override\r
+  public void onCreate(final Bundle savedInstanceState) {\r
+      super.onCreate(savedInstanceState);\r
+      setContentView(R.layout.about);\r
+  }\r
+\r
+}\r
index 7c1565a65b3c9743953eb923769609701b5390bb..99125935fc88877db6dcb7219201b397bc43c4a8 100755 (executable)
@@ -112,29 +112,30 @@ public final class Dictionary implements RAFSerializable<Dictionary> {
       return Math.min(sortedIndex.size() - 1, start);\r
     }\r
 \r
-    public int getTokenRow(final int rowIndex) {\r
+    public IndexEntry getIndexEntryForRow(final int rowIndex) {\r
+      // TODO: this kinda blows.\r
       int r = rowIndex;\r
       Row row;\r
       while (true) {\r
         row = rows.get(r); \r
-        if (row.isToken() || row.tokenRow != -1) {\r
+        if (row.isToken() || row.indexEntry != null) {\r
           break;\r
         }\r
         --r;\r
       }\r
-      final int result = row.isToken() ? r : row.tokenRow;\r
+      final IndexEntry indexEntry = row.isToken() ? sortedIndex.get(row.getIndex()) : row.indexEntry;\r
       for (; r <= rowIndex; ++r) {\r
-        rows.get(r).tokenRow = result;\r
+        rows.get(r).indexEntry = indexEntry;\r
       }\r
-      assert rows.get(result).isToken();\r
-      return result;\r
+      assert false && rows.get(indexEntry.startRow).isToken();\r
+      return indexEntry;\r
     }\r
   }\r
 \r
   public static final class Row implements RAFSerializable<Row> {\r
     final int index;\r
 \r
-    int tokenRow = -1;\r
+    IndexEntry indexEntry = null;\r
 \r
     public Row(final int index) {\r
       this.index = index;\r
index 382e81ce6155bfe4bbef9fb4d00d891fd7ea1b08..daa79dd2f7dedaadc0c894d7d68bb36271f86c10 100755 (executable)
@@ -10,11 +10,14 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import android.app.ListActivity;
-import android.graphics.Color;
+import android.content.Intent;
+import android.graphics.Typeface;
 import android.os.Bundle;
 import android.os.Handler;
 import android.text.Editable;
+import android.text.Spannable;
 import android.text.TextWatcher;
+import android.text.style.StyleSpan;
 import android.util.Log;
 import android.view.ContextMenu;
 import android.view.KeyEvent;
@@ -56,6 +59,8 @@ public class DictionaryActivity extends ListActivity {
   private DictionaryListAdapter dictionaryListAdapter = new DictionaryListAdapter();
   private int selectedRowIndex = -1;
   private int selectedTokenRowIndex = -1;
+  
+  private final Intent aboutIntent = new Intent().setClassName(AboutActivity.class.getPackage().getName(), AboutActivity.class.getCanonicalName());
 
   /** Called when the activity is first created. */
   @Override
@@ -73,8 +78,7 @@ public class DictionaryActivity extends ListActivity {
 
     setContentView(R.layout.main);
 
-    final EditText searchText = (EditText) findViewById(R.id.SearchText);
-    searchText.addTextChangedListener(new DictionaryTextWatcher());
+    getSearchText().addTextChangedListener(new DictionaryTextWatcher());
 
     setListAdapter(dictionaryListAdapter);
 
@@ -117,22 +121,24 @@ public class DictionaryActivity extends ListActivity {
         jumpToRow(destRowIndex);
       }});
 
-    // Context menu.
+    // ContextMenu.
     registerForContextMenu(getListView());
-    
+
+    // ItemSelectedListener.
     getListView().setOnItemSelectedListener(new OnItemSelectedListener() {
       public void onItemSelected(AdapterView<?> arg0, View arg1, int rowIndex,
           long arg3) {
         Log.d("THAD", "onItemSelected: " + rowIndex);
         selectedRowIndex = rowIndex;
-        selectedTokenRowIndex = activeLangaugeData.getTokenRow(rowIndex);
+        selectedTokenRowIndex = activeLangaugeData.getIndexEntryForRow(rowIndex).startRow;
         updateSearchText();
       }
 
       public void onNothingSelected(AdapterView<?> arg0) {
       }});
     
-    
+
+    // LongClickListener.
     getListView().setOnItemLongClickListener((new OnItemLongClickListener() {
       public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int rowIndex,
           long arg3) {
@@ -145,12 +151,33 @@ public class DictionaryActivity extends ListActivity {
   public String getSelectedRowText() {
     return activeLangaugeData.rowToString(activeLangaugeData.rows.get(selectedRowIndex));
   }
+  
+  public EditText getSearchText() {
+    return (EditText) findViewById(R.id.SearchText);
+  }
+  
+  // ----------------------------------------------------------------
+  // OptionsMenu
+  // ----------------------------------------------------------------
 
   private MenuItem switchLanguageMenuItem = null;
   
   @Override
   public boolean onCreateOptionsMenu(final Menu menu) {
     switchLanguageMenuItem = menu.add("Switch to language.");
+    switchLanguageMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener(){
+      public boolean onMenuItemClick(final MenuItem menuItem) {
+        switchLanguage();
+        return false;
+      }});
+
+    final MenuItem about = menu.add("About...");
+    about.setOnMenuItemClickListener(new OnMenuItemClickListener(){
+      public boolean onMenuItemClick(final MenuItem menuItem) {
+        startActivity(aboutIntent);
+        return false;
+      }});
+
     return true;
   }
   
@@ -159,22 +186,32 @@ public class DictionaryActivity extends ListActivity {
     switchLanguageMenuItem.setTitle(String.format("Switch to %s", dictionary.languageDatas[Entry.otherLang(activeLangaugeData.lang)].language.symbol));
     return super.onPrepareOptionsMenu(menu);
   }
+
+  void switchLanguage() {
+    activeLangaugeData = dictionary.languageDatas[(activeLangaugeData == dictionary.languageDatas[0]) ? 1 : 0];
+    selectedRowIndex = 0;
+    selectedTokenRowIndex = 0;
+    updateLangButton();
+    dictionaryListAdapter.notifyDataSetChanged();
+    onSearchTextChange(getSearchText().getText().toString());
+  }
   
-  @Override
-  public boolean onOptionsItemSelected(final MenuItem item) {
-    if (item == switchLanguageMenuItem) {
-      switchLanguage();
-    }
-    return super.onOptionsItemSelected(item);
+  void updateLangButton() {
+    final Button langButton = (Button) findViewById(R.id.LangButton);
+    langButton.setText(activeLangaugeData.language.symbol);
   }
-
+  
+  // ----------------------------------------------------------------
+  // ContextMenu
+  // ----------------------------------------------------------------
+  
   @Override
   public void onCreateContextMenu(ContextMenu menu, View v,
       ContextMenuInfo menuInfo) {
     if (selectedRowIndex == -1) {
       return;
     }
-    final MenuItem addToWordlist = menu.add("Add to wordlist.");
+    final MenuItem addToWordlist = menu.add("Add to wordlist: " + wordList.getName());
     addToWordlist.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       public boolean onMenuItemClick(MenuItem item) {
         final String rawText = getSelectedRowText();
@@ -191,23 +228,10 @@ public class DictionaryActivity extends ListActivity {
     });
   }
   
-  void switchLanguage() {
-    activeLangaugeData = dictionary.languageDatas[(activeLangaugeData == dictionary.languageDatas[0]) ? 1 : 0];
-    updateLangButton();
-    dictionaryListAdapter.notifyDataSetChanged();
-    final EditText searchText = (EditText) findViewById(R.id.SearchText);
-    onSearchTextChange(searchText.getText().toString());
-  }
-  
-  void updateLangButton() {
-    final Button langButton = (Button) findViewById(R.id.LangButton);
-    langButton.setText(activeLangaugeData.language.symbol);
-  }
-  
   @Override
   public boolean onKeyDown(int keyCode, KeyEvent event) {
     if (event.getUnicodeChar() != 0) {
-      final EditText searchText = (EditText) findViewById(R.id.SearchText);
+      final EditText searchText = getSearchText();
       if (!searchText.hasFocus()) {
         searchText.setText("" + (char)event.getUnicodeChar());
         onSearchTextChange(searchText.getText().toString());
@@ -235,17 +259,23 @@ public class DictionaryActivity extends ListActivity {
   }
   
   private void jumpToRow(final int rowIndex) {
+    Log.d("THAD", "jumpToRow: " + rowIndex);
     selectedRowIndex = rowIndex;
-    selectedTokenRowIndex = activeLangaugeData.getTokenRow(rowIndex);
+    selectedTokenRowIndex = activeLangaugeData.getIndexEntryForRow(rowIndex).startRow;
     getListView().setSelection(rowIndex);
-    getListView().setSelected(true);
+    getListView().setSelected(true);  // TODO: is this doing anything?
     updateSearchText();
   }
 
   private void updateSearchText() {
-    final EditText searchText = (EditText) findViewById(R.id.SearchText);
+    final EditText searchText = getSearchText();
     if (!searchText.hasFocus()) {
-      searchText.setText(activeLangaugeData.rowToString(activeLangaugeData.rows.get(selectedTokenRowIndex)));
+      // TODO: Not so nice:
+      final String word = activeLangaugeData.getIndexEntryForRow(selectedRowIndex).word;
+      if (!word.equals(searchText.getText().toString())) {
+        Log.d("THAD", "updateSearchText: setText: " + word);
+        searchText.setText(word);
+      }
     }
   }
 
@@ -304,6 +334,7 @@ public class DictionaryActivity extends ListActivity {
         result.setText(activeLangaugeData.rowToString(row));
         result.setTextAppearance(parent.getContext(),
             android.R.style.TextAppearance_Large);
+        result.setClickable(false);
         return result;
       }
 
@@ -341,8 +372,17 @@ public class DictionaryActivity extends ListActivity {
         // column1.setTextAppearance(parent.getContext(), android.R.style.Text);
         
         // TODO: highlight query word in entries.
-        column1.setText(entry.getAllText(activeLangaugeData.lang)[r]);
-        column2.setText(entry.getAllText(Entry.otherLang(activeLangaugeData.lang))[r]);
+        final String col1Text = entry.getAllText(activeLangaugeData.lang)[r]; 
+        column1.setText(col1Text, TextView.BufferType.SPANNABLE);
+        final Spannable col1Spannable = (Spannable) column1.getText();
+        int startPos = 0;
+        final String token = activeLangaugeData.getIndexEntryForRow(rowIndex).word;
+        while ((startPos = col1Text.indexOf(token, startPos)) != -1) {
+          col1Spannable.setSpan(new StyleSpan(Typeface.BOLD), startPos, startPos + token.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+         startPos += token.length();
+        }
+        
+        column2.setText(entry.getAllText(Entry.otherLang(activeLangaugeData.lang))[r], TextView.BufferType.NORMAL);
         
         result.addView(tableRow);
       }
@@ -353,7 +393,9 @@ public class DictionaryActivity extends ListActivity {
 
   private class DictionaryTextWatcher implements TextWatcher {
     public void afterTextChanged(Editable searchText) {
-      onSearchTextChange(searchText.toString());
+      if (getSearchText().hasFocus()) {
+        onSearchTextChange(searchText.toString());
+      }
     }
 
     public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
index 2a750f4dc41761ebacc910d0a1075b415185b775..4ec8d9b9e537eb57dfcf09068c9f529fb9151f37 100755 (executable)
@@ -14,19 +14,28 @@ public final class R {
         public static final int icon=0x7f020000;\r
     }\r
     public static final class id {\r
-        public static final int DownButton=0x7f050005;\r
-        public static final int LangButton=0x7f050004;\r
-        public static final int SearchBarLinearLayout=0x7f050000;\r
-        public static final int SearchBarTableLayout=0x7f050001;\r
-        public static final int SearchBarTableRow=0x7f050002;\r
-        public static final int SearchText=0x7f050003;\r
-        public static final int UpButton=0x7f050006;\r
+        public static final int DownButton=0x7f05000d;\r
+        public static final int ImageView01=0x7f050002;\r
+        public static final int LangButton=0x7f05000c;\r
+        public static final int LinearLayout01=0x7f050000;\r
+        public static final int LinearLayout02=0x7f050001;\r
+        public static final int SearchBarLinearLayout=0x7f050008;\r
+        public static final int SearchBarTableLayout=0x7f050009;\r
+        public static final int SearchBarTableRow=0x7f05000a;\r
+        public static final int SearchText=0x7f05000b;\r
+        public static final int UpButton=0x7f05000e;\r
+        public static final int author=0x7f050006;\r
+        public static final int copyright=0x7f050005;\r
+        public static final int email=0x7f050007;\r
+        public static final int space1=0x7f050004;\r
+        public static final int title=0x7f050003;\r
     }\r
     public static final class layout {\r
-        public static final int main=0x7f030000;\r
+        public static final int about=0x7f030000;\r
+        public static final int main=0x7f030001;\r
     }\r
     public static final class string {\r
-        public static final int app_name=0x7f040001;\r
-        public static final int hello=0x7f040000;\r
+        public static final int about_text=0x7f040001;\r
+        public static final int app_name=0x7f040000;\r
     }\r
 }\r