Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved handling of the backkey longpress, added more actions to backkey/backkey longpress screens. #284

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions assets/resources/application/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -795,11 +795,20 @@
</node>
<node name="backKeyAction" value="Back key action">
<node name="exit" value="Close FBReader"/>
<node name="goToPreferences" value="Go directly to your preferences"/>
<node name="goToPreviousBook" value="Go directly to your previously opened book"/>
<node name="goToLibrary" value="Go directly to your library"/>
<node name="goToNetworkLibrary" value="Go directly to your network library"/>
<node name="goBack" value="Navigate back"/>
<node name="cancelMenu" value="Show cancel menu"/>
<node name="none" value="No action"/>
</node>
<node name="backKeyLongPressAction" value="Back key long press action">
<node name="exit" value="Close FBReader"/>
<node name="goToPreferences" value="Go directly to your preferences"/>
<node name="goToPreviousBook" value="Go directly to your previously opened book"/>
<node name="goToLibrary" value="Go directly to your library"/>
<node name="goToNetworkLibrary" value="Go directly to your network library"/>
<node name="goBack" value="Navigate back"/>
<node name="cancelMenu" value="Show cancel menu"/>
<node name="none" value="No action"/>
Expand Down
4 changes: 4 additions & 0 deletions src/org/geometerplus/android/fbreader/FBReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ public void run() {
myFBReaderApp.addAction(ActionCode.OPEN_VIDEO, new OpenVideoAction(this, myFBReaderApp));

myFBReaderApp.addAction(ActionCode.SHOW_CANCEL_MENU, new ShowCancelMenuAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.GO_TO_PREFERENCES, new ShowPreferencesAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.GO_TO_LIBRARY, new ShowLibraryAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.GO_TO_NETWORK_LIBRARY, new ShowNetworkLibraryAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.GO_TO_PREVIOUS_BOOK, new GoToPreviousBookAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.OPEN_START_SCREEN, new StartScreenAction(this, myFBReaderApp));

myFBReaderApp.addAction(ActionCode.SET_SCREEN_ORIENTATION_SYSTEM, new SetScreenOrientationAction(this, myFBReaderApp, ZLibrary.SCREEN_ORIENTATION_SYSTEM));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,17 +716,21 @@ protected void onDialogClosed(boolean result) {
cancelMenuScreen.addOption(cancelMenuHelper.ShowNetworkLibraryItemOption, "networkLibrary");
cancelMenuScreen.addOption(cancelMenuHelper.ShowPreviousBookItemOption, "previousBook");
cancelMenuScreen.addOption(cancelMenuHelper.ShowPositionItemsOption, "positions");
final String[] backKeyActions =
{ ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU };
final String[] backKeyAndBackKeyLongPressActions = {
ActionCode.SHOW_CANCEL_MENU,
ActionCode.GO_TO_PREFERENCES,
ActionCode.GO_TO_LIBRARY,
ActionCode.GO_TO_NETWORK_LIBRARY,
ActionCode.GO_TO_PREVIOUS_BOOK,
ActionCode.EXIT,
FBReaderApp.NoAction };
cancelMenuScreen.addPreference(new ZLStringChoicePreference(
this, cancelMenuScreen.Resource.getResource("backKeyAction"),
keyBindings.getOption(KeyEvent.KEYCODE_BACK, false), backKeyActions
keyBindings.getOption(KeyEvent.KEYCODE_BACK, false), backKeyAndBackKeyLongPressActions
));
final String[] backKeyLongPressActions =
{ ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU, FBReaderApp.NoAction };
cancelMenuScreen.addPreference(new ZLStringChoicePreference(
this, cancelMenuScreen.Resource.getResource("backKeyLongPressAction"),
keyBindings.getOption(KeyEvent.KEYCODE_BACK, true), backKeyLongPressActions
keyBindings.getOption(KeyEvent.KEYCODE_BACK, true), backKeyAndBackKeyLongPressActions
));

final Screen tipsScreen = createPreferenceScreen("tips");
Expand Down
4 changes: 4 additions & 0 deletions src/org/geometerplus/fbreader/fbreader/ActionCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public interface ActionCode {
String GO_BACK = "goBack";
String EXIT = "exit";
String SHOW_CANCEL_MENU = "cancelMenu";
String GO_TO_PREFERENCES = "goToPreferences";
String GO_TO_LIBRARY = "goToLibrary";
String GO_TO_NETWORK_LIBRARY = "goToNetworkLibrary";
String GO_TO_PREVIOUS_BOOK = "goToPreviousBook";

String SET_SCREEN_ORIENTATION_SYSTEM = "screenOrientationSystem";
String SET_SCREEN_ORIENTATION_SENSOR = "screenOrientationSensor";
Expand Down
40 changes: 40 additions & 0 deletions src/org/geometerplus/fbreader/fbreader/GoToPreviousBookAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2007-2014 Geometer Plus <[email protected]>
*
* 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.book.Book;
import org.geometerplus.fbreader.fbreader.FBReaderApp;

import group.pals.android.lib.ui.filechooser.utils.ui.Dlg;

class GoToPreviousBookAction extends FBAndroidAction {
GoToPreviousBookAction(FBReader baseActivity, FBReaderApp fbreader) {
super(baseActivity, fbreader);
}

@Override
protected void run(Object ... params) {
Book recentBook = Reader.Collection.getRecentBook(1);
// TODO: use resource file
Dlg.toast(BaseActivity, recentBook == null ?
"No previous book" : "Returned to " + recentBook.getTitle(), 1);
Reader.openBook(recentBook, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,13 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
bindings.hasBinding(keyCode, false)) {
if (myKeyUnderTracking != -1) {
if (myKeyUnderTracking == keyCode) {
return true;
final boolean longPress = System.currentTimeMillis() >
myTrackingStartTime + ViewConfiguration.getLongPressTimeout()/3;
if(longPress) {
application.runActionByKey(keyCode, longPress);
myKeyUnderTracking = -1;
}
return longPress;
} else {
myKeyUnderTracking = -1;
}
Expand All @@ -468,9 +474,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (myKeyUnderTracking != -1) {
if (myKeyUnderTracking == keyCode) {
final boolean longPress = System.currentTimeMillis() >
myTrackingStartTime + ViewConfiguration.getLongPressTimeout();
ZLApplication.Instance().runActionByKey(keyCode, longPress);
ZLApplication.Instance().runActionByKey(keyCode, false);
}
myKeyUnderTracking = -1;
return true;
Expand Down