mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
SlovoEd integration: we support 780 SlovoEd dictionaries
Conflicts: src/org/geometerplus/android/fbreader/FBReader.java
This commit is contained in:
parent
42f6b51fc6
commit
1783b9ad7a
9 changed files with 4093 additions and 181 deletions
|
@ -1,5 +1,6 @@
|
|||
===== 1.3.4 (??? ??, 2012) =====
|
||||
* About section in the preferences dialog
|
||||
* Better SlovoEd dictionary integration (780 dictionaries are supported)
|
||||
* CHANGE_WIFI_STATE permission is not required more
|
||||
* getBookFileName() API method has been implemented
|
||||
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<dictionaries>
|
||||
<dictionary
|
||||
id="ColorDict"
|
||||
title="ColorDict 3"
|
||||
action="colordict.intent.action.SEARCH"
|
||||
dataKey="EXTRA_QUERY"
|
||||
pattern="%s"
|
||||
list="always"
|
||||
/>
|
||||
<dictionary
|
||||
id="ColorDict2"
|
||||
title="ColorDict Old Style"
|
||||
package="com.socialnmobile.colordict"
|
||||
class=".activity.Main"
|
||||
action="android.intent.action.SEARCH"
|
||||
dataKey="query"
|
||||
pattern="%s"
|
||||
list="always"
|
||||
/>
|
||||
<dictionary
|
||||
id="Fora Dictionary"
|
||||
package="com.ngc.fora"
|
||||
class=".ForaDictionary"
|
||||
action="android.intent.action.SEARCH"
|
||||
dataKey="query"
|
||||
pattern="%s"
|
||||
list="always"
|
||||
/>
|
||||
<dictionary
|
||||
id="Free Dictionary . org"
|
||||
package="org.freedictionary"
|
||||
class=".MainActivity"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s"
|
||||
list="always"
|
||||
/>
|
||||
<dictionary
|
||||
id="SlovoEd Deluxe German->English"
|
||||
package="com.slovoed.noreg.english_german.deluxe"
|
||||
class=".Start"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s/808464950"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="SlovoEd Deluxe English->German"
|
||||
package="com.slovoed.noreg.english_german.deluxe"
|
||||
class=".Start"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s/808464949"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="Langenscheidt Professional German->English"
|
||||
package="com.slovoed.noreg.langenscheidt.professional.german_english"
|
||||
class=".Start"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s/808661296"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="Langenscheidt Professional English->German"
|
||||
package="com.slovoed.noreg.langenscheidt.professional.german_english"
|
||||
class=".Start"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s/808661297"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="Duden - Deutsches Universalwoerterbuch"
|
||||
package="com.slovoed.noreg.duden.duden_german_explanatory_dictionary"
|
||||
class=".Start"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s/808596281"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="Merriam-Webster's Unabridged"
|
||||
package="com.slovoed.noreg.merriam_webster.english_english_unabridged"
|
||||
class=".Start"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s/808595524"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="SlovoEd Deluxe French->Russian"
|
||||
package="com.slovoed.french_russian.deluxe"
|
||||
class=".Start"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s/808532019"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="SlovoEd Deluxe Russian->French"
|
||||
package="com.slovoed.french_russian.deluxe"
|
||||
class=".Start"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s/808532018"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="Lingo Quiz Lite"
|
||||
package="mnm.lite.lingoquiz"
|
||||
class=".ExchangeActivity"
|
||||
action="lingoquiz.intent.action.ADD_WORD"
|
||||
dataKey="EXTRA_WORD"
|
||||
pattern="%s"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="Lingo Quiz"
|
||||
package="mnm.lingoquiz"
|
||||
class=".ExchangeActivity"
|
||||
action="lingoquiz.intent.action.ADD_WORD"
|
||||
dataKey="EXTRA_WORD"
|
||||
pattern="%s"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="Aard Dictionary"
|
||||
package="aarddict.android"
|
||||
class=".Article"
|
||||
action="android.intent.action.SEARCH"
|
||||
dataKey="query"
|
||||
pattern="%s"
|
||||
list="installed"
|
||||
/>
|
||||
<dictionary
|
||||
id="Aard Dictionary Lookup"
|
||||
package="aarddict.android"
|
||||
class=".Lookup"
|
||||
action="android.intent.action.SEARCH"
|
||||
dataKey="query"
|
||||
pattern="%s"
|
||||
list="installed"
|
||||
/>
|
||||
</dictionaries>
|
70
assets/dictionaries/main.xml
Normal file
70
assets/dictionaries/main.xml
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<dictionaries>
|
||||
<dictionary
|
||||
id="ColorDict"
|
||||
title="ColorDict 3"
|
||||
action="colordict.intent.action.SEARCH"
|
||||
dataKey="EXTRA_QUERY"
|
||||
pattern="%s"
|
||||
list="always"
|
||||
/>
|
||||
<dictionary
|
||||
id="ColorDict2"
|
||||
title="ColorDict Old Style"
|
||||
package="com.socialnmobile.colordict"
|
||||
class=".activity.Main"
|
||||
action="android.intent.action.SEARCH"
|
||||
dataKey="query"
|
||||
pattern="%s"
|
||||
list="always"
|
||||
/>
|
||||
<dictionary
|
||||
id="Fora Dictionary"
|
||||
package="com.ngc.fora"
|
||||
class=".ForaDictionary"
|
||||
action="android.intent.action.SEARCH"
|
||||
dataKey="query"
|
||||
pattern="%s"
|
||||
list="always"
|
||||
/>
|
||||
<dictionary
|
||||
id="Free Dictionary . org"
|
||||
package="org.freedictionary"
|
||||
class=".MainActivity"
|
||||
action="android.intent.action.VIEW"
|
||||
pattern="%s"
|
||||
list="always"
|
||||
/>
|
||||
<dictionary
|
||||
id="Lingo Quiz Lite"
|
||||
package="mnm.lite.lingoquiz"
|
||||
class=".ExchangeActivity"
|
||||
action="lingoquiz.intent.action.ADD_WORD"
|
||||
dataKey="EXTRA_WORD"
|
||||
pattern="%s"
|
||||
/>
|
||||
<dictionary
|
||||
id="Lingo Quiz"
|
||||
package="mnm.lingoquiz"
|
||||
class=".ExchangeActivity"
|
||||
action="lingoquiz.intent.action.ADD_WORD"
|
||||
dataKey="EXTRA_WORD"
|
||||
pattern="%s"
|
||||
/>
|
||||
<dictionary
|
||||
id="Aard Dictionary"
|
||||
package="aarddict.android"
|
||||
class=".Article"
|
||||
action="android.intent.action.SEARCH"
|
||||
dataKey="query"
|
||||
pattern="%s"
|
||||
/>
|
||||
<dictionary
|
||||
id="Aard Dictionary Lookup"
|
||||
package="aarddict.android"
|
||||
class=".Lookup"
|
||||
action="android.intent.action.SEARCH"
|
||||
dataKey="query"
|
||||
pattern="%s"
|
||||
/>
|
||||
</dictionaries>
|
3903
assets/dictionaries/slovoEd.xml
Normal file
3903
assets/dictionaries/slovoEd.xml
Normal file
File diff suppressed because it is too large
Load diff
|
@ -42,12 +42,17 @@ import org.geometerplus.android.util.UIUtil;
|
|||
import org.geometerplus.android.util.PackageUtil;
|
||||
|
||||
public abstract class DictionaryUtil {
|
||||
// Map: dictionary info -> hide if package is not installed
|
||||
private static LinkedHashMap<PackageInfo,Boolean> ourDictionaryInfos =
|
||||
new LinkedHashMap<PackageInfo,Boolean>();
|
||||
private static int FLAG_INSTALLED_ONLY = 1;
|
||||
private static int FLAG_SHOW_AS_DICTIONARY = 2;
|
||||
private static int FLAG_SHOW_AS_TRANSLATOR = 4;
|
||||
|
||||
private static ZLStringOption ourSingleWordTranslatorOption;
|
||||
private static ZLStringOption ourMultiWordTranslatorOption;
|
||||
|
||||
// Map: dictionary info -> mode if package is not installed
|
||||
private static Map<PackageInfo,Integer> ourInfos =
|
||||
Collections.synchronizedMap(new LinkedHashMap<PackageInfo,Integer>());
|
||||
|
||||
private static class InfoReader extends ZLXMLReaderAdapter {
|
||||
@Override
|
||||
public boolean dontCacheAttributeValues() {
|
||||
|
@ -59,7 +64,12 @@ public abstract class DictionaryUtil {
|
|||
if ("dictionary".equals(tag)) {
|
||||
final String id = attributes.getValue("id");
|
||||
final String title = attributes.getValue("title");
|
||||
ourDictionaryInfos.put(new PackageInfo(
|
||||
|
||||
int flags = FLAG_SHOW_AS_DICTIONARY | FLAG_SHOW_AS_TRANSLATOR;
|
||||
if (!"always".equals(attributes.getValue("list"))) {
|
||||
flags |= FLAG_INSTALLED_ONLY;
|
||||
}
|
||||
ourInfos.put(new PackageInfo(
|
||||
id,
|
||||
attributes.getValue("package"),
|
||||
attributes.getValue("class"),
|
||||
|
@ -67,7 +77,43 @@ public abstract class DictionaryUtil {
|
|||
attributes.getValue("action"),
|
||||
attributes.getValue("dataKey"),
|
||||
attributes.getValue("pattern")
|
||||
), !"always".equals(attributes.getValue("list")));
|
||||
), flags);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SlovoEdInfoReader extends ZLXMLReaderAdapter {
|
||||
private final Context myContext;
|
||||
private int myCounter;
|
||||
|
||||
SlovoEdInfoReader(Context context) {
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dontCacheAttributeValues() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startElementHandler(String tag, ZLStringMap attributes) {
|
||||
if ("dictionary".equals(tag)) {
|
||||
final String id = attributes.getValue("id");
|
||||
final String title = attributes.getValue("title");
|
||||
|
||||
final PackageInfo info = new PackageInfo(
|
||||
String.valueOf(++myCounter),
|
||||
attributes.getValue("package"),
|
||||
".Start",
|
||||
attributes.getValue("title"),
|
||||
Intent.ACTION_VIEW,
|
||||
null,
|
||||
attributes.getValue("pattern")
|
||||
);
|
||||
if (PackageUtil.canBeStarted(myContext, getDictionaryIntent(info, "test"), false)) {
|
||||
ourInfos.put(info, FLAG_SHOW_AS_DICTIONARY | FLAG_INSTALLED_ONLY);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -86,31 +132,60 @@ public abstract class DictionaryUtil {
|
|||
String FULLSCREEN = "EXTRA_FULLSCREEN";
|
||||
}
|
||||
|
||||
private static Map<PackageInfo,Boolean> infos() {
|
||||
if (ourDictionaryInfos.isEmpty()) {
|
||||
new InfoReader().read(ZLFile.createFileByPath("dictionaries.xml"));
|
||||
public static void init(final Context context) {
|
||||
if (ourInfos.isEmpty()) {
|
||||
final Thread initThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
new InfoReader().read(ZLFile.createFileByPath("dictionaries/main.xml"));
|
||||
new SlovoEdInfoReader(context).read(ZLFile.createFileByPath("dictionaries/slovoEd.xml"));
|
||||
}
|
||||
});
|
||||
initThread.setPriority(Thread.MIN_PRIORITY);
|
||||
initThread.start();
|
||||
}
|
||||
return ourDictionaryInfos;
|
||||
}
|
||||
|
||||
public static List<PackageInfo> dictionaryInfos(Context context) {
|
||||
public static List<PackageInfo> dictionaryInfos(Context context, boolean dictionaryNotTranslator) {
|
||||
final LinkedList<PackageInfo> list = new LinkedList<PackageInfo>();
|
||||
for (Map.Entry<PackageInfo,Boolean> entry : infos().entrySet()) {
|
||||
final HashSet<String> installedPackages = new HashSet<String>();
|
||||
final HashSet<String> notInstalledPackages = new HashSet<String>();
|
||||
synchronized (ourInfos) {
|
||||
for (Map.Entry<PackageInfo,Integer> entry : ourInfos.entrySet()) {
|
||||
final PackageInfo info = entry.getKey();
|
||||
if (!entry.getValue() ||
|
||||
PackageUtil.canBeStarted(context, getDictionaryIntent(info, "test"), false)) {
|
||||
final int flags = entry.getValue();
|
||||
if (dictionaryNotTranslator) {
|
||||
if ((flags & FLAG_SHOW_AS_DICTIONARY) == 0) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if ((flags & FLAG_SHOW_AS_TRANSLATOR) == 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (((flags & FLAG_INSTALLED_ONLY) == 0) ||
|
||||
installedPackages.contains(info.PackageName)) {
|
||||
list.add(info);
|
||||
} else if (!notInstalledPackages.contains(info.PackageName)) {
|
||||
if (PackageUtil.canBeStarted(context, getDictionaryIntent(info, "test"), false)) {
|
||||
list.add(info);
|
||||
installedPackages.add(info.PackageName);
|
||||
} else {
|
||||
notInstalledPackages.add(info.PackageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static PackageInfo firstInfo() {
|
||||
for (Map.Entry<PackageInfo,Boolean> entry : infos().entrySet()) {
|
||||
if (!entry.getValue()) {
|
||||
synchronized (ourInfos) {
|
||||
for (Map.Entry<PackageInfo,Integer> entry : ourInfos.entrySet()) {
|
||||
if ((entry.getValue() & FLAG_INSTALLED_ONLY) == 0) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("There are no available dictionary infos");
|
||||
}
|
||||
|
||||
|
@ -132,11 +207,13 @@ public abstract class DictionaryUtil {
|
|||
final ZLStringOption option = singleWord
|
||||
? singleWordTranslatorOption() : multiWordTranslatorOption();
|
||||
final String id = option.getValue();
|
||||
for (PackageInfo info : infos().keySet()) {
|
||||
synchronized (ourInfos) {
|
||||
for (PackageInfo info : ourInfos.keySet()) {
|
||||
if (info.Id.equals(id)) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
return firstInfo();
|
||||
}
|
||||
|
||||
|
|
|
@ -102,6 +102,10 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
DictionaryUtil.init(this);
|
||||
|
||||
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
|
||||
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLibrary.Instance();
|
||||
myFullScreenFlag =
|
||||
zlibrary.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||
|
@ -109,7 +113,6 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
WindowManager.LayoutParams.FLAG_FULLSCREEN, myFullScreenFlag
|
||||
);
|
||||
|
||||
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
|
||||
if (fbReader.getPopupById(TextSearchPopup.ID) == null) {
|
||||
new TextSearchPopup(fbReader);
|
||||
}
|
||||
|
|
|
@ -26,17 +26,15 @@ import android.content.Context;
|
|||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.android.fbreader.DictionaryUtil;
|
||||
import org.geometerplus.android.fbreader.PackageInfo;
|
||||
|
||||
class DictionaryPreference extends ZLStringListPreference {
|
||||
private final ZLStringOption myOption;
|
||||
|
||||
DictionaryPreference(Context context, ZLResource resource, String resourceKey, ZLStringOption dictionaryOption) {
|
||||
DictionaryPreference(Context context, ZLResource resource, String resourceKey, ZLStringOption dictionaryOption, List<PackageInfo> infos) {
|
||||
super(context, resource, resourceKey);
|
||||
|
||||
myOption = dictionaryOption;
|
||||
final List<PackageInfo> infos = DictionaryUtil.dictionaryInfos(context);
|
||||
|
||||
final String[] values = new String[infos.size()];
|
||||
final String[] texts = new String[infos.size()];
|
||||
|
|
|
@ -391,13 +391,15 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
|||
this,
|
||||
dictionaryScreen.Resource,
|
||||
"dictionary",
|
||||
DictionaryUtil.singleWordTranslatorOption()
|
||||
DictionaryUtil.singleWordTranslatorOption(),
|
||||
DictionaryUtil.dictionaryInfos(this, true)
|
||||
));
|
||||
dictionaryScreen.addPreference(new DictionaryPreference(
|
||||
this,
|
||||
dictionaryScreen.Resource,
|
||||
"translator",
|
||||
DictionaryUtil.multiWordTranslatorOption()
|
||||
DictionaryUtil.multiWordTranslatorOption(),
|
||||
DictionaryUtil.dictionaryInfos(this, false)
|
||||
));
|
||||
dictionaryScreen.addPreference(new ZLBooleanPreference(
|
||||
this,
|
||||
|
|
|
@ -50,25 +50,21 @@ abstract class ZLStringListPreference extends ListPreference {
|
|||
}
|
||||
|
||||
protected final boolean setInitialValue(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
// throws NPE in some cases (?)
|
||||
//final int index = findIndexOfValue(value);
|
||||
int index = -1;
|
||||
int index = 0;
|
||||
boolean found = false;;
|
||||
final CharSequence[] entryValues = getEntryValues();
|
||||
if (value != null) {
|
||||
for (int i = 0; i < entryValues.length; ++i) {
|
||||
if (value.equals(entryValues[i])) {
|
||||
index = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index >= 0) {
|
||||
}
|
||||
setValueIndex(index);
|
||||
setSummary(getEntry());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return found;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue