mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
TextSearchControls: changed to be more universal
ZLTextMark: code cleanup git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@954 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
cf8344e1ac
commit
cb7925da6b
6 changed files with 64 additions and 69 deletions
|
@ -1,24 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/tools_plate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/zoom_plate"
|
||||
android:gravity="bottom"
|
||||
android:paddingLeft="15dip"
|
||||
android:paddingRight="15dip">
|
||||
<ZoomButton android:id="@+id/previous"
|
||||
android:background="@drawable/text_search_previous"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<ZoomButton android:id="@+id/close"
|
||||
android:background="@drawable/text_search_close"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<ZoomButton android:id="@+id/next"
|
||||
android:background="@drawable/text_search_next"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.geometerplus.android.fbreader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.content.Context;
|
||||
|
@ -33,10 +35,21 @@ import org.geometerplus.zlibrary.ui.android.R;
|
|||
import org.geometerplus.zlibrary.core.application.ZLApplication;
|
||||
import org.geometerplus.fbreader.fbreader.ActionCode;
|
||||
|
||||
class ActionButton extends ZoomButton {
|
||||
final String ActionId;
|
||||
final boolean IsCloseButton;
|
||||
|
||||
ActionButton(Context context, String actionId, boolean isCloseButton) {
|
||||
super(context);
|
||||
ActionId = actionId;
|
||||
IsCloseButton = isCloseButton;
|
||||
setImageResource(R.drawable.text_search_previous);
|
||||
}
|
||||
}
|
||||
|
||||
public class TextSearchControls extends LinearLayout implements View.OnClickListener {
|
||||
private final ZoomButton myFindPreviousButton;
|
||||
private final ZoomButton myFindNextButton;
|
||||
private final ZoomButton myCloseButton;
|
||||
private final ArrayList<ActionButton> myButtons = new ArrayList<ActionButton>();
|
||||
private final LinearLayout myPlateLayout;
|
||||
|
||||
public TextSearchControls(Context context) {
|
||||
super(context);
|
||||
|
@ -46,36 +59,25 @@ public class TextSearchControls extends LinearLayout implements View.OnClickList
|
|||
final LayoutInflater inflater =
|
||||
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater.inflate(R.layout.text_search_controls, this, true);
|
||||
//setBackgroundResource(android.R.drawable.zoom_plate);
|
||||
//setPadding(15, 15, 15, 0);
|
||||
myPlateLayout = (LinearLayout)findViewById(R.id.tools_plate);
|
||||
|
||||
myFindPreviousButton = (ZoomButton)findViewById(R.id.previous);
|
||||
//myFindPreviousButton = new ZoomButton(context);
|
||||
//myFindPreviousButton.setImageResource(R.drawable.text_search_previous);
|
||||
myFindPreviousButton.setOnClickListener(this);
|
||||
//addView(myFindPreviousButton);
|
||||
addButton(ActionCode.FIND_PREVIOUS, false, R.drawable.text_search_previous);
|
||||
addButton(ActionCode.CLEAR_FIND_RESULTS, true, R.drawable.text_search_close);
|
||||
addButton(ActionCode.FIND_NEXT, false, R.drawable.text_search_next);
|
||||
}
|
||||
|
||||
myCloseButton = (ZoomButton)findViewById(R.id.close);
|
||||
//myCloseButton = new ZoomButton(context);
|
||||
//myCloseButton.setImageResource(R.drawable.text_search_close);
|
||||
myCloseButton.setEnabled(true);
|
||||
myCloseButton.setOnClickListener(this);
|
||||
//addView(myCloseButton);
|
||||
|
||||
myFindNextButton = (ZoomButton)findViewById(R.id.next);
|
||||
//myFindNextButton = new ZoomButton(context);
|
||||
//myFindNextButton.setImageResource(R.drawable.text_search_next);
|
||||
myFindNextButton.setOnClickListener(this);
|
||||
//addView(myFindNextButton);
|
||||
public void addButton(String actionId, boolean isCloseButton, int imageId) {
|
||||
final ActionButton button = new ActionButton(getContext(), actionId, isCloseButton);
|
||||
button.setImageResource(imageId);
|
||||
button.setOnClickListener(this);
|
||||
myPlateLayout.addView(button);
|
||||
myButtons.add(button);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if (view == myFindPreviousButton) {
|
||||
ZLApplication.Instance().doAction(ActionCode.FIND_PREVIOUS);
|
||||
} else if (view == myFindNextButton) {
|
||||
ZLApplication.Instance().doAction(ActionCode.FIND_NEXT);
|
||||
} else {
|
||||
ZLApplication.Instance().doAction(ActionCode.CLEAR_FIND_RESULTS);
|
||||
final ActionButton button = (ActionButton)view;
|
||||
ZLApplication.Instance().doAction(button.ActionId);
|
||||
if (button.IsCloseButton) {
|
||||
hide(true);
|
||||
}
|
||||
}
|
||||
|
@ -128,12 +130,18 @@ public class TextSearchControls extends LinearLayout implements View.OnClickList
|
|||
|
||||
public void updateStates() {
|
||||
final ZLApplication application = ZLApplication.Instance();
|
||||
myFindNextButton.setEnabled(application.isActionEnabled(ActionCode.FIND_NEXT));
|
||||
myFindPreviousButton.setEnabled(application.isActionEnabled(ActionCode.FIND_PREVIOUS));
|
||||
for (ActionButton button : myButtons) {
|
||||
button.setEnabled(application.isActionEnabled(button.ActionId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFocus() {
|
||||
return myFindPreviousButton.hasFocus() || myFindNextButton.hasFocus() || myCloseButton.hasFocus();
|
||||
for (ActionButton button : myButtons) {
|
||||
if (button.hasFocus()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,17 +19,11 @@
|
|||
|
||||
package org.geometerplus.zlibrary.text.model;
|
||||
|
||||
public class ZLTextMark {
|
||||
public class ZLTextMark implements Comparable<ZLTextMark> {
|
||||
public final int ParagraphIndex;
|
||||
public final int Offset;
|
||||
public final int Length;
|
||||
|
||||
public ZLTextMark() {
|
||||
ParagraphIndex = -1;
|
||||
Offset = -1;
|
||||
Length = -1;
|
||||
}
|
||||
|
||||
public ZLTextMark(int paragraphIndex, int offset, int length) {
|
||||
ParagraphIndex = paragraphIndex;
|
||||
Offset = offset;
|
||||
|
|
|
@ -285,37 +285,43 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
}
|
||||
|
||||
public ZLTextMark getFirstMark() {
|
||||
return myMarks.size() == 0 ? new ZLTextMark() : myMarks.get(0);
|
||||
return myMarks.isEmpty() ? null : myMarks.get(0);
|
||||
}
|
||||
|
||||
public ZLTextMark getLastMark() {
|
||||
return myMarks.size() == 0 ? new ZLTextMark() : myMarks.get(myMarks.size() - 1);
|
||||
return myMarks.isEmpty() ? null : myMarks.get(myMarks.size() - 1);
|
||||
}
|
||||
|
||||
public ZLTextMark getNextMark(ZLTextMark position) {
|
||||
if (position == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ZLTextMark mark = null;
|
||||
for (int i = 0; i < myMarks.size(); i++) {
|
||||
ZLTextMark current = myMarks.get(i);
|
||||
if (current.compareTo(position) > 0) {
|
||||
for (ZLTextMark current : myMarks) {
|
||||
if (current.compareTo(position) >= 0) {
|
||||
if ((mark == null) || (mark.compareTo(current) > 0)) {
|
||||
mark = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (mark != null) ? mark : new ZLTextMark();
|
||||
return mark;
|
||||
}
|
||||
|
||||
public ZLTextMark getPreviousMark(ZLTextMark position) {
|
||||
if (position == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ZLTextMark mark = null;
|
||||
for (int i = 0; i < myMarks.size(); i++) {
|
||||
ZLTextMark current = myMarks.get(i);
|
||||
if (current.compareTo(position) < 0) {
|
||||
for (ZLTextMark current : myMarks) {
|
||||
if (current.compareTo(position) <= 0) {
|
||||
if ((mark == null) || (mark.compareTo(current) < 0)) {
|
||||
mark = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (mark != null) ? mark : new ZLTextMark();
|
||||
return mark;
|
||||
}
|
||||
|
||||
public final int search(final String text, int startIndex, int endIndex, boolean ignoreCase) {
|
||||
|
|
|
@ -288,11 +288,12 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
}
|
||||
|
||||
public void gotoMark(ZLTextMark mark) {
|
||||
myPreviousPage.reset();
|
||||
myNextPage.reset();
|
||||
if (mark.ParagraphIndex < 0) {
|
||||
if (mark == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
myPreviousPage.reset();
|
||||
myNextPage.reset();
|
||||
boolean doRepaint = false;
|
||||
if (myCurrentPage.StartCursor.isNull()) {
|
||||
doRepaint = true;
|
||||
|
@ -366,7 +367,7 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
|
||||
public boolean canFindNext() {
|
||||
final ZLTextWordCursor end = myCurrentPage.EndCursor;
|
||||
return !end.isNull() && (myModel != null) && (myModel.getNextMark(end.getPosition()).ParagraphIndex > -1);
|
||||
return !end.isNull() && (myModel != null) && (myModel.getNextMark(end.getPosition()) != null);
|
||||
}
|
||||
|
||||
public void findNext() {
|
||||
|
@ -378,7 +379,7 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
|
||||
public boolean canFindPrevious() {
|
||||
final ZLTextWordCursor start = myCurrentPage.StartCursor;
|
||||
return !start.isNull() && (myModel != null) && (myModel.getPreviousMark(start.getPosition()).ParagraphIndex > -1);
|
||||
return !start.isNull() && (myModel != null) && (myModel.getPreviousMark(start.getPosition()) != null);
|
||||
}
|
||||
|
||||
public void findPrevious() {
|
||||
|
|
|
@ -85,7 +85,7 @@ public final class ZLTextWordCursor {
|
|||
|
||||
public ZLTextMark getPosition() {
|
||||
if (myParagraphCursor == null) {
|
||||
return new ZLTextMark();
|
||||
return null;
|
||||
}
|
||||
final ZLTextParagraphCursor paragraph = myParagraphCursor;
|
||||
int paragraphLength = paragraph.getParagraphLength();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue