diff --git a/icons/selection/selection_dictionary.xml b/icons/selection/selection_translate.xml
similarity index 63%
rename from icons/selection/selection_dictionary.xml
rename to icons/selection/selection_translate.xml
index 973bdffda4b..328527f400e 100644
--- a/icons/selection/selection_dictionary.xml
+++ b/icons/selection/selection_translate.xml
@@ -1,5 +1,5 @@
-
-
+
+
diff --git a/icons/selection/selection_dictionary_active.png b/icons/selection/selection_translate_active.png
similarity index 100%
rename from icons/selection/selection_dictionary_active.png
rename to icons/selection/selection_translate_active.png
diff --git a/icons/selection/selection_dictionary_default.png b/icons/selection/selection_translate_default.png
similarity index 100%
rename from icons/selection/selection_dictionary_default.png
rename to icons/selection/selection_translate_default.png
diff --git a/src/org/geometerplus/android/fbreader/DictionaryUtil.java b/src/org/geometerplus/android/fbreader/DictionaryUtil.java
index f50e96a349c..73680d3eb69 100644
--- a/src/org/geometerplus/android/fbreader/DictionaryUtil.java
+++ b/src/org/geometerplus/android/fbreader/DictionaryUtil.java
@@ -45,7 +45,8 @@ public abstract class DictionaryUtil {
// Map: dictionary info -> hide if package is not installed
private static LinkedHashMap ourDictionaryInfos =
new LinkedHashMap();
- private static ZLStringOption ourDictionaryOption;
+ private static ZLStringOption ourSingleWordTranslatorOption;
+ private static ZLStringOption ourMultiWordTranslatorOption;
private static class InfoReader extends ZLXMLReaderAdapter {
@Override
@@ -113,15 +114,24 @@ private static PackageInfo firstInfo() {
throw new RuntimeException("There are no available dictionary infos");
}
- public static ZLStringOption dictionaryOption() {
- if (ourDictionaryOption == null) {
- ourDictionaryOption = new ZLStringOption("Dictionary", "Id", firstInfo().Id);
+ public static ZLStringOption singleWordTranslatorOption() {
+ if (ourSingleWordTranslatorOption == null) {
+ ourSingleWordTranslatorOption = new ZLStringOption("Dictionary", "Id", firstInfo().Id);
}
- return ourDictionaryOption;
+ return ourSingleWordTranslatorOption;
}
- private static PackageInfo getCurrentDictionaryInfo() {
- final String id = dictionaryOption().getValue();
+ public static ZLStringOption multiWordTranslatorOption() {
+ if (ourMultiWordTranslatorOption == null) {
+ ourMultiWordTranslatorOption = new ZLStringOption("Translator", "Id", firstInfo().Id);
+ }
+ return ourMultiWordTranslatorOption;
+ }
+
+ private static PackageInfo getCurrentDictionaryInfo(boolean singleWord) {
+ final ZLStringOption option = singleWord
+ ? singleWordTranslatorOption() : multiWordTranslatorOption();
+ final String id = option.getValue();
for (PackageInfo info : infos().keySet()) {
if (info.Id.equals(id)) {
return info;
@@ -130,8 +140,8 @@ private static PackageInfo getCurrentDictionaryInfo() {
return firstInfo();
}
- private static Intent getDictionaryIntent(String text) {
- return getDictionaryIntent(getCurrentDictionaryInfo(), text);
+ private static Intent getDictionaryIntent(String text, boolean singleWord) {
+ return getDictionaryIntent(getCurrentDictionaryInfo(singleWord), text);
}
public static Intent getDictionaryIntent(PackageInfo dictionaryInfo, String text) {
@@ -154,8 +164,8 @@ public static Intent getDictionaryIntent(PackageInfo dictionaryInfo, String text
}
}
- public static void openTextInDictionary(Activity activity, String text, int selectionTop, int selectionBottom) {
- final PackageInfo info = getCurrentDictionaryInfo();
+ public static void openTextInDictionary(Activity activity, String text, boolean singleWord, int selectionTop, int selectionBottom) {
+ final PackageInfo info = getCurrentDictionaryInfo(singleWord);
final Intent intent = getDictionaryIntent(info, text);
try {
if ("ColorDict".equals(info.Id)) {
@@ -175,7 +185,7 @@ public static void openTextInDictionary(Activity activity, String text, int sele
}
activity.startActivity(intent);
} catch (ActivityNotFoundException e) {
- DictionaryUtil.installDictionaryIfNotInstalled(activity);
+ DictionaryUtil.installDictionaryIfNotInstalled(activity, singleWord);
}
}
@@ -190,15 +200,15 @@ public static void openWordInDictionary(Activity activity, ZLTextWord word, ZLTe
}
openTextInDictionary(
- activity, text.substring(start, end), region.getTop(), region.getBottom()
+ activity, text.substring(start, end), true, region.getTop(), region.getBottom()
);
}
- public static void installDictionaryIfNotInstalled(final Activity activity) {
- if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test"), false)) {
+ public static void installDictionaryIfNotInstalled(final Activity activity, boolean singleWord) {
+ if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test", singleWord), false)) {
return;
}
- final PackageInfo dictionaryInfo = getCurrentDictionaryInfo();
+ final PackageInfo dictionaryInfo = getCurrentDictionaryInfo(singleWord);
final ZLResource dialogResource = ZLResource.resource("dialog");
final ZLResource buttonResource = dialogResource.getResource("button");
diff --git a/src/org/geometerplus/android/fbreader/FBReader.java b/src/org/geometerplus/android/fbreader/FBReader.java
index 1afafb69758..4a7eae9f4c1 100644
--- a/src/org/geometerplus/android/fbreader/FBReader.java
+++ b/src/org/geometerplus/android/fbreader/FBReader.java
@@ -101,8 +101,8 @@ public void onCreate(Bundle icicle) {
fbReader.addAction(ActionCode.SELECTION_HIDE_PANEL, new SelectionHidePanelAction(this, fbReader));
fbReader.addAction(ActionCode.SELECTION_COPY_TO_CLIPBOARD, new SelectionCopyAction(this, fbReader));
fbReader.addAction(ActionCode.SELECTION_SHARE, new SelectionShareAction(this, fbReader));
- fbReader.addAction(ActionCode.SELECTION_OPEN_IN_DICTIONARY, new SelectionDictionaryAction(this, fbReader));
- fbReader.addAction(ActionCode.SELECTION_ADD_BOOKMARK, new SelectionBookmarkAction(this, fbReader));
+ fbReader.addAction(ActionCode.SELECTION_TRANSLATE, new SelectionTranslateAction(this, fbReader));
+ fbReader.addAction(ActionCode.SELECTION_BOOKMARK, new SelectionBookmarkAction(this, fbReader));
fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader));
diff --git a/src/org/geometerplus/android/fbreader/SelectionPopup.java b/src/org/geometerplus/android/fbreader/SelectionPopup.java
index dfee9a3192d..bf76b86057b 100644
--- a/src/org/geometerplus/android/fbreader/SelectionPopup.java
+++ b/src/org/geometerplus/android/fbreader/SelectionPopup.java
@@ -48,8 +48,8 @@ public void createControlPanel(FBReader activity, RelativeLayout root, PopupWind
addButton(ActionCode.SELECTION_COPY_TO_CLIPBOARD, true, R.drawable.selection_copy);
addButton(ActionCode.SELECTION_SHARE, true, R.drawable.selection_share);
- addButton(ActionCode.SELECTION_OPEN_IN_DICTIONARY, true, R.drawable.selection_dictionary);
- addButton(ActionCode.SELECTION_ADD_BOOKMARK, true, R.drawable.selection_bookmark);
+ addButton(ActionCode.SELECTION_TRANSLATE, true, R.drawable.selection_translate);
+ addButton(ActionCode.SELECTION_BOOKMARK, true, R.drawable.selection_bookmark);
addButton(ActionCode.SELECTION_CLEAR, true, R.drawable.selection_close);
}
diff --git a/src/org/geometerplus/android/fbreader/SelectionDictionaryAction.java b/src/org/geometerplus/android/fbreader/SelectionTranslateAction.java
similarity index 88%
rename from src/org/geometerplus/android/fbreader/SelectionDictionaryAction.java
rename to src/org/geometerplus/android/fbreader/SelectionTranslateAction.java
index c0c4b554fc0..81c3172339a 100644
--- a/src/org/geometerplus/android/fbreader/SelectionDictionaryAction.java
+++ b/src/org/geometerplus/android/fbreader/SelectionTranslateAction.java
@@ -22,8 +22,8 @@
import org.geometerplus.fbreader.fbreader.FBReaderApp;
import org.geometerplus.fbreader.fbreader.FBView;
-public class SelectionDictionaryAction extends FBAndroidAction {
- SelectionDictionaryAction(FBReader baseActivity, FBReaderApp fbreader) {
+public class SelectionTranslateAction extends FBAndroidAction {
+ SelectionTranslateAction(FBReader baseActivity, FBReaderApp fbreader) {
super(baseActivity, fbreader);
}
@@ -32,7 +32,7 @@ public void run() {
final int selectionStartY = fbview.getSelectionStartY(), selectionEndY = fbview.getSelectionEndY();
final String text = fbview.getSelectedText();
Reader.getTextView().clearSelection();
- DictionaryUtil.openTextInDictionary(BaseActivity, text, selectionStartY, selectionEndY);
+ DictionaryUtil.openTextInDictionary(BaseActivity, text, false, selectionStartY, selectionEndY);
}
}
diff --git a/src/org/geometerplus/android/fbreader/preferences/DictionaryPreference.java b/src/org/geometerplus/android/fbreader/preferences/DictionaryPreference.java
index f5d734dabb3..b2d046a1596 100644
--- a/src/org/geometerplus/android/fbreader/preferences/DictionaryPreference.java
+++ b/src/org/geometerplus/android/fbreader/preferences/DictionaryPreference.java
@@ -32,10 +32,10 @@
class DictionaryPreference extends ZLStringListPreference {
private final ZLStringOption myOption;
- DictionaryPreference(Context context, ZLResource resource, String resourceKey) {
+ DictionaryPreference(Context context, ZLResource resource, String resourceKey, ZLStringOption dictionaryOption) {
super(context, resource, resourceKey);
- myOption = DictionaryUtil.dictionaryOption();
+ myOption = dictionaryOption;
final List infos = DictionaryUtil.dictionaryInfos(context);
final String[] values = new String[infos.size()];
diff --git a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java
index ed7e6a28874..c29c5a0d3bc 100644
--- a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java
+++ b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java
@@ -34,6 +34,8 @@
import org.geometerplus.fbreader.Paths;
import org.geometerplus.fbreader.bookmodel.FBTextKind;
+import org.geometerplus.android.fbreader.DictionaryUtil;
+
public class PreferenceActivity extends ZLPreferenceActivity {
public PreferenceActivity() {
super("Preferences");
@@ -375,7 +377,14 @@ protected void onClick() {
dictionaryScreen.addPreference(new DictionaryPreference(
this,
dictionaryScreen.Resource,
- "dictionary"
+ "dictionary",
+ DictionaryUtil.singleWordTranslatorOption()
+ ));
+ dictionaryScreen.addPreference(new DictionaryPreference(
+ this,
+ dictionaryScreen.Resource,
+ "translator",
+ DictionaryUtil.multiWordTranslatorOption()
));
dictionaryScreen.addPreference(new ZLBooleanPreference(
this,
diff --git a/src/org/geometerplus/fbreader/fbreader/ActionCode.java b/src/org/geometerplus/fbreader/fbreader/ActionCode.java
index 9f31f9b999c..f5138e25820 100644
--- a/src/org/geometerplus/fbreader/fbreader/ActionCode.java
+++ b/src/org/geometerplus/fbreader/fbreader/ActionCode.java
@@ -61,6 +61,6 @@ public interface ActionCode {
String SELECTION_CLEAR = "selectionClear";
String SELECTION_COPY_TO_CLIPBOARD = "selectionCopyToClipboard";
String SELECTION_SHARE = "selectionShare";
- String SELECTION_OPEN_IN_DICTIONARY = "selectionOpenInDictionary";
- String SELECTION_ADD_BOOKMARK = "selectionAddBookmark";
+ String SELECTION_TRANSLATE = "selectionTranslate";
+ String SELECTION_BOOKMARK = "selectionBookmark";
}