mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
extra parameters in ZLActions
This commit is contained in:
parent
042cc633cf
commit
345dd95384
29 changed files with 89 additions and 67 deletions
|
@ -177,8 +177,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());
|
||||
System.err.println("fragment = " + data.getFragment());
|
||||
fbReader.doAction(data.getEncodedSchemeSpecificPart(), data.getFragment());
|
||||
} else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
||||
final String pattern = intent.getStringExtra(SearchManager.QUERY);
|
||||
final Runnable runnable = new Runnable() {
|
||||
|
|
|
@ -40,11 +40,13 @@ class ProcessHyperlinkAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return Reader.getTextView().getSelectedRegion() != null;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
final ZLTextRegion region = Reader.getTextView().getSelectedRegion();
|
||||
if (region == null) {
|
||||
return;
|
||||
|
|
|
@ -31,7 +31,8 @@ abstract class RunActivityAction extends FBAndroidAction {
|
|||
myActivityClass = activityClass;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
BaseActivity.startActivity(new Intent(BaseActivity.getApplicationContext(), myActivityClass));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ class RunPluginAction extends FBAndroidAction {
|
|||
myUri = uri;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
try {
|
||||
BaseActivity.startActivity(new Intent("android.fbreader.action.plugin.RUN", myUri));
|
||||
} catch (ActivityNotFoundException e) {
|
||||
|
|
|
@ -26,11 +26,13 @@ class SearchAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return Reader.Model != null;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
BaseActivity.onSearchRequested();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ public class SelectionBookmarkAction extends FBAndroidAction {
|
|||
super(baseApplication, fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
final FBView fbview = Reader.getTextView();
|
||||
final String text = fbview.getSelectedText();
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@ public class SelectionCopyAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
final String text = Reader.getTextView().getSelectedText();
|
||||
Reader.getTextView().clearSelection();
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class SelectionHidePanelAction extends FBAndroidAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
protected void run(Object ... params) {
|
||||
BaseActivity.hideSelectionPanel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ public class SelectionShareAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
final String text = Reader.getTextView().getSelectedText();
|
||||
final String title = Reader.Model.Book.getTitle();
|
||||
Reader.getTextView().clearSelection();
|
||||
|
|
|
@ -32,7 +32,7 @@ class SelectionShowPanelAction extends FBAndroidAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
protected void run(Object ... params) {
|
||||
BaseActivity.showSelectionPanel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ public class SelectionTranslateAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
final FBView fbview = Reader.getTextView();
|
||||
DictionaryUtil.openTextInDictionary(
|
||||
BaseActivity,
|
||||
|
|
|
@ -30,11 +30,13 @@ class ShowBookInfoAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return Reader.Model != null;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
BaseActivity.startActivityForResult(
|
||||
new Intent(BaseActivity.getApplicationContext(), BookInfoActivity.class)
|
||||
.putExtra(BookInfoActivity.CURRENT_BOOK_PATH_KEY, Reader.Model.Book.File.getPath())
|
||||
|
|
|
@ -30,7 +30,8 @@ class ShowCancelMenuAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
if (Reader.getCurrentView() != Reader.BookTextView) {
|
||||
Reader.showBookTextView();
|
||||
} else {
|
||||
|
|
|
@ -31,7 +31,8 @@ class ShowLibraryAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
final BookModel model = Reader.Model;
|
||||
Intent intent = new Intent(BaseActivity.getApplicationContext(), LibraryActivity.class);
|
||||
if (model != null && model.Book != null) {
|
||||
|
|
|
@ -26,7 +26,8 @@ class ShowMenuAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
BaseActivity.openOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,8 @@ class ShowNavigationAction extends FBAndroidAction {
|
|||
return textModel != null && textModel.getParagraphsNumber() != 0;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
BaseActivity.navigate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,13 @@ class ShowPreferencesAction extends FBAndroidAction {
|
|||
super(baseActivity, fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
BaseActivity.startActivityForResult(
|
||||
new Intent(BaseActivity.getApplicationContext(), PreferenceActivity.class),
|
||||
FBReader.REPAINT_CODE
|
||||
);
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
final Intent intent =
|
||||
new Intent(BaseActivity.getApplicationContext(), PreferenceActivity.class);
|
||||
if (params.length == 1 && params[0] instanceof String) {
|
||||
intent.putExtra(PreferenceActivity.SCREEN_KEY, (String)params[0]);
|
||||
}
|
||||
BaseActivity.startActivityForResult(intent, FBReader.REPAINT_CODE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ class ChangeFontSizeAction extends FBAction {
|
|||
myDelta = delta;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
ZLIntegerRangeOption option =
|
||||
ZLTextStyleCollection.Instance().getBaseStyle().FontSizeOption;
|
||||
option.setValue(option.getValue() + myDelta);
|
||||
|
|
|
@ -24,7 +24,8 @@ class ClearFindResultsAction extends FBAction {
|
|||
super(fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
Reader.getTextView().clearFindResults();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ class ExitAction extends FBAction {
|
|||
super(fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
if (Reader.getCurrentView() != Reader.BookTextView) {
|
||||
Reader.showBookTextView();
|
||||
} else {
|
||||
|
|
|
@ -83,7 +83,7 @@ public final class FBView extends ZLTextView {
|
|||
return true;
|
||||
}
|
||||
|
||||
myReader.doActionWithCoordinates(getZoneMap().getActionByCoordinates(
|
||||
myReader.doAction(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.doActionWithCoordinates(getZoneMap().getActionByCoordinates(
|
||||
myReader.doAction(getZoneMap().getActionByCoordinates(
|
||||
x, y, myContext.getWidth(), myContext.getHeight(), TapZoneMap.Tap.doubleTap
|
||||
), x, y);
|
||||
return true;
|
||||
|
|
|
@ -24,12 +24,14 @@ class FindNextAction extends FBAction {
|
|||
super(fbreader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
FBView view = Reader.getTextView();
|
||||
return (view != null) && view.canFindNext();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
Reader.getTextView().findNext();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,12 +26,14 @@ class FindPreviousAction extends FBAction {
|
|||
super(fbreader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
ZLTextView view = Reader.getTextView();
|
||||
return (view != null) && view.canFindPrevious();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
Reader.getTextView().findPrevious();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,12 @@ class RotateAction extends FBAction {
|
|||
super(fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
protected void run(Object ... params) {
|
||||
Reader.rotateScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return Reader.canRotateScreen();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class SelectionClearAction extends FBAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
protected void run(Object ... params) {
|
||||
Reader.getTextView().clearSelection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,13 @@ class SwitchProfileAction extends FBAction {
|
|||
myProfileName = profileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return !myProfileName.equals(Reader.getColorProfileName());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
public void run(Object ... params) {
|
||||
Reader.setColorProfileName(myProfileName);
|
||||
Reader.getViewWidget().reset();
|
||||
Reader.getViewWidget().repaint();
|
||||
|
|
|
@ -27,6 +27,7 @@ class TurnPageAction extends FBAction {
|
|||
myForward = forward;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
|
||||
|
||||
|
@ -37,24 +38,26 @@ class TurnPageAction extends FBAction {
|
|||
fingerScrolling == ScrollingPreferences.FingerScrolling.byTapAndFlick;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
public void run(Object ... params) {
|
||||
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
|
||||
Reader.getViewWidget().startAnimatedScrolling(
|
||||
myForward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
preferences.HorizontalOption.getValue()
|
||||
? FBView.Direction.rightToLeft : FBView.Direction.up,
|
||||
preferences.AnimationSpeedOption.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
public void runWithCoordinates(int x, int y) {
|
||||
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
|
||||
Reader.getViewWidget().startAnimatedScrolling(
|
||||
myForward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
x, y,
|
||||
preferences.HorizontalOption.getValue()
|
||||
? FBView.Direction.rightToLeft : FBView.Direction.up,
|
||||
preferences.AnimationSpeedOption.getValue()
|
||||
);
|
||||
if (params.length == 2 && params[0] instanceof Integer && params[1] instanceof Integer) {
|
||||
final int x = (Integer)params[0];
|
||||
final int y = (Integer)params[1];
|
||||
Reader.getViewWidget().startAnimatedScrolling(
|
||||
myForward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
x, y,
|
||||
preferences.HorizontalOption.getValue()
|
||||
? FBView.Direction.rightToLeft : FBView.Direction.up,
|
||||
preferences.AnimationSpeedOption.getValue()
|
||||
);
|
||||
} else {
|
||||
Reader.getViewWidget().startAnimatedScrolling(
|
||||
myForward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
preferences.HorizontalOption.getValue()
|
||||
? FBView.Direction.rightToLeft : FBView.Direction.up,
|
||||
preferences.AnimationSpeedOption.getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ class VolumeKeyTurnPageAction extends FBAction {
|
|||
myForward = forward;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
public void run(Object ... params) {
|
||||
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
|
||||
Reader.getViewWidget().startAnimatedScrolling(
|
||||
myForward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
|
|
|
@ -129,17 +129,10 @@ public abstract class ZLApplication {
|
|||
return (action != null) && action.isEnabled();
|
||||
}
|
||||
|
||||
public final void doAction(String actionId) {
|
||||
public final void doAction(String actionId, Object ... params) {
|
||||
final ZLAction action = myIdToActionMap.get(actionId);
|
||||
if (action != null) {
|
||||
action.checkAndRun();
|
||||
}
|
||||
}
|
||||
|
||||
public final void doActionWithCoordinates(String actionId, int x, int y) {
|
||||
final ZLAction action = myIdToActionMap.get(actionId);
|
||||
if (action != null && action.isEnabled()) {
|
||||
action.runWithCoordinates(x, y);
|
||||
action.checkAndRun(params);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,19 +189,15 @@ public abstract class ZLApplication {
|
|||
return isVisible();
|
||||
}
|
||||
|
||||
public final boolean checkAndRun() {
|
||||
public final boolean checkAndRun(Object ... params) {
|
||||
if (isEnabled()) {
|
||||
run();
|
||||
run(params);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
abstract protected void run();
|
||||
|
||||
protected void runWithCoordinates(int x, int y) {
|
||||
run();
|
||||
}
|
||||
abstract protected void run(Object ... params);
|
||||
}
|
||||
|
||||
public static abstract class PopupPanel {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue