<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" />
<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
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
--- /dev/null
+<?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
+++ /dev/null
-<?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
+++ /dev/null
-<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>
--- /dev/null
+<?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
<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>
<!-- 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>
<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>
<!--
<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>
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";
private SearchOperation currentSearchOperation = null;
-
TextToSpeech textToSpeech;
volatile boolean ttsReady;
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;
}
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
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);
theme = application.getSelectedTheme();
textColorFg = getResources().getColor(theme.tokenRowFgColor);
-
-
final Intent intent = getIntent();
String intentAction = intent.getAction();
/**
}
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;
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());
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);
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();
}
}
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();
}
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);
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();
return installedDicts.size();
}
});
-
dialog.show();
}
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);
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;
// 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) {
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) {
}
+ private File dictDir;
+
@Override
public void onCreate() {
super.onCreate();
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();
}
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();
defaultLangName = null;
}
if (defaultLangName == null) {
- defaultLangName = getLanguageName(defaultLangISO2);
+ defaultLangName = isoCodeToLocalizedLanguageName(defaultLangISO2);
}
String name = fileToNameCache.get(uncompressedFilename);
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 {
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);
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);
}
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;
}
}
final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(dictFile);
if (dictionaryInfo != null) {
newDictionaryConfig.dictionaryFilesOrdered.add(uncompressedFilename);
- newDictionaryConfig.dictionaryInfoCache.put(uncompressedFilename, dictionaryInfo);
+ newDictionaryConfig.uncompressedFilenameToDictionaryInfo.put(uncompressedFilename, dictionaryInfo);
}
}
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;
}
}
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());
}}).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);
}
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;
}
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);
allTokenCount = Integer.parseInt(fields[i++]);
mainTokenCount = Integer.parseInt(fields[i++]);
}
-
}
// Stuff populated from the text file.
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");
}
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;
+// }
+// }
}
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()];
public void onClick(View v) {
go();
}
-
-
}