]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
DictionaryManager can launch dictionaries again.
authorThad Hughes <thadh@google.com>
Wed, 11 Dec 2013 05:12:31 +0000 (21:12 -0800)
committerThad Hughes <thadh@google.com>
Wed, 11 Dec 2013 05:12:31 +0000 (21:12 -0800)
16 files changed:
AndroidManifest.xml
res/layout/dictionary_manager_activity.xml
res/layout/dictionary_on_device_row.xml [new file with mode: 0644]
res/layout/dictionary_search_view.xml [deleted file]
res/menu/dictionary_manager.xml [deleted file]
res/menu/dictionary_manager_options_menu.xml [new file with mode: 0644]
res/values-v11/styles.xml
res/values/strings.xml
res/values/styles.xml
src/com/hughes/android/dictionary/C.java
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/DictionaryApplication.java
src/com/hughes/android/dictionary/DictionaryInfo.java
src/com/hughes/android/dictionary/DictionaryManagerActivity.java
src/com/hughes/android/dictionary/PreferenceActivity.java
src/com/hughes/android/util/IntentLauncher.java

index bdcaa593070633e85ae1c0a9403b131f244d7a83..245ba6fea8489211cf0b98e3a58688f28a3fecf7 100644 (file)
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-    
+
     <application
-        android:allowBackup="true"
         android:name=".DictionaryApplication"
+        android:allowBackup="true"
         android:icon="@drawable/icon"
         android:label="@string/app_name"
         android:theme="@style/AppTheme" >
-
         <meta-data
             android:name="com.google.android.backup.api_key"
             android:value="AEdPqrEAAAAIUa0cU0ZHbBpYXJqm0vVUP5IAjr5D4iUeX7UwiQ" />
@@ -37,7 +36,7 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
 
-               <!--   
+            <!--
             <intent-filter>
                 <action android:name="android.intent.action.SEND" />
                 <category android:name="android.intent.category.DEFAULT" />
                                                <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
                </intent-filter>
-                  -->          
+            -->
         </activity>
-        
-        
-        <activity android:name=".DictionaryActivity"  android:label="@string/app_name">
-                <!-- @author Dominik Köppl
+        <activity
+            android:name=".DictionaryActivity"
+            android:label="@string/app_name"
+            android:parentActivityName=".DictionaryActivity" >
+
+            <!-- Parent activity meta-data to support API level 7+ -->
+            <meta-data
+                android:name="android.support.PARENT_ACTIVITY"
+                android:value=".DictionaryActivity" />
+
+            <!--
+           @author Dominik Köppl
                        Added two different intents to catch simple and advanced queries from other extern applications.
-                       -->
-           <intent-filter>
-             <action android:name="android.intent.action.SEARCH" />      
-                <category android:name="android.intent.category.DEFAULT" />
-               </intent-filter>
-       
-                        
+            -->
             <intent-filter>
-                <action android:name="com.hughes.action.ACTION_SEARCH_DICT" />
-                <category android:name="android.intent.category.DEFAULT" />
-               </intent-filter>
-       
-         </activity>
-            
-            
-        <activity android:name=".DictionaryEditActivity" />
-        <activity android:name=".AboutActivity" />
-        <activity android:name=".HtmlDisplayActivity" />
-        <activity android:name=".PreferenceActivity" />
+                <action android:name="android.intent.action.SEARCH" />
+
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="com.hughes.action.ACTION_SEARCH_DICT" />
+
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+        <activity
+            android:name=".AboutActivity"
+            android:parentActivityName=".DictionaryActivity" >
+
+            <!-- Parent activity meta-data to support API level 7+ -->
+            <meta-data
+                android:name="android.support.PARENT_ACTIVITY"
+                android:value=".DictionaryActivity" />
+        </activity>
+        <activity
+            android:name=".HtmlDisplayActivity"
+            android:parentActivityName=".DictionaryActivity" >
+
+            <!-- Parent activity meta-data to support API level 7+ -->
+            <meta-data
+                android:name="android.support.PARENT_ACTIVITY"
+                android:value=".DictionaryActivity" />
+        </activity>
         <activity
-            android:name=".DownloadActivity"
-            android:configChanges="keyboardHidden|orientation" />
+            android:name=".PreferenceActivity"
+            android:parentActivityName=".DictionaryActivity" >
+
+            <!-- Parent activity meta-data to support API level 7+ -->
+            <meta-data
+                android:name="android.support.PARENT_ACTIVITY"
+                android:value=".DictionaryActivity" />
+        </activity>
     </application>
 
-    
-        
-    
 </manifest>
\ No newline at end of file
index b808593d986c900dbbc6c7fd62f43cf8073aa37d..07d8596f4b7e169f520f1144c1d13d7d2b43395b 100644 (file)
@@ -5,51 +5,77 @@
     android:layout_height="fill_parent"
     android:orientation="vertical" >
 
-    <LinearLayout
-        android:id="@+id/linearLayout1"
+    <ScrollView
+        android:id="@+id/scrollView"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content" >
+        android:layout_height="match_parent" >
 
-        <EditText
-            android:id="@+id/filterText"
-            android:layout_width="wrap_content"
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:hint="@string/managerFilterText" />
+            android:orientation="vertical" >
 
-        <ImageButton
-            android:id="@+id/ClearSearchTextButton"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_weight="0"
-            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
-        android:id="@id/android:list"
-        android:layout_width="fill_parent"
-        android:layout_height="0dip"
-        android:layout_weight="1.0"
-        android:choiceMode="singleChoice"
-        android:clickable="true"
-        android:fastScrollEnabled="true"
-        android:focusable="true"
-        tools:listitem="@layout/dictionary_manager_row" />
-
-    <TextView
-        android:id="@+id/DictionaryListHeader"
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
-        android:hint="@string/helpText" />
+            <!-- Dictionaries on device -->
+
+            <LinearLayout
+                android:id="@+id/onDeviceHeaderLayout"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:background="@color/gray"
+                android:orientation="horizontal"
+                android:padding="10dip" >
+
+                <TextView
+                    android:id="@+id/onDeviceTextId"
+                    android:layout_width="0dip"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:text="@string/dictionariesOnDevice"
+                    android:textAppearance="?android:attr/textAppearanceLarge" />
+            </LinearLayout>
+
+            <LinearLayout
+                android:id="@+id/dictionariesOnDeviceGoHere"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="vertical"
+                android:paddingBottom="10dip" >
+            </LinearLayout>
+
+            <!-- Downloadable dictionaries -->
+
+            <LinearLayout
+                android:id="@+id/downloadableHeaderLayout"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:background="@color/gray"
+                android:orientation="horizontal"
+                android:padding="10dip" >
+
+                <TextView
+                    android:id="@+id/downloadableTextId"
+                    android:layout_width="0dip"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:text="@string/downloadableDictionaries"
+                    android:textAppearance="?android:attr/textAppearanceLarge" />
+
+                <ToggleButton
+                    android:id="@+id/hideDownloadable"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="0"
+                    android:textOff="@string/managerShow"
+                    android:textOn="@string/managerHide" />
+            </LinearLayout>
+
+            <LinearLayout
+                android:id="@+id/downloadableDictionariesGoHere"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="vertical" >
+            </LinearLayout>
+        </LinearLayout>
+    </ScrollView>
 
 </LinearLayout>
\ No newline at end of file
diff --git a/res/layout/dictionary_on_device_row.xml b/res/layout/dictionary_on_device_row.xml
new file mode 100644 (file)
index 0000000..63f459b
--- /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" >
+
+        <LinearLayout
+            android:id="@+id/dictionaryLauncherButtons"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal"
+            android:paddingRight="5dip" >
+        </LinearLayout>
+
+        <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" />
+    </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
deleted file mode 100644 (file)
index 62fcb18..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?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/menu/dictionary_manager.xml b/res/menu/dictionary_manager.xml
deleted file mode 100644 (file)
index cc0c8c1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
-
-    <item
-        android:id="@+id/action_settings"
-        android:orderInCategory="100"
-        android:showAsAction="never"
-        android:title="@string/settings"/>
-
-</menu>
diff --git a/res/menu/dictionary_manager_options_menu.xml b/res/menu/dictionary_manager_options_menu.xml
new file mode 100644 (file)
index 0000000..ac85202
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    
+    <item android:id="@+id/filterText"
+          android:title="@string/managerFilterText"
+          android:icon="@drawable/abs__ic_search"
+          android:showAsAction="collapseActionView|ifRoom"
+          android:actionViewClass="com.actionbarsherlock.widget.SearchView" />
+        
+    <item
+        android:id="@+id/action_settings"
+        android:orderInCategory="100"
+        android:showAsAction="never"
+        android:title="@string/settings"/>
+
+</menu>
\ No newline at end of file
index 41bcbbd497796eb08a84e2fe3a07d1bfabe6df6c..5b00ba21ff125eef6dc2838a482370af022f6d52 100644 (file)
@@ -1,4 +1,24 @@
 <resources>
+    
+    <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.
+        -->
+      <item name="actionButtonStyle">@style/MyActionButtonStyle</item>
+      <item name="android:actionButtonStyle">@style/MyActionButtonStyle</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.
+        -->
+        <item name="actionButtonStyle">@style/MyActionButtonStyle</item>
+        <item name="android:actionButtonStyle">@style/MyActionButtonStyle</item>
+    </style>
 
     <style name="BorderlessButton">
         <item name="android:background">?android:attr/selectableItemBackground</item>
index c925821ee1c5f6d4f4a14fd36f8b5cf5cc389617..305eac4dbaf3a3d6da840ad80a4bb04bc97a576f 100644 (file)
   
    <!-- DictionaryManagerActivity -->
   <string name="dictionaryManager">Dictionary manager</string>
-  <string name="helpText">Long-press a dictionary for more options.</string>
+  <string name="dictionariesOnDevice">Dictionaries on device</string>
+  <string name="noDictionariesOnDevice">No dictionaries on device</string>
+  <string name="downloadableDictionaries">Downloadable dictionaries</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="managerFilterCheckboxAll">All</string>
-  <string name="managerFilterCheckboxLocal">Local</string>
+  <string name="managerShow">Show</string>
+  <string name="managerHide">Hide</string>
 
   <string name="thanksForUpdatingVersion">4.0.1_en_a</string>
 
   <string name="themeTitle">UI theme</string>
   <string name="themeSummary">User-interface color theme.</string>
   
+  <string name="emptyString"></string>
+  
 </resources>
index afcc3b132bf463c618a7adbf288c812ede209e83..069097cea02d50c042ddfa75245071b5dcbca7d1 100644 (file)
@@ -2,6 +2,10 @@
     
     <style name="MyActionButtonStyle" parent="Widget.Sherlock.ActionButton">
         <item name="android:minWidth">28dip</item>
+        <!-- 
+        <item name="android:paddingLeft">0dip</item>
+        <item name="android:paddingRight">0dip</item>
+         -->
     </style>
 
     <!--
@@ -72,6 +76,8 @@
     <color name="theme_light_token_row_other_bg">#EEEEEE</color>
     <color name="theme_light_other_lang_bg">#FFFFFF</color>
 
+    <color name="gray">#777777</color>
+    
     <style name="BorderlessButton">
         <item name="android:background">@null</item>
         <item name="android:paddingLeft">4dip</item>
index 5d5751423a0a71f5a96b319bb1d6767456b63e62..7baba54e6512b84d97ac922d684813702e226f79 100644 (file)
@@ -19,7 +19,7 @@ public class C {
     static final String DICTIONARY_CONFIGS = "dictionaryConfigs2";
 
     public static final String DICT_FILE = "dictFile";
-    public static final String INDEX_INDEX = "indexIndex";
+    public static final String INDEX_SHORT_NAME = "indexShortName";
     public static final String SEARCH_TOKEN = "searchToken";
     public static final String CAN_AUTO_LAUNCH_DICT = "canAutoLaunch";
     public static final String SHOW_LOCAL = "showLocal";
index 6e4bb9106cf6b4ae014a55c109edc83af6cfd1b8..d99de3c65ff67617879a5175e3eeb3e6f497a7e6 100644 (file)
@@ -134,7 +134,6 @@ public class DictionaryActivity extends SherlockListActivity {
 
     private SearchOperation currentSearchOperation = null;
 
-
     TextToSpeech textToSpeech;
     volatile boolean ttsReady;
 
@@ -167,13 +166,13 @@ public class DictionaryActivity extends SherlockListActivity {
     public DictionaryActivity() {
     }
 
-    public static Intent getLaunchIntent(final File dictFile, final int indexIndex,
+    public static Intent getLaunchIntent(final File dictFile, final String indexShortName,
             final String searchToken) {
         final Intent intent = new Intent();
         intent.setClassName(DictionaryActivity.class.getPackage().getName(),
                 DictionaryActivity.class.getName());
         intent.putExtra(C.DICT_FILE, dictFile.getPath());
-        intent.putExtra(C.INDEX_INDEX, indexIndex);
+        intent.putExtra(C.INDEX_SHORT_NAME, indexShortName);
         intent.putExtra(C.SEARCH_TOKEN, searchToken);
         return intent;
     }
@@ -182,15 +181,15 @@ public class DictionaryActivity extends SherlockListActivity {
     protected void onSaveInstanceState(final Bundle outState) {
         super.onSaveInstanceState(outState);        
         Log.d(LOG, "onSaveInstanceState: " + searchView.getQuery().toString());
-        outState.putInt(C.INDEX_INDEX, indexIndex);
+        outState.putString(C.INDEX_SHORT_NAME, index.shortName);
         outState.putString(C.SEARCH_TOKEN, searchView.getQuery().toString());
     }
 
     @Override
-    protected void onRestoreInstanceState(final Bundle outState) {
-        super.onRestoreInstanceState(outState);
-        Log.d(LOG, "onRestoreInstanceState: " + outState.getString(C.SEARCH_TOKEN));
-        onCreate(outState);
+    protected void onRestoreInstanceState(final Bundle savedInstanceState) {
+        super.onRestoreInstanceState(savedInstanceState);
+        Log.d(LOG, "onRestoreInstanceState: " + savedInstanceState.getString(C.SEARCH_TOKEN));
+        onCreate(savedInstanceState);
     }
 
     @Override
@@ -201,7 +200,7 @@ public class DictionaryActivity extends SherlockListActivity {
         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
         
         // Don't auto-launch if this fails.
-        prefs.edit().remove(C.INDEX_INDEX).commit(); 
+        prefs.edit().remove(C.INDEX_SHORT_NAME).commit(); 
 
         setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId);
 
@@ -209,8 +208,6 @@ public class DictionaryActivity extends SherlockListActivity {
         theme = application.getSelectedTheme();
         textColorFg = getResources().getColor(theme.tokenRowFgColor);
 
-        
-
         final Intent intent = getIntent();
         String intentAction = intent.getAction();
         /**
@@ -235,8 +232,8 @@ public class DictionaryActivity extends SherlockListActivity {
                }
                if(intent.getStringExtra(C.DICT_FILE) == null && (from != null || to != null))
                {
-                        Log.d(LOG, "DictSearch: from: " + from + " to " + to);
-                       List<DictionaryInfo> dicts = application.getUsableDicts();
+                       Log.d(LOG, "DictSearch: from: " + from + " to " + to);
+                       List<DictionaryInfo> dicts = application.getDictionariesOnDevice();
                        for(DictionaryInfo info : dicts)
                        {
                                boolean hasFrom = from == null;
@@ -256,7 +253,7 @@ public class DictionaryActivity extends SherlockListActivity {
                                                if(info.indexInfos.get(which_index).shortName.toLowerCase(Locale.US).equals(from))
                                                        break;
                                        }
-                                       intent.putExtra(C.INDEX_INDEX, which_index);
+                                       intent.putExtra(C.INDEX_SHORT_NAME, info.indexInfos.get(which_index).shortName);
                                        
                                        }
                                        intent.putExtra(C.DICT_FILE, application.getPath(info.uncompressedFilename).toString());
@@ -328,9 +325,16 @@ public class DictionaryActivity extends SherlockListActivity {
             finish();
             return;
         }
-        indexIndex = intent.getIntExtra(C.INDEX_INDEX, 0);
-        if (savedInstanceState != null) {
-            indexIndex = savedInstanceState.getInt(C.INDEX_INDEX, indexIndex);
+        String targetIndex = intent.getStringExtra(C.INDEX_SHORT_NAME);
+        if (savedInstanceState != null && savedInstanceState.getString(C.INDEX_SHORT_NAME) != null) {
+            targetIndex = savedInstanceState.getString(C.INDEX_SHORT_NAME);
+        }
+        indexIndex = 0;
+        for (int i = 0; i < dictionary.indices.size(); ++i) {
+            if (dictionary.indices.get(i).shortName.equals(targetIndex)) {
+                indexIndex = i;
+                break;
+            }
         }
         indexIndex %= dictionary.indices.size();
         Log.d(LOG, "Loading index " + indexIndex);
@@ -420,7 +424,7 @@ public class DictionaryActivity extends SherlockListActivity {
         setSearchText(text, true);
         Log.d(LOG, "Trying to restore searchText=" + text);
 
-        setDictionaryPrefs(this, dictFile, indexIndex, searchView.getQuery().toString());
+        setDictionaryPrefs(this, dictFile, index.shortName, searchView.getQuery().toString());
 
         updateLangButton();
     }
@@ -513,11 +517,11 @@ public class DictionaryActivity extends SherlockListActivity {
     }
 
     private static void setDictionaryPrefs(final Context context, final File dictFile,
-            final int indexIndex, final String searchToken) {
+            final String indexShortName, final String searchToken) {
         final SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(
                 context).edit();
         prefs.putString(C.DICT_FILE, dictFile.getPath());
-        prefs.putInt(C.INDEX_INDEX, indexIndex);
+        prefs.putString(C.INDEX_SHORT_NAME, indexShortName);
         prefs.putString(C.SEARCH_TOKEN, ""); // Don't need to save search token.
         prefs.commit();
     }
@@ -609,11 +613,9 @@ public class DictionaryActivity extends SherlockListActivity {
         dialog.setContentView(R.layout.select_dictionary_dialog);
         dialog.setTitle(R.string.selectDictionary);
 
-        final List<DictionaryInfo> installedDicts = ((DictionaryApplication) getApplication())
-                .getUsableDicts();
+        final List<DictionaryInfo> installedDicts = application.getDictionariesOnDevice();
 
         ListView listView = (ListView) dialog.findViewById(android.R.id.list);
-
         final Button button = new Button(listView.getContext());
         final String name = getString(R.string.dictionaryManager);
         button.setText(name);
@@ -648,7 +650,7 @@ public class DictionaryActivity extends SherlockListActivity {
                     final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(),
                             getLaunchIntent(
                                     application.getPath(dictionaryInfo.uncompressedFilename),
-                                    i, searchView.getQuery().toString())) {
+                                    indexInfo.shortName, searchView.getQuery().toString())) {
                         @Override
                         protected void onGo() {
                             dialog.dismiss();
@@ -689,7 +691,6 @@ public class DictionaryActivity extends SherlockListActivity {
                 return installedDicts.size();
             }
         });
-
         dialog.show();
     }
 
@@ -1011,7 +1012,7 @@ public class DictionaryActivity extends SherlockListActivity {
             indexAdapter = new IndexAdapter(index);
             setListAdapter(indexAdapter);
             Log.d(LOG, "changingIndex, newLang=" + index.longName);
-            setDictionaryPrefs(this, dictFile, indexIndex, searchView.getQuery().toString());
+            setDictionaryPrefs(this, dictFile, index.shortName, searchView.getQuery().toString());
             updateLangButton();
         }
         setSearchText(newSearchText, true);
index ca8d4ac0fb432a963eedaef5e19b3ad897cd4a7a..e6b509c2f587ec7d2a13817ef13b9cc82cea8062 100644 (file)
@@ -22,13 +22,21 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.net.Uri;
 import android.preference.PreferenceManager;
 import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.ImageView.ScaleType;
 
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuItem;
 import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
+import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
 import com.hughes.android.dictionary.engine.Dictionary;
 import com.hughes.android.dictionary.engine.Language;
 import com.hughes.android.dictionary.engine.TransliteratorManager;
+import com.hughes.android.dictionary.engine.Language.LanguageResources;
+import com.hughes.android.util.IntentLauncher;
 import com.hughes.android.util.PersistentObjectCache;
 import com.hughes.util.ListUtil;
 import com.ibm.icu.text.Collator;
@@ -52,31 +60,31 @@ public class DictionaryApplication extends Application {
   
   // Static, determined by resources (and locale).
   // Unordered.
-  static Map<String,DictionaryInfo> DOWNLOADABLE_NAME_TO_INFO = null;
+  static Map<String,DictionaryInfo> DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = null;
   
   static final class DictionaryConfig implements Serializable {
     private static final long serialVersionUID = -1444177164708201263L;
     // User-ordered list, persisted, just the ones that are/have been present.
     final List<String> dictionaryFilesOrdered = new ArrayList<String>();
-    final Map<String, DictionaryInfo> dictionaryInfoCache = new LinkedHashMap<String, DictionaryInfo>();
+    
+    final Map<String, DictionaryInfo> uncompressedFilenameToDictionaryInfo = new LinkedHashMap<String, DictionaryInfo>();
   }
   DictionaryConfig dictionaryConfig = null;
 
-  static final class DictionaryHistory implements Serializable {
-    private static final long serialVersionUID = -4842995032541390284L;
-    // User-ordered list, persisted, just the ones that are/have been present.
-    final List<DictionaryLink> dictionaryLinks = new ArrayList<DictionaryLink>();
-  }
-  DictionaryHistory dictionaryHistory = null;
+//  static final class DictionaryHistory implements Serializable {
+//    private static final long serialVersionUID = -4842995032541390284L;
+//    // User-ordered list, persisted, just the ones that are/have been present.
+//    final List<DictionaryLink> dictionaryLinks = new ArrayList<DictionaryLink>();
+//  }
+//  DictionaryHistory dictionaryHistory = null;
   
-  private File dictDir;
-
   static synchronized void staticInit(final Context context) {
-    if (DOWNLOADABLE_NAME_TO_INFO != null) {
+    if (DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO != null) {
       return;
     }
-    DOWNLOADABLE_NAME_TO_INFO = new LinkedHashMap<String,DictionaryInfo>();
-    final BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(R.raw.dictionary_info)));
+    DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = new LinkedHashMap<String,DictionaryInfo>();
+    final BufferedReader reader = new BufferedReader(
+            new InputStreamReader(context.getResources().openRawResource(R.raw.dictionary_info)));
     try {
       String line;
       while ((line = reader.readLine()) != null) {
@@ -84,7 +92,8 @@ public class DictionaryApplication extends Application {
           continue;
         }
         final DictionaryInfo dictionaryInfo = new DictionaryInfo(line);
-        DOWNLOADABLE_NAME_TO_INFO.put(dictionaryInfo.uncompressedFilename, dictionaryInfo);
+        DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.put(
+                dictionaryInfo.uncompressedFilename, dictionaryInfo);
       }
       reader.close();
     } catch (IOException e) {
@@ -93,6 +102,8 @@ public class DictionaryApplication extends Application {
   }
 
   
+  private File dictDir;
+
   @Override
   public void onCreate() {
     super.onCreate();
@@ -101,7 +112,8 @@ public class DictionaryApplication extends Application {
     staticInit(getApplicationContext());
     
     // Load the dictionaries we know about.
-    dictionaryConfig = PersistentObjectCache.init(getApplicationContext()).read(C.DICTIONARY_CONFIGS, DictionaryConfig.class);
+    dictionaryConfig = PersistentObjectCache.init(getApplicationContext()).read(
+            C.DICTIONARY_CONFIGS, DictionaryConfig.class);
     if (dictionaryConfig == null) {
       dictionaryConfig = new DictionaryConfig();
     }
@@ -198,12 +210,23 @@ public class DictionaryApplication extends Application {
   String defaultLangName = null;
   final Map<String, String> fileToNameCache = new LinkedHashMap<String, String>();
 
-  public String getLanguageName(final String isoCode) {
+  public String isoCodeToLocalizedLanguageName(final String isoCode) {
     final Language.LanguageResources languageResources = Language.isoCodeToResources.get(isoCode); 
     final String lang = languageResources != null ? getApplicationContext().getString(languageResources.nameId) : isoCode;
     return lang;
   }
   
+  public List<IndexInfo> sortedIndexInfos(List<IndexInfo> indexInfos) {
+      // Hack to put the default locale first in the name.
+      if (indexInfos.size() > 1 && 
+          indexInfos.get(1).shortName.toLowerCase().equals(defaultLangISO2)) {
+        List<IndexInfo> result = new ArrayList<DictionaryInfo.IndexInfo>(indexInfos);
+        ListUtil.swap(result, 0, 1);
+        return result;
+      }
+      return indexInfos;
+  }
+  
 
   public synchronized String getDictionaryName(final String uncompressedFilename) {
     final String currentLocale = Locale.getDefault().getLanguage().toLowerCase(); 
@@ -213,7 +236,7 @@ public class DictionaryApplication extends Application {
       defaultLangName = null;
     }
     if (defaultLangName == null) {
-      defaultLangName = getLanguageName(defaultLangISO2);
+      defaultLangName = isoCodeToLocalizedLanguageName(defaultLangISO2);
     }
     
     String name = fileToNameCache.get(uncompressedFilename);
@@ -221,25 +244,16 @@ public class DictionaryApplication extends Application {
       return name;
     }
     
-    final DictionaryInfo dictionaryInfo = DOWNLOADABLE_NAME_TO_INFO.get(uncompressedFilename);
+    final DictionaryInfo dictionaryInfo = DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.get(uncompressedFilename);
     if (dictionaryInfo != null) {
       final StringBuilder nameBuilder = new StringBuilder();
 
-      // Hack to put the default locale first in the name.
-      boolean swapped = false;
-      if (dictionaryInfo.indexInfos.size() > 1 && 
-          dictionaryInfo.indexInfos.get(1).shortName.toLowerCase().equals(defaultLangISO2)) {
-        ListUtil.swap(dictionaryInfo.indexInfos, 0, 1);
-        swapped = true;
-      }
-      for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) {
+      List<IndexInfo> sortedIndexInfos = sortedIndexInfos(dictionaryInfo.indexInfos);
+      for (int i = 0; i < sortedIndexInfos.size(); ++i) {
         if (i > 0) {
           nameBuilder.append("-");
         }
-        nameBuilder.append(getLanguageName(dictionaryInfo.indexInfos.get(i).shortName));
-      }
-      if (swapped) {
-        ListUtil.swap(dictionaryInfo.indexInfos, 0, 1);
+        nameBuilder.append(isoCodeToLocalizedLanguageName(sortedIndexInfos.get(i).shortName));
       }
       name = nameBuilder.toString();
     } else {
@@ -248,6 +262,27 @@ public class DictionaryApplication extends Application {
     fileToNameCache.put(uncompressedFilename, name);
     return name;
   }
+  
+  public View createButton(final Context context, final DictionaryInfo dictionaryInfo,
+          final IndexInfo indexInfo) {
+      LanguageResources languageResources = Language.isoCodeToResources.get(indexInfo.shortName);
+      View result;
+      if (languageResources == null || languageResources.flagId <= 0) {
+          Button button = new Button(context);
+          button.setText(indexInfo.shortName);
+          result = button;
+      } else {
+          ImageButton button = new ImageButton(context);
+          button.setImageResource(languageResources.flagId);
+          button.setScaleType(ScaleType.FIT_CENTER);
+          result = button;
+      }
+      result.setOnClickListener(
+              new IntentLauncher(context, 
+              DictionaryActivity.getLaunchIntent(getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName, "")));
+      return result;
+  }
+
 
   public synchronized void moveDictionaryToTop(final DictionaryInfo dictionaryInfo) {
     dictionaryConfig.dictionaryFilesOrdered.remove(dictionaryInfo.uncompressedFilename);
@@ -257,7 +292,7 @@ public class DictionaryApplication extends Application {
 
   public synchronized void deleteDictionary(final DictionaryInfo dictionaryInfo) {
     while (dictionaryConfig.dictionaryFilesOrdered.remove(dictionaryInfo.uncompressedFilename)) {};
-    dictionaryConfig.dictionaryInfoCache.remove(dictionaryInfo.uncompressedFilename);
+    dictionaryConfig.uncompressedFilenameToDictionaryInfo.remove(dictionaryInfo.uncompressedFilename);
     getPath(dictionaryInfo.uncompressedFilename).delete();
     PersistentObjectCache.getInstance().write(C.DICTIONARY_CONFIGS, dictionaryConfig);
   }
@@ -269,9 +304,9 @@ public class DictionaryApplication extends Application {
       final String name1 = getDictionaryName(uncompressedFilename1);
       final String name2 = getDictionaryName(uncompressedFilename2);
       if (defaultLangName.length() > 0) {
-        if (name1.startsWith(defaultLangName) && !name2.startsWith(defaultLangName)) {
+        if (name1.startsWith(defaultLangName + "-") && !name2.startsWith(defaultLangName + "-")) {
           return -1;
-        } else if (name2.startsWith(defaultLangName) && !name1.startsWith(defaultLangName)) {
+        } else if (name2.startsWith(defaultLangName + "-") && !name1.startsWith(defaultLangName + "-")) {
           return 1;
         }
       }
@@ -303,7 +338,7 @@ public class DictionaryApplication extends Application {
           final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(dictFile);
           if (dictionaryInfo != null) {
             newDictionaryConfig.dictionaryFilesOrdered.add(uncompressedFilename);
-            newDictionaryConfig.dictionaryInfoCache.put(uncompressedFilename, dictionaryInfo);
+            newDictionaryConfig.uncompressedFilenameToDictionaryInfo.put(uncompressedFilename, dictionaryInfo);
           }
         }
         
@@ -314,14 +349,14 @@ public class DictionaryApplication extends Application {
         if (dictDirFiles != null) {
           for (final File file : dictDirFiles) {
             if (file.getName().endsWith(".zip")) {
-              if (DOWNLOADABLE_NAME_TO_INFO.containsKey(file.getName().replace(".zip", ""))) {
+              if (DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.containsKey(file.getName().replace(".zip", ""))) {
                 file.delete();
               }
             }
             if (!file.getName().endsWith(".quickdic")) {
               continue;
             }
-            if (newDictionaryConfig.dictionaryInfoCache.containsKey(file.getName())) {
+            if (newDictionaryConfig.uncompressedFilenameToDictionaryInfo.containsKey(file.getName())) {
               // We have it in our list already.
               continue;
             }
@@ -332,7 +367,7 @@ public class DictionaryApplication extends Application {
             }
             
             toAddSorted.add(file.getName());
-            newDictionaryConfig.dictionaryInfoCache.put(file.getName(), dictionaryInfo);
+            newDictionaryConfig.uncompressedFilenameToDictionaryInfo.put(file.getName(), dictionaryInfo);
           }
         } else {
           Log.w(LOG, "dictDir is not a diretory: " + getDictDir().getPath());
@@ -355,22 +390,22 @@ public class DictionaryApplication extends Application {
       }}).start();
   }
 
-  public synchronized List<DictionaryInfo> getUsableDicts() {
+  public synchronized List<DictionaryInfo> getDictionariesOnDevice() {
     final List<DictionaryInfo> result = new ArrayList<DictionaryInfo>(dictionaryConfig.dictionaryFilesOrdered.size());
     for (final String uncompressedFilename : dictionaryConfig.dictionaryFilesOrdered) {
-      final DictionaryInfo dictionaryInfo = dictionaryConfig.dictionaryInfoCache.get(uncompressedFilename);
+      final DictionaryInfo dictionaryInfo = dictionaryConfig.uncompressedFilenameToDictionaryInfo.get(uncompressedFilename);
       if (dictionaryInfo != null) {
         result.add(dictionaryInfo);
       }
     }
     return result;
   }
-
+  
   public synchronized List<DictionaryInfo> getAllDictionaries() {
-    final List<DictionaryInfo> result = getUsableDicts();
+    final List<DictionaryInfo> result = getDictionariesOnDevice();
     
     // The downloadable ones.
-    final Map<String,DictionaryInfo> remaining = new LinkedHashMap<String, DictionaryInfo>(DOWNLOADABLE_NAME_TO_INFO);
+    final Map<String,DictionaryInfo> remaining = new LinkedHashMap<String, DictionaryInfo>(DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO);
     remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered);
     final List<DictionaryInfo> toAddSorted = new ArrayList<DictionaryInfo>(remaining.values());
     Collections.sort(toAddSorted, dictionaryInfoComparator);
@@ -380,16 +415,16 @@ public class DictionaryApplication extends Application {
   }
 
   public synchronized boolean isDictionaryOnDevice(String uncompressedFilename) {
-    return dictionaryConfig.dictionaryInfoCache.get(uncompressedFilename) != null;
+    return dictionaryConfig.uncompressedFilenameToDictionaryInfo.get(uncompressedFilename) != null;
   }
 
   public boolean updateAvailable(final DictionaryInfo dictionaryInfo) {
-    final DictionaryInfo downloadable = DOWNLOADABLE_NAME_TO_INFO.get(dictionaryInfo.uncompressedFilename);
+    final DictionaryInfo downloadable = DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.get(dictionaryInfo.uncompressedFilename);
     return downloadable != null && downloadable.creationMillis > dictionaryInfo.creationMillis;
   }
 
   public DictionaryInfo getDownloadable(final String uncompressedFilename) {
-    final DictionaryInfo downloadable = DOWNLOADABLE_NAME_TO_INFO.get(uncompressedFilename);
+    final DictionaryInfo downloadable = DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.get(uncompressedFilename);
     return downloadable;
   }
 
index 4db56a3c798995f208b4aab614803403cc390c59..5d90589dbf85a797109692eb2ad4f26285848193 100644 (file)
@@ -25,16 +25,17 @@ public class DictionaryInfo implements Serializable {
   public static final class IndexInfo implements Serializable {
     private static final long serialVersionUID = 6524751236198309438L;
 
+    public static final int NUM_CSV_FIELDS = 3;
+
+    public final String shortName;  // Often LangISO.
+    public final int allTokenCount;
+    public final int mainTokenCount;
+    
     public IndexInfo(String shortName, int allTokenCount, int mainTokenCount) {
       this.shortName = shortName;
       this.allTokenCount = allTokenCount;
       this.mainTokenCount = mainTokenCount;
     }
-    public final String shortName;  // Often LangISO.
-    public final int allTokenCount;
-    public final int mainTokenCount;
-    
-    public static final int SIZE = 3;
     
     public StringBuilder append(StringBuilder result) {
       result.append(shortName);
@@ -48,7 +49,6 @@ public class DictionaryInfo implements Serializable {
       allTokenCount = Integer.parseInt(fields[i++]);
       mainTokenCount = Integer.parseInt(fields[i++]);
     }
-
   }
   
   // Stuff populated from the text file.
@@ -89,7 +89,7 @@ public class DictionaryInfo implements Serializable {
     final int size = Integer.parseInt(fields[i++]);
     for (int j = 0; j < size; ++j) {
       indexInfos.add(new IndexInfo(fields, i));
-      i += IndexInfo.SIZE;
+      i += IndexInfo.NUM_CSV_FIELDS;
     }
     dictInfo = fields[i++].replaceAll("\\\\n", "\n");
   }
index af50112dbc98f36ff15b0693e5ffd7b24cdf4bc3..b9a85b06324c061be2ead5781f568da13f07bd37 100644 (file)
@@ -37,344 +37,419 @@ import android.widget.CompoundButton;
 import android.widget.CompoundButton.OnCheckedChangeListener;
 import android.widget.EditText;
 import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 import android.widget.ToggleButton;
 
+import com.actionbarsherlock.app.SherlockActivity;
 import com.actionbarsherlock.app.SherlockListActivity;
 import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.widget.SearchView;
+import com.actionbarsherlock.widget.SearchView.OnQueryTextListener;
 import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
+import com.hughes.android.dictionary.engine.Language;
+import com.hughes.android.dictionary.engine.Language.LanguageResources;
 import com.hughes.android.util.IntentLauncher;
 
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
-public class DictionaryManagerActivity extends SherlockListActivity {
-
-  static final String LOG = "QuickDic";
-  static boolean blockAutoLaunch = false;
-
-  DictionaryApplication application;
-  Adapter adapter;
-  
-  EditText filterText;
-  ToggleButton showLocal;
-  
-  Handler uiHandler;
-  
-  public static Intent getLaunchIntent() {
-    final Intent intent = new Intent();
-    intent.setClassName(DictionaryManagerActivity.class.getPackage().getName(),
-        DictionaryManagerActivity.class.getName());
-    intent.putExtra(C.CAN_AUTO_LAUNCH_DICT, false);
-    return intent;
-  }
-  
-  public void onCreate(Bundle savedInstanceState) {
-    setTheme(((DictionaryApplication)getApplication()).getSelectedTheme().themeId);
-
-    super.onCreate(savedInstanceState);
-    Log.d(LOG, "onCreate:" + this);
-    
-    application = (DictionaryApplication) getApplication();
-
-    // UI init.
-    setContentView(R.layout.dictionary_manager_activity);
-    
-    filterText = (EditText) findViewById(R.id.filterText);
-    showLocal = (ToggleButton) findViewById(R.id.showLocal);
-    
-    filterText.addTextChangedListener(new TextWatcher() {
-      @Override
-      public void onTextChanged(CharSequence s, int start, int before, int count) {
-      }
-      
-      @Override
-      public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-      }
-      
-      @Override
-      public void afterTextChanged(Editable s) {
-        onFilterTextChanged();
-      }
-    });
-    
-    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) {
-        onShowLocalChanged();
-      }
-    });
-
-    getListView().setOnItemClickListener(new OnItemClickListener() {
-      @Override
-      public void onItemClick(AdapterView<?> arg0, View arg1, int index,
-          long id) {
-        onClick(index);
-      }
-    });
-    
-    getListView().setClickable(true);
-
-    // ContextMenu.
-    registerForContextMenu(getListView());
-
-    blockAutoLaunch = false;
-    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
-    final String thanksForUpdatingLatestVersion = getString(R.string.thanksForUpdatingVersion);
-    if (!prefs.getString(C.THANKS_FOR_UPDATING_VERSION, "").equals(thanksForUpdatingLatestVersion)) {
-      blockAutoLaunch = true;
-      startActivity(HtmlDisplayActivity.getWhatsNewLaunchIntent());
-      prefs.edit().putString(C.THANKS_FOR_UPDATING_VERSION, thanksForUpdatingLatestVersion).commit();
-    }
-  }
-  
-  @Override
-  protected void onStart() {
-    super.onStart();
-    uiHandler = new Handler();
-  }
-  
-  @Override
-  protected void onStop() {
-    super.onStop();
-    uiHandler = null;
-  }
-  
-  @Override
-  protected void onResume() {
-    super.onResume();
-    
-    if (PreferenceActivity.prefsMightHaveChanged) {
-        PreferenceActivity.prefsMightHaveChanged = false;
-      finish();
-      startActivity(getIntent());
-    }
-    
-    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
-    showLocal.setChecked(prefs.getBoolean(C.SHOW_LOCAL, false));
-    
-    if (!blockAutoLaunch &&
-        getIntent().getBooleanExtra(C.CAN_AUTO_LAUNCH_DICT, true) &&
-        prefs.contains(C.DICT_FILE) && 
-        prefs.contains(C.INDEX_INDEX)) {
-      Log.d(LOG, "Skipping Dictionary List, going straight to dictionary.");
-      startActivity(DictionaryActivity.getLaunchIntent(new File(prefs.getString(C.DICT_FILE, "")), prefs.getInt(C.INDEX_INDEX, 0), prefs.getString(C.SEARCH_TOKEN, "")));
-      finish();
-      return;
+public class DictionaryManagerActivity extends SherlockActivity {
+
+    static final String LOG = "QuickDic";
+    static boolean blockAutoLaunch = false;
+
+    DictionaryApplication application;
+//    Adapter adapter;
+
+    // EditText filterText;
+    SearchView filterSearchView;
+    ToggleButton hideDownloadable;
+
+    LinearLayout dictionariesOnDevice;
+    LinearLayout downloadableDictionaries;
+
+    Handler uiHandler;
+
+    public static Intent getLaunchIntent() {
+        final Intent intent = new Intent();
+        intent.setClassName(DictionaryManagerActivity.class.getPackage().getName(),
+                DictionaryManagerActivity.class.getName());
+        intent.putExtra(C.CAN_AUTO_LAUNCH_DICT, false);
+        return intent;
     }
-    
-    application.backgroundUpdateDictionaries(new Runnable() {
-      @Override
-      public void run() {
-        if (uiHandler == null) {
-          return;
-        }
-        uiHandler.post(new Runnable() {
-          @Override
-          public void run() {
-            setListAdapter(adapter = new Adapter());
-          }
+
+    public void onCreate(Bundle savedInstanceState) {
+        setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId);
+
+        super.onCreate(savedInstanceState);
+        Log.d(LOG, "onCreate:" + this);
+
+        application = (DictionaryApplication) getApplication();
+
+        // UI init.
+        setContentView(R.layout.dictionary_manager_activity);
+
+        dictionariesOnDevice = (LinearLayout) findViewById(R.id.dictionariesOnDeviceGoHere);
+        downloadableDictionaries = (LinearLayout) findViewById(R.id.downloadableDictionariesGoHere);
+
+        // filterText = (EditText) findViewById(R.id.filterText);
+        //
+        // filterText.addTextChangedListener(new TextWatcher() {
+        // @Override
+        // public void onTextChanged(CharSequence s, int start, int before, int
+        // count) {
+        // }
+        //
+        // @Override
+        // public void beforeTextChanged(CharSequence s, int start, int count,
+        // int after) {
+        // }
+        //
+        // @Override
+        // public void afterTextChanged(Editable s) {
+        // onFilterTextChanged();
+        // }
+        // });
+
+        // final ImageButton clearSearchText = (ImageButton)
+        // findViewById(R.id.ClearSearchTextButton);
+        // clearSearchText.setOnClickListener(new View.OnClickListener() {
+        // @Override
+        // public void onClick(View arg0) {
+        // filterText.setText("");
+        // filterText.requestFocus();
+        // }
+        // });
+
+        hideDownloadable = (ToggleButton) findViewById(R.id.hideDownloadable);
+        hideDownloadable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                onShowLocalChanged();
+            }
         });
-      }
-    });
-
-    setListAdapter(adapter = new Adapter());
-  }
-
-  public boolean onCreateOptionsMenu(final Menu menu) {
-    application.onCreateGlobalOptionsMenu(this, menu);
-    return true;
-  }
-  
-
-  @Override
-  public void onCreateContextMenu(final ContextMenu menu, final View view,
-      final ContextMenuInfo menuInfo) {
-    super.onCreateContextMenu(menu, view, menuInfo);
-    
-    final AdapterContextMenuInfo adapterContextMenuInfo = (AdapterContextMenuInfo) menuInfo;
-    final int position = adapterContextMenuInfo.position;
-    final DictionaryInfo dictionaryInfo = adapter.getItem(position);
-    
-    if (position > 0 && application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)) {
-      final android.view.MenuItem moveToTopMenuItem = menu.add(R.string.moveToTop);
-      moveToTopMenuItem.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
-        @Override
-        public boolean onMenuItemClick(android.view.MenuItem item) {
-          application.moveDictionaryToTop(dictionaryInfo);
-          setListAdapter(adapter = new Adapter());
-          return true;
+
+        // ContextMenu.
+        // registerForContextMenu(getListView());
+
+        blockAutoLaunch = false;
+        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+        final String thanksForUpdatingLatestVersion = getString(R.string.thanksForUpdatingVersion);
+        if (!prefs.getString(C.THANKS_FOR_UPDATING_VERSION, "").equals(
+                thanksForUpdatingLatestVersion)) {
+            blockAutoLaunch = true;
+            startActivity(HtmlDisplayActivity.getWhatsNewLaunchIntent());
+            prefs.edit().putString(C.THANKS_FOR_UPDATING_VERSION, thanksForUpdatingLatestVersion)
+                    .commit();
         }
-      });
     }
 
-    final android.view.MenuItem deleteMenuItem = menu.add(R.string.deleteDictionary);
-    deleteMenuItem.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
-      @Override
-      public boolean onMenuItemClick(android.view.MenuItem item) {
-        application.deleteDictionary(dictionaryInfo);
-        setListAdapter(adapter = new Adapter());
-        return true;
-      }
-    });
-
-    final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
-    if (downloadable != null) {
-      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(android.view.MenuItem item) {
-          final Intent intent = getDownloadIntent(downloadable);
-          startActivity(intent);
-          setListAdapter(adapter = new Adapter());
-          return true;
-        }
-      });
+    @Override
+    protected void onStart() {
+        super.onStart();
+        uiHandler = new Handler();
     }
 
-  }
-
-  private Intent getDownloadIntent(final DictionaryInfo downloadable) {
-//      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() {
-    setListAdapter(adapter = new Adapter());
-
-  }
-
-  private void onShowLocalChanged() {
-    setListAdapter(adapter = new Adapter());
-    Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
-    prefs.putBoolean(C.SHOW_LOCAL, showLocal.isChecked());
-    prefs.commit();
-  }
-  
-  private void onClick(int index) {
-    final DictionaryInfo dictionaryInfo = adapter.getItem(index);
-    final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
-    if (!application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename) && downloadable != null) {
-      final Intent intent = getDownloadIntent(downloadable);
-      startActivity(intent);
-    } else {
-      final Intent intent = DictionaryActivity.getLaunchIntent(application.getPath(dictionaryInfo.uncompressedFilename), 0, "");
-      startActivity(intent);
+    @Override
+    protected void onStop() {
+        super.onStop();
+        uiHandler = null;
     }
-  }
-  
-  class Adapter extends BaseAdapter {
-    
-    final List<DictionaryInfo> dictionaryInfos = new ArrayList<DictionaryInfo>();
-    
-    Adapter() {
-      final String filter = filterText.getText().toString().trim().toLowerCase();
-      for (final DictionaryInfo dictionaryInfo : application.getAllDictionaries()) {
-        boolean canShow = true;
-        if (showLocal.isChecked() && !application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)) {
-          canShow = false;
-        }
-        if (canShow && filter.length() > 0) {
-          if (!application.getDictionaryName(dictionaryInfo.uncompressedFilename).toLowerCase().contains(filter)) {
-            canShow = false;
-          }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+
+        if (PreferenceActivity.prefsMightHaveChanged) {
+            PreferenceActivity.prefsMightHaveChanged = false;
+            finish();
+            startActivity(getIntent());
         }
-        if (canShow) {
-          dictionaryInfos.add(dictionaryInfo);
+
+        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+        hideDownloadable.setChecked(prefs.getBoolean(C.SHOW_LOCAL, false));
+
+        if (!blockAutoLaunch &&
+                getIntent().getBooleanExtra(C.CAN_AUTO_LAUNCH_DICT, true) &&
+                prefs.contains(C.DICT_FILE) &&
+                prefs.contains(C.INDEX_SHORT_NAME)) {
+            Log.d(LOG, "Skipping Dictionary List, going straight to dictionary.");
+            startActivity(DictionaryActivity.getLaunchIntent(
+                    new File(prefs.getString(C.DICT_FILE, "")), prefs.getString(C.INDEX_SHORT_NAME, ""),
+                    prefs.getString(C.SEARCH_TOKEN, "")));
+            finish();
+            return;
         }
-      }
+
+        application.backgroundUpdateDictionaries(new Runnable() {
+            @Override
+            public void run() {
+                if (uiHandler == null) {
+                    return;
+                }
+                uiHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        populateDictionaryLists("");
+                    }
+                });
+            }
+        });
+
+        populateDictionaryLists("");
     }
 
     @Override
-    public int getCount() {
-      return dictionaryInfos.size();
+    public boolean onCreateOptionsMenu(final Menu menu) {
+        MenuInflater inflater = getSupportMenuInflater();
+        inflater.inflate(R.menu.dictionary_manager_options_menu, menu);
+        
+        filterSearchView = (SearchView) menu.findItem(R.id.filterText).getActionView();
+        filterSearchView.setOnQueryTextListener(new OnQueryTextListener() {
+            @Override
+            public boolean onQueryTextSubmit(String query) {
+                return true;
+            }
+            
+            @Override
+            public boolean onQueryTextChange(String filterText) {
+                populateDictionaryLists(filterText);
+                return true;
+            }
+        });
+
+        application.onCreateGlobalOptionsMenu(this, menu);
+        return true;
     }
 
-    @Override
-    public DictionaryInfo getItem(int position) {
-      return dictionaryInfos.get(position);
+        // @Override
+        // public void onCreateContextMenu(final ContextMenu menu, final View
+        // view,
+        // final ContextMenuInfo menuInfo) {
+        // super.onCreateContextMenu(menu, view, menuInfo);
+        //
+        // final AdapterContextMenuInfo adapterContextMenuInfo =
+        // (AdapterContextMenuInfo) menuInfo;
+        // final int position = adapterContextMenuInfo.position;
+        // final DictionaryInfo dictionaryInfo = adapter.getItem(position);
+        //
+        // if (position > 0 &&
+        // application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename))
+        // {
+        // final android.view.MenuItem moveToTopMenuItem =
+        // menu.add(R.string.moveToTop);
+        // moveToTopMenuItem.setOnMenuItemClickListener(new
+        // android.view.MenuItem.OnMenuItemClickListener() {
+        // @Override
+        // public boolean onMenuItemClick(android.view.MenuItem item) {
+        // application.moveDictionaryToTop(dictionaryInfo);
+        // setListAdapter(adapter = new Adapter());
+        // return true;
+        // }
+        // });
+        // }
+//
+//        final android.view.MenuItem deleteMenuItem = menu.add(R.string.deleteDictionary);
+//        deleteMenuItem
+//                .setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
+//                    @Override
+//                    public boolean onMenuItemClick(android.view.MenuItem item) {
+//                        application.deleteDictionary(dictionaryInfo);
+//                        setListAdapter(adapter = new Adapter());
+//                        return true;
+//                    }
+//                });
+//
+//        final DictionaryInfo downloadable = application
+//                .getDownloadable(dictionaryInfo.uncompressedFilename);
+//        if (downloadable != null) {
+//            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(android.view.MenuItem item) {
+//                            final Intent intent = getDownloadIntent(downloadable);
+//                            startActivity(intent);
+//                            setListAdapter(adapter = new Adapter());
+//                            return true;
+//                        }
+//                    });
+//        }
+//
+//    }
+
+    private Intent getDownloadIntent(final DictionaryInfo downloadable) {
+        // DownloadManager downloadManager = (DownloadManager)
+        // getSystemService(DOWNLOAD_SERVICE);
+        // DownloadManager.Request request = new
+        // DownloadManager.Request(Uri.parse(""));
+        // long id = downloadManager.enqueue(request);
+        // DownloadManager.Query query;
+        return null;
     }
 
-    @Override
-    public long getItemId(int position) {
-      return position;
+    private void onShowLocalChanged() {
+        downloadableDictionaries.setVisibility(hideDownloadable.isChecked() ? View.GONE
+                : View.VISIBLE);
+        Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
+        prefs.putBoolean(C.SHOW_LOCAL, hideDownloadable.isChecked());
+        prefs.commit();
     }
-    
-    @Override
-    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);
-
-      final TextView textView = (TextView) convertView.findViewById(R.id.dictionaryName);
-      final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);
-      textView.setText(name);
-      
-      final Button downloadButton = (Button) convertView.findViewById(R.id.dictionaryDownloadButton);
-      final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
-      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 {
-          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 TextView dictionaryDetails = (TextView) convertView.findViewById(R.id.dictionaryDetails);
-      final StringBuilder builder = new StringBuilder();
-      for (final IndexInfo indexInfo : dictionaryInfo.indexInfos) {
-        if (builder.length() > 0) {
-          builder.append(" | ");
-        }
-        builder.append(getString(R.string.indexInfo, indexInfo.shortName, indexInfo.mainTokenCount));
-      }
-      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
-      //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);
+
+    // private void onClick(int index) {
+    // final DictionaryInfo dictionaryInfo = adapter.getItem(index);
+    // final DictionaryInfo downloadable =
+    // application.getDownloadable(dictionaryInfo.uncompressedFilename);
+    // if
+    // (!application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)
+    // && downloadable != null) {
+    // final Intent intent = getDownloadIntent(downloadable);
+    // startActivity(intent);
+    // } else {
+    // final Intent intent =
+    // DictionaryActivity.getLaunchIntent(application.getPath(dictionaryInfo.uncompressedFilename),
+    // 0, "");
+    // startActivity(intent);
+    // }
+    // }
+
+    private void populateDictionaryLists(String filterText) {
+        // On device.
+        dictionariesOnDevice.removeAllViews();
+        final List<DictionaryInfo> dictionaryInfos = application.getDictionariesOnDevice();
+        for (final DictionaryInfo dictionaryInfo : dictionaryInfos) {
+            View row = LayoutInflater.from(dictionariesOnDevice.getContext()).inflate(
+                    R.layout.dictionary_on_device_row, dictionariesOnDevice, false);
+            final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
+            name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));
+            
+            LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
+            final List<IndexInfo> sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos);
+            for (IndexInfo indexInfo : sortedIndexInfos) {
+                final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo);
+                buttons.addView(button);
+            }
+            
+            dictionariesOnDevice.addView(row);
         }
-      });
-      
-      return convertView;
+
+        // Downloadable.
+
     }
-  }
+
+//    class Adapter extends BaseAdapter {
+//
+//        final List<DictionaryInfo> dictionaryInfos = new ArrayList<DictionaryInfo>();
+//
+//        Adapter() {
+//            final String filter = filterSearchView.getText().toString().trim().toLowerCase();
+//            for (final DictionaryInfo dictionaryInfo : application.getAllDictionaries()) {
+//                boolean canShow = true;
+//                if (hideDownloadable.isChecked()
+//                        && !application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)) {
+//                    canShow = false;
+//                }
+//                if (canShow && filter.length() > 0) {
+//                    if (!application.getDictionaryName(dictionaryInfo.uncompressedFilename)
+//                            .toLowerCase().contains(filter)) {
+//                        canShow = false;
+//                    }
+//                }
+//                if (canShow) {
+//                    dictionaryInfos.add(dictionaryInfo);
+//                }
+//            }
+//        }
+//
+//        @Override
+//        public int getCount() {
+//            return dictionaryInfos.size();
+//        }
+//
+//        @Override
+//        public DictionaryInfo getItem(int position) {
+//            return dictionaryInfos.get(position);
+//        }
+//
+//        @Override
+//        public long getItemId(int position) {
+//            return position;
+//        }
+//
+//        @Override
+//        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);
+//
+//            final TextView textView = (TextView) convertView.findViewById(R.id.dictionaryName);
+//            final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);
+//            textView.setText(name);
+//
+//            final Button downloadButton = (Button) convertView
+//                    .findViewById(R.id.dictionaryDownloadButton);
+//            final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
+//            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 {
+//                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 TextView dictionaryDetails = (TextView) convertView
+//                    .findViewById(R.id.dictionaryDetails);
+//            final StringBuilder builder = new StringBuilder();
+//            for (final IndexInfo indexInfo : dictionaryInfo.indexInfos) {
+//                if (builder.length() > 0) {
+//                    builder.append(" | ");
+//                }
+//                builder.append(getString(R.string.indexInfo, indexInfo.shortName,
+//                        indexInfo.mainTokenCount));
+//            }
+//            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
+//            // 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 convertView;
+//        }
+//    }
 
 }
index 5e74a3cd0554d1d903873465753c0c155bb19faf..edc50e44c2a96586c023a49029ff5641051e6ad5 100644 (file)
@@ -37,7 +37,7 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
     addPreferencesFromResource(R.xml.preferences);
     ListPreference defaultDic = (ListPreference) findPreference(getResources().getString(R.string.defaultDicKey));
     DictionaryApplication application = (DictionaryApplication) getApplication();
-    List<DictionaryInfo> dicts = application.getUsableDicts();
+    List<DictionaryInfo> dicts = application.getDictionariesOnDevice();
     
        final CharSequence[] entries = new CharSequence[dicts.size()];
        final CharSequence[] entryvalues = new CharSequence[dicts.size()];
index 03cc102ef7b858a377217a2be2432eb7ee61071d..036f46c15505d59409d5a4680a983911bf2bc071 100644 (file)
@@ -28,7 +28,5 @@ public class IntentLauncher implements OnClickListener {
   public void onClick(View v) {
     go();
   }
-  
-  
 
 }