diff --git a/ChangeLog b/ChangeLog index c41be12ac..23016d14d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ ===== 1.4.5 (Apr ??, 2012) ===== +* book sharing via e-mail, skype, etc +* 'Open library' and 'Open network library' items in back button menu * ePub reader does not fail if NCX file in referenced but missing * native plugin does not crash if cache file cannot be created diff --git a/assets/resources/application/en.xml b/assets/resources/application/en.xml index 8c3b126a3..6074a3e7a 100644 --- a/assets/resources/application/en.xml +++ b/assets/resources/application/en.xml @@ -212,6 +212,8 @@ + + @@ -245,6 +247,7 @@ + @@ -651,6 +654,14 @@ + + + + + + + + diff --git a/assets/resources/application/ru.xml b/assets/resources/application/ru.xml index 573be2022..0306d0e98 100644 --- a/assets/resources/application/ru.xml +++ b/assets/resources/application/ru.xml @@ -43,6 +43,7 @@ + @@ -222,6 +223,8 @@ + + @@ -255,6 +258,7 @@ + diff --git a/src/org/geometerplus/android/fbreader/ButtonsPopupPanel.java b/src/org/geometerplus/android/fbreader/ButtonsPopupPanel.java index 123123dbd..52bfff831 100644 --- a/src/org/geometerplus/android/fbreader/ButtonsPopupPanel.java +++ b/src/org/geometerplus/android/fbreader/ButtonsPopupPanel.java @@ -62,7 +62,7 @@ abstract class ButtonsPopupPanel extends PopupPanel implements View.OnClickListe public void onClick(View view) { final ActionButton button = (ActionButton)view; - Application.doAction(button.ActionId); + Application.runAction(button.ActionId); if (button.IsCloseButton) { storePosition(); StartPosition = null; diff --git a/src/org/geometerplus/android/fbreader/FBReader.java b/src/org/geometerplus/android/fbreader/FBReader.java index e19abdd3a..8c5dd55b4 100644 --- a/src/org/geometerplus/android/fbreader/FBReader.java +++ b/src/org/geometerplus/android/fbreader/FBReader.java @@ -150,6 +150,7 @@ public final class FBReader extends ZLAndroidActivity { fbReader.addAction(ActionCode.SHOW_MENU, new ShowMenuAction(this, fbReader)); fbReader.addAction(ActionCode.SHOW_NAVIGATION, new ShowNavigationAction(this, fbReader)); fbReader.addAction(ActionCode.SEARCH, new SearchAction(this, fbReader)); + fbReader.addAction(ActionCode.SHARE_BOOK, new ShareBookAction(this, fbReader)); fbReader.addAction(ActionCode.SELECTION_SHOW_PANEL, new SelectionShowPanelAction(this, fbReader)); fbReader.addAction(ActionCode.SELECTION_HIDE_PANEL, new SelectionHidePanelAction(this, fbReader)); @@ -207,7 +208,7 @@ public final class FBReader extends ZLAndroidActivity { super.onNewIntent(intent); } else if (Intent.ACTION_VIEW.equals(intent.getAction()) && data != null && "fbreader-action".equals(data.getScheme())) { - fbReader.doAction(data.getEncodedSchemeSpecificPart(), data.getFragment()); + fbReader.runAction(data.getEncodedSchemeSpecificPart(), data.getFragment()); } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) { final String pattern = intent.getStringExtra(SearchManager.QUERY); final Runnable runnable = new Runnable() { @@ -441,6 +442,7 @@ public final class FBReader extends ZLAndroidActivity { addMenuItem(menu, ActionCode.SWITCH_TO_NIGHT_PROFILE, R.drawable.ic_menu_night); addMenuItem(menu, ActionCode.SWITCH_TO_DAY_PROFILE, R.drawable.ic_menu_day); addMenuItem(menu, ActionCode.SEARCH, R.drawable.ic_menu_search); + addMenuItem(menu, ActionCode.SHARE_BOOK, R.drawable.ic_menu_search); addMenuItem(menu, ActionCode.SHOW_PREFERENCES); addMenuItem(menu, ActionCode.SHOW_BOOK_INFO); final Menu subMenu = addSubMenu(menu, "screenOrientation"); diff --git a/src/org/geometerplus/android/fbreader/ShareBookAction.java b/src/org/geometerplus/android/fbreader/ShareBookAction.java new file mode 100644 index 000000000..885bf3b4f --- /dev/null +++ b/src/org/geometerplus/android/fbreader/ShareBookAction.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2012 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.fbreader.fbreader.FBReaderApp; + +public class ShareBookAction extends FBAndroidAction { + ShareBookAction(FBReader baseActivity, FBReaderApp fbreader) { + super(baseActivity, fbreader); + } + + @Override + public boolean isVisible() { + return Reader.Model != null && Reader.Model.Book.File.getPhysicalFile() != null; + } + + @Override + protected void run(Object ... params) { + Util.shareBook(BaseActivity, Reader.Model.Book); + } +} diff --git a/src/org/geometerplus/android/fbreader/Util.java b/src/org/geometerplus/android/fbreader/Util.java new file mode 100644 index 000000000..fafb8f056 --- /dev/null +++ b/src/org/geometerplus/android/fbreader/Util.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2010-2012 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 android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.net.Uri; + +import org.geometerplus.zlibrary.core.filesystem.ZLPhysicalFile; + +import org.geometerplus.fbreader.library.Book; +import org.geometerplus.fbreader.filetype.FileTypeCollection; + +public abstract class Util { + public static void shareBook(Activity activity, Book book) { + try { + final ZLPhysicalFile file = book.File.getPhysicalFile(); + if (file == null) { + // That should be impossible + return; + } + activity.startActivity( + new Intent(Intent.ACTION_SEND) + .setType(FileTypeCollection.Instance.mimeType(book.File).Name) + .putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file.javaFile())) + ); + } catch (ActivityNotFoundException e) { + // TODO: show toast + } + } +} diff --git a/src/org/geometerplus/android/fbreader/library/LibraryActivity.java b/src/org/geometerplus/android/fbreader/library/LibraryActivity.java index 54bf5f728..9deda20fa 100644 --- a/src/org/geometerplus/android/fbreader/library/LibraryActivity.java +++ b/src/org/geometerplus/android/fbreader/library/LibraryActivity.java @@ -21,7 +21,6 @@ package org.geometerplus.android.fbreader.library; import android.app.AlertDialog; import android.content.*; -import android.net.Uri; import android.os.Bundle; import android.view.*; import android.widget.AdapterView; @@ -37,10 +36,10 @@ import org.geometerplus.zlibrary.ui.android.R; import org.geometerplus.fbreader.library.*; import org.geometerplus.fbreader.tree.FBTree; -import org.geometerplus.fbreader.filetype.FileTypeCollection; import org.geometerplus.android.util.UIUtil; import org.geometerplus.android.fbreader.FBReader; +import org.geometerplus.android.fbreader.Util; import org.geometerplus.android.fbreader.tree.TreeActivity; public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItemClickListener, View.OnCreateContextMenuListener, Library.ChangeListener { @@ -132,23 +131,6 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem ); } - private void shareBook(Book book) { - try { - final ZLPhysicalFile file = book.File.getPhysicalFile(); - if (file == null) { - // That should be impossible - return; - } - startActivity( - new Intent(Intent.ACTION_SEND) - .setType(FileTypeCollection.Instance.mimeType(book.File).Name) - .putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file.javaFile())) - ); - } catch (ActivityNotFoundException e) { - // TODO: show toast - } - } - @Override protected void onActivityResult(int requestCode, int returnCode, Intent intent) { if (requestCode == BOOK_INFO_REQUEST && intent != null) { @@ -236,7 +218,7 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem showBookInfo(book); return true; case SHARE_BOOK_ITEM_ID: - shareBook(book); + Util.shareBook(this, book); return true; case ADD_TO_FAVORITES_ITEM_ID: myLibrary.addBookToFavorites(book); diff --git a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java index 8c2614eda..ddd772881 100644 --- a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java +++ b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java @@ -433,6 +433,8 @@ public class PreferenceActivity extends ZLPreferenceActivity { imagesScreen.addOption(fbReader.ImageViewBackgroundOption, "backgroundColor"); final Screen cancelMenuScreen = createPreferenceScreen("cancelMenu"); + cancelMenuScreen.addOption(fbReader.ShowLibraryInCancelMenuOption, "library"); + cancelMenuScreen.addOption(fbReader.ShowNetworkLibraryInCancelMenuOption, "networkLibrary"); cancelMenuScreen.addOption(fbReader.ShowPreviousBookInCancelMenuOption, "previousBook"); cancelMenuScreen.addOption(fbReader.ShowPositionsInCancelMenuOption, "positions"); final String[] backKeyActions = diff --git a/src/org/geometerplus/fbreader/fbreader/ActionCode.java b/src/org/geometerplus/fbreader/fbreader/ActionCode.java index 8abd447e7..214036a53 100644 --- a/src/org/geometerplus/fbreader/fbreader/ActionCode.java +++ b/src/org/geometerplus/fbreader/fbreader/ActionCode.java @@ -30,6 +30,8 @@ public interface ActionCode { String SWITCH_TO_NIGHT_PROFILE = "night"; String SWITCH_TO_DAY_PROFILE = "day"; + String SHARE_BOOK = "shareBook"; + String SEARCH = "search"; String FIND_PREVIOUS = "findPrevious"; String FIND_NEXT = "findNext"; diff --git a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java index c172f8ba7..c4edeb1a4 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java +++ b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java @@ -97,6 +97,10 @@ public final class FBReaderApp extends ZLApplication { final ZLStringOption ColorProfileOption = new ZLStringOption("Options", "ColorProfile", ColorProfile.DAY); + public final ZLBooleanOption ShowLibraryInCancelMenuOption = + new ZLBooleanOption("CancelMenu", "library", true); + public final ZLBooleanOption ShowNetworkLibraryInCancelMenuOption = + new ZLBooleanOption("CancelMenu", "networkLibrary", false); public final ZLBooleanOption ShowPreviousBookInCancelMenuOption = new ZLBooleanOption("CancelMenu", "previousBook", false); public final ZLBooleanOption ShowPositionsInCancelMenuOption = @@ -362,6 +366,8 @@ public final class FBReaderApp extends ZLApplication { } static enum CancelActionType { + library, + networkLibrary, previousBook, returnTo, close @@ -394,6 +400,16 @@ public final class FBReaderApp extends ZLApplication { public List getCancelActionsList() { myCancelActionsList.clear(); + if (ShowLibraryInCancelMenuOption.getValue()) { + myCancelActionsList.add(new CancelActionDescription( + CancelActionType.library, null + )); + } + if (ShowNetworkLibraryInCancelMenuOption.getValue()) { + myCancelActionsList.add(new CancelActionDescription( + CancelActionType.networkLibrary, null + )); + } if (ShowPreviousBookInCancelMenuOption.getValue()) { final Book previousBook = Library.Instance().getPreviousBook(); if (previousBook != null) { @@ -422,6 +438,12 @@ public final class FBReaderApp extends ZLApplication { final CancelActionDescription description = myCancelActionsList.get(index); switch (description.Type) { + case library: + runAction(ActionCode.SHOW_LIBRARY); + break; + case networkLibrary: + runAction(ActionCode.SHOW_NETWORK_LIBRARY); + break; case previousBook: openBook(Library.Instance().getPreviousBook(), null, null); break; diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java index f4a9412c2..8811df9f8 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBView.java +++ b/src/org/geometerplus/fbreader/fbreader/FBView.java @@ -79,11 +79,11 @@ public final class FBView extends ZLTextView { selectRegion(region); myReader.getViewWidget().reset(); myReader.getViewWidget().repaint(); - myReader.doAction(ActionCode.PROCESS_HYPERLINK); + myReader.runAction(ActionCode.PROCESS_HYPERLINK); return true; } - myReader.doAction(getZoneMap().getActionByCoordinates( + myReader.runAction(getZoneMap().getActionByCoordinates( x, y, myContext.getWidth(), myContext.getHeight(), isDoubleTapSupported() ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.singleTap ), x, y); @@ -101,7 +101,7 @@ public final class FBView extends ZLTextView { if (super.onFingerDoubleTap(x, y)) { return true; } - myReader.doAction(getZoneMap().getActionByCoordinates( + myReader.runAction(getZoneMap().getActionByCoordinates( x, y, myContext.getWidth(), myContext.getHeight(), TapZoneMap.Tap.doubleTap ), x, y); return true; @@ -114,7 +114,7 @@ public final class FBView extends ZLTextView { final ZLTextSelectionCursor cursor = findSelectionCursor(x, y, MAX_SELECTION_DISTANCE); if (cursor != ZLTextSelectionCursor.None) { - myReader.doAction(ActionCode.SELECTION_HIDE_PANEL); + myReader.runAction(ActionCode.SELECTION_HIDE_PANEL); moveSelectionCursorTo(cursor, x, y); return true; } @@ -216,7 +216,7 @@ public final class FBView extends ZLTextView { if (soul instanceof ZLTextWordRegionSoul) { switch (myReader.WordTappingActionOption.getValue()) { case startSelecting: - myReader.doAction(ActionCode.SELECTION_HIDE_PANEL); + myReader.runAction(ActionCode.SELECTION_HIDE_PANEL); initSelection(x, y); final ZLTextSelectionCursor cursor = findSelectionCursor(x, y); if (cursor != ZLTextSelectionCursor.None) { @@ -308,7 +308,7 @@ public final class FBView extends ZLTextView { } if (doRunAction) { - myReader.doAction(ActionCode.PROCESS_HYPERLINK); + myReader.runAction(ActionCode.PROCESS_HYPERLINK); return true; } } @@ -584,7 +584,7 @@ public final class FBView extends ZLTextView { protected void releaseSelectionCursor() { super.releaseSelectionCursor(); if (getCountOfSelectedWords() > 0) { - myReader.doAction(ActionCode.SELECTION_SHOW_PANEL); + myReader.runAction(ActionCode.SELECTION_SHOW_PANEL); } } diff --git a/src/org/geometerplus/zlibrary/core/application/ZLApplication.java b/src/org/geometerplus/zlibrary/core/application/ZLApplication.java index 9254c4c53..16ac4a00a 100644 --- a/src/org/geometerplus/zlibrary/core/application/ZLApplication.java +++ b/src/org/geometerplus/zlibrary/core/application/ZLApplication.java @@ -141,7 +141,7 @@ public abstract class ZLApplication { return action != null ? action.isChecked() : ZLBoolean3.B3_UNDEFINED; } - public final void doAction(String actionId, Object ... params) { + public final void runAction(String actionId, Object ... params) { final ZLAction action = myIdToActionMap.get(actionId); if (action != null) { action.checkAndRun(params); @@ -156,7 +156,7 @@ public abstract class ZLApplication { return actionId != null && !NoAction.equals(actionId); } - public final boolean doActionByKey(int key, boolean longPress) { + public final boolean runActionByKey(int key, boolean longPress) { final String actionId = keyBindings().getBinding(key, longPress); if (actionId != null) { final ZLAction action = myIdToActionMap.get(actionId); diff --git a/src/org/geometerplus/zlibrary/ui/android/application/ZLAndroidApplicationWindow.java b/src/org/geometerplus/zlibrary/ui/android/application/ZLAndroidApplicationWindow.java index 11cf964ae..ff180f11f 100644 --- a/src/org/geometerplus/zlibrary/ui/android/application/ZLAndroidApplicationWindow.java +++ b/src/org/geometerplus/zlibrary/ui/android/application/ZLAndroidApplicationWindow.java @@ -46,7 +46,7 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow { private final MenuItem.OnMenuItemClickListener myMenuListener = new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { - getApplication().doAction(myMenuItemMap.get(item)); + getApplication().runAction(myMenuItemMap.get(item)); return true; } }; diff --git a/src/org/geometerplus/zlibrary/ui/android/view/ZLAndroidWidget.java b/src/org/geometerplus/zlibrary/ui/android/view/ZLAndroidWidget.java index dc405ef70..de51d6777 100644 --- a/src/org/geometerplus/zlibrary/ui/android/view/ZLAndroidWidget.java +++ b/src/org/geometerplus/zlibrary/ui/android/view/ZLAndroidWidget.java @@ -406,7 +406,7 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl myTrackingStartTime = System.currentTimeMillis(); return true; } else { - return application.doActionByKey(keyCode, false); + return application.runActionByKey(keyCode, false); } } else { return false; @@ -418,7 +418,7 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl if (myKeyUnderTracking == keyCode) { final boolean longPress = System.currentTimeMillis() > myTrackingStartTime + ViewConfiguration.getLongPressTimeout(); - ZLApplication.Instance().doActionByKey(keyCode, longPress); + ZLApplication.Instance().runActionByKey(keyCode, longPress); } myKeyUnderTracking = -1; return true;