mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
dictionary descriptions in XML file; more dictionaries (by Steffen Siebert)
This commit is contained in:
parent
a44f8d497f
commit
af8cd0f2a1
3 changed files with 137 additions and 56 deletions
102
assets/dictionaries.xml
Normal file
102
assets/dictionaries.xml
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
<?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"
|
||||||
|
/>
|
||||||
|
</dictionaries>
|
|
@ -27,8 +27,11 @@ import android.net.Uri;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
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.zlibrary.core.xml.ZLXMLReaderAdapter;
|
||||||
|
import org.geometerplus.zlibrary.core.xml.ZLStringMap;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextWordRegion;
|
import org.geometerplus.zlibrary.text.view.ZLTextWordRegion;
|
||||||
|
|
||||||
|
@ -43,6 +46,31 @@ public abstract class DictionaryUtil {
|
||||||
new LinkedHashMap<PackageInfo,Boolean>();
|
new LinkedHashMap<PackageInfo,Boolean>();
|
||||||
private static ZLStringOption ourDictionaryOption;
|
private static ZLStringOption ourDictionaryOption;
|
||||||
|
|
||||||
|
private static class InfoReader extends ZLXMLReaderAdapter {
|
||||||
|
@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");
|
||||||
|
ourDictionaryInfos.put(new PackageInfo(
|
||||||
|
id,
|
||||||
|
attributes.getValue("package"),
|
||||||
|
attributes.getValue("class"),
|
||||||
|
title != null ? title : id,
|
||||||
|
attributes.getValue("action"),
|
||||||
|
attributes.getValue("dataKey"),
|
||||||
|
attributes.getValue("pattern")
|
||||||
|
), !"always".equals(attributes.getValue("list")));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private interface ColorDict3 {
|
private interface ColorDict3 {
|
||||||
String ACTION = "colordict.intent.action.SEARCH";
|
String ACTION = "colordict.intent.action.SEARCH";
|
||||||
String QUERY = "EXTRA_QUERY";
|
String QUERY = "EXTRA_QUERY";
|
||||||
|
@ -58,60 +86,7 @@ public abstract class DictionaryUtil {
|
||||||
|
|
||||||
private static Map<PackageInfo,Boolean> infos() {
|
private static Map<PackageInfo,Boolean> infos() {
|
||||||
if (ourDictionaryInfos.isEmpty()) {
|
if (ourDictionaryInfos.isEmpty()) {
|
||||||
ourDictionaryInfos.put(new PackageInfo(
|
new InfoReader().read(ZLFile.createFileByPath("dictionaries.xml"));
|
||||||
"ColorDict", // Id
|
|
||||||
null, // Package
|
|
||||||
null, // Class
|
|
||||||
"ColorDict 3", // Title
|
|
||||||
ColorDict3.ACTION,
|
|
||||||
ColorDict3.QUERY,
|
|
||||||
"%s"
|
|
||||||
), false);
|
|
||||||
ourDictionaryInfos.put(new PackageInfo(
|
|
||||||
"ColorDict2", // Id
|
|
||||||
"com.socialnmobile.colordict", // Package
|
|
||||||
"com.socialnmobile.colordict.activity.Main", // Class
|
|
||||||
"ColorDict Old Style", // Title
|
|
||||||
Intent.ACTION_SEARCH,
|
|
||||||
SearchManager.QUERY,
|
|
||||||
"%s"
|
|
||||||
), false);
|
|
||||||
ourDictionaryInfos.put(new PackageInfo(
|
|
||||||
"Fora Dictionary", // Id
|
|
||||||
"com.ngc.fora", // Package
|
|
||||||
"com.ngc.fora.ForaDictionary", // Class
|
|
||||||
"Fora Dictionary", // Title
|
|
||||||
Intent.ACTION_SEARCH,
|
|
||||||
SearchManager.QUERY,
|
|
||||||
"%s"
|
|
||||||
), false);
|
|
||||||
ourDictionaryInfos.put(new PackageInfo(
|
|
||||||
"Free Dictionary . org", // Id
|
|
||||||
"org.freedictionary", // Package
|
|
||||||
"org.freedictionary.MainActivity", // Class
|
|
||||||
"Free Dictionary . org", // Title
|
|
||||||
Intent.ACTION_VIEW,
|
|
||||||
null,
|
|
||||||
"%s"
|
|
||||||
), false);
|
|
||||||
ourDictionaryInfos.put(new PackageInfo(
|
|
||||||
"SlovoEd Deluxe German->English", // Id
|
|
||||||
"com.slovoed.noreg.english_german.deluxe", // Package
|
|
||||||
"com.slovoed.noreg.english_german.deluxe.Start", // Class
|
|
||||||
"SlovoEd Deluxe German->English", // Title
|
|
||||||
Intent.ACTION_VIEW,
|
|
||||||
null,
|
|
||||||
"%s/808464950"
|
|
||||||
), true);
|
|
||||||
ourDictionaryInfos.put(new PackageInfo(
|
|
||||||
"SlovoEd Deluxe English->German", // Id
|
|
||||||
"com.slovoed.noreg.english_german.deluxe", // Package
|
|
||||||
"com.slovoed.noreg.english_german.deluxe.Start", // Class
|
|
||||||
"SlovoEd Deluxe English->German", // Title
|
|
||||||
Intent.ACTION_VIEW,
|
|
||||||
null,
|
|
||||||
"%s/808464949"
|
|
||||||
), true);
|
|
||||||
}
|
}
|
||||||
return ourDictionaryInfos;
|
return ourDictionaryInfos;
|
||||||
}
|
}
|
||||||
|
@ -161,8 +136,12 @@ public abstract class DictionaryUtil {
|
||||||
public static Intent getDictionaryIntent(PackageInfo dictionaryInfo, String text) {
|
public static Intent getDictionaryIntent(PackageInfo dictionaryInfo, String text) {
|
||||||
final Intent intent = new Intent(dictionaryInfo.IntentAction);
|
final Intent intent = new Intent(dictionaryInfo.IntentAction);
|
||||||
if (dictionaryInfo.PackageName != null) {
|
if (dictionaryInfo.PackageName != null) {
|
||||||
|
String cls = dictionaryInfo.ClassName;
|
||||||
|
if (cls != null && cls.startsWith(".")) {
|
||||||
|
cls = dictionaryInfo.PackageName + cls;
|
||||||
|
}
|
||||||
intent.setComponent(new ComponentName(
|
intent.setComponent(new ComponentName(
|
||||||
dictionaryInfo.PackageName, dictionaryInfo.ClassName
|
dictionaryInfo.PackageName, cls
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
|
@ -24,7 +24,7 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
|
||||||
public class ZLXMLReaderAdapter implements ZLXMLReader {
|
public abstract class ZLXMLReaderAdapter implements ZLXMLReader {
|
||||||
private Map<String,String> myNamespaceMap = Collections.emptyMap();
|
private Map<String,String> myNamespaceMap = Collections.emptyMap();
|
||||||
|
|
||||||
public boolean read(ZLFile file) {
|
public boolean read(ZLFile file) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue