mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
common base class for all android actions
This commit is contained in:
parent
392a131ccd
commit
c98b56d182
9 changed files with 38 additions and 73 deletions
|
@ -27,7 +27,6 @@ import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
import org.geometerplus.fbreader.bookmodel.FBHyperlinkType;
|
import org.geometerplus.fbreader.bookmodel.FBHyperlinkType;
|
||||||
import org.geometerplus.fbreader.network.NetworkLibrary;
|
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||||
|
@ -36,14 +35,11 @@ import org.geometerplus.android.fbreader.network.BookDownloader;
|
||||||
import org.geometerplus.android.fbreader.network.BookDownloaderService;
|
import org.geometerplus.android.fbreader.network.BookDownloaderService;
|
||||||
import org.geometerplus.android.fbreader.image.ImageViewActivity;
|
import org.geometerplus.android.fbreader.image.ImageViewActivity;
|
||||||
|
|
||||||
class ProcessHyperlinkAction extends FBAction {
|
class ProcessHyperlinkAction extends FBAndroidAction {
|
||||||
private static final String ACTION_LINK_PREFIX = "fbreader-action://";
|
private static final String ACTION_LINK_PREFIX = "fbreader-action://";
|
||||||
|
|
||||||
private final FBReader myBaseActivity;
|
|
||||||
|
|
||||||
ProcessHyperlinkAction(FBReader baseActivity, FBReaderApp fbreader) {
|
ProcessHyperlinkAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
super(fbreader);
|
super(baseActivity, fbreader);
|
||||||
myBaseActivity = baseActivity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
@ -76,20 +72,20 @@ class ProcessHyperlinkAction extends FBAction {
|
||||||
if (uriString != null) {
|
if (uriString != null) {
|
||||||
try {
|
try {
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.setClass(myBaseActivity, ImageViewActivity.class);
|
intent.setClass(BaseActivity, ImageViewActivity.class);
|
||||||
intent.setData(Uri.parse(uriString));
|
intent.setData(Uri.parse(uriString));
|
||||||
intent.putExtra(
|
intent.putExtra(
|
||||||
ImageViewActivity.BACKGROUND_COLOR_KEY,
|
ImageViewActivity.BACKGROUND_COLOR_KEY,
|
||||||
Reader.ImageViewBackgroundOption.getValue().getIntValue()
|
Reader.ImageViewBackgroundOption.getValue().getIntValue()
|
||||||
);
|
);
|
||||||
myBaseActivity.startActivity(intent);
|
BaseActivity.startActivity(intent);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (region instanceof ZLTextWordRegion) {
|
} else if (region instanceof ZLTextWordRegion) {
|
||||||
DictionaryUtil.openWordInDictionary(
|
DictionaryUtil.openWordInDictionary(
|
||||||
myBaseActivity, (ZLTextWordRegion)region
|
BaseActivity, (ZLTextWordRegion)region
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +94,7 @@ class ProcessHyperlinkAction extends FBAction {
|
||||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
boolean externalUrl = true;
|
boolean externalUrl = true;
|
||||||
if (BookDownloader.acceptsUri(Uri.parse(urlString))) {
|
if (BookDownloader.acceptsUri(Uri.parse(urlString))) {
|
||||||
intent.setClass(myBaseActivity, BookDownloader.class);
|
intent.setClass(BaseActivity, BookDownloader.class);
|
||||||
intent.putExtra(BookDownloaderService.SHOW_NOTIFICATIONS_KEY, BookDownloaderService.Notifications.ALL);
|
intent.putExtra(BookDownloaderService.SHOW_NOTIFICATIONS_KEY, BookDownloaderService.Notifications.ALL);
|
||||||
externalUrl = false;
|
externalUrl = false;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +105,7 @@ class ProcessHyperlinkAction extends FBAction {
|
||||||
}
|
}
|
||||||
intent.setData(Uri.parse(NetworkLibrary.Instance().rewriteUrl(urlString, externalUrl)));
|
intent.setData(Uri.parse(NetworkLibrary.Instance().rewriteUrl(urlString, externalUrl)));
|
||||||
try {
|
try {
|
||||||
myBaseActivity.startActivity(intent);
|
BaseActivity.startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
// TODO: show an error message
|
// TODO: show an error message
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,20 +21,17 @@ package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
|
||||||
abstract class RunActivityAction extends FBAction {
|
abstract class RunActivityAction extends FBAndroidAction {
|
||||||
private final FBReader myBaseActivity;
|
|
||||||
private final Class<?> myActivityClass;
|
private final Class<?> myActivityClass;
|
||||||
|
|
||||||
RunActivityAction(FBReader baseActivity, FBReaderApp fbreader, Class<?> activityClass) {
|
RunActivityAction(FBReader baseActivity, FBReaderApp fbreader, Class<?> activityClass) {
|
||||||
super(fbreader);
|
super(baseActivity, fbreader);
|
||||||
myBaseActivity = baseActivity;
|
|
||||||
myActivityClass = activityClass;
|
myActivityClass = activityClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
myBaseActivity.startActivity(new Intent(myBaseActivity.getApplicationContext(), myActivityClass));
|
BaseActivity.startActivity(new Intent(BaseActivity.getApplicationContext(), myActivityClass));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,10 @@
|
||||||
package org.geometerplus.android.fbreader;
|
package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
|
||||||
|
|
||||||
class SearchAction extends FBAction {
|
class SearchAction extends FBAndroidAction {
|
||||||
private final FBReader myActivity;
|
SearchAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
|
super(baseActivity, fbreader);
|
||||||
SearchAction(FBReader activity, FBReaderApp fbreader) {
|
|
||||||
super(fbreader);
|
|
||||||
myActivity = activity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVisible() {
|
public boolean isVisible() {
|
||||||
|
@ -35,6 +31,6 @@ class SearchAction extends FBAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
myActivity.onSearchRequested();
|
BaseActivity.onSearchRequested();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,11 @@ package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
|
||||||
class ShowBookInfoAction extends FBAction {
|
class ShowBookInfoAction extends FBAndroidAction {
|
||||||
private final FBReader myBaseActivity;
|
|
||||||
|
|
||||||
ShowBookInfoAction(FBReader baseActivity, FBReaderApp fbreader) {
|
ShowBookInfoAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
super(fbreader);
|
super(baseActivity, fbreader);
|
||||||
myBaseActivity = baseActivity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVisible() {
|
public boolean isVisible() {
|
||||||
|
@ -37,8 +33,8 @@ class ShowBookInfoAction extends FBAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
myBaseActivity.startActivityForResult(
|
BaseActivity.startActivityForResult(
|
||||||
new Intent(myBaseActivity.getApplicationContext(), BookInfoActivity.class)
|
new Intent(BaseActivity.getApplicationContext(), BookInfoActivity.class)
|
||||||
.putExtra(BookInfoActivity.CURRENT_BOOK_PATH_KEY, Reader.Model.Book.File.getPath())
|
.putExtra(BookInfoActivity.CURRENT_BOOK_PATH_KEY, Reader.Model.Book.File.getPath())
|
||||||
.putExtra(BookInfoActivity.HIDE_OPEN_BUTTON_KEY, true),
|
.putExtra(BookInfoActivity.HIDE_OPEN_BUTTON_KEY, true),
|
||||||
FBReader.REPAINT_CODE
|
FBReader.REPAINT_CODE
|
||||||
|
|
|
@ -23,15 +23,11 @@ import java.util.List;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
|
||||||
class ShowCancelMenuAction extends FBAction {
|
class ShowCancelMenuAction extends FBAndroidAction {
|
||||||
private final FBReader myBaseActivity;
|
|
||||||
|
|
||||||
ShowCancelMenuAction(FBReader baseActivity, FBReaderApp fbreader) {
|
ShowCancelMenuAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
super(fbreader);
|
super(baseActivity, fbreader);
|
||||||
myBaseActivity = baseActivity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -44,7 +40,7 @@ class ShowCancelMenuAction extends FBAction {
|
||||||
Reader.closeWindow();
|
Reader.closeWindow();
|
||||||
} else {
|
} else {
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.setClass(myBaseActivity, CancelActivity.class);
|
intent.setClass(BaseActivity, CancelActivity.class);
|
||||||
intent.putExtra(CancelActivity.LIST_SIZE, descriptionList.size());
|
intent.putExtra(CancelActivity.LIST_SIZE, descriptionList.size());
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (FBReaderApp.CancelActionDescription description : descriptionList) {
|
for (FBReaderApp.CancelActionDescription description : descriptionList) {
|
||||||
|
@ -52,7 +48,7 @@ class ShowCancelMenuAction extends FBAction {
|
||||||
intent.putExtra(CancelActivity.ITEM_SUMMARY + index, description.Summary);
|
intent.putExtra(CancelActivity.ITEM_SUMMARY + index, description.Summary);
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
myBaseActivity.startActivityForResult(intent, FBReader.CANCEL_CODE);
|
BaseActivity.startActivityForResult(intent, FBReader.CANCEL_CODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,26 +21,22 @@ package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.library.LibraryTopLevelActivity;
|
import org.geometerplus.android.fbreader.library.LibraryTopLevelActivity;
|
||||||
|
|
||||||
class ShowLibraryAction extends FBAction {
|
class ShowLibraryAction extends FBAndroidAction {
|
||||||
private final FBReader myBaseActivity;
|
|
||||||
|
|
||||||
ShowLibraryAction(FBReader baseActivity, FBReaderApp fbreader) {
|
ShowLibraryAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
super(fbreader);
|
super(baseActivity, fbreader);
|
||||||
myBaseActivity = baseActivity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
final BookModel model = Reader.Model;
|
final BookModel model = Reader.Model;
|
||||||
Intent intent = new Intent(myBaseActivity.getApplicationContext(), LibraryTopLevelActivity.class);
|
Intent intent = new Intent(BaseActivity.getApplicationContext(), LibraryTopLevelActivity.class);
|
||||||
if (model != null && model.Book != null) {
|
if (model != null && model.Book != null) {
|
||||||
intent.putExtra(LibraryTopLevelActivity.SELECTED_BOOK_PATH_KEY, model.Book.File.getPath());
|
intent.putExtra(LibraryTopLevelActivity.SELECTED_BOOK_PATH_KEY, model.Book.File.getPath());
|
||||||
}
|
}
|
||||||
myBaseActivity.startActivity(intent);
|
BaseActivity.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,18 +19,14 @@
|
||||||
|
|
||||||
package org.geometerplus.android.fbreader;
|
package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
|
||||||
class ShowMenuAction extends FBAction {
|
class ShowMenuAction extends FBAndroidAction {
|
||||||
private final FBReader myActivity;
|
ShowMenuAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
|
super(baseActivity, fbreader);
|
||||||
ShowMenuAction(FBReader activity, FBReaderApp fbreader) {
|
|
||||||
super(fbreader);
|
|
||||||
myActivity = activity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
myActivity.openOptionsMenu();
|
BaseActivity.openOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,11 @@ package org.geometerplus.android.fbreader;
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextView;
|
import org.geometerplus.zlibrary.text.view.ZLTextView;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
|
||||||
class ShowNavigationAction extends FBAction {
|
class ShowNavigationAction extends FBAndroidAction {
|
||||||
private final FBReader myActivity;
|
ShowNavigationAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
|
super(baseActivity, fbreader);
|
||||||
ShowNavigationAction(FBReader activity, FBReaderApp fbreader) {
|
|
||||||
super(fbreader);
|
|
||||||
myActivity = activity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,6 +37,6 @@ class ShowNavigationAction extends FBAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
myActivity.navigate();
|
BaseActivity.navigate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,22 +21,18 @@ package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.preferences.PreferenceActivity;
|
import org.geometerplus.android.fbreader.preferences.PreferenceActivity;
|
||||||
|
|
||||||
class ShowPreferencesAction extends FBAction {
|
class ShowPreferencesAction extends FBAndroidAction {
|
||||||
private final FBReader myBaseActivity;
|
|
||||||
|
|
||||||
ShowPreferencesAction(FBReader baseActivity, FBReaderApp fbreader) {
|
ShowPreferencesAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
super(fbreader);
|
super(baseActivity, fbreader);
|
||||||
myBaseActivity = baseActivity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
myBaseActivity.startActivityForResult(
|
BaseActivity.startActivityForResult(
|
||||||
new Intent(myBaseActivity.getApplicationContext(), PreferenceActivity.class),
|
new Intent(BaseActivity.getApplicationContext(), PreferenceActivity.class),
|
||||||
FBReader.REPAINT_CODE
|
FBReader.REPAINT_CODE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue