diff --git a/assets/default/keymap.xml b/assets/default/keymap.xml
index 8373239ac..f3a3b3814 100644
--- a/assets/default/keymap.xml
+++ b/assets/default/keymap.xml
@@ -3,6 +3,6 @@
-
-
+
+
diff --git a/src/org/geometerplus/android/fbreader/FBReader.java b/src/org/geometerplus/android/fbreader/FBReader.java
index 8244763ca..27453958e 100644
--- a/src/org/geometerplus/android/fbreader/FBReader.java
+++ b/src/org/geometerplus/android/fbreader/FBReader.java
@@ -118,7 +118,7 @@ public final class FBReader extends ZLAndroidActivity {
fbReader.addAction(ActionCode.SHOW_NAVIGATION, new ShowNavigationAction(this, fbReader));
fbReader.addAction(ActionCode.SEARCH, new SearchAction(this, fbReader));
- fbReader.addAction(ActionCode.TRANSLATE, new TranslateAction(this, fbReader));
+ fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader));
}
@Override
diff --git a/src/org/geometerplus/android/fbreader/ProcessHyperlinkAction.java b/src/org/geometerplus/android/fbreader/ProcessHyperlinkAction.java
new file mode 100644
index 000000000..c6aab1f7e
--- /dev/null
+++ b/src/org/geometerplus/android/fbreader/ProcessHyperlinkAction.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2010 Geometer Plus
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+package org.geometerplus.android.fbreader;
+
+import org.geometerplus.zlibrary.core.resources.ZLResource;
+import org.geometerplus.zlibrary.core.library.ZLibrary;
+
+import org.geometerplus.zlibrary.text.view.ZLTextView;
+import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
+
+import org.geometerplus.fbreader.fbreader.FBAction;
+import org.geometerplus.fbreader.fbreader.FBReaderApp;
+import org.geometerplus.fbreader.bookmodel.FBHyperlinkType;
+
+import android.app.SearchManager;
+import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.widget.Toast;
+
+class ProcessHyperlinkAction extends FBAction {
+ private final FBReader myBaseActivity;
+
+ ProcessHyperlinkAction(FBReader baseActivity, FBReaderApp fbreader) {
+ super(fbreader);
+ myBaseActivity = baseActivity;
+ }
+
+ public boolean isEnabled() {
+ final ZLTextView view = Reader.getTextView();
+ return
+ view.getSelectedText() != null ||
+ view.getCurrentHyperlink() != null;
+ }
+
+ public void run() {
+ final ZLTextHyperlink hyperlink = Reader.getTextView().getCurrentHyperlink();
+ if (hyperlink != null) {
+ switch (hyperlink.Type) {
+ case FBHyperlinkType.EXTERNAL:
+ ZLibrary.Instance().openInBrowser(hyperlink.Id);
+ break;
+ case FBHyperlinkType.INTERNAL:
+ Reader.tryOpenFootnote(hyperlink.Id);
+ break;
+ }
+ return;
+ }
+
+ final String text = Reader.getTextView().getSelectedText();
+ if (text != null) {
+ int start = 0;
+ int end = text.length();
+ for (; start < end && !Character.isLetterOrDigit(text.charAt(start)); ++start);
+ for (; start < end && !Character.isLetterOrDigit(text.charAt(end - 1)); --end);
+ if (start == end) {
+ return;
+ }
+ Intent intent = new Intent(Intent.ACTION_SEARCH);
+ intent.setComponent(new ComponentName(
+ "com.socialnmobile.colordict",
+ "com.socialnmobile.colordict.activity.Main"
+ ));
+ intent.putExtra(SearchManager.QUERY, text.substring(start, end));
+ try {
+ myBaseActivity.startActivity(intent);
+ } catch(ActivityNotFoundException e){
+ Toast.makeText(
+ myBaseActivity,
+ ZLResource.resource("errorMessage").getResource("dictNotInstalled").getValue(),
+ Toast.LENGTH_LONG
+ ).show();
+ }
+ }
+ }
+ /*
+ final Intent intent = new Intent(Intent.ACTION_VIEW);
+ boolean externalUrl = true;
+ if (BookDownloader.acceptsUri(Uri.parse(reference))) {
+ intent.setClass(myActivity, BookDownloader.class);
+ intent.putExtra(BookDownloaderService.SHOW_NOTIFICATIONS_KEY, BookDownloaderService.Notifications.ALL);
+ externalUrl = false;
+ }
+ final NetworkLibrary nLibrary = NetworkLibrary.Instance();
+ try {
+ nLibrary.initialize();
+ } catch (ZLNetworkException e) {
+ }
+ reference = NetworkLibrary.Instance().rewriteUrl(reference, externalUrl);
+ intent.setData(Uri.parse(reference));
+ myActivity.startActivity(intent);
+ */
+}
diff --git a/src/org/geometerplus/android/fbreader/TranslateAction.java b/src/org/geometerplus/android/fbreader/TranslateAction.java
deleted file mode 100644
index dc3ad2018..000000000
--- a/src/org/geometerplus/android/fbreader/TranslateAction.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2010 Geometer Plus
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-package org.geometerplus.android.fbreader;
-
-import org.geometerplus.zlibrary.core.resources.ZLResource;
-import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
-import org.geometerplus.zlibrary.ui.android.library.ZLAndroidLibrary;
-import org.geometerplus.zlibrary.ui.android.view.ZLAndroidWidget;
-
-import org.geometerplus.fbreader.fbreader.FBAction;
-import org.geometerplus.fbreader.fbreader.FBReaderApp;
-
-import android.app.SearchManager;
-import android.content.ActivityNotFoundException;
-import android.content.ComponentName;
-import android.content.Intent;
-import android.widget.Toast;
-
-class TranslateAction extends FBAction {
- private final FBReader myBaseActivity;
-
- TranslateAction(FBReader baseActivity, FBReaderApp fbreader) {
- super(fbreader);
- myBaseActivity = baseActivity;
- }
-
- /*
- private ZLAndroidWidget getWidget() {
- return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
- }
- */
-
- public boolean isVisible() {
- return true;
- //return Reader.Model != null;// && getWidget().myLongPressWord != "";
- }
-
- public void run() {
- Intent intent = new Intent(Intent.ACTION_SEARCH);
- intent.setComponent(new ComponentName(
- "com.socialnmobile.colordict",
- "com.socialnmobile.colordict.activity.Main"
- ));
- //intent.putExtra(SearchManager.QUERY, getWidget().myLongPressWord);
- intent.putExtra(SearchManager.QUERY, "biology");
- try {
- myBaseActivity.startActivity(intent);
- }
- catch(ActivityNotFoundException e){
- Toast.makeText(
- myBaseActivity,
- ZLResource.resource("errorMessage").getResource("dictNotInstalled").getValue(),
- Toast.LENGTH_LONG
- ).show();
- }
- }
-}
diff --git a/src/org/geometerplus/fbreader/fbreader/ActionCode.java b/src/org/geometerplus/fbreader/fbreader/ActionCode.java
index 3e3ca6322..fd7355f0b 100644
--- a/src/org/geometerplus/fbreader/fbreader/ActionCode.java
+++ b/src/org/geometerplus/fbreader/fbreader/ActionCode.java
@@ -52,5 +52,5 @@ public interface ActionCode {
String CLEAR_SELECTION = "clearSelection";
String TRANSLATE = "translate";
- String FOLLOW_HYPERLINK = "followHyperlink";
-};
+ String PROCESS_HYPERLINK = "processHyperlink";
+}
diff --git a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java
index 7bb81d056..7efad7986 100644
--- a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java
+++ b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java
@@ -109,7 +109,6 @@ public final class FBReaderApp extends ZLApplication {
//addAction(ActionCode.COPY_SELECTED_TEXT_TO_CLIPBOARD, new DummyAction(this));
//addAction(ActionCode.OPEN_SELECTED_TEXT_IN_DICTIONARY, new DummyAction(this));
//addAction(ActionCode.CLEAR_SELECTION, new DummyAction(this));
- addAction(ActionCode.FOLLOW_HYPERLINK, new FollowHyperlinkAction(this));
addAction(ActionCode.SWITCH_TO_DAY_PROFILE, new SwitchProfileAction(this, ColorProfile.DAY));
addAction(ActionCode.SWITCH_TO_NIGHT_PROFILE, new SwitchProfileAction(this, ColorProfile.NIGHT));
@@ -170,7 +169,7 @@ public final class FBReaderApp extends ZLApplication {
return (FBView)getCurrentView();
}
- void tryOpenFootnote(String id) {
+ public void tryOpenFootnote(String id) {
if (Model != null) {
BookModel.Label label = Model.getLabel(id);
if (label != null) {
diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java
index 5a19fdda4..08335349a 100644
--- a/src/org/geometerplus/fbreader/fbreader/FBView.java
+++ b/src/org/geometerplus/fbreader/fbreader/FBView.java
@@ -69,17 +69,6 @@ public final class FBView extends ZLTextView {
}
}
- void followHyperlink(ZLTextHyperlink hyperlink) {
- switch (hyperlink.Type) {
- case FBHyperlinkType.EXTERNAL:
- ZLibrary.Instance().openInBrowser(hyperlink.Id);
- break;
- case FBHyperlinkType.INTERNAL:
- myReader.tryOpenFootnote(hyperlink.Id);
- break;
- }
- }
-
private int myStartX;
private int myStartY;
private boolean myIsManualScrollingActive;
@@ -107,7 +96,8 @@ public final class FBView extends ZLTextView {
if (hyperlink != null) {
selectHyperlink(hyperlink);
myReader.repaintView();
- followHyperlink(hyperlink);
+ myReader.doAction(ActionCode.PROCESS_HYPERLINK);
+ //followHyperlink(hyperlink);
return true;
}
diff --git a/src/org/geometerplus/fbreader/fbreader/FollowHyperlinkAction.java b/src/org/geometerplus/fbreader/fbreader/FollowHyperlinkAction.java
deleted file mode 100644
index 3fd63a39f..000000000
--- a/src/org/geometerplus/fbreader/fbreader/FollowHyperlinkAction.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2009-2010 Geometer Plus
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-package org.geometerplus.fbreader.fbreader;
-
-public class FollowHyperlinkAction extends FBAction {
- FollowHyperlinkAction(FBReaderApp fbreader) {
- super(fbreader);
- }
-
- public boolean isEnabled() {
- FBView view = Reader.getTextView();
- return (view != null) && (view.getCurrentHyperlink() != null);
- }
-
- public void run() {
- FBView view = Reader.getTextView();
- view.followHyperlink(view.getCurrentHyperlink());
- }
-}
diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java
index b49d2b36d..c6cf4f332 100644
--- a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java
+++ b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java
@@ -1306,6 +1306,14 @@ public abstract class ZLTextView extends ZLTextViewBase {
return (area instanceof ZLTextHyperlinkRegion) ? ((ZLTextHyperlinkRegion)area).Hyperlink : null;
}
+ public String getSelectedText() {
+ final ZLTextElementRegion area = getCurrentElementRegion(myCurrentPage);
+ if (area instanceof ZLTextWordRegion) {
+ return ((ZLTextWordRegion)area).Word.toString();
+ }
+ return null;
+ }
+
protected ZLTextHyperlink findHyperlink(int x, int y, int maxDistance) {
ZLTextHyperlinkRegion hyperlinkRegion = null;
int distance = maxDistance + 1;
diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextWord.java b/src/org/geometerplus/zlibrary/text/view/ZLTextWord.java
index 242b0412f..d66b467df 100644
--- a/src/org/geometerplus/zlibrary/text/view/ZLTextWord.java
+++ b/src/org/geometerplus/zlibrary/text/view/ZLTextWord.java
@@ -98,10 +98,6 @@ public final class ZLTextWord extends ZLTextElement {
}
public String toString() {
- StringBuffer sb = new StringBuffer();
- for (int i = Offset; i < Offset + Length; i++) {
- sb.append(Data[i]);
- }
- return sb.toString();
+ return new String(Data, Offset, Length);
}
}