diff --git a/assets/dictionaries/main.xml b/assets/dictionaries/main.xml index 423694070..7a4b54fdf 100644 --- a/assets/dictionaries/main.xml +++ b/assets/dictionaries/main.xml @@ -17,6 +17,16 @@ dataKey="query" list="always" /> + - + + + + + + diff --git a/assets/resources/application/be.xml b/assets/resources/application/be.xml index bbc47e355..c0de4c6f0 100644 --- a/assets/resources/application/be.xml +++ b/assets/resources/application/be.xml @@ -1149,4 +1149,10 @@ + + + + + + diff --git a/assets/resources/application/bg.xml b/assets/resources/application/bg.xml index 6286f4c6b..738d76bdd 100644 --- a/assets/resources/application/bg.xml +++ b/assets/resources/application/bg.xml @@ -1155,4 +1155,10 @@ + + + + + + diff --git a/assets/resources/application/ca.xml b/assets/resources/application/ca.xml index 5925d6ed1..3f52501a3 100644 --- a/assets/resources/application/ca.xml +++ b/assets/resources/application/ca.xml @@ -1155,4 +1155,10 @@ + + + + + + diff --git a/assets/resources/application/cs.xml b/assets/resources/application/cs.xml index aad490507..90848f14e 100644 --- a/assets/resources/application/cs.xml +++ b/assets/resources/application/cs.xml @@ -1158,4 +1158,10 @@ + + + + + + diff --git a/assets/resources/application/da.xml b/assets/resources/application/da.xml index 2c4d158d4..ae573af39 100644 --- a/assets/resources/application/da.xml +++ b/assets/resources/application/da.xml @@ -1148,4 +1148,10 @@ + + + + + + diff --git a/assets/resources/application/de.xml b/assets/resources/application/de.xml index 9ec0315d3..c22e5c988 100644 --- a/assets/resources/application/de.xml +++ b/assets/resources/application/de.xml @@ -1154,4 +1154,10 @@ + + + + + + diff --git a/assets/resources/application/el.xml b/assets/resources/application/el.xml index 77370528f..baf8a7752 100644 --- a/assets/resources/application/el.xml +++ b/assets/resources/application/el.xml @@ -1147,4 +1147,10 @@ + + + + + + diff --git a/assets/resources/application/en.xml b/assets/resources/application/en.xml index b8661c95c..a3e19a886 100644 --- a/assets/resources/application/en.xml +++ b/assets/resources/application/en.xml @@ -1149,4 +1149,10 @@ + + + + + + diff --git a/assets/resources/application/es.xml b/assets/resources/application/es.xml index c32673078..9b74a4848 100644 --- a/assets/resources/application/es.xml +++ b/assets/resources/application/es.xml @@ -1154,4 +1154,10 @@ + + + + + + diff --git a/assets/resources/application/eu.xml b/assets/resources/application/eu.xml index e546d2335..04a313f6b 100644 --- a/assets/resources/application/eu.xml +++ b/assets/resources/application/eu.xml @@ -1150,4 +1150,10 @@ + + + + + + diff --git a/assets/resources/application/fa.xml b/assets/resources/application/fa.xml index 4ea198c6f..77b11a897 100644 --- a/assets/resources/application/fa.xml +++ b/assets/resources/application/fa.xml @@ -1148,4 +1148,10 @@ + + + + + + diff --git a/assets/resources/application/fr.xml b/assets/resources/application/fr.xml index 1cd6c5638..be3da3f55 100644 --- a/assets/resources/application/fr.xml +++ b/assets/resources/application/fr.xml @@ -1142,4 +1142,10 @@ + + + + + + diff --git a/assets/resources/application/gl.xml b/assets/resources/application/gl.xml index 93f1f6789..f94944378 100644 --- a/assets/resources/application/gl.xml +++ b/assets/resources/application/gl.xml @@ -1139,4 +1139,10 @@ + + + + + + diff --git a/assets/resources/application/hu.xml b/assets/resources/application/hu.xml index e2fbdbbd5..a75866e78 100644 --- a/assets/resources/application/hu.xml +++ b/assets/resources/application/hu.xml @@ -1139,4 +1139,10 @@ + + + + + + diff --git a/assets/resources/application/hy.xml b/assets/resources/application/hy.xml index 4d8cf44c7..5b81fa515 100644 --- a/assets/resources/application/hy.xml +++ b/assets/resources/application/hy.xml @@ -1154,4 +1154,10 @@ + + + + + + diff --git a/assets/resources/application/it.xml b/assets/resources/application/it.xml index 828fb2d1a..142a9b72b 100644 --- a/assets/resources/application/it.xml +++ b/assets/resources/application/it.xml @@ -1140,4 +1140,10 @@ + + + + + + diff --git a/assets/resources/application/ja.xml b/assets/resources/application/ja.xml index b2a2096e5..af88c5080 100644 --- a/assets/resources/application/ja.xml +++ b/assets/resources/application/ja.xml @@ -1149,4 +1149,10 @@ + + + + + + diff --git a/assets/resources/application/ka.xml b/assets/resources/application/ka.xml index 84103b99a..d8c610df4 100644 --- a/assets/resources/application/ka.xml +++ b/assets/resources/application/ka.xml @@ -1154,4 +1154,10 @@ + + + + + + diff --git a/assets/resources/application/nb.xml b/assets/resources/application/nb.xml index fd297205b..70ffd5be2 100644 --- a/assets/resources/application/nb.xml +++ b/assets/resources/application/nb.xml @@ -1149,4 +1149,10 @@ + + + + + + diff --git a/assets/resources/application/nl.xml b/assets/resources/application/nl.xml index 78844a5d7..8efc290d6 100644 --- a/assets/resources/application/nl.xml +++ b/assets/resources/application/nl.xml @@ -1149,4 +1149,10 @@ + + + + + + diff --git a/assets/resources/application/pl.xml b/assets/resources/application/pl.xml index f4cd1022e..9d62b9196 100644 --- a/assets/resources/application/pl.xml +++ b/assets/resources/application/pl.xml @@ -1139,4 +1139,10 @@ + + + + + + diff --git a/assets/resources/application/pt.xml b/assets/resources/application/pt.xml index 784c65106..e98224b99 100644 --- a/assets/resources/application/pt.xml +++ b/assets/resources/application/pt.xml @@ -1153,4 +1153,10 @@ + + + + + + diff --git a/assets/resources/application/ro.xml b/assets/resources/application/ro.xml index 5bb45e301..27b18339e 100644 --- a/assets/resources/application/ro.xml +++ b/assets/resources/application/ro.xml @@ -1141,4 +1141,10 @@ + + + + + + diff --git a/assets/resources/application/ru.xml b/assets/resources/application/ru.xml index ad556cf3f..acf7879f4 100644 --- a/assets/resources/application/ru.xml +++ b/assets/resources/application/ru.xml @@ -1158,4 +1158,10 @@ + + + + + + diff --git a/assets/resources/application/sr.xml b/assets/resources/application/sr.xml index cdabe9b7c..7ed47403a 100644 --- a/assets/resources/application/sr.xml +++ b/assets/resources/application/sr.xml @@ -1149,4 +1149,10 @@ + + + + + + diff --git a/assets/resources/application/th.xml b/assets/resources/application/th.xml index 36b477dfe..162586d39 100644 --- a/assets/resources/application/th.xml +++ b/assets/resources/application/th.xml @@ -1139,4 +1139,10 @@ + + + + + + diff --git a/assets/resources/application/tr.xml b/assets/resources/application/tr.xml index 6f35801e0..7f2a99405 100644 --- a/assets/resources/application/tr.xml +++ b/assets/resources/application/tr.xml @@ -1149,4 +1149,10 @@ + + + + + + diff --git a/assets/resources/application/uk.xml b/assets/resources/application/uk.xml index acf26af5c..0718dfdcf 100644 --- a/assets/resources/application/uk.xml +++ b/assets/resources/application/uk.xml @@ -1139,4 +1139,10 @@ + + + + + + diff --git a/assets/resources/application/vi.xml b/assets/resources/application/vi.xml index 1eab34e26..3c0a25dde 100644 --- a/assets/resources/application/vi.xml +++ b/assets/resources/application/vi.xml @@ -1140,4 +1140,10 @@ + + + + + + diff --git a/assets/resources/application/zh.xml b/assets/resources/application/zh.xml index c5b6a5313..b02e0186f 100644 --- a/assets/resources/application/zh.xml +++ b/assets/resources/application/zh.xml @@ -1139,4 +1139,10 @@ + + + + + + diff --git a/assets/resources/application/zh_TW.xml b/assets/resources/application/zh_TW.xml index f02345729..fcd06eb86 100644 --- a/assets/resources/application/zh_TW.xml +++ b/assets/resources/application/zh_TW.xml @@ -1139,4 +1139,10 @@ + + + + + + diff --git a/src/org/geometerplus/android/fbreader/DictionaryUtil.java b/src/org/geometerplus/android/fbreader/DictionaryUtil.java index 7d6f91b2e..7653b6d73 100644 --- a/src/org/geometerplus/android/fbreader/DictionaryUtil.java +++ b/src/org/geometerplus/android/fbreader/DictionaryUtil.java @@ -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); + } + } } diff --git a/src/org/geometerplus/android/fbreader/FBReader.java b/src/org/geometerplus/android/fbreader/FBReader.java index e3077887d..de92aaca0 100644 --- a/src/org/geometerplus/android/fbreader/FBReader.java +++ b/src/org/geometerplus/android/fbreader/FBReader.java @@ -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(); + } } diff --git a/src/org/geometerplus/android/fbreader/ProcessHyperlinkAction.java b/src/org/geometerplus/android/fbreader/ProcessHyperlinkAction.java index 4e5fa9143..d6c0188c7 100644 --- a/src/org/geometerplus/android/fbreader/ProcessHyperlinkAction.java +++ b/src/org/geometerplus/android/fbreader/ProcessHyperlinkAction.java @@ -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) { diff --git a/src/org/geometerplus/android/fbreader/SelectionTranslateAction.java b/src/org/geometerplus/android/fbreader/SelectionTranslateAction.java index 0d4706f26..edb066b9a 100644 --- a/src/org/geometerplus/android/fbreader/SelectionTranslateAction.java +++ b/src/org/geometerplus/android/fbreader/SelectionTranslateAction.java @@ -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(); } diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java index db91dba72..fb9ac675a 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBView.java +++ b/src/org/geometerplus/fbreader/fbreader/FBView.java @@ -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(); diff --git a/src/org/geometerplus/fbreader/fbreader/MoveCursorAction.java b/src/org/geometerplus/fbreader/fbreader/MoveCursorAction.java index d45118f57..5cfb509cd 100644 --- a/src/org/geometerplus/fbreader/fbreader/MoveCursorAction.java +++ b/src/org/geometerplus/fbreader/fbreader/MoveCursorAction.java @@ -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: diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextSelection.java b/src/org/geometerplus/zlibrary/text/view/ZLTextSelection.java index f2be836cf..65f5833e7 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextSelection.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextSelection.java @@ -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; diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java index 847840fbc..00228205d 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java @@ -57,8 +57,8 @@ public abstract class ZLTextView extends ZLTextViewBase { private final HashMap myLineInfoCache = new HashMap(); - 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 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