1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

SlovoEd integration: we support 780 SlovoEd dictionaries

Conflicts:

	src/org/geometerplus/android/fbreader/FBReader.java
This commit is contained in:
Nikolay Pultsin 2012-01-29 00:27:49 +00:00
parent 42f6b51fc6
commit 1783b9ad7a
9 changed files with 4093 additions and 181 deletions

View file

@ -1,5 +1,6 @@
===== 1.3.4 (??? ??, 2012) ===== ===== 1.3.4 (??? ??, 2012) =====
* About section in the preferences dialog * About section in the preferences dialog
* Better SlovoEd dictionary integration (780 dictionaries are supported)
* CHANGE_WIFI_STATE permission is not required more * CHANGE_WIFI_STATE permission is not required more
* getBookFileName() API method has been implemented * getBookFileName() API method has been implemented

View file

@ -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-&gt;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-&gt;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-&gt;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-&gt;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-&gt;Russian"
package="com.slovoed.french_russian.deluxe"
class=".Start"
action="android.intent.action.VIEW"
pattern="%s/808532019"
list="installed"
/>
<dictionary
id="SlovoEd Deluxe Russian-&gt;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>

View 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>

File diff suppressed because it is too large Load diff

View file

@ -42,12 +42,17 @@ import org.geometerplus.android.util.UIUtil;
import org.geometerplus.android.util.PackageUtil; import org.geometerplus.android.util.PackageUtil;
public abstract class DictionaryUtil { public abstract class DictionaryUtil {
// Map: dictionary info -> hide if package is not installed private static int FLAG_INSTALLED_ONLY = 1;
private static LinkedHashMap<PackageInfo,Boolean> ourDictionaryInfos = private static int FLAG_SHOW_AS_DICTIONARY = 2;
new LinkedHashMap<PackageInfo,Boolean>(); private static int FLAG_SHOW_AS_TRANSLATOR = 4;
private static ZLStringOption ourSingleWordTranslatorOption; private static ZLStringOption ourSingleWordTranslatorOption;
private static ZLStringOption ourMultiWordTranslatorOption; 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 { private static class InfoReader extends ZLXMLReaderAdapter {
@Override @Override
public boolean dontCacheAttributeValues() { public boolean dontCacheAttributeValues() {
@ -59,7 +64,12 @@ public abstract class DictionaryUtil {
if ("dictionary".equals(tag)) { if ("dictionary".equals(tag)) {
final String id = attributes.getValue("id"); final String id = attributes.getValue("id");
final String title = attributes.getValue("title"); 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, id,
attributes.getValue("package"), attributes.getValue("package"),
attributes.getValue("class"), attributes.getValue("class"),
@ -67,7 +77,43 @@ public abstract class DictionaryUtil {
attributes.getValue("action"), attributes.getValue("action"),
attributes.getValue("dataKey"), attributes.getValue("dataKey"),
attributes.getValue("pattern") 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; return false;
} }
@ -86,29 +132,58 @@ public abstract class DictionaryUtil {
String FULLSCREEN = "EXTRA_FULLSCREEN"; String FULLSCREEN = "EXTRA_FULLSCREEN";
} }
private static Map<PackageInfo,Boolean> infos() { public static void init(final Context context) {
if (ourDictionaryInfos.isEmpty()) { if (ourInfos.isEmpty()) {
new InfoReader().read(ZLFile.createFileByPath("dictionaries.xml")); 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>(); final LinkedList<PackageInfo> list = new LinkedList<PackageInfo>();
for (Map.Entry<PackageInfo,Boolean> entry : infos().entrySet()) { final HashSet<String> installedPackages = new HashSet<String>();
final PackageInfo info = entry.getKey(); final HashSet<String> notInstalledPackages = new HashSet<String>();
if (!entry.getValue() || synchronized (ourInfos) {
PackageUtil.canBeStarted(context, getDictionaryIntent(info, "test"), false)) { for (Map.Entry<PackageInfo,Integer> entry : ourInfos.entrySet()) {
list.add(info); final PackageInfo info = entry.getKey();
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; return list;
} }
private static PackageInfo firstInfo() { private static PackageInfo firstInfo() {
for (Map.Entry<PackageInfo,Boolean> entry : infos().entrySet()) { synchronized (ourInfos) {
if (!entry.getValue()) { for (Map.Entry<PackageInfo,Integer> entry : ourInfos.entrySet()) {
return entry.getKey(); if ((entry.getValue() & FLAG_INSTALLED_ONLY) == 0) {
return entry.getKey();
}
} }
} }
throw new RuntimeException("There are no available dictionary infos"); throw new RuntimeException("There are no available dictionary infos");
@ -132,9 +207,11 @@ public abstract class DictionaryUtil {
final ZLStringOption option = singleWord final ZLStringOption option = singleWord
? singleWordTranslatorOption() : multiWordTranslatorOption(); ? singleWordTranslatorOption() : multiWordTranslatorOption();
final String id = option.getValue(); final String id = option.getValue();
for (PackageInfo info : infos().keySet()) { synchronized (ourInfos) {
if (info.Id.equals(id)) { for (PackageInfo info : ourInfos.keySet()) {
return info; if (info.Id.equals(id)) {
return info;
}
} }
} }
return firstInfo(); return firstInfo();

View file

@ -102,6 +102,10 @@ public final class FBReader extends ZLAndroidActivity {
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
DictionaryUtil.init(this);
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLibrary.Instance(); final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLibrary.Instance();
myFullScreenFlag = myFullScreenFlag =
zlibrary.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN; zlibrary.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
@ -109,7 +113,6 @@ public final class FBReader extends ZLAndroidActivity {
WindowManager.LayoutParams.FLAG_FULLSCREEN, myFullScreenFlag WindowManager.LayoutParams.FLAG_FULLSCREEN, myFullScreenFlag
); );
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
if (fbReader.getPopupById(TextSearchPopup.ID) == null) { if (fbReader.getPopupById(TextSearchPopup.ID) == null) {
new TextSearchPopup(fbReader); new TextSearchPopup(fbReader);
} }

View file

@ -26,17 +26,15 @@ import android.content.Context;
import org.geometerplus.zlibrary.core.options.ZLStringOption; import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.android.fbreader.DictionaryUtil;
import org.geometerplus.android.fbreader.PackageInfo; import org.geometerplus.android.fbreader.PackageInfo;
class DictionaryPreference extends ZLStringListPreference { class DictionaryPreference extends ZLStringListPreference {
private final ZLStringOption myOption; 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); super(context, resource, resourceKey);
myOption = dictionaryOption; myOption = dictionaryOption;
final List<PackageInfo> infos = DictionaryUtil.dictionaryInfos(context);
final String[] values = new String[infos.size()]; final String[] values = new String[infos.size()];
final String[] texts = new String[infos.size()]; final String[] texts = new String[infos.size()];

View file

@ -391,13 +391,15 @@ public class PreferenceActivity extends ZLPreferenceActivity {
this, this,
dictionaryScreen.Resource, dictionaryScreen.Resource,
"dictionary", "dictionary",
DictionaryUtil.singleWordTranslatorOption() DictionaryUtil.singleWordTranslatorOption(),
DictionaryUtil.dictionaryInfos(this, true)
)); ));
dictionaryScreen.addPreference(new DictionaryPreference( dictionaryScreen.addPreference(new DictionaryPreference(
this, this,
dictionaryScreen.Resource, dictionaryScreen.Resource,
"translator", "translator",
DictionaryUtil.multiWordTranslatorOption() DictionaryUtil.multiWordTranslatorOption(),
DictionaryUtil.dictionaryInfos(this, false)
)); ));
dictionaryScreen.addPreference(new ZLBooleanPreference( dictionaryScreen.addPreference(new ZLBooleanPreference(
this, this,

View file

@ -50,25 +50,21 @@ abstract class ZLStringListPreference extends ListPreference {
} }
protected final boolean setInitialValue(String value) { protected final boolean setInitialValue(String value) {
if (value == null) { int index = 0;
return false; boolean found = false;;
}
// throws NPE in some cases (?)
//final int index = findIndexOfValue(value);
int index = -1;
final CharSequence[] entryValues = getEntryValues(); final CharSequence[] entryValues = getEntryValues();
for (int i = 0; i < entryValues.length; ++i) { if (value != null) {
if (value.equals(entryValues[i])) { for (int i = 0; i < entryValues.length; ++i) {
index = i; if (value.equals(entryValues[i])) {
break; index = i;
found = true;
break;
}
} }
} }
if (index >= 0) { setValueIndex(index);
setValueIndex(index); setSummary(getEntry());
setSummary(getEntry()); return found;
return true;
}
return false;
} }
@Override @Override