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

dictan integration (in progress)

This commit is contained in:
Nikolay Pultsin 2015-05-05 14:44:57 +01:00
parent 448ce0fcd1
commit 26e157d06a
41 changed files with 458 additions and 74 deletions

View file

@ -17,6 +17,16 @@
dataKey="query"
list="always"
/>
<dictionary
id="dictan"
title="Dictan"
package="info.softex.dictan"
category="info.softex.dictan.EXTERNAL_DISPATCHER"
action="android.intent.action.VIEW"
dataKey="article.word"
role="dictionary"
list="always"
/>
<dictionary
id="Fora Dictionary"
package="com.ngc.fora"
@ -42,15 +52,6 @@
role="dictionary"
supportsTargetLanguage="true"
/>
<!--dictionary
id="dictan"
title="Dictan"
package="info.softex.dictan"
category="info.softex.dictan.EXTERNAL_DISPATCHER"
action="android.intent.action.VIEW"
dataKey="article.word"
role="dictionary"
/-->
<dictionary
id="Lingo Quiz Lite"
package="mnm.lite.lingoquiz"

View file

@ -1147,4 +1147,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1149,4 +1149,10 @@
<node name="length" value="Узор: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="Узор: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1155,4 +1155,10 @@
<node name="length" value="Например: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="Например: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1155,4 +1155,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1158,4 +1158,10 @@
<node name="length" value="Např.: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="Např.: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1148,4 +1148,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1154,4 +1154,10 @@
<node name="length" value="z.B.: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="z.B.: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1147,4 +1147,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1149,4 +1149,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="E.g.: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error"/>
<node name="noArticle" value="no artcle found for “%s”"/>
<node name="cannotOpenDictionary" value="cannot open dictionary"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings"/>
</node>
</resources>

View file

@ -1154,4 +1154,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1150,4 +1150,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1148,4 +1148,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1142,4 +1142,10 @@
<node name="length" value="i.e.: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="i.e.: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1139,4 +1139,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1139,4 +1139,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1154,4 +1154,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1140,4 +1140,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1149,4 +1149,10 @@
<node name="length" value="例: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="例: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1154,4 +1154,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1149,4 +1149,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1149,4 +1149,10 @@
<node name="length" value="Bijv.: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="Bijv.: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1139,4 +1139,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1153,4 +1153,10 @@
<node name="length" value="Exemplo: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="Exemplo: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1141,4 +1141,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="E.g.: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1158,4 +1158,10 @@
<node name="length" value="Например: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="Например: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="неизвестная ошибка"/>
<node name="noArticle" value="нет статьи для «%s»"/>
<node name="cannotOpenDictionary" value="не удалось открыть словать"/>
<node name="noDictionarySelected" value="словарь не выбран; сделайте это в настроках Dictan"/>
</node>
</resources>

View file

@ -1149,4 +1149,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1139,4 +1139,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1149,4 +1149,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1139,4 +1139,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1140,4 +1140,10 @@
<node name="length" value="VD: -2px, 10pt, -0.8em, 1.1ex, -40%%"/>
<node name="percent" value="VD: 125%%"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1139,4 +1139,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -1139,4 +1139,10 @@
<node name="length" value="E.g.: -2px, 10pt, -0.8em, 1.1ex, -40%%" toBeTranslated="true"/>
<node name="percent" value="E.g.: 125%%" toBeTranslated="true"/>
</node>
<node name="dictanErrors">
<node name="unknown" value="unknown error" toBeTranslated="true"/>
<node name="noArticle" value="no artcle found for “%s”" toBeTranslated="true"/>
<node name="cannotOpenDictionary" value="cannot open dictionary" toBeTranslated="true"/>
<node name="noDictionarySelected" value="dictionary not selected; please fix in Dictan settings" toBeTranslated="true"/>
</node>
</resources>

View file

@ -26,12 +26,19 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.github.johnpersano.supertoasts.SuperActivityToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.OnDismissWrapper;
import android.app.*;
import android.content.*;
import android.net.Uri;
import android.os.Looper;
import android.os.Parcelable;
import android.util.DisplayMetrics;
import android.util.Xml;
import android.view.View;
import com.abbyy.mobile.lingvo.api.MinicardContract;
import com.paragon.dictionary.fbreader.OpenDictionaryFlyout;
@ -56,6 +63,8 @@ public abstract class DictionaryUtil {
private static int FLAG_SHOW_AS_DICTIONARY = 2;
private static int FLAG_SHOW_AS_TRANSLATOR = 4;
private static final int MAX_LENGTH_FOR_TOAST = 180;
private static ZLStringOption ourSingleWordTranslatorOption;
private static ZLStringOption ourMultiWordTranslatorOption;
@ -98,10 +107,6 @@ public abstract class DictionaryUtil {
intent.addCategory(category);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final String key = get("dataKey");
if (key != null) {
return intent.putExtra(key, text);
@ -110,7 +115,7 @@ public abstract class DictionaryUtil {
}
}
abstract void open(String text, Activity context, PopupFrameMetric frameMetrics);
abstract void open(String text, ZLTextRegion.Soul soulToSelect, FBReader fbreader, PopupFrameMetric frameMetrics);
}
private static class PlainPackageInfo extends PackageInfo {
@ -119,7 +124,7 @@ public abstract class DictionaryUtil {
}
@Override
void open(String text, Activity context, PopupFrameMetric frameMetrics) {
void open(String text, ZLTextRegion.Soul soulToSelect, FBReader fbreader, PopupFrameMetric frameMetrics) {
final Intent intent = getDictionaryIntent(text);
try {
if ("ABBYY Lingvo".equals(Id)) {
@ -138,10 +143,35 @@ public abstract class DictionaryUtil {
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLAndroidLibrary.Instance();
intent.putExtra(ColorDict3.FULLSCREEN, !zlibrary.ShowStatusBarOption.getValue());
}
context.startActivity(intent);
context.overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
fbreader.startActivity(intent);
fbreader.overridePendingTransition(0, 0);
} catch (ActivityNotFoundException e) {
installDictionaryIfNotInstalled(context, this);
installDictionaryIfNotInstalled(fbreader, this);
}
}
}
private static class DictanPackageInfo extends PackageInfo {
DictanPackageInfo(String id, String title, boolean supportsTargetLanguageSetting) {
super(id, title, supportsTargetLanguageSetting);
}
@Override
void open(String text, ZLTextRegion.Soul soulToSelect, FBReader fbreader, PopupFrameMetric frameMetrics) {
final Intent intent = getDictionaryIntent(text);
try {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.putExtra("article.mode", 20);
intent.putExtra("article.text.size.max", MAX_LENGTH_FOR_TOAST);
fbreader.startActivityForResult(intent, FBReader.REQUEST_DICTIONARY);
fbreader.overridePendingTransition(0, 0);
fbreader.outlineRegion(soulToSelect);
} catch (ActivityNotFoundException e) {
fbreader.hideOutline();
installDictionaryIfNotInstalled(fbreader, this);
}
}
}
@ -161,8 +191,8 @@ public abstract class DictionaryUtil {
}
@Override
void open(String text, Activity context, PopupFrameMetric frameMetrics) {
Flyout.showTranslation(context, text, frameMetrics);
void open(String text, ZLTextRegion.Soul soulToSelect, FBReader fbreader, PopupFrameMetric frameMetrics) {
Flyout.showTranslation(fbreader, text, frameMetrics);
}
}
@ -187,11 +217,20 @@ public abstract class DictionaryUtil {
if (!"always".equals(attributes.getValue("list"))) {
flags |= FLAG_INSTALLED_ONLY;
}
final PackageInfo info = new PlainPackageInfo(
id,
title != null ? title : id,
"true".equals(attributes.getValue("supportsTargetLanguage"))
);
final PackageInfo info;
if ("dictan".equals(id)) {
info = new DictanPackageInfo(
id,
title != null ? title : id,
false
);
} else {
info = new PlainPackageInfo(
id,
title != null ? title : id,
"true".equals(attributes.getValue("supportsTargetLanguage"))
);
}
for (int i = attributes.getLength() - 1; i >= 0; --i) {
info.put(attributes.getLocalName(i), attributes.getValue(i));
}
@ -375,10 +414,7 @@ public abstract class DictionaryUtil {
return ourMultiWordTranslatorOption;
}
public static PackageInfo getCurrentDictionaryInfo(boolean singleWord) {
final ZLStringOption option = singleWord
? singleWordTranslatorOption() : multiWordTranslatorOption();
final String id = option.getValue();
private static PackageInfo getInfo(String id) {
synchronized (ourInfos) {
for (PackageInfo info : ourInfos.keySet()) {
if (info.Id.equals(id)) {
@ -389,6 +425,12 @@ public abstract class DictionaryUtil {
return firstInfo();
}
public static PackageInfo getCurrentDictionaryInfo(boolean singleWord) {
final ZLStringOption option = singleWord
? singleWordTranslatorOption() : multiWordTranslatorOption();
return getInfo(option.getValue());
}
public static class PopupFrameMetric {
public final int Height;
public final int Gravity;
@ -407,7 +449,7 @@ public abstract class DictionaryUtil {
}
}
public static void openTextInDictionary(final Activity activity, String text, boolean singleWord, int selectionTop, int selectionBottom) {
public static void openTextInDictionary(final FBReader fbreader, String text, boolean singleWord, int selectionTop, int selectionBottom, final ZLTextRegion.Soul soulToSelect) {
final String textToTranslate;
if (singleWord) {
int start = 0;
@ -423,21 +465,21 @@ public abstract class DictionaryUtil {
}
final DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
fbreader.getWindowManager().getDefaultDisplay().getMetrics(metrics);
final PopupFrameMetric frameMetrics =
new PopupFrameMetric(metrics, selectionTop, selectionBottom);
final PackageInfo info = getCurrentDictionaryInfo(singleWord);
activity.runOnUiThread(new Runnable() {
fbreader.runOnUiThread(new Runnable() {
public void run() {
info.open(textToTranslate, activity, frameMetrics);
info.open(textToTranslate, soulToSelect, fbreader, frameMetrics);
}
});
}
public static void openWordInDictionary(Activity activity, ZLTextWord word, ZLTextRegion region) {
public static void openWordInDictionary(FBReader fbreader, ZLTextWord word, ZLTextRegion region) {
openTextInDictionary(
activity, word.toString(), true, region.getTop(), region.getBottom()
fbreader, word.toString(), true, region.getTop(), region.getBottom(), region.getSoul()
);
}
@ -470,4 +512,111 @@ public abstract class DictionaryUtil {
UIUtil.showErrorMessage(activity, "cannotRunAndroidMarket", dictionaryInfo.Title);
}
}
static void onActivityResult(final FBReader fbreader, int resultCode, final Intent data) {
if (data == null) {
fbreader.hideOutline();
return;
}
final int errorCode = data.getIntExtra("error.code", -1);
if (resultCode != Activity.RESULT_OK || errorCode != -1) {
showDictanError(fbreader, errorCode, data);
return;
}
String text = data.getStringExtra("article.text");
if (text == null) {
showDictanError(fbreader, -1, data);
return;
}
final int index = text.indexOf("\000");
if (index >= 0) {
text = text.substring(0, index);
}
final SuperActivityToast toast;
if (text.length() == MAX_LENGTH_FOR_TOAST) {
text = trimArticle(text);
toast = new SuperActivityToast(fbreader, SuperToast.Type.BUTTON);
toast.setButtonIcon(
android.R.drawable.ic_menu_more,
ZLResource.resource("footnoteToast").getResource("more").getValue()
);
toast.setOnClickWrapper(new OnClickWrapper("dict", new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
final String word = data.getStringExtra("article.word");
final PackageInfo info = getInfo("dictan");
final Intent intent = info.getDictionaryIntent(word);
try {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
fbreader.startActivity(intent);
fbreader.overridePendingTransition(0, 0);
} catch (ActivityNotFoundException e) {
// ignore
}
}
}));
} else {
toast = new SuperActivityToast(fbreader, SuperToast.Type.STANDARD);
}
toast.setText(text);
toast.setDuration(20000);
toast.setOnDismissWrapper(new OnDismissWrapper("ftnt", new SuperToast.OnDismissListener() {
@Override
public void onDismiss(View view) {
fbreader.hideOutline();
}
}));
fbreader.showToast(toast);
}
private static void showDictanError(final FBReader fbreader, int code, Intent data) {
final ZLResource resource = ZLResource.resource("dictanErrors");
String message;
switch (code) {
default:
message = data.getStringExtra("error.message");
if (message == null) {
message = resource.getResource("unknown").getValue();
}
break;
case 100:
{
final String word = data.getStringExtra("article.word");
message = resource.getResource("noArticle").getValue().replaceAll("%s", word);
break;
}
case 130:
message = resource.getResource("cannotOpenDictionary").getValue();
break;
case 131:
message = resource.getResource("noDictionarySelected").getValue();
break;
}
final SuperActivityToast toast = new SuperActivityToast(fbreader, SuperToast.Type.STANDARD);
toast.setText("Dictan: " + message);
toast.setDuration(5000);
toast.setOnDismissWrapper(new OnDismissWrapper("ftnt", new SuperToast.OnDismissListener() {
@Override
public void onDismiss(View view) {
fbreader.hideOutline();
}
}));
fbreader.showToast(toast);
}
private static String trimArticle(String text) {
final int len = text.length();
final int eolIndex = text.lastIndexOf("\n");
final int spaceIndex = text.lastIndexOf(" ");
if (spaceIndex < eolIndex || eolIndex >= len * 2 / 3) {
return text.substring(0, eolIndex);
} else {
return text.substring(0, spaceIndex);
}
}
}

View file

@ -42,6 +42,7 @@ import org.geometerplus.zlibrary.core.options.Config;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.view.ZLViewWidget;
import org.geometerplus.zlibrary.text.view.ZLTextRegion;
import org.geometerplus.zlibrary.text.view.ZLTextView;
import org.geometerplus.zlibrary.ui.android.R;
@ -73,6 +74,7 @@ public final class FBReader extends Activity implements ZLApplicationWindow {
public static final int REQUEST_PREFERENCES = 1;
public static final int REQUEST_CANCEL_MENU = 2;
public static final int REQUEST_DICTIONARY = 3;
public static final int RESULT_DO_NOTHING = RESULT_FIRST_USER;
public static final int RESULT_REPAINT = RESULT_FIRST_USER + 1;
@ -708,6 +710,9 @@ public final class FBReader extends Activity implements ZLApplicationWindow {
case REQUEST_CANCEL_MENU:
runCancelAction(data);
break;
case REQUEST_DICTIONARY:
DictionaryUtil.onActivityResult(this, resultCode, data);
break;
}
}
@ -1071,4 +1076,14 @@ public final class FBReader extends Activity implements ZLApplicationWindow {
myToast = toast;
toast.show();
}
public void outlineRegion(ZLTextRegion.Soul soul) {
myFBReaderApp.getTextView().outlineRegion(soul);
myFBReaderApp.getViewWidget().repaint();
}
public void hideOutline() {
myFBReaderApp.getTextView().hideOutline();
myFBReaderApp.getViewWidget().repaint();
}
}

View file

@ -28,6 +28,7 @@ import android.view.View;
import com.github.johnpersano.supertoasts.SuperActivityToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.OnDismissWrapper;
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
import org.geometerplus.zlibrary.core.resources.ZLResource;
@ -50,19 +51,19 @@ class ProcessHyperlinkAction extends FBAndroidAction {
@Override
public boolean isEnabled() {
return Reader.getTextView().getSelectedRegion() != null;
return Reader.getTextView().getOutlinedRegion() != null;
}
@Override
protected void run(Object ... params) {
final ZLTextRegion region = Reader.getTextView().getSelectedRegion();
final ZLTextRegion region = Reader.getTextView().getOutlinedRegion();
if (region == null) {
return;
}
final ZLTextRegion.Soul soul = region.getSoul();
if (soul instanceof ZLTextHyperlinkRegionSoul) {
Reader.getTextView().hideSelectedRegionBorder();
Reader.getTextView().hideOutline();
Reader.getViewWidget().repaint();
final ZLTextHyperlink hyperlink = ((ZLTextHyperlinkRegionSoul)soul).Hyperlink;
switch (hyperlink.Type) {
@ -115,6 +116,14 @@ class ProcessHyperlinkAction extends FBAndroidAction {
}
toast.setText(snippet.getText());
toast.setDuration(Reader.MiscOptions.FootnoteToastDuration.getValue().Value);
toast.setOnDismissWrapper(new OnDismissWrapper("ftnt", new SuperToast.OnDismissListener() {
@Override
public void onDismiss(View view) {
Reader.getTextView().hideOutline();
Reader.getViewWidget().repaint();
}
}));
Reader.getTextView().outlineRegion(region);
BaseActivity.showToast(toast);
} else {
Reader.tryOpenFootnote(hyperlink.Id);
@ -123,7 +132,7 @@ class ProcessHyperlinkAction extends FBAndroidAction {
}
}
} else if (soul instanceof ZLTextImageRegionSoul) {
Reader.getTextView().hideSelectedRegionBorder();
Reader.getTextView().hideOutline();
Reader.getViewWidget().repaint();
final String url = ((ZLTextImageRegionSoul)soul).ImageElement.URL;
if (url != null) {

View file

@ -35,7 +35,8 @@ public class SelectionTranslateAction extends FBAndroidAction {
fbview.getSelectedSnippet().getText(),
fbview.getCountOfSelectedWords() == 1,
fbview.getSelectionStartY(),
fbview.getSelectionEndY()
fbview.getSelectionEndY(),
fbview.getSelectionSoul()
);
fbview.clearSelection();
}

View file

@ -93,7 +93,7 @@ public final class FBView extends ZLTextView {
final ZLTextRegion hyperlinkRegion = findRegion(x, y, maxSelectionDistance(), ZLTextRegion.HyperlinkFilter);
if (hyperlinkRegion != null) {
selectRegion(hyperlinkRegion);
outlineRegion(hyperlinkRegion);
myReader.getViewWidget().reset();
myReader.getViewWidget().repaint();
myReader.runAction(ActionCode.PROCESS_HYPERLINK);
@ -108,7 +108,7 @@ public final class FBView extends ZLTextView {
final ZLTextRegion videoRegion = findRegion(x, y, 0, ZLTextRegion.VideoFilter);
if (videoRegion != null) {
selectRegion(videoRegion);
outlineRegion(videoRegion);
myReader.getViewWidget().reset();
myReader.getViewWidget().repaint();
myReader.runAction(ActionCode.OPEN_VIDEO, (ZLTextVideoRegionSoul)videoRegion.getSoul());
@ -139,9 +139,12 @@ public final class FBView extends ZLTextView {
@Override
public boolean onFingerDoubleTap(int x, int y) {
myReader.runAction(ActionCode.HIDE_TOAST);
if (super.onFingerDoubleTap(x, y)) {
return true;
}
myReader.runAction(getZoneMap().getActionByCoordinates(
x, y, getContextWidth(), getContextHeight(), TapZoneMap.Tap.doubleTap
), x, y);
@ -149,6 +152,8 @@ public final class FBView extends ZLTextView {
}
public boolean onFingerPress(int x, int y) {
myReader.runAction(ActionCode.HIDE_TOAST);
if (super.onFingerPress(x, y)) {
return true;
}
@ -246,6 +251,8 @@ public final class FBView extends ZLTextView {
}
public boolean onFingerLongPress(int x, int y) {
myReader.runAction(ActionCode.HIDE_TOAST);
if (super.onFingerLongPress(x, y)) {
return true;
}
@ -278,7 +285,7 @@ public final class FBView extends ZLTextView {
}
if (doSelectRegion) {
selectRegion(region);
outlineRegion(region);
myReader.getViewWidget().reset();
myReader.getViewWidget().repaint();
return true;
@ -299,7 +306,7 @@ public final class FBView extends ZLTextView {
return true;
}
ZLTextRegion region = getSelectedRegion();
ZLTextRegion region = getOutlinedRegion();
if (region != null) {
ZLTextRegion.Soul soul = region.getSoul();
if (soul instanceof ZLTextHyperlinkRegionSoul ||
@ -311,7 +318,7 @@ public final class FBView extends ZLTextView {
soul = region.getSoul();
if (soul instanceof ZLTextHyperlinkRegionSoul
|| soul instanceof ZLTextWordRegionSoul) {
selectRegion(region);
outlineRegion(region);
myReader.getViewWidget().reset();
myReader.getViewWidget().repaint();
}
@ -333,7 +340,7 @@ public final class FBView extends ZLTextView {
return true;
}
final ZLTextRegion region = getSelectedRegion();
final ZLTextRegion region = getOutlinedRegion();
if (region != null) {
final ZLTextRegion.Soul soul = region.getSoul();

View file

@ -33,14 +33,14 @@ class MoveCursorAction extends FBAction {
@Override
protected void run(Object ... params) {
final FBView fbView = Reader.getTextView();
ZLTextRegion region = fbView.getSelectedRegion();
ZLTextRegion region = fbView.getOutlinedRegion();
final ZLTextRegion.Filter filter =
(region != null && region.getSoul() instanceof ZLTextWordRegionSoul)
|| Reader.MiscOptions.NavigateAllWords.getValue()
? ZLTextRegion.AnyRegionFilter : ZLTextRegion.ImageOrHyperlinkFilter;
region = fbView.nextRegion(myDirection, filter);
if (region != null) {
fbView.selectRegion(region);
fbView.outlineRegion(region);
} else {
switch (myDirection) {
case down:

View file

@ -42,11 +42,14 @@ class ZLTextSelection extends ZLTextHighlighting {
private Scroller myScroller;
ZLTextSelection(ZLTextView view) {
myView = view;
}
ZLTextRegion.Soul getSoul() {
return myLeftMostRegionSoul != null && myLeftMostRegionSoul.equals(myRightMostRegionSoul) ? myLeftMostRegionSoul : null;
}
@Override
public boolean isEmpty() {
return myLeftMostRegionSoul == null;

View file

@ -57,8 +57,8 @@ public abstract class ZLTextView extends ZLTextViewBase {
private final HashMap<ZLTextLineInfo,ZLTextLineInfo> myLineInfoCache = new HashMap<ZLTextLineInfo,ZLTextLineInfo>();
private ZLTextRegion.Soul mySelectedRegionSoul;
private boolean myHighlightSelectedRegion = true;
private ZLTextRegion.Soul myOutlinedRegionSoul;
private boolean myShowOutline = true;
private final ZLTextSelection mySelection = new ZLTextSelection(this);
private final Set<ZLTextHighlighting> myHighlightings =
@ -543,9 +543,9 @@ public abstract class ZLTextView extends ZLTextViewBase {
}
}
final ZLTextRegion selectedElementRegion = getSelectedRegion(page);
if (selectedElementRegion != null && myHighlightSelectedRegion) {
selectedElementRegion.draw(context);
final ZLTextRegion outlinedElementRegion = getOutlinedRegion(page);
if (outlinedElementRegion != null && myShowOutline) {
outlinedElementRegion.draw(context);
}
drawSelectionCursor(context, getSelectionCursorPoint(page, ZLTextSelectionCursor.Left));
@ -1721,19 +1721,35 @@ public abstract class ZLTextView extends ZLTextViewBase {
return myCurrentPage.TextElementMap.binarySearch(x, y);
}
public void hideSelectedRegionBorder() {
myHighlightSelectedRegion = false;
public final void outlineRegion(ZLTextRegion region) {
outlineRegion(region != null ? region.getSoul() : null);
}
public final void outlineRegion(ZLTextRegion.Soul soul) {
myShowOutline = true;
myOutlinedRegionSoul = soul;
}
public void hideOutline() {
myShowOutline = false;
Application.getViewWidget().reset();
}
private ZLTextRegion getSelectedRegion(ZLTextPage page) {
return page.TextElementMap.getRegion(mySelectedRegionSoul);
private ZLTextRegion getOutlinedRegion(ZLTextPage page) {
return page.TextElementMap.getRegion(myOutlinedRegionSoul);
}
public ZLTextRegion getSelectedRegion() {
return getSelectedRegion(myCurrentPage);
public ZLTextRegion getOutlinedRegion() {
return getOutlinedRegion(myCurrentPage);
}
/*
public void resetRegionPointer() {
myOutlinedRegionSoul = null;
myShowOutline = true;
}
*/
protected ZLTextHighlighting findHighlighting(int x, int y, int maxDistance) {
final ZLTextRegion region = findRegion(x, y, maxDistance, ZLTextRegion.AnyRegionFilter);
if (region == null) {
@ -1757,14 +1773,6 @@ public abstract class ZLTextView extends ZLTextViewBase {
return myCurrentPage.TextElementMap.findRegion(x, y, maxDistance, filter);
}
public void selectRegion(ZLTextRegion region) {
final ZLTextRegion.Soul soul = region != null ? region.getSoul() : null;
if (soul == null || !soul.equals(mySelectedRegionSoul)) {
myHighlightSelectedRegion = true;
}
mySelectedRegionSoul = soul;
}
protected boolean initSelection(int x, int y) {
y -= getTextStyleCollection().getBaseStyle().getFontSize() / 2;
if (!mySelection.start(x, y)) {
@ -1782,6 +1790,10 @@ public abstract class ZLTextView extends ZLTextViewBase {
}
}
public ZLTextRegion.Soul getSelectionSoul() {
return mySelection.getSoul();
}
public int getSelectionStartY() {
if (mySelection.isEmpty()) {
return 0;
@ -1828,13 +1840,8 @@ public abstract class ZLTextView extends ZLTextViewBase {
return mySelection.isEmpty();
}
public void resetRegionPointer() {
mySelectedRegionSoul = null;
myHighlightSelectedRegion = true;
}
public ZLTextRegion nextRegion(Direction direction, ZLTextRegion.Filter filter) {
return myCurrentPage.TextElementMap.nextRegion(getSelectedRegion(), direction, filter);
return myCurrentPage.TextElementMap.nextRegion(getOutlinedRegion(), direction, filter);
}
@Override