mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
getCurrentFilter() method is replaced by a method argument
This commit is contained in:
parent
c0874a3c5e
commit
f1ee1ee676
9 changed files with 27 additions and 44 deletions
|
@ -36,13 +36,13 @@ import org.geometerplus.zlibrary.core.view.ZLView;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextView;
|
import org.geometerplus.zlibrary.text.view.ZLTextView;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextViewMode;
|
|
||||||
import org.geometerplus.zlibrary.ui.android.R;
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidActivity;
|
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidActivity;
|
||||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
|
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.ActionCode;
|
import org.geometerplus.fbreader.fbreader.ActionCode;
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
import org.geometerplus.fbreader.fbreader.FBView;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.library.KillerCallback;
|
import org.geometerplus.android.fbreader.library.KillerCallback;
|
||||||
|
|
||||||
|
@ -137,8 +137,8 @@ public final class FBReader extends ZLAndroidActivity {
|
||||||
fbReader.addAction(ActionCode.SEARCH, new SearchAction(this, fbReader));
|
fbReader.addAction(ActionCode.SEARCH, new SearchAction(this, fbReader));
|
||||||
|
|
||||||
fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader));
|
fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader));
|
||||||
fbReader.addAction(ActionCode.SET_TEXT_VIEW_MODE_VISIT_HYPERLINKS, new SwitchTextViewModeAction(this, fbReader, ZLTextViewMode.MODE_VISIT_HYPERLINKS));
|
fbReader.addAction(ActionCode.SET_TEXT_VIEW_MODE_VISIT_HYPERLINKS, new SwitchTextViewModeAction(this, fbReader, FBView.MODE_VISIT_HYPERLINKS));
|
||||||
fbReader.addAction(ActionCode.SET_TEXT_VIEW_MODE_VISIT_ALL_WORDS, new SwitchTextViewModeAction(this, fbReader, ZLTextViewMode.MODE_VISIT_ALL_WORDS));
|
fbReader.addAction(ActionCode.SET_TEXT_VIEW_MODE_VISIT_ALL_WORDS, new SwitchTextViewModeAction(this, fbReader, FBView.MODE_VISIT_ALL_WORDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.geometerplus.android.fbreader;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.widget.Toast;
|
//import android.widget.Toast;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
@ -80,11 +80,14 @@ class ProcessHyperlinkAction extends FBAction {
|
||||||
try {
|
try {
|
||||||
myBaseActivity.startActivity(intent);
|
myBaseActivity.startActivity(intent);
|
||||||
} catch(ActivityNotFoundException e){
|
} catch(ActivityNotFoundException e){
|
||||||
|
DictionaryUtil.installDictionaryIfNotInstalled(myBaseActivity);
|
||||||
|
/*
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
myBaseActivity,
|
myBaseActivity,
|
||||||
ZLResource.resource("errorMessage").getResource("dictionaryIsNotInstalled").getValue(),
|
ZLResource.resource("errorMessage").getResource("dictionaryIsNotInstalled").getValue(),
|
||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
).show();
|
).show();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
package org.geometerplus.android.fbreader;
|
package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextViewMode;
|
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
import org.geometerplus.fbreader.fbreader.FBAction;
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
|
||||||
|
@ -41,10 +39,6 @@ class SwitchTextViewModeAction extends FBAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (myMode == ZLTextViewMode.MODE_VISIT_ALL_WORDS) {
|
|
||||||
DictionaryUtil.installDictionaryIfNotInstalled(myBaseActivity);
|
|
||||||
}
|
|
||||||
|
|
||||||
Reader.TextViewModeOption.setValue(myMode);
|
Reader.TextViewModeOption.setValue(myMode);
|
||||||
Reader.BookTextView.resetRegionPointer();
|
Reader.BookTextView.resetRegionPointer();
|
||||||
Reader.FootnoteView.resetRegionPointer();
|
Reader.FootnoteView.resetRegionPointer();
|
||||||
|
|
|
@ -94,7 +94,7 @@ public final class FBView extends ZLTextView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
final ZLTextElementRegion region = findRegion(x, y, 10);
|
final ZLTextElementRegion region = findRegion(x, y, 10, getRegionFilter());
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
final int action = myReader.DictionaryModeTappingActionOption.getValue();
|
final int action = myReader.DictionaryModeTappingActionOption.getValue();
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ public final class FBView extends ZLTextView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ZLTextElementRegion region = findRegion(x, y, 10);
|
final ZLTextElementRegion region = findRegion(x, y, 10, getRegionFilter());
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
selectRegion(region);
|
selectRegion(region);
|
||||||
myReader.repaintView();
|
myReader.repaintView();
|
||||||
|
@ -263,7 +263,7 @@ public final class FBView extends ZLTextView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ZLTextElementRegion region = findRegion(x, y, 10);
|
final ZLTextElementRegion region = findRegion(x, y, 10, getRegionFilter());
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
selectRegion(region);
|
selectRegion(region);
|
||||||
myReader.repaintView();
|
myReader.repaintView();
|
||||||
|
@ -280,7 +280,7 @@ public final class FBView extends ZLTextView {
|
||||||
(diffY > 0 ? Direction.DOWN : Direction.UP) :
|
(diffY > 0 ? Direction.DOWN : Direction.UP) :
|
||||||
(diffX > 0 ? Direction.RIGHT : Direction.LEFT);
|
(diffX > 0 ? Direction.RIGHT : Direction.LEFT);
|
||||||
|
|
||||||
if (!moveRegionPointer(direction)) {
|
if (!moveRegionPointer(direction, getRegionFilter())) {
|
||||||
if (direction == Direction.DOWN) {
|
if (direction == Direction.DOWN) {
|
||||||
scrollPage(true, ZLTextView.ScrollingMode.SCROLL_LINES, 1);
|
scrollPage(true, ZLTextView.ScrollingMode.SCROLL_LINES, 1);
|
||||||
} else if (direction == Direction.UP) {
|
} else if (direction == Direction.UP) {
|
||||||
|
@ -293,9 +293,16 @@ public final class FBView extends ZLTextView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public final static int MODE_VISIT_HYPERLINKS = 0;
|
||||||
public int getMode() {
|
public final static int MODE_VISIT_ALL_WORDS = 1;
|
||||||
return myReader.TextViewModeOption.getValue();
|
private ZLTextElementRegion.Filter getRegionFilter() {
|
||||||
|
switch (myReader.TextViewModeOption.getValue()) {
|
||||||
|
default:
|
||||||
|
case MODE_VISIT_ALL_WORDS:
|
||||||
|
return ZLTextElementRegion.Filter;
|
||||||
|
case MODE_VISIT_HYPERLINKS:
|
||||||
|
return ZLTextHyperlinkRegion.Filter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,11 +24,11 @@ import java.util.*;
|
||||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||||
|
|
||||||
public abstract class ZLTextElementRegion {
|
public abstract class ZLTextElementRegion {
|
||||||
static interface Filter {
|
public static interface Filter {
|
||||||
boolean accepts(ZLTextElementRegion region);
|
boolean accepts(ZLTextElementRegion region);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Filter Filter = new Filter() {
|
public static Filter Filter = new Filter() {
|
||||||
public boolean accepts(ZLTextElementRegion region) {
|
public boolean accepts(ZLTextElementRegion region) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.geometerplus.zlibrary.text.view;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ZLTextHyperlinkRegion extends ZLTextElementRegion {
|
public class ZLTextHyperlinkRegion extends ZLTextElementRegion {
|
||||||
static Filter Filter = new Filter() {
|
public static Filter Filter = new Filter() {
|
||||||
public boolean accepts(ZLTextElementRegion region) {
|
public boolean accepts(ZLTextElementRegion region) {
|
||||||
return region instanceof ZLTextHyperlinkRegion;
|
return region instanceof ZLTextHyperlinkRegion;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1314,8 +1314,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ZLTextElementRegion findRegion(int x, int y, int maxDistance) {
|
protected ZLTextElementRegion findRegion(int x, int y, int maxDistance, ZLTextElementRegion.Filter filter) {
|
||||||
final ZLTextElementRegion.Filter filter = getCurrentFilter();
|
|
||||||
ZLTextElementRegion bestRegion = null;
|
ZLTextElementRegion bestRegion = null;
|
||||||
int distance = maxDistance + 1;
|
int distance = maxDistance + 1;
|
||||||
for (ZLTextElementRegion region : myCurrentPage.TextElementMap.ElementRegions) {
|
for (ZLTextElementRegion region : myCurrentPage.TextElementMap.ElementRegions) {
|
||||||
|
@ -1345,17 +1344,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
int DOWN = 3;
|
int DOWN = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZLTextElementRegion.Filter getCurrentFilter() {
|
protected boolean moveRegionPointer(int direction, ZLTextElementRegion.Filter filter) {
|
||||||
switch (getMode()) {
|
|
||||||
default:
|
|
||||||
case MODE_VISIT_ALL_WORDS:
|
|
||||||
return ZLTextElementRegion.Filter;
|
|
||||||
case MODE_VISIT_HYPERLINKS:
|
|
||||||
return ZLTextHyperlinkRegion.Filter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean moveRegionPointer(int direction) {
|
|
||||||
final ArrayList<ZLTextElementRegion> elementRegions = myCurrentPage.TextElementMap.ElementRegions;
|
final ArrayList<ZLTextElementRegion> elementRegions = myCurrentPage.TextElementMap.ElementRegions;
|
||||||
if (elementRegions.isEmpty()) {
|
if (elementRegions.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1385,8 +1374,6 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ZLTextElementRegion.Filter filter = getCurrentFilter();
|
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case Direction.LEFT:
|
case Direction.LEFT:
|
||||||
for (; index >= 0; --index) {
|
for (; index >= 0; --index) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||||
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection;
|
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection;
|
||||||
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleDecoration;
|
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleDecoration;
|
||||||
|
|
||||||
abstract class ZLTextViewBase extends ZLView implements ZLTextViewMode {
|
abstract class ZLTextViewBase extends ZLView {
|
||||||
private ZLTextStyle myTextStyle;
|
private ZLTextStyle myTextStyle;
|
||||||
private int myWordHeight = -1;
|
private int myWordHeight = -1;
|
||||||
|
|
||||||
|
@ -47,8 +47,6 @@ abstract class ZLTextViewBase extends ZLView implements ZLTextViewMode {
|
||||||
public abstract int getTopMargin();
|
public abstract int getTopMargin();
|
||||||
public abstract int getBottomMargin();
|
public abstract int getBottomMargin();
|
||||||
|
|
||||||
public abstract int getMode();
|
|
||||||
|
|
||||||
public abstract ZLColor getBackgroundColor();
|
public abstract ZLColor getBackgroundColor();
|
||||||
public abstract ZLColor getSelectedBackgroundColor();
|
public abstract ZLColor getSelectedBackgroundColor();
|
||||||
public abstract ZLColor getTextColor(byte hyperlinkType);
|
public abstract ZLColor getTextColor(byte hyperlinkType);
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
package org.geometerplus.zlibrary.text.view;
|
|
||||||
|
|
||||||
public interface ZLTextViewMode {
|
|
||||||
int MODE_VISIT_HYPERLINKS = 0;
|
|
||||||
int MODE_VISIT_ALL_WORDS = 1;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue