mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
renaming: dictionary => translate
This commit is contained in:
parent
fe64b6169d
commit
5df9f5fd9a
10 changed files with 49 additions and 30 deletions
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:state_pressed="true" android:drawable="@drawable/selection_dictionary_active" />
|
<item android:state_pressed="true" android:drawable="@drawable/selection_translate_active" />
|
||||||
<item android:drawable="@drawable/selection_dictionary_default" />
|
<item android:drawable="@drawable/selection_translate_default" />
|
||||||
</selector>
|
</selector>
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
@ -45,7 +45,8 @@ public abstract class DictionaryUtil {
|
||||||
// Map: dictionary info -> hide if package is not installed
|
// Map: dictionary info -> hide if package is not installed
|
||||||
private static LinkedHashMap<PackageInfo,Boolean> ourDictionaryInfos =
|
private static LinkedHashMap<PackageInfo,Boolean> ourDictionaryInfos =
|
||||||
new LinkedHashMap<PackageInfo,Boolean>();
|
new LinkedHashMap<PackageInfo,Boolean>();
|
||||||
private static ZLStringOption ourDictionaryOption;
|
private static ZLStringOption ourSingleWordTranslatorOption;
|
||||||
|
private static ZLStringOption ourMultiWordTranslatorOption;
|
||||||
|
|
||||||
private static class InfoReader extends ZLXMLReaderAdapter {
|
private static class InfoReader extends ZLXMLReaderAdapter {
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,15 +114,24 @@ public abstract class DictionaryUtil {
|
||||||
throw new RuntimeException("There are no available dictionary infos");
|
throw new RuntimeException("There are no available dictionary infos");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ZLStringOption dictionaryOption() {
|
public static ZLStringOption singleWordTranslatorOption() {
|
||||||
if (ourDictionaryOption == null) {
|
if (ourSingleWordTranslatorOption == null) {
|
||||||
ourDictionaryOption = new ZLStringOption("Dictionary", "Id", firstInfo().Id);
|
ourSingleWordTranslatorOption = new ZLStringOption("Dictionary", "Id", firstInfo().Id);
|
||||||
}
|
}
|
||||||
return ourDictionaryOption;
|
return ourSingleWordTranslatorOption;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PackageInfo getCurrentDictionaryInfo() {
|
public static ZLStringOption multiWordTranslatorOption() {
|
||||||
final String id = dictionaryOption().getValue();
|
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()) {
|
for (PackageInfo info : infos().keySet()) {
|
||||||
if (info.Id.equals(id)) {
|
if (info.Id.equals(id)) {
|
||||||
return info;
|
return info;
|
||||||
|
@ -130,8 +140,8 @@ public abstract class DictionaryUtil {
|
||||||
return firstInfo();
|
return firstInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Intent getDictionaryIntent(String text) {
|
private static Intent getDictionaryIntent(String text, boolean singleWord) {
|
||||||
return getDictionaryIntent(getCurrentDictionaryInfo(), text);
|
return getDictionaryIntent(getCurrentDictionaryInfo(singleWord), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Intent getDictionaryIntent(PackageInfo dictionaryInfo, String text) {
|
public static Intent getDictionaryIntent(PackageInfo dictionaryInfo, String text) {
|
||||||
|
@ -154,8 +164,8 @@ public abstract class DictionaryUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openTextInDictionary(Activity activity, String text, int selectionTop, int selectionBottom) {
|
public static void openTextInDictionary(Activity activity, String text, boolean singleWord, int selectionTop, int selectionBottom) {
|
||||||
final PackageInfo info = getCurrentDictionaryInfo();
|
final PackageInfo info = getCurrentDictionaryInfo(singleWord);
|
||||||
final Intent intent = getDictionaryIntent(info, text);
|
final Intent intent = getDictionaryIntent(info, text);
|
||||||
try {
|
try {
|
||||||
if ("ColorDict".equals(info.Id)) {
|
if ("ColorDict".equals(info.Id)) {
|
||||||
|
@ -175,7 +185,7 @@ public abstract class DictionaryUtil {
|
||||||
}
|
}
|
||||||
activity.startActivity(intent);
|
activity.startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
DictionaryUtil.installDictionaryIfNotInstalled(activity);
|
DictionaryUtil.installDictionaryIfNotInstalled(activity, singleWord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,15 +200,15 @@ public abstract class DictionaryUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
openTextInDictionary(
|
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) {
|
public static void installDictionaryIfNotInstalled(final Activity activity, boolean singleWord) {
|
||||||
if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test"), false)) {
|
if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test", singleWord), false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final PackageInfo dictionaryInfo = getCurrentDictionaryInfo();
|
final PackageInfo dictionaryInfo = getCurrentDictionaryInfo(singleWord);
|
||||||
|
|
||||||
final ZLResource dialogResource = ZLResource.resource("dialog");
|
final ZLResource dialogResource = ZLResource.resource("dialog");
|
||||||
final ZLResource buttonResource = dialogResource.getResource("button");
|
final ZLResource buttonResource = dialogResource.getResource("button");
|
||||||
|
|
|
@ -101,8 +101,8 @@ public final class FBReader extends ZLAndroidActivity {
|
||||||
fbReader.addAction(ActionCode.SELECTION_HIDE_PANEL, new SelectionHidePanelAction(this, fbReader));
|
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_COPY_TO_CLIPBOARD, new SelectionCopyAction(this, fbReader));
|
||||||
fbReader.addAction(ActionCode.SELECTION_SHARE, new SelectionShareAction(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_TRANSLATE, new SelectionTranslateAction(this, fbReader));
|
||||||
fbReader.addAction(ActionCode.SELECTION_ADD_BOOKMARK, new SelectionBookmarkAction(this, fbReader));
|
fbReader.addAction(ActionCode.SELECTION_BOOKMARK, new SelectionBookmarkAction(this, fbReader));
|
||||||
|
|
||||||
fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader));
|
fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader));
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ class SelectionPopup extends ButtonsPopupPanel {
|
||||||
|
|
||||||
addButton(ActionCode.SELECTION_COPY_TO_CLIPBOARD, true, R.drawable.selection_copy);
|
addButton(ActionCode.SELECTION_COPY_TO_CLIPBOARD, true, R.drawable.selection_copy);
|
||||||
addButton(ActionCode.SELECTION_SHARE, true, R.drawable.selection_share);
|
addButton(ActionCode.SELECTION_SHARE, true, R.drawable.selection_share);
|
||||||
addButton(ActionCode.SELECTION_OPEN_IN_DICTIONARY, true, R.drawable.selection_dictionary);
|
addButton(ActionCode.SELECTION_TRANSLATE, true, R.drawable.selection_translate);
|
||||||
addButton(ActionCode.SELECTION_ADD_BOOKMARK, true, R.drawable.selection_bookmark);
|
addButton(ActionCode.SELECTION_BOOKMARK, true, R.drawable.selection_bookmark);
|
||||||
addButton(ActionCode.SELECTION_CLEAR, true, R.drawable.selection_close);
|
addButton(ActionCode.SELECTION_CLEAR, true, R.drawable.selection_close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ package org.geometerplus.android.fbreader;
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
import org.geometerplus.fbreader.fbreader.FBView;
|
import org.geometerplus.fbreader.fbreader.FBView;
|
||||||
|
|
||||||
public class SelectionDictionaryAction extends FBAndroidAction {
|
public class SelectionTranslateAction extends FBAndroidAction {
|
||||||
SelectionDictionaryAction(FBReader baseActivity, FBReaderApp fbreader) {
|
SelectionTranslateAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
super(baseActivity, fbreader);
|
super(baseActivity, fbreader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class SelectionDictionaryAction extends FBAndroidAction {
|
||||||
final int selectionStartY = fbview.getSelectionStartY(), selectionEndY = fbview.getSelectionEndY();
|
final int selectionStartY = fbview.getSelectionStartY(), selectionEndY = fbview.getSelectionEndY();
|
||||||
final String text = fbview.getSelectedText();
|
final String text = fbview.getSelectedText();
|
||||||
Reader.getTextView().clearSelection();
|
Reader.getTextView().clearSelection();
|
||||||
DictionaryUtil.openTextInDictionary(BaseActivity, text, selectionStartY, selectionEndY);
|
DictionaryUtil.openTextInDictionary(BaseActivity, text, false, selectionStartY, selectionEndY);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -32,10 +32,10 @@ import org.geometerplus.android.fbreader.PackageInfo;
|
||||||
class DictionaryPreference extends ZLStringListPreference {
|
class DictionaryPreference extends ZLStringListPreference {
|
||||||
private final ZLStringOption myOption;
|
private final ZLStringOption myOption;
|
||||||
|
|
||||||
DictionaryPreference(Context context, ZLResource resource, String resourceKey) {
|
DictionaryPreference(Context context, ZLResource resource, String resourceKey, ZLStringOption dictionaryOption) {
|
||||||
super(context, resource, resourceKey);
|
super(context, resource, resourceKey);
|
||||||
|
|
||||||
myOption = DictionaryUtil.dictionaryOption();
|
myOption = dictionaryOption;
|
||||||
final List<PackageInfo> infos = DictionaryUtil.dictionaryInfos(context);
|
final List<PackageInfo> infos = DictionaryUtil.dictionaryInfos(context);
|
||||||
|
|
||||||
final String[] values = new String[infos.size()];
|
final String[] values = new String[infos.size()];
|
||||||
|
|
|
@ -34,6 +34,8 @@ import org.geometerplus.fbreader.fbreader.*;
|
||||||
import org.geometerplus.fbreader.Paths;
|
import org.geometerplus.fbreader.Paths;
|
||||||
import org.geometerplus.fbreader.bookmodel.FBTextKind;
|
import org.geometerplus.fbreader.bookmodel.FBTextKind;
|
||||||
|
|
||||||
|
import org.geometerplus.android.fbreader.DictionaryUtil;
|
||||||
|
|
||||||
public class PreferenceActivity extends ZLPreferenceActivity {
|
public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
public PreferenceActivity() {
|
public PreferenceActivity() {
|
||||||
super("Preferences");
|
super("Preferences");
|
||||||
|
@ -375,7 +377,14 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
dictionaryScreen.addPreference(new DictionaryPreference(
|
dictionaryScreen.addPreference(new DictionaryPreference(
|
||||||
this,
|
this,
|
||||||
dictionaryScreen.Resource,
|
dictionaryScreen.Resource,
|
||||||
"dictionary"
|
"dictionary",
|
||||||
|
DictionaryUtil.singleWordTranslatorOption()
|
||||||
|
));
|
||||||
|
dictionaryScreen.addPreference(new DictionaryPreference(
|
||||||
|
this,
|
||||||
|
dictionaryScreen.Resource,
|
||||||
|
"translator",
|
||||||
|
DictionaryUtil.multiWordTranslatorOption()
|
||||||
));
|
));
|
||||||
dictionaryScreen.addPreference(new ZLBooleanPreference(
|
dictionaryScreen.addPreference(new ZLBooleanPreference(
|
||||||
this,
|
this,
|
||||||
|
|
|
@ -61,6 +61,6 @@ public interface ActionCode {
|
||||||
String SELECTION_CLEAR = "selectionClear";
|
String SELECTION_CLEAR = "selectionClear";
|
||||||
String SELECTION_COPY_TO_CLIPBOARD = "selectionCopyToClipboard";
|
String SELECTION_COPY_TO_CLIPBOARD = "selectionCopyToClipboard";
|
||||||
String SELECTION_SHARE = "selectionShare";
|
String SELECTION_SHARE = "selectionShare";
|
||||||
String SELECTION_OPEN_IN_DICTIONARY = "selectionOpenInDictionary";
|
String SELECTION_TRANSLATE = "selectionTranslate";
|
||||||
String SELECTION_ADD_BOOKMARK = "selectionAddBookmark";
|
String SELECTION_BOOKMARK = "selectionBookmark";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue