Skip to content

Commit

Permalink
renaming: dictionary => translate
Browse files Browse the repository at this point in the history
  • Loading branch information
geometer committed Jun 11, 2011
1 parent fe64b61 commit 5df9f5f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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>
42 changes: 26 additions & 16 deletions src/org/geometerplus/android/fbreader/DictionaryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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)) {
Expand All @@ -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);
}
}

Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/org/geometerplus/android/fbreader/FBReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions src/org/geometerplus/android/fbreader/SelectionPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<PackageInfo> infos = DictionaryUtil.dictionaryInfos(context);

final String[] values = new String[infos.size()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/org/geometerplus/fbreader/fbreader/ActionCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

0 comments on commit 5df9f5f

Please sign in to comment.