mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +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"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:drawable="@drawable/selection_dictionary_active" />
|
||||
<item android:drawable="@drawable/selection_dictionary_default" />
|
||||
<item android:state_pressed="true" android:drawable="@drawable/selection_translate_active" />
|
||||
<item android:drawable="@drawable/selection_translate_default" />
|
||||
</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
|
||||
private static LinkedHashMap<PackageInfo,Boolean> ourDictionaryInfos =
|
||||
new LinkedHashMap<PackageInfo,Boolean>();
|
||||
private static ZLStringOption ourDictionaryOption;
|
||||
private static ZLStringOption ourSingleWordTranslatorOption;
|
||||
private static ZLStringOption ourMultiWordTranslatorOption;
|
||||
|
||||
private static class InfoReader extends ZLXMLReaderAdapter {
|
||||
@Override
|
||||
|
@ -113,15 +114,24 @@ public abstract class DictionaryUtil {
|
|||
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 @@ public abstract class DictionaryUtil {
|
|||
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 abstract class DictionaryUtil {
|
|||
}
|
||||
}
|
||||
|
||||
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 abstract class DictionaryUtil {
|
|||
}
|
||||
activity.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
DictionaryUtil.installDictionaryIfNotInstalled(activity);
|
||||
DictionaryUtil.installDictionaryIfNotInstalled(activity, singleWord);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,15 +200,15 @@ public abstract class DictionaryUtil {
|
|||
}
|
||||
|
||||
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");
|
||||
|
|
|
@ -101,8 +101,8 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
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));
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ class SelectionPopup extends ButtonsPopupPanel {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ package org.geometerplus.android.fbreader;
|
|||
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 class SelectionDictionaryAction extends FBAndroidAction {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -32,10 +32,10 @@ import org.geometerplus.android.fbreader.PackageInfo;
|
|||
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<PackageInfo> infos = DictionaryUtil.dictionaryInfos(context);
|
||||
|
||||
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.bookmodel.FBTextKind;
|
||||
|
||||
import org.geometerplus.android.fbreader.DictionaryUtil;
|
||||
|
||||
public class PreferenceActivity extends ZLPreferenceActivity {
|
||||
public PreferenceActivity() {
|
||||
super("Preferences");
|
||||
|
@ -375,7 +377,14 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
|||
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,
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue