]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Picking back up in the middle of a major refactoring of the UI, tyring
authorThad Hughes <thadh@google.com>
Fri, 29 Nov 2013 20:38:08 +0000 (12:38 -0800)
committerThad Hughes <thadh@google.com>
Fri, 29 Nov 2013 20:38:08 +0000 (12:38 -0800)
to introduct Actionbar Sherlock and the DownloadManager.  Things are not
likely to be working at this point.

22 files changed:
.classpath
libs/android-support-v4.jar [new file with mode: 0644]
project.properties
res/layout/about_activity.xml
res/layout/dictionary_activity.xml
res/layout/dictionary_manager_activity.xml
res/layout/dictionary_manager_row.xml [new file with mode: 0644]
res/layout/dictionary_search_view.xml [new file with mode: 0644]
res/layout/download_activity.xml [deleted file]
res/values-v11/styles.xml
res/values-v11/themes.xml [deleted file]
res/values-v14/styles.xml
res/values/strings.xml
res/values/styles.xml
res/values/themes.xml [deleted file]
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/DictionaryApplication.java
src/com/hughes/android/dictionary/DictionaryManagerActivity.java
src/com/hughes/android/dictionary/DownloadActivity.java [deleted file]
src/com/hughes/android/dictionary/MyWebView.java
src/com/hughes/android/dictionary/engine/Language.java
todo.txt [new file with mode: 0644]

index 73b4bf7063a04ea6daba107022cc0d43b8b03f0a..b62bfa712da6cd02781477981f01d001d1a2ecdc 100644 (file)
@@ -6,6 +6,7 @@
        <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
        <classpathentry combineaccessrules="false" exported="true" kind="src" path="/Util"/>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/actionbarsherlock"/>
        <classpathentry kind="output" path="bin/classes"/>
 </classpath>
diff --git a/libs/android-support-v4.jar b/libs/android-support-v4.jar
new file mode 100644 (file)
index 0000000..428bdbc
Binary files /dev/null and b/libs/android-support-v4.jar differ
index 6f491fbdea8260fcf801da734851134f8b97e68a..550d14c5c397ef07e5792526bc4b55f9cc0ad0d5 100644 (file)
@@ -11,4 +11,6 @@
 split.density=false
 # Project target.
 target=android-17
-android.library.reference.1=../Util
+android.library.reference.1=../JakeWharton-ActionBarSherlock-071a61c/actionbarsherlock
+android.library.reference.1=../JakeWharton-ActionBarSherlock-071a61c/actionbarsherlock
+android.library.reference.2=../Util
index e47364161afc8fd88f0710e6e7cf91ccd2b81852..8b3410fa40849270d650572d1dc9bbcc5696291e 100644 (file)
@@ -1,61 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/ScrollView01"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    tools:ignore="HardcodedText" >
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
 
     <LinearLayout
-        android:id="@+id/LinearLayout01"
-        android:layout_width="fill_parent"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical" >
 
-        <LinearLayout
-            android:id="@+id/LinearLayout02"
+        <TextView
+            android:id="@+id/textView1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
-            android:paddingBottom="10dip" >
-
-            <ImageView
-                android:id="@+id/ImageView01"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center_horizontal"
-                android:background="@drawable/icon"
-                android:contentDescription="icon" />
-
-            <TextView
-                android:id="@+id/title"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center_vertical|fill_vertical"
-                android:text="@string/titleWithVersion"
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-        </LinearLayout>
+            android:drawableLeft="@drawable/icon"
+            android:text="@string/titleWithVersion"
+            android:textAppearance="?android:attr/textAppearanceLarge" />
 
         <TextView
-            android:id="@+id/copyright"
+            android:id="@+id/textView2"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
-            android:text="Copyright 2009-2011 Google Inc." />
+            android:text="Copyright 2009-2013 Google Inc."
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            tools:ignore="HardcodedText" />
 
         <TextView
-            android:id="@+id/author"
+            android:id="@+id/textView3"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
-            android:paddingBottom="10dip"
-            android:text="Thad Hughes" />
+            android:text="Thad Hughes"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            tools:ignore="HardcodedText" />
 
         <TextView
-            android:id="@+id/emailMe"
+            android:id="@+id/textView4"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="@string/contactMe" />
-
+            android:text="@string/contactMe"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+        
         <TextView
             android:id="@+id/email"
             android:layout_width="wrap_content"
@@ -63,8 +50,9 @@
             android:layout_gravity="left"
             android:autoLink="email"
             android:clickable="true"
+            android:text="@string/myEmail"
             android:paddingBottom="10dip"
-            android:text="@string/myEmail" />
+            />
 
         <TextView
             android:id="@+id/webPage"
@@ -79,8 +67,9 @@
             android:layout_gravity="left"
             android:autoLink="web"
             android:clickable="true"
+            android:text="@string/webPageUrl"
             android:paddingBottom="10dip"
-            android:text="@string/webPageUrl" />
+             />
 
         <TextView
             android:id="@+id/license"
index 640d9749ebdc9b3c39354642a69f68d8489d8cac..d21b74394299f90a2aceef16cb449676232ec9cf 100644 (file)
             style="@style/BorderlessButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:padding="@dimen/default_padding"
             android:src="@drawable/ic_input_delete" />
 
-        <ImageButton
-            android:id="@+id/DownButton"
-            style="@style/BorderlessButton"
-            android:layout_width="48dp"
-            android:layout_height="48dp"
-            android:src="@drawable/arrow_down_float" />
-
-        <ImageButton
-            android:id="@+id/UpButton"
-            style="@style/BorderlessButton"
-            android:layout_width="48dp"
-            android:layout_height="48dp"
-            android:src="@drawable/arrow_up_float" />
     </LinearLayout>
 
     <ListView
index 0bdc6b85df5fe0d4274887b3410bd790f38d94d4..b808593d986c900dbbc6c7fd62f43cf8073aa37d 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >
             android:layout_weight="1"
             android:hint="@string/managerFilterText" />
 
-        <CheckBox
-            android:id="@+id/showLocal"
+        <ImageButton
+            android:id="@+id/ClearSearchTextButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="0"
-            android:text="@string/managerFilterCheckbox" />
+            android:src="@android:drawable/ic_input_delete" 
+            android:contentDescription="@string/clearSearchText"/>
+
+        <ToggleButton
+            android:id="@+id/showLocal"
+            android:layout_width="wrap_content"
+            android:layout_height="fill_parent"
+            android:layout_weight="0"
+            android:textOff="@string/managerFilterCheckboxAll"
+            android:textOn="@string/managerFilterCheckboxLocal" />
+
     </LinearLayout>
 
     <ListView
@@ -32,7 +43,8 @@
         android:choiceMode="singleChoice"
         android:clickable="true"
         android:fastScrollEnabled="true"
-        android:focusable="true" />
+        android:focusable="true"
+        tools:listitem="@layout/dictionary_manager_row" />
 
     <TextView
         android:id="@+id/DictionaryListHeader"
diff --git a/res/layout/dictionary_manager_row.xml b/res/layout/dictionary_manager_row.xml
new file mode 100644 (file)
index 0000000..175b21f
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical" >
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal" >
+
+        <TextView
+            android:id="@+id/dictionaryName"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:text="English-German"
+            android:textAppearance="?android:attr/textAppearanceLarge"
+            tools:ignore="HardcodedText" />
+
+        <Button
+            android:id="@+id/dictionaryDownloadButton"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_weight="0"
+            android:drawableLeft="@android:drawable/ic_menu_add"
+            android:text="@string/downloadButton" />
+    </LinearLayout>
+
+    <TextView
+        android:id="@+id/dictionaryDetails"
+        android:layout_width="fill_parent"
+        android:layout_height="0dip"
+        android:layout_weight="1"
+        android:text="@string/indexInfo"
+        android:textAppearance="?android:attr/textAppearanceSmall"
+        tools:ignore="HardcodedText" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/dictionary_search_view.xml b/res/layout/dictionary_search_view.xml
new file mode 100644 (file)
index 0000000..62fcb18
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="horizontal" >
+
+    <EditText
+        android:id="@+id/SearchText"
+        android:layout_width="0dip"
+        android:layout_height="wrap_content"
+        android:layout_weight="1.0"
+        android:hint="@string/searchText"
+        android:imeOptions="actionSearch|flagNoEnterAction|flagNoExtractUi"
+        android:inputType="text" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/download_activity.xml b/res/layout/download_activity.xml
deleted file mode 100755 (executable)
index 39bebce..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<LinearLayout android:id="@+id/LinearLayout01"
-       android:orientation="vertical" android:layout_width="fill_parent"
-       android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
-
-       <TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
-               android:layout_height="wrap_content" android:text="Downloading..."/>
-
-       <LinearLayout android:id="@+id/sourceLayout"
-               android:orientation="horizontal" android:layout_width="fill_parent"
-               android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
-               <TextView android:id="@+id/sourceTitle" android:layout_width="wrap_content"
-                       android:layout_height="wrap_content" android:text="Source: "/>
-               <TextView android:id="@+id/source" android:layout_width="wrap_content"
-                       android:layout_height="wrap_content" android:text="source"/>
-       </LinearLayout>
-
-       <LinearLayout android:id="@+id/destLayout"
-               android:orientation="horizontal" android:layout_width="fill_parent"
-               android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
-               <TextView android:id="@+id/destTitle" android:layout_width="wrap_content"
-                       android:layout_height="wrap_content" android:text="Destination: "/>
-               <TextView android:id="@+id/dest" android:layout_width="wrap_content"
-                       android:layout_height="wrap_content" android:text="dest"/>
-       </LinearLayout>
-
-       <ProgressBar android:id="@+id/downloadProgressBar" style="?android:attr/progressBarStyleHorizontal"
-    android:max="100" android:progress="50"
-               android:layout_width="fill_parent" android:layout_height="wrap_content" android:indeterminate="false"/>
-
-  <TextView android:id="@+id/downloadMessage" android:layout_width="wrap_content"
-    android:layout_height="wrap_content" android:visibility="visible" android:text="Download message."
-    android:layout_marginTop="10dip"
-    android:layout_marginBottom="10dip"/>
-       <TextView android:id="@+id/downloadStatus" android:layout_width="wrap_content"
-               android:layout_height="wrap_content" android:visibility="visible" android:text="Download status."/>
-
-</LinearLayout>
index b1b626499a07cc4a7ea03e591921938bc1e7d43d..41bcbbd497796eb08a84e2fe3a07d1bfabe6df6c 100644 (file)
@@ -1,17 +1,9 @@
 <resources>
 
-    <!--
-        Base application theme for API 11+. This theme completely replaces
-        AppBaseTheme from res/values/styles.xml on API 11+ devices.
-    -->
-    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
-        <!-- API 11 theme customizations can go here. -->
-    </style>
-    
     <style name="BorderlessButton">
         <item name="android:background">?android:attr/selectableItemBackground</item>
         <item name="android:paddingLeft">4dip</item>
         <item name="android:paddingRight">4dip</item>
     </style>
 
-</resources>
\ No newline at end of file
+</resources>
diff --git a/res/values-v11/themes.xml b/res/values-v11/themes.xml
deleted file mode 100644 (file)
index 90e8b5b..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
-  
-  <!-- Default: dark theme -->
-    
-  <style name="Theme.Default" parent="@android:style/Theme.Holo">
-  </style>
-  
-  
-  <!-- ****************************************************************** -->
-
-  <style name="Theme.Light" parent="@android:style/Theme.Holo.Light">
-  </style>
-  
-
-</resources>
\ No newline at end of file
index a91fd0372b20f85e284fc2fa2ce949176dfdf6e5..94fd7e0e329a2a356d312b41f3307e6c5cef5d3d 100644 (file)
@@ -1,12 +1,3 @@
 <resources>
-
-    <!--
-        Base application theme for API 14+. This theme completely replaces
-        AppBaseTheme from BOTH res/values/styles.xml and
-        res/values-v11/styles.xml on API 14+ devices.
-    -->
-    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
-        <!-- API 14 theme customizations can go here. -->
-    </style>
-
+    
 </resources>
index b28da4bd4a423d69e8da3141f8101ebd30453718..8185bb1d3f8df7554b00473edf379300be8107b7 100644 (file)
   <string name="help">Help</string>
   <string name="reportIssue">Report issue…</string>
   <string name="fontWorkaround">Detected font problem (common on Sony Ericsson devices), switching back to default font.</string>
+  <string name="clearSearchText">Clear search text</string>
   
   
    <!-- DictionaryManagerActivity -->
   <string name="dictionaryManager">Dictionary manager</string>
   <string name="helpText">Long-press a dictionary for more options.</string>
-  <string name="downloadButton">Download (%.1fMB)</string>
-  <string name="updateButton">Update (%.1fMB)</string>
+  <string name="downloadButton">%.1fMB</string>
   <string name="moveToTop">Move to top</string>
   <string name="deleteDictionary">Delete dictionary</string>
   <string name="indexInfo">%1$s: %2$,d words</string>
   <string name="managerFilterText">List filter</string>
-  <string name="managerFilterCheckbox">Local only</string>
-  
+  <string name="managerFilterCheckboxAll">All</string>
+  <string name="managerFilterCheckboxLocal">Local</string>
 
   <string name="thanksForUpdatingVersion">4.0.1_en_a</string>
 
@@ -43,6 +43,8 @@
   <string name="fontFailure">Font failure: %s</string> 
   <string name="seeAlso">See also: %1$s (%2$s)</string> 
   <string name="speak">Speak</string> 
+  <string name="nextWord">Next word</string> 
+  <string name="previousWord">Previous word</string> 
   
 
   <!-- About dictionary. -->
index 46e7d9025c3c1e44ae707445d26b46772155f141..c2c6e4be527d196b9725c12a3b8008996ba79e29 100644 (file)
@@ -4,23 +4,68 @@
         Base application theme, dependent on API level. This theme is replaced
         by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
     -->
-    <style name="AppBaseTheme" parent="android:Theme.Light">
+    <style name="AppBaseThemeLight" parent="Theme.Sherlock.Light">
         <!--
             Theme customizations available in newer API levels can go in
             res/values-vXX/styles.xml, while customizations related to
             backward-compatibility can go here.
         -->
+        <!--
+            Make search icon magnifying glass disappear:
+            http://stackoverflow.com/questions/13604506/show-actionbarsherlock-searchview-always-expanded
+        -->
+      <item name="searchViewSearchIcon">@android:color/transparent</item>
+      <item name="searchViewCloseIcon">@android:color/transparent</item>
+    </style>
+    
+    <style name="AppBaseThemeDark" parent="Theme.Sherlock">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+        <!--
+            Make search icon magnifying glass disappear:
+            http://stackoverflow.com/questions/13604506/show-actionbarsherlock-searchview-always-expanded
+        -->
+      <item name="searchViewSearchIcon">@android:color/transparent</item>
+      <item name="searchViewCloseIcon">@android:color/transparent</item>
     </style>
 
-    <!-- Application theme. -->
-    <style name="AppTheme" parent="AppBaseTheme">
-        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    <!-- Dark theme -->
+
+    <style name="Theme.Default" parent="AppBaseThemeDark"></style>
+
+    <style name="Theme.Default.TokenRow.Fg" parent="Theme.Default">
+        <!-- <item name="android:textColor">#FFFFFF</item> -->
+        <item name="android:textColorLink">#00AAFF</item>
     </style>
 
+    <color name="theme_default_token_row_fg">#FFFFFF</color>
+    <color name="theme_default_token_row_main_bg">#222222</color>
+    <color name="theme_default_token_row_other_bg">#222222</color>
+    <color name="theme_default_other_lang_bg">#000000</color>
+
+    <!-- ****************************************************************** -->
+
+    <!-- Light theme -->
+
+    <style name="Theme.Light" parent="AppBaseThemeLight"></style>
+
+    <style name="Theme.Light.TokenRow.Fg" parent="Theme.Light">
+        <!-- <item name="android:textColor">#000000</item> -->
+        <item name="android:textColorLink">#0000FF</item>
+    </style>
+
+    <color name="theme_light_token_row_fg">#000000</color>
+    <color name="theme_light_token_row_main_bg">#EEEEEE</color>
+    <color name="theme_light_token_row_other_bg">#EEEEEE</color>
+    <color name="theme_light_other_lang_bg">#FFFFFF</color>
+
     <style name="BorderlessButton">
         <item name="android:background">@null</item>
         <item name="android:paddingLeft">4dip</item>
         <item name="android:paddingRight">4dip</item>
     </style>
 
-</resources>
+</resources>
\ No newline at end of file
diff --git a/res/values/themes.xml b/res/values/themes.xml
deleted file mode 100644 (file)
index 932fff0..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
-  
-  <!-- Default: dark theme -->
-    
-  <style name="Theme.Default" parent="@android:style/Theme">
-  </style>
-
-  <style name="Theme.Default.TokenRow.Fg" parent="@style/Theme.Default">
-<!--       <item name="android:textColor">#FFFFFF</item>   -->
-      <item name="android:textColorLink">#00AAFF</item>
-  </style>
-  
-  <color name="theme_default_token_row_fg">#FFFFFF</color>
-  <color name="theme_default_token_row_main_bg">#222222</color>
-  <color name="theme_default_token_row_other_bg">#222222</color>
-  <color name="theme_default_other_lang_bg">#000000</color>
-  
-  
-  <!-- ****************************************************************** -->
-
-  <style name="Theme.Light" parent="@android:style/Theme.Light">
-  </style>
-
-  <style name="Theme.Light.TokenRow.Fg" parent="@style/Theme.Light">
-      <!-- <item name="android:textColor">#000000</item> -->
-      <item name="android:textColorLink">#0000FF</item> 
-  </style>
-  
-  <color name="theme_light_token_row_fg">#000000</color>
-  <color name="theme_light_token_row_main_bg">#EEEEEE</color>
-  <color name="theme_light_token_row_other_bg">#EEEEEE</color>
-  <color name="theme_light_other_lang_bg">#FFFFFF</color>
-  
-</resources>
\ No newline at end of file
index 56ded03c6c97e86634905d7f435546141795a1ff..fb546dd7a8bec3d87be6d745e0237c6e14262264 100644 (file)
@@ -14,8 +14,8 @@
 
 package com.hughes.android.dictionary;
 
+import android.annotation.SuppressLint;
 import android.app.Dialog;
-import android.app.ListActivity;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
@@ -40,9 +40,7 @@ import android.util.TypedValue;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MenuItem.OnMenuItemClickListener;
+import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -50,6 +48,7 @@ import android.view.View.OnFocusChangeListener;
 import android.view.View.OnLongClickListener;
 import android.view.ViewGroup;
 import android.view.WindowManager;
+import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.AdapterView.AdapterContextMenuInfo;
 import android.widget.BaseAdapter;
@@ -66,6 +65,12 @@ import android.widget.TextView;
 import android.widget.TextView.BufferType;
 import android.widget.Toast;
 
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.app.SherlockListActivity;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuItem;
+import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
+import com.actionbarsherlock.widget.SearchView;
 import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
 import com.hughes.android.dictionary.engine.Dictionary;
 import com.hughes.android.dictionary.engine.EntrySource;
@@ -103,7 +108,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-public class DictionaryActivity extends ListActivity {
+public class DictionaryActivity extends SherlockListActivity {
 
     static final String LOG = "QuickDic";
 
@@ -148,6 +153,8 @@ public class DictionaryActivity extends ListActivity {
     EditText searchText;
 
     Button langButton;
+    
+    MenuItem nextWordMenuItem, previousWordMenuItem;
 
     // Never null.
     private File wordList = null;
@@ -361,25 +368,6 @@ public class DictionaryActivity extends ListActivity {
         });
         updateLangButton();
 
-        final View upButton = findViewById(R.id.UpButton);
-        upButton.setOnClickListener(new OnClickListener() {
-            public void onClick(View v) {
-                onUpDownButton(true);
-            }
-        });
-        final View downButton = findViewById(R.id.DownButton);
-        downButton.setOnClickListener(new OnClickListener() {
-            public void onClick(View v) {
-                onUpDownButton(false);
-            }
-        });
-        upButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this)
-                .getBoolean(getString(R.string.showPrevNextButtonsKey), true) ? View.VISIBLE
-                : View.GONE);
-        downButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this)
-                .getBoolean(getString(R.string.showPrevNextButtonsKey), true) ? View.VISIBLE
-                : View.GONE);
-
 //        getListView().setOnItemSelectedListener(new ListView.OnItemSelectedListener() {
 //            @Override
 //            public void onItemSelected(AdapterView<?> adapterView, View arg1, final int position,
@@ -416,6 +404,31 @@ public class DictionaryActivity extends ListActivity {
         Log.d(LOG, "wordList=" + wordList + ", saveOnlyFirstSubentry=" + saveOnlyFirstSubentry);
 
         setDictionaryPrefs(this, dictFile, indexIndex, searchText.getText().toString());
+        
+        ActionBar actionBar = getSupportActionBar();
+        actionBar.setDisplayShowTitleEnabled(false);
+        
+        //Inflate the custom view
+//        View customNav = LayoutInflater.from(this).inflate(R.layout.dictionary_search_view, null);
+      SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
+      searchView.setIconifiedByDefault(false);
+      searchView.setQueryHint(getString(R.string.searchText));
+      searchView.setSubmitButtonEnabled(false);
+//      searchView.setMaxWidth(200);
+      searchView.setImeOptions(
+              EditorInfo.IME_ACTION_SEARCH |
+              EditorInfo.IME_FLAG_NO_EXTRACT_UI | 
+              EditorInfo.IME_FLAG_NO_ENTER_ACTION | 
+//              EditorInfo.IME_FLAG_NO_FULLSCREEN |
+              EditorInfo.IME_MASK_ACTION |
+              EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
+//      searchView.setOnQueryTextListener(this);
+//      menu.add("Search")
+////          .setIcon(isLight ? R.drawable.ic_search_inverse : R.drawable.abs__ic_search)
+//          .setActionView(searchView)
+//          .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+        actionBar.setCustomView(searchView);
+        actionBar.setDisplayShowCustomEnabled(true);        
     }
 
     @Override
@@ -682,9 +695,56 @@ public class DictionaryActivity extends ListActivity {
     // --------------------------------------------------------------------------
 
     final Random random = new Random();
-
+    
     @Override
     public boolean onCreateOptionsMenu(final Menu menu) {
+        //Create the search view
+//        SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
+//        searchView.setIconifiedByDefault(false);
+//        searchView.setQueryHint(getString(R.string.searchText));
+//        searchView.setSubmitButtonEnabled(false);
+//        searchView.setMaxWidth(200);
+//        searchView.setImeOptions(
+//                EditorInfo.IME_ACTION_SEARCH |
+//                EditorInfo.IME_FLAG_NO_EXTRACT_UI | 
+//                EditorInfo.IME_FLAG_NO_ENTER_ACTION | 
+////                EditorInfo.IME_FLAG_NO_FULLSCREEN |
+//                EditorInfo.IME_MASK_ACTION |
+//                EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
+////        searchView.setOnQueryTextListener(this);
+//        menu.add("Search")
+////            .setIcon(isLight ? R.drawable.ic_search_inverse : R.drawable.abs__ic_search)
+//            .setActionView(searchView)
+//            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+        
+        
+        if (PreferenceManager.getDefaultSharedPreferences(this)
+                .getBoolean(getString(R.string.showPrevNextButtonsKey), true)) {
+            // Next word.
+            nextWordMenuItem = menu.add(getString(R.string.nextWord))
+                .setIcon(R.drawable.arrow_down_float);
+            nextWordMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+            nextWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+                    @Override
+                    public boolean onMenuItemClick(MenuItem item) {
+                        onUpDownButton(true);
+                        return true;
+                    }
+                });
+    
+            // Previous word.
+            previousWordMenuItem = menu.add(getString(R.string.previousWord))
+                .setIcon(R.drawable.arrow_up_float);
+            previousWordMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+            previousWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+                    @Override
+                    public boolean onMenuItemClick(MenuItem item) {
+                        onUpDownButton(false);
+                        return true;
+                    }
+                });
+        }
+
         application.onCreateGlobalOptionsMenu(this, menu);
 
 //        {
@@ -701,6 +761,7 @@ public class DictionaryActivity extends ListActivity {
 
         {
             final MenuItem dictionaryList = menu.add(getString(R.string.dictionaryManager));
+            dictionaryList.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
             dictionaryList.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                 public boolean onMenuItemClick(final MenuItem menuItem) {
                     startActivity(DictionaryManagerActivity.getLaunchIntent());
@@ -712,6 +773,7 @@ public class DictionaryActivity extends ListActivity {
 
         {
             final MenuItem aboutDictionary = menu.add(getString(R.string.aboutDictionary));
+            aboutDictionary.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
             aboutDictionary.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                 public boolean onMenuItemClick(final MenuItem menuItem) {
                     final Context context = getListView().getContext();
@@ -778,18 +840,18 @@ public class DictionaryActivity extends ListActivity {
         AdapterContextMenuInfo adapterContextMenuInfo = (AdapterContextMenuInfo) menuInfo;
         final RowBase row = (RowBase) getListAdapter().getItem(adapterContextMenuInfo.position);
 
-        final MenuItem addToWordlist = menu.add(getString(R.string.addToWordList,
+        final android.view.MenuItem addToWordlist = menu.add(getString(R.string.addToWordList,
                 wordList.getName()));
-        addToWordlist.setOnMenuItemClickListener(new OnMenuItemClickListener() {
-            public boolean onMenuItemClick(MenuItem item) {
+        addToWordlist.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
+            public boolean onMenuItemClick(android.view.MenuItem item) {
                 onAppendToWordList(row);
                 return false;
             }
         });
 
-        final MenuItem share = menu.add("Share");
-        share.setOnMenuItemClickListener(new OnMenuItemClickListener() {
-            public boolean onMenuItemClick(MenuItem item) {
+        final android.view.MenuItem share = menu.add("Share");
+        share.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
+            public boolean onMenuItemClick(android.view.MenuItem item) {
                 Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
                 shareIntent.setType("text/plain");
                 shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, row.getTokenRow(true).getToken());
@@ -799,9 +861,9 @@ public class DictionaryActivity extends ListActivity {
             }
         });
 
-        final MenuItem copy = menu.add(android.R.string.copy);
-        copy.setOnMenuItemClickListener(new OnMenuItemClickListener() {
-            public boolean onMenuItemClick(MenuItem item) {
+        final android.view.MenuItem copy = menu.add(android.R.string.copy);
+        copy.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
+            public boolean onMenuItemClick(android.view.MenuItem item) {
                 onCopy(row);
                 return false;
             }
@@ -809,10 +871,10 @@ public class DictionaryActivity extends ListActivity {
 
         if (selectedSpannableText != null) {
             final String selectedText = selectedSpannableText;
-            final MenuItem searchForSelection = menu.add(getString(R.string.searchForSelection,
+            final android.view.MenuItem searchForSelection = menu.add(getString(R.string.searchForSelection,
                     selectedSpannableText));
-            searchForSelection.setOnMenuItemClickListener(new OnMenuItemClickListener() {
-                public boolean onMenuItemClick(MenuItem item) {
+            searchForSelection.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
+                public boolean onMenuItemClick(android.view.MenuItem item) {
                     jumpToTextFromHyperLink(selectedText, selectedSpannableIndex);
                     return false;
                 }
@@ -820,10 +882,10 @@ public class DictionaryActivity extends ListActivity {
         }
 
         if (row instanceof TokenRow && ttsReady) {
-            final MenuItem speak = menu.add(R.string.speak);
-            speak.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+            final android.view.MenuItem speak = menu.add(R.string.speak);
+            speak.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
                 @Override
-                public boolean onMenuItemClick(MenuItem item) {
+                public boolean onMenuItemClick(android.view.MenuItem item) {
                     textToSpeech.speak(((TokenRow) row).getToken(), TextToSpeech.QUEUE_FLUSH,
                             new HashMap<String, String>());
                     return false;
@@ -871,6 +933,7 @@ public class DictionaryActivity extends ListActivity {
         }
     }
 
+    @SuppressLint("SimpleDateFormat")
     void onAppendToWordList(final RowBase row) {
         defocusSearchText();
 
@@ -1465,15 +1528,19 @@ public class DictionaryActivity extends ListActivity {
     }
 
     void setFiltered(final SearchOperation searchOperation) {
-        ((ImageButton) findViewById(R.id.UpButton)).setEnabled(false);
-        ((ImageButton) findViewById(R.id.DownButton)).setEnabled(false);
+        if (nextWordMenuItem != null) {
+            nextWordMenuItem.setEnabled(false);
+            previousWordMenuItem.setEnabled(false);
+        }
         rowsToShow = searchOperation.multiWordSearchResult;
         setListAdapter(new IndexAdapter(index, rowsToShow, searchOperation.searchTokens));
     }
 
     void clearFiltered() {
-        ((ImageButton) findViewById(R.id.UpButton)).setEnabled(true);
-        ((ImageButton) findViewById(R.id.DownButton)).setEnabled(true);
+        if (nextWordMenuItem != null) {
+            nextWordMenuItem.setEnabled(true);
+            previousWordMenuItem.setEnabled(true);
+        }
         setListAdapter(new IndexAdapter(index));
         rowsToShow = null;
     }
index e6de29f6ac30a739ceef2ceeb42529f9c2b90e83..09e7ba44e995d2ef7f425d799863aea400435e98 100644 (file)
@@ -22,10 +22,10 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.net.Uri;
 import android.preference.PreferenceManager;
 import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MenuItem.OnMenuItemClickListener;
 
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuItem;
+import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
 import com.hughes.android.dictionary.engine.Dictionary;
 import com.hughes.android.dictionary.engine.Language;
 import com.hughes.android.dictionary.engine.TransliteratorManager;
@@ -124,6 +124,7 @@ public class DictionaryApplication extends Application {
   public void onCreateGlobalOptionsMenu(
       final Context context, final Menu menu) {
     final MenuItem about = menu.add(getString(R.string.about));
+    about.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
     about.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       public boolean onMenuItemClick(final MenuItem menuItem) {
         final Intent intent = new Intent().setClassName(AboutActivity.class
@@ -134,6 +135,7 @@ public class DictionaryApplication extends Application {
     });
 
     final MenuItem help = menu.add(getString(R.string.help));
+    help.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
     help.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       public boolean onMenuItemClick(final MenuItem menuItem) {
         context.startActivity(HtmlDisplayActivity.getHelpLaunchIntent());
@@ -142,6 +144,7 @@ public class DictionaryApplication extends Application {
     });
 
     final MenuItem preferences = menu.add(getString(R.string.settings));
+    preferences.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
     preferences.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       public boolean onMenuItemClick(final MenuItem menuItem) {
         SettingsActivity.settingsMightHaveChanged = true;
@@ -154,6 +157,7 @@ public class DictionaryApplication extends Application {
     
     
     final MenuItem reportIssue = menu.add(getString(R.string.reportIssue));
+    reportIssue.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
     reportIssue.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       public boolean onMenuItemClick(final MenuItem menuItem) {
         final Intent intent = new Intent(Intent.ACTION_VIEW);
index 98f3a1e19b4f43924d04118df9195facf1fcabcb..74ac89500ce905f4a9eb14f652f15fe934d82c60 100644 (file)
@@ -14,7 +14,6 @@
 
 package com.hughes.android.dictionary;
 
-import android.app.ListActivity;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
@@ -24,28 +23,25 @@ import android.preference.PreferenceManager;
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.util.Log;
-import android.util.TypedValue;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MenuItem.OnMenuItemClickListener;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.WindowManager;
 import android.widget.AdapterView;
 import android.widget.AdapterView.AdapterContextMenuInfo;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.BaseAdapter;
 import android.widget.Button;
-import android.widget.CheckBox;
 import android.widget.CompoundButton;
 import android.widget.CompoundButton.OnCheckedChangeListener;
 import android.widget.EditText;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
+import android.widget.ImageButton;
 import android.widget.TextView;
+import android.widget.ToggleButton;
 
+import com.actionbarsherlock.app.SherlockListActivity;
+import com.actionbarsherlock.view.Menu;
 import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
 import com.hughes.android.util.IntentLauncher;
 
@@ -53,7 +49,7 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
-public class DictionaryManagerActivity extends ListActivity {
+public class DictionaryManagerActivity extends SherlockListActivity {
 
   static final String LOG = "QuickDic";
   static boolean blockAutoLaunch = false;
@@ -62,7 +58,7 @@ public class DictionaryManagerActivity extends ListActivity {
   Adapter adapter;
   
   EditText filterText;
-  CheckBox showLocal;
+  ToggleButton showLocal;
   
   Handler uiHandler;
   
@@ -86,7 +82,7 @@ public class DictionaryManagerActivity extends ListActivity {
     setContentView(R.layout.dictionary_manager_activity);
     
     filterText = (EditText) findViewById(R.id.filterText);
-    showLocal = (CheckBox) findViewById(R.id.showLocal);
+    showLocal = (ToggleButton) findViewById(R.id.showLocal);
     
     filterText.addTextChangedListener(new TextWatcher() {
       @Override
@@ -103,6 +99,15 @@ public class DictionaryManagerActivity extends ListActivity {
       }
     });
     
+    final ImageButton clearSearchText = (ImageButton) findViewById(R.id.ClearSearchTextButton);
+    clearSearchText.setOnClickListener(new View.OnClickListener() {
+        @Override
+        public void onClick(View arg0) {
+            filterText.setText("");
+            filterText.requestFocus();
+        }
+    });
+    
     showLocal.setOnCheckedChangeListener(new OnCheckedChangeListener() {
       @Override
       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@@ -202,10 +207,10 @@ public class DictionaryManagerActivity extends ListActivity {
     final DictionaryInfo dictionaryInfo = adapter.getItem(position);
     
     if (position > 0 && application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)) {
-      final MenuItem moveToTopMenuItem = menu.add(R.string.moveToTop);
-      moveToTopMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+      final android.view.MenuItem moveToTopMenuItem = menu.add(R.string.moveToTop);
+      moveToTopMenuItem.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
         @Override
-        public boolean onMenuItemClick(MenuItem item) {
+        public boolean onMenuItemClick(android.view.MenuItem item) {
           application.moveDictionaryToTop(dictionaryInfo);
           setListAdapter(adapter = new Adapter());
           return true;
@@ -213,10 +218,10 @@ public class DictionaryManagerActivity extends ListActivity {
       });
     }
 
-    final MenuItem deleteMenuItem = menu.add(R.string.deleteDictionary);
-    deleteMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+    final android.view.MenuItem deleteMenuItem = menu.add(R.string.deleteDictionary);
+    deleteMenuItem.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
       @Override
-      public boolean onMenuItemClick(MenuItem item) {
+      public boolean onMenuItemClick(android.view.MenuItem item) {
         application.deleteDictionary(dictionaryInfo);
         setListAdapter(adapter = new Adapter());
         return true;
@@ -225,10 +230,10 @@ public class DictionaryManagerActivity extends ListActivity {
 
     final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
     if (downloadable != null) {
-      final MenuItem downloadMenuItem = menu.add(getString(R.string.downloadButton, downloadable.zipBytes/1024.0/1024.0));
-      downloadMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+      final android.view.MenuItem downloadMenuItem = menu.add(getString(R.string.downloadButton, downloadable.zipBytes/1024.0/1024.0));
+      downloadMenuItem.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
         @Override
-        public boolean onMenuItemClick(MenuItem item) {
+        public boolean onMenuItemClick(android.view.MenuItem item) {
           final Intent intent = getDownloadIntent(downloadable);
           startActivity(intent);
           setListAdapter(adapter = new Adapter());
@@ -240,10 +245,11 @@ public class DictionaryManagerActivity extends ListActivity {
   }
 
   private Intent getDownloadIntent(final DictionaryInfo downloadable) {
-    final Intent intent = DownloadActivity.getLaunchIntent(downloadable.downloadUrl,
-        application.getPath(downloadable.uncompressedFilename).getPath() + ".zip",
-        downloadable.dictInfo);
-    return intent;
+//      DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
+//      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(""));
+//      long id = downloadManager.enqueue(request);
+//      DownloadManager.Query query;
+      return null;
   }
   
   private void onFilterTextChanged() {
@@ -288,7 +294,6 @@ public class DictionaryManagerActivity extends ListActivity {
         }
         if (canShow) {
           dictionaryInfos.add(dictionaryInfo);
-          
         }
       }
     }
@@ -309,58 +314,42 @@ public class DictionaryManagerActivity extends ListActivity {
     }
     
     @Override
-    public View getView(final int position, final View convertView, final ViewGroup parent) {
-      final LinearLayout result;
-      // Android 4.0.3 leaks memory like crazy if we don't do this.
-      if (convertView instanceof LinearLayout) {
-        result = (LinearLayout) convertView;
-        result.removeAllViews();
-      } else {
-        result = new LinearLayout(parent.getContext());
-      }
-      
+    public View getView(final int position, View convertView, final ViewGroup parent) {
+       if (convertView == null) {
+           convertView = LayoutInflater.from(parent.getContext()).inflate(
+                   R.layout.dictionary_manager_row, parent, false);
+       }
+        
       final DictionaryInfo dictionaryInfo = getItem(position);
-      result.setOrientation(LinearLayout.VERTICAL);
-
-      final LinearLayout row = new LinearLayout(parent.getContext());
-      row.setOrientation(LinearLayout.HORIZONTAL);
-      result.addView(row);
 
-      {
-      final TextView textView = new TextView(parent.getContext());
+      final TextView textView = (TextView) convertView.findViewById(R.id.dictionaryName);
       final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);
       textView.setText(name);
-      textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
-      row.addView(textView);
-      LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
-      layoutParams.weight = 1.0f;
-      textView.setLayoutParams(layoutParams);
-      }
       
+      final Button downloadButton = (Button) convertView.findViewById(R.id.dictionaryDownloadButton);
       final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
-      final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename); 
-      if ((!application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename) || updateAvailable) && downloadable != null) {
-        final Button downloadButton = new Button(parent.getContext());
-        downloadButton.setText(getString(updateAvailable ? R.string.updateButton : R.string.downloadButton, downloadable.zipBytes / 1024.0 / 1024.0));
-        final Intent intent = getDownloadIntent(downloadable);
-        downloadButton.setOnClickListener(new IntentLauncher(parent.getContext(), intent));
-        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
-        layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
-        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
-        downloadButton.setLayoutParams(layoutParams);
-        row.addView(downloadButton);
+      final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
+      if (updateAvailable) {
+          downloadButton.setCompoundDrawablesWithIntrinsicBounds(
+                              android.R.drawable.ic_menu_add, 
+                          0, 0, 0);
+          downloadButton.setText(getString(R.string.downloadButton, downloadable.zipBytes / 1024.0 / 1024.0));
+      } else if (!application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)) {
+          downloadButton.setCompoundDrawablesWithIntrinsicBounds(
+                  android.R.drawable.ic_menu_add, 
+              0, 0, 0);
+          downloadButton.setText(getString(R.string.downloadButton, downloadable.zipBytes / 1024.0 / 1024.0));
       } else {
-        final ImageView checkMark = new ImageView(parent.getContext());
-        checkMark.setImageResource(R.drawable.btn_check_buttonless_on);
-        row.addView(checkMark);
+          downloadButton.setCompoundDrawablesWithIntrinsicBounds(
+                  android.R.drawable.checkbox_on_background, 
+              0, 0, 0);
+          downloadButton.setText("");
       }
+      final Intent intent = getDownloadIntent(downloadable);
+      downloadButton.setOnClickListener(new IntentLauncher(parent.getContext(), intent));
 
       // Add the information about each index.
-      final LinearLayout row2 = new LinearLayout(parent.getContext());
-      row2.setOrientation(LinearLayout.HORIZONTAL);
-      final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
-      row2.setLayoutParams(layoutParams);
-      result.addView(row2);
+      final TextView dictionaryDetails = (TextView) convertView.findViewById(R.id.dictionaryDetails);
       final StringBuilder builder = new StringBuilder();
       for (final IndexInfo indexInfo : dictionaryInfo.indexInfos) {
         if (builder.length() > 0) {
@@ -368,26 +357,23 @@ public class DictionaryManagerActivity extends ListActivity {
         }
         builder.append(getString(R.string.indexInfo, indexInfo.shortName, indexInfo.mainTokenCount));
       }
-      final TextView indexView = new TextView(parent.getContext());
-      indexView.setText(builder.toString());
-      row2.addView(indexView);
-      
+      dictionaryDetails.setText(builder.toString());
       
-      // Because we have a Button inside a ListView row:
-      // http://groups.google.com/group/android-developers/browse_thread/thread/3d96af1530a7d62a?pli=1
-      result.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
-      result.setClickable(true);
-      result.setFocusable(true);
-      result.setLongClickable(true);
-      result.setBackgroundResource(android.R.drawable.menuitem_background);
-      result.setOnClickListener(new TextView.OnClickListener() {
+//      // Because we have a Button inside a ListView row:
+//      // http://groups.google.com/group/android-developers/browse_thread/thread/3d96af1530a7d62a?pli=1
+      //convertView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
+      convertView.setClickable(true);
+      convertView.setFocusable(true);
+      convertView.setLongClickable(true);
+//      result.setBackgroundResource(android.R.drawable.menuitem_background);
+      convertView.setOnClickListener(new TextView.OnClickListener() {
         @Override
         public void onClick(View v) {
           DictionaryManagerActivity.this.onClick(position);
         }
       });
       
-      return result;
+      return convertView;
     }
   }
 
diff --git a/src/com/hughes/android/dictionary/DownloadActivity.java b/src/com/hughes/android/dictionary/DownloadActivity.java
deleted file mode 100644 (file)
index a5cfc9a..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the "License");\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-//     http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-\r
-package com.hughes.android.dictionary;\r
-\r
-import android.app.Activity;\r
-import android.content.Intent;\r
-import android.os.Bundle;\r
-import android.os.Handler;\r
-import android.util.Log;\r
-import android.widget.ProgressBar;\r
-import android.widget.TextView;\r
-\r
-import java.io.File;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.OutputStream;\r
-import java.net.URL;\r
-import java.net.URLConnection;\r
-import java.util.concurrent.Executor;\r
-import java.util.concurrent.Executors;\r
-import java.util.concurrent.atomic.AtomicBoolean;\r
-import java.util.zip.ZipEntry;\r
-import java.util.zip.ZipFile;\r
-\r
-public class DownloadActivity extends Activity {\r
-\r
-  public static final String SOURCE = "source";\r
-  public static final String DEST = "dest";\r
-  public static final String MESSAGE = "message";\r
-\r
-  String source;\r
-  String dest;\r
-  String message;\r
-  long bytesProcessed = 0;\r
-  long contentLength = -1;\r
-\r
-  private final Executor downloadExecutor = Executors.newSingleThreadExecutor();\r
-  private final Handler uiHandler = new Handler();\r
-\r
-  final AtomicBoolean stop = new AtomicBoolean(false);\r
-  \r
-  public static Intent getLaunchIntent(final String source, final String dest, final String message) {\r
-    final Intent intent = new Intent();\r
-    intent.setClassName(DownloadActivity.class.getPackage().getName(), DownloadActivity.class.getName());\r
-    intent.putExtra(SOURCE, source);\r
-    intent.putExtra(DEST, dest);\r
-    intent.putExtra(MESSAGE, message);\r
-    return intent;\r
-  }\r
-\r
-  /** Called when the activity is first created. */\r
-  @Override\r
-  public void onCreate(final Bundle savedInstanceState) {\r
-    setTheme(((DictionaryApplication)getApplication()).getSelectedTheme().themeId);\r
-\r
-    super.onCreate(savedInstanceState);\r
-    final Intent intent = getIntent();\r
-    source = intent.getStringExtra(SOURCE);\r
-    dest = intent.getStringExtra(DEST);\r
-    message = intent.getStringExtra(MESSAGE);\r
-    if (source == null || dest == null) {\r
-      throw new RuntimeException("null source or dest.");\r
-    }\r
-    setContentView(R.layout.download_activity);\r
-\r
-    final TextView sourceTextView = (TextView) findViewById(R.id.source);\r
-    sourceTextView.setText(source);\r
-\r
-    final TextView destTextView = (TextView) findViewById(R.id.dest);\r
-    destTextView.setText(dest);\r
-\r
-    final TextView messageTextView = (TextView) findViewById(R.id.downloadMessage);\r
-    messageTextView.setText(message);\r
-\r
-    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.downloadProgressBar);\r
-    progressBar.setIndeterminate(false);\r
-    progressBar.setMax(100);\r
-    \r
-    bytesProcessed = 0;\r
-    contentLength = 100;\r
-    setDownloadStatus(getString(R.string.openingConnection));\r
-\r
-    final Runnable runnable = new Runnable() {\r
-      public void run() {\r
-\r
-        try {\r
-          final File destFile = new File(dest);\r
-          if (destFile.getAbsoluteFile().getParent() != null) {\r
-            destFile.getAbsoluteFile().getParentFile().mkdirs();\r
-          }\r
-\r
-          final File destTmpFile = File.createTempFile("dictionaryDownload", "tmp", destFile\r
-              .getParentFile());\r
-          destTmpFile.deleteOnExit();\r
-\r
-          final URL uri = new URL(source);\r
-          final URLConnection connection = uri.openConnection();\r
-          contentLength = connection.getContentLength();\r
-          final InputStream in = connection.getInputStream();\r
-          if (in == null) {\r
-            throw new IOException("Unable to open InputStream from source: " + source);\r
-          }\r
-          final FileOutputStream out = new FileOutputStream(destTmpFile); \r
-          int bytesRead = copyStream(in, out, R.string.downloading);\r
-          \r
-          if (bytesRead == -1 && !stop.get()) {\r
-            destFile.delete();\r
-            destTmpFile.renameTo(destFile);\r
-          } else {\r
-           Log.d("THAD", "Stopped downloading file.");\r
-          }\r
-          \r
-          if (dest.toLowerCase().endsWith(".zip")) {\r
-            final ZipFile zipFile = new ZipFile(destFile);\r
-            final File destUnzipped = new File(dest.substring(0, dest.length() - 4));\r
-            final ZipEntry zipEntry = zipFile.getEntry(destUnzipped.getName());\r
-            if (zipEntry != null) {\r
-              destUnzipped.delete();\r
-              Log.d("THAD", "Unzipping entry: " + zipEntry.getName() + " to " + destUnzipped);\r
-              final InputStream zipIn = zipFile.getInputStream(zipEntry);\r
-              final OutputStream zipOut = new FileOutputStream(destUnzipped);\r
-              contentLength = zipEntry.getSize();\r
-              bytesRead = copyStream(zipIn, zipOut, R.string.unzipping);\r
-              destFile.delete();\r
-            }\r
-          }\r
-          \r
-          setDownloadStatus(String.format(getString(R.string.downloadFinished),\r
-              bytesProcessed));\r
-          \r
-          // If all went well, we can exit this activity.\r
-          uiHandler.post(new Runnable() {\r
-            @Override\r
-            public void run() {\r
-              finish();\r
-            }\r
-          });\r
-          \r
-        } catch (IOException e) {\r
-          Log.e("THAD", "Error downloading file", e);\r
-          setDownloadStatus(String.format(getString(R.string.errorDownloadingFile), e.getLocalizedMessage()));\r
-        }\r
-      }\r
-\r
-      private int copyStream(final InputStream in, final OutputStream out, final int messageId)\r
-          throws IOException {\r
-        bytesProcessed = 0;\r
-        int bytesRead;\r
-        final byte[] bytes = new byte[1024 * 16];\r
-        int count = 0;\r
-        while ((bytesRead = in.read(bytes)) != -1 && !stop.get()) {\r
-          out.write(bytes, 0, bytesRead);\r
-          bytesProcessed += bytesRead;\r
-          if (count++ % 20 == 0) {\r
-            setDownloadStatus(getString(messageId, bytesProcessed, contentLength));\r
-          }\r
-        }\r
-        in.close();\r
-        out.close();\r
-        return bytesRead;\r
-      }\r
-    };\r
-\r
-    downloadExecutor.execute(runnable);\r
-  }\r
-\r
-  @Override\r
-  protected void onStop() {\r
-    stop.set(true);\r
-    super.onStop();\r
-  }\r
-\r
-  private void setDownloadStatus(final String status) {\r
-    uiHandler.post(new Runnable() {\r
-      public void run() {\r
-        final ProgressBar progressBar = (ProgressBar) findViewById(R.id.downloadProgressBar);\r
-        if (contentLength > 0) {\r
-          progressBar.setProgress((int) (bytesProcessed * 100 / contentLength));\r
-        }\r
-        \r
-        final TextView downloadStatus = (TextView) findViewById(R.id.downloadStatus);\r
-        downloadStatus.setText(status);\r
-      }\r
-    });\r
-  }\r
-\r
-}\r
index 4e1dcb3c2e17d954f3e3ba2f5231d58cd4a5db6b..d11cec05f6e6d7385db2481ffbb9d18bc855f940 100644 (file)
@@ -37,7 +37,6 @@ public class MyWebView extends WebView {
                     activity.finish();
                     return true;
                 }
-                // TODO Auto-generated method stub
                 return super.shouldOverrideUrlLoading(view, url);
             }
         };
index 1955ad739ce69ddca7e34398e0368cbc27b664a7..8f84de08e670cce3ff9a69be8ee73363b87e1a9e 100644 (file)
@@ -39,8 +39,10 @@ public class Language {
     private LanguageResources(final String englishName, int nameId) {\r
       this(englishName, nameId, 0);\r
     }\r
-}\r
+  }\r
 \r
+  // Useful:\r
+  // http://www.loc.gov/standards/iso639-2/php/code_list.php\r
   public static final Map<String,LanguageResources> isoCodeToResources = new LinkedHashMap<String,LanguageResources>();\r
   static {\r
     isoCodeToResources.put("AF", new LanguageResources("Afrikaans", R.string.AF));\r
diff --git a/todo.txt b/todo.txt
new file mode 100644 (file)
index 0000000..7d2dc8f
--- /dev/null
+++ b/todo.txt
@@ -0,0 +1,10 @@
+* Make top of Dictionary activity good
+  * Fit search text alongside other buttons if possible.
+  * List other dictinaries beside 
+  * Make search text work.
+  
+ http://stackoverflow.com/questions/13604506/show-actionbarsherlock-searchview-always-expanded
+  <style name="application_theme" parent="application_base_theme">
+    <item name="searchViewSearchIcon">@android:color/transparent</item>
+    <item name="searchViewCloseIcon">@android:color/transparent</item>
+</style>
\ No newline at end of file