From: Thad Hughes Date: Fri, 23 Mar 2012 03:26:24 +0000 (-0700) Subject: Added filtering to manager, remove timeout on auto-launch (and finish X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=133a6113ded7fd6a709083e8aad7b2c7c7385cc1 Added filtering to manager, remove timeout on auto-launch (and finish after it). --- diff --git a/res/layout/dictionary_manager_activity.xml b/res/layout/dictionary_manager_activity.xml new file mode 100644 index 0000000..96a0967 --- /dev/null +++ b/res/layout/dictionary_manager_activity.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + diff --git a/res/layout/list_activity.xml b/res/layout/list_activity.xml deleted file mode 100644 index 0957b5e..0000000 --- a/res/layout/list_activity.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - diff --git a/res/values/strings.xml b/res/values/strings.xml index ac0b54e..e7d6508 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -20,6 +20,9 @@ Move to top Delete dictionary %1$s: %2$,d words + List filter + Local only + 3.2_en_b diff --git a/src/com/hughes/android/dictionary/C.java b/src/com/hughes/android/dictionary/C.java index 654a56a..c8511da 100644 --- a/src/com/hughes/android/dictionary/C.java +++ b/src/com/hughes/android/dictionary/C.java @@ -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, diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 052018a..3b01133 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -444,11 +444,33 @@ public class DictionaryActivity extends ListActivity { dialog.setTitle(R.string.selectDictionary); final List installedDicts = ((DictionaryApplication)getApplication()).getUsableDicts(); + ListView listView = (ListView) dialog.findViewById(android.R.id.list); + +// final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); +// layoutParams.width = 0; +// layoutParams.weight = 1.0f; + + final Button button = new Button(listView.getContext()); + final String name = getString(R.string.dictionaryManager); + button.setText(name); + final IntentLauncher intentLauncher = new IntentLauncher(listView.getContext(), DictionaryManagerActivity.getLaunchIntent()) { + @Override + protected void onGo() { + dialog.dismiss(); + DictionaryActivity.this.finish(); + }; + }; + button.setOnClickListener(intentLauncher); +// button.setLayoutParams(layoutParams); + listView.addHeaderView(button); +// listView.setHeaderDividersEnabled(true); + listView.setAdapter(new BaseAdapter() { @Override public View getView(int position, View convertView, ViewGroup parent) { final LinearLayout result = new LinearLayout(parent.getContext()); + final DictionaryInfo dictionaryInfo = getItem(position); final Button button = new Button(parent.getContext()); final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename); @@ -461,12 +483,10 @@ public class DictionaryActivity extends ListActivity { }; }; button.setOnClickListener(intentLauncher); - final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.width = 0; layoutParams.weight = 1.0f; button.setLayoutParams(layoutParams); - result.addView(button); return result; } @@ -747,9 +767,9 @@ public class DictionaryActivity extends ListActivity { return true; } if (keyCode == KeyEvent.KEYCODE_BACK) { - Log.d(LOG, "Clearing dictionary prefs."); + //Log.d(LOG, "Clearing dictionary prefs."); // Pretend that we just autolaunched so that we won't do it again. - DictionaryManagerActivity.lastAutoLaunchMillis = System.currentTimeMillis(); + //DictionaryManagerActivity.lastAutoLaunchMillis = System.currentTimeMillis(); } if (keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(LOG, "Trying to hide soft keyboard."); diff --git a/src/com/hughes/android/dictionary/DictionaryApplication.java b/src/com/hughes/android/dictionary/DictionaryApplication.java index ba8960d..53cbd0a 100644 --- a/src/com/hughes/android/dictionary/DictionaryApplication.java +++ b/src/com/hughes/android/dictionary/DictionaryApplication.java @@ -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; diff --git a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java index cc24e22..dab77f5 100644 --- a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java @@ -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 dictionaryInfos = application.getAllDictionaries(); + final List dictionaryInfos = new ArrayList(); + + 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() {