]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Added filtering to manager, remove timeout on auto-launch (and finish
authorThad Hughes <thad.hughes@gmail.com>
Fri, 23 Mar 2012 03:26:24 +0000 (20:26 -0700)
committerThad Hughes <thad.hughes@gmail.com>
Fri, 23 Mar 2012 03:26:24 +0000 (20:26 -0700)
after it).

res/layout/dictionary_manager_activity.xml [new file with mode: 0644]
res/layout/list_activity.xml [deleted file]
res/values/strings.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/DictionaryManagerActivity.java

diff --git a/res/layout/dictionary_manager_activity.xml b/res/layout/dictionary_manager_activity.xml
new file mode 100644 (file)
index 0000000..96a0967
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout 
+       xmlns:android="http://schemas.android.com/apk/res/android"
+       android:orientation="vertical" 
+ android:layout_width="fill_parent"
+       android:layout_height="fill_parent">
+
+    <LinearLayout
+        android:id="@+id/linearLayout1"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
+
+        <EditText
+            android:id="@+id/filterText"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:hint="@string/managerFilterText" />
+
+        <CheckBox
+            android:id="@+id/showLocal"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_weight="0"
+            android:text="@string/managerFilterCheckbox" />
+
+    </LinearLayout>
+
+       <ListView 
+               android:id="@id/android:list" 
+               android:layout_width="fill_parent"
+               android:layout_height="0dip" 
+               android:choiceMode="singleChoice"
+               android:clickable="true" 
+               android:focusable="true"
+    android:layout_weight="1.0"
+    />
+
+   <TextView 
+     android:id="@+id/DictionaryListHeader"
+     android:hint="@string/helpText"
+     android:layout_width="fill_parent"
+     android:layout_height="wrap_content" 
+     android:imeOptions="actionSearch|flagNoEnterAction|flagNoExtractUi"
+     android:inputType="text"/>
+
+</LinearLayout>
diff --git a/res/layout/list_activity.xml b/res/layout/list_activity.xml
deleted file mode 100644 (file)
index 0957b5e..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<LinearLayout 
-       xmlns:android="http://schemas.android.com/apk/res/android"
-       android:orientation="vertical" android:layout_width="fill_parent"
-       android:layout_height="fill_parent">
-
-       <ListView 
-               android:id="@id/android:list" 
-               android:layout_width="fill_parent"
-               android:layout_height="0dip" 
-               android:choiceMode="singleChoice"
-               android:clickable="true" 
-               android:focusable="true"
-    android:layout_weight="1.0"
-    />
-
-   <TextView 
-     android:id="@+id/DictionaryListHeader"
-     android:hint="@string/helpText"
-     android:layout_width="fill_parent"
-     android:layout_height="wrap_content" 
-     android:imeOptions="actionSearch|flagNoEnterAction|flagNoExtractUi"
-     android:inputType="text"/>
-
-</LinearLayout>
index ac0b54ee88f4cf08a6efa3099f77bcb4685caa28..e7d650886a8ca16e442d061f223461c2e23080d3 100644 (file)
@@ -20,6 +20,9 @@
   <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="thanksForUpdatingVersion">3.2_en_b</string>
 
index 654a56a7cb99f63b249d19a3fdbb67e49331d961..c8511da3474087118fc473d2687d18690328d531 100644 (file)
@@ -22,9 +22,11 @@ public class C {
   static final String INDEX_INDEX = "indexIndex";
   static final String SEARCH_TOKEN = "searchToken";
   static final String CAN_AUTO_LAUNCH_DICT = "canAutoLaunch";
+  public static final String SHOW_LOCAL = "showLocal";
 
   public static final String THANKS_FOR_UPDATING_VERSION = "thanksForUpdatingVersion";
 
+
   enum Theme {
     DEFAULT(R.style.Theme_Default, R.style.Theme_Default_TokenRow_Fg,
         R.drawable.theme_default_token_row_main_bg,
index 052018a469a30325535da42a717e26662b10c302..3b01133c0f4bf999e762c3080c2365cd40ea1cac 100644 (file)
@@ -444,11 +444,33 @@ public class DictionaryActivity extends ListActivity {
     dialog.setTitle(R.string.selectDictionary);\r
 \r
     final List<DictionaryInfo> installedDicts = ((DictionaryApplication)getApplication()).getUsableDicts();\r
+    \r
     ListView listView = (ListView) dialog.findViewById(android.R.id.list);\r
+\r
+//    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);\r
+//    layoutParams.width = 0;\r
+//    layoutParams.weight = 1.0f;\r
+\r
+    final Button button = new Button(listView.getContext());\r
+    final String name = getString(R.string.dictionaryManager);\r
+    button.setText(name);\r
+    final IntentLauncher intentLauncher = new IntentLauncher(listView.getContext(), DictionaryManagerActivity.getLaunchIntent()) {\r
+      @Override\r
+      protected void onGo() {\r
+        dialog.dismiss();\r
+        DictionaryActivity.this.finish();\r
+      };\r
+    };\r
+    button.setOnClickListener(intentLauncher);\r
+//    button.setLayoutParams(layoutParams);\r
+    listView.addHeaderView(button);\r
+//    listView.setHeaderDividersEnabled(true);\r
+    \r
     listView.setAdapter(new BaseAdapter() {\r
       @Override\r
       public View getView(int position, View convertView, ViewGroup parent) {\r
         final LinearLayout result = new LinearLayout(parent.getContext());\r
+\r
         final DictionaryInfo dictionaryInfo = getItem(position);\r
           final Button button = new Button(parent.getContext());\r
           final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);\r
@@ -461,12 +483,10 @@ public class DictionaryActivity extends ListActivity {
             };\r
           };\r
           button.setOnClickListener(intentLauncher);\r
-          \r
           final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);\r
           layoutParams.width = 0;\r
           layoutParams.weight = 1.0f;\r
           button.setLayoutParams(layoutParams);\r
-\r
           result.addView(button);\r
         return result;\r
       }\r
@@ -747,9 +767,9 @@ public class DictionaryActivity extends ListActivity {
       return true;\r
     }\r
     if (keyCode == KeyEvent.KEYCODE_BACK) {\r
-      Log.d(LOG, "Clearing dictionary prefs.");\r
+      //Log.d(LOG, "Clearing dictionary prefs.");\r
       // Pretend that we just autolaunched so that we won't do it again.\r
-      DictionaryManagerActivity.lastAutoLaunchMillis = System.currentTimeMillis();\r
+      //DictionaryManagerActivity.lastAutoLaunchMillis = System.currentTimeMillis();\r
     }\r
     if (keyCode == KeyEvent.KEYCODE_ENTER) {\r
       Log.d(LOG, "Trying to hide soft keyboard.");\r
index ba8960d02314817c8adcec4350cbde0d8b490001..53cbd0a451511061a6349780d0efe8be9e7265c0 100644 (file)
@@ -38,6 +38,7 @@ import android.view.Menu;
 import android.view.MenuItem;
 import android.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;
index cc24e2245b5b4c4821e84ea28759196aa68617fa..dab77f5d776bad583940fbe6e134e77d8fd53407 100644 (file)
@@ -15,6 +15,7 @@
 package com.hughes.android.dictionary;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
 
 import android.app.AlertDialog;
@@ -22,9 +23,12 @@ import android.app.ListActivity;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
 import android.os.Bundle;
 import android.os.Handler;
 import android.preference.PreferenceManager;
+import android.text.Editable;
+import android.text.TextWatcher;
 import android.util.Log;
 import android.util.TypedValue;
 import android.view.ContextMenu;
@@ -41,6 +45,10 @@ 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.TextView;
@@ -52,13 +60,14 @@ import com.hughes.util.StringUtil;
 public class DictionaryManagerActivity extends ListActivity {
 
   static final String LOG = "QuickDic";
-  static final long AUTO_LAUNCH_WAIT_MILLIS = 10 * 1000;
-  static long lastAutoLaunchMillis = -1;
   static boolean blockAutoLaunch = false;
 
   DictionaryApplication application;
   Adapter adapter;
   
+  EditText filterText;
+  CheckBox showLocal;
+  
   Handler uiHandler;
   
   public static Intent getLaunchIntent() {
@@ -78,7 +87,32 @@ public class DictionaryManagerActivity extends ListActivity {
     application = (DictionaryApplication) getApplication();
 
     // UI init.
-    setContentView(R.layout.list_activity);
+    setContentView(R.layout.dictionary_manager_activity);
+    
+    filterText = (EditText) findViewById(R.id.filterText);
+    showLocal = (CheckBox) 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();
+      }
+    });
+    
+    showLocal.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+      @Override
+      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+        onShowLocalChanged();
+      }
+    });
 
     getListView().setOnItemClickListener(new OnItemClickListener() {
       @Override
@@ -130,18 +164,6 @@ public class DictionaryManagerActivity extends ListActivity {
     super.onStop();
     uiHandler = null;
   }
-
-  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 onResume() {
@@ -153,18 +175,16 @@ public class DictionaryManagerActivity extends ListActivity {
       startActivity(getIntent());
     }
     
-    final long now = System.currentTimeMillis();
     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
-    if (now - lastAutoLaunchMillis > AUTO_LAUNCH_WAIT_MILLIS &&
+    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) &&
-        !blockAutoLaunch) {
+        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, "")));
-      lastAutoLaunchMillis = now;
-      // Don't finish, so that user can hit back and get here.
-      //finish();
+      finish();
       return;
     }
     
@@ -234,7 +254,6 @@ public class DictionaryManagerActivity extends ListActivity {
           setListAdapter(adapter = new Adapter());
           return true;
         }
-
       });
     }
 
@@ -246,10 +265,53 @@ public class DictionaryManagerActivity extends ListActivity {
         downloadable.dictInfo);
     return intent;
   }
+  
+  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);
+    }
+  }
+  
   class Adapter extends BaseAdapter {
     
-    final List<DictionaryInfo> dictionaryInfos = application.getAllDictionaries();
+    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;
+          }
+        }
+        if (canShow) {
+          dictionaryInfos.add(dictionaryInfo);
+          
+        }
+      }
+    }
 
     @Override
     public int getCount() {