after it).
--- /dev/null
+<?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>
+++ /dev/null
-<?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>
<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>
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,
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
};\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
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
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;
package com.hughes.android.dictionary;
import java.io.File;
+import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
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;
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;
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() {
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
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() {
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;
}
setListAdapter(adapter = new Adapter());
return true;
}
-
});
}
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() {