1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 19:42:17 +02:00

added "search control" panel

better search view


git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@950 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Nikolay Pultsin 2009-04-28 12:33:30 +00:00
parent 47e3339b7a
commit bf8af28f20
54 changed files with 474 additions and 417 deletions

View file

@ -42,8 +42,6 @@
<node name="clearSelection" value="Clear"/>
</node>
<node name="search" value="Search"/>
<node name="findNext" value="Find next"/>
<node name="findPrevious" value="Find previous"/>
<node name="view" value="View">
<node name="rotate" value="Rotate Screen"/>
<node name="toggleFullscreen" value="Full Screen"/>
@ -64,8 +62,8 @@
<node name="summaryOff" value="The display will not rotate when user moves the device"/>
</node>
<node name="showStatusBar" value="Show status bar">
<node name="summaryOn" value="The status bar will be shown in reading mode"/>
<node name="summaryOff" value="The status bar will be hidden in reading mode"/>
<node name="summaryOn" value="Show status bar in reading mode"/>
<node name="summaryOff" value="Hide status bar in reading mode"/>
</node>
</node>
<node name="Scrolling" value="Scrolling">
@ -74,12 +72,12 @@
<node name="summaryOff" value="Pages will be scrolled by finger tap"/>
</node>
<node name="volumeKeys" value="Volume keys scrolling">
<node name="summaryOn" value="Volume keys will be used for scrolling"/>
<node name="summaryOff" value="Volume keys will be used as usual"/>
<node name="summaryOn" value="Use volume keys to scroll"/>
<node name="summaryOff" value="Keep volume keys for sound"/>
</node>
<node name="animated" value="Animated scrolling">
<node name="summaryOn" value="Pages will be scrolled smoothly"/>
<node name="summaryOff" value="Pages will be scrolled instantly"/>
<node name="summaryOn" value="Scroll pages smoother"/>
<node name="summaryOff" value="Scroll pages faster"/>
</node>
<node name="horizontal" value="Horizontal scrolling">
<node name="summaryOn" value="Scroll pages horizontally"/>
@ -245,6 +243,10 @@
<node name="updatingBooksDatabase" value="Updating books database. Please, wait..."/>
</node>
</node>
<node name="errorMessage">
<node name="textNotFound" value="There is no suitable text in the book"/>
<node name="bookNotFound" value="There are no suitable books in the library"/>
</node>
<node name="style">
<node name="Base" value="Base"/>
<node name="Regular Paragraph" value="Regular Paragraph"/>

View file

@ -40,8 +40,6 @@
<node name="clearSelection" value="Убрать пометку"/>
</node>
<node name="search" value="Поиск"/>
<node name="findNext" value="Искать дальше"/>
<node name="findPrevious" value="Искать раньше"/>
<node name="view" value="Изображение">
<node name="rotate" value="Повернуть"/>
<node name="toggleFullscreen" value="На весь экран"/>
@ -245,6 +243,10 @@
<node name="updatingBooksDatabase" value="Обновляется база книг. Подождите, пожалуйста..."/>
</node>
</node>
<node name="errorMessage">
<node name="textNotFound" value="В этой книге нет такого текста"/>
<node name="bookNotFound" value="Нет подходящих книг"/>
</node>
<node name="style">
<node name="Base" value="текста по умолчанию"/>
<node name="Regular Paragraph" value="обычного текста"/>

View file

@ -9,6 +9,7 @@ drawable_res_dir = platform_dir + "/res/drawable"
data_dir_common = project_dir + "/data"
application_icons_dir_common = project_dir + "/icons/application"
tree_icons_dir_android = platform_dir + "/icons/tree"
text_search_icons_dir_android = platform_dir + "/icons/text_search"
data_dir_android = platform_dir + "/data"
print os.getcwd()
@ -37,3 +38,4 @@ process_data_dir("data__", data_dir_common, raw_res_dir)
process_data_dir("data__", data_dir_android, raw_res_dir)
shutil.copyfile(application_icons_dir_common + "/48x48.png", drawable_res_dir + "/fbreader.png")
process_data_dir("tree_icon_", tree_icons_dir_android, drawable_res_dir, 0)
process_data_dir("text_search_", text_search_icons_dir_android, drawable_res_dir, 0)

View file

@ -15,6 +15,4 @@
<item id="preferences"/>
<item id="preferences-old"/>
<item id="bookInfo"/>
<item id="findPrevious"/>
<item id="findNext"/>
</menubar>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1,015 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/text_search_close_active" />
<item android:drawable="@drawable/text_search_close_default" />
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 B

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/text_search_next_disabled" />
<item android:state_pressed="true" android:drawable="@drawable/text_search_next_active" />
<item android:drawable="@drawable/text_search_next_default" />
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 B

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/text_search_previous_disabled" />
<item android:state_pressed="true" android:drawable="@drawable/text_search_previous_active" />
<item android:drawable="@drawable/text_search_previous_default" />
</selector>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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>

View file

@ -20,30 +20,38 @@
package org.geometerplus.android.fbreader;
import android.app.Activity;
import android.app.SearchManager;
import android.os.Bundle;
import android.content.Intent;
import org.geometerplus.zlibrary.core.dialogs.ZLDialogManager;
import org.geometerplus.fbreader.fbreader.FBReader;
import org.geometerplus.fbreader.collection.*;
public class BookSearchActivity extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
public class BookSearchActivity extends SearchActivity {
private CollectionTree myTree;
final Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
final FBReader fbreader = (FBReader)FBReader.Instance();
final String pattern = intent.getStringExtra(SearchManager.QUERY);
fbreader.BookSearchPatternOption.setValue(pattern);
CollectionTree tree = BookCollection.Instance().searchBooks(pattern);
if (tree.hasChildren()) {
LibraryTabActivity.Instance.showSearchResultsTab(tree);
}
}
finish();
@Override
void onSuccess() {
LibraryTabActivity.Instance.showSearchResultsTab(myTree);
}
@Override
String getFailureMessageResourceKey() {
return "bookNotFound";
}
@Override
String getWaitMessageResourceKey() {
return "bookSearch";
}
@Override
boolean runSearch(final String pattern) {
final FBReader fbreader = (FBReader)FBReader.Instance();
fbreader.BookSearchPatternOption.setValue(pattern);
myTree = BookCollection.Instance().searchBooks(pattern);
return myTree.hasChildren();
}
@Override
Activity getParentActivity() {
return LibraryTabActivity.Instance;
}
}

View file

@ -19,21 +19,26 @@
package org.geometerplus.android.fbreader;
import android.app.SearchManager;
import android.content.Intent;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.content.pm.ActivityInfo;
import android.widget.ZoomControls;
import android.widget.RelativeLayout;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidActivity;
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
import org.geometerplus.zlibrary.ui.android.R;
public class FBReader extends ZLAndroidActivity {
static FBReader Instance;
private int myFullScreenFlag;
private TextSearchControls myTextSearchControls;
private boolean myRestoreTextSearchControls;
@Override
public void onCreate(Bundle icicle) {
@ -63,13 +68,51 @@ public class FBReader extends ZLAndroidActivity {
ActivityInfo.SCREEN_ORIENTATION_SENSOR :
ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
);
if (myTextSearchControls == null) {
myTextSearchControls = new TextSearchControls(this);
myTextSearchControls.Visible = myRestoreTextSearchControls;
RelativeLayout root = (RelativeLayout)findViewById(R.id.root_view);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
p.addRule(RelativeLayout.CENTER_HORIZONTAL);
root.addView(myTextSearchControls, p);
}
}
void showZoomControls() {
final ZoomControls controls = new ZoomControls(this);
controls.setVisibility(View.GONE);
controls.setZoomSpeed(0);
controls.show();
@Override
public void onResume() {
super.onResume();
if (myTextSearchControls != null) {
final org.geometerplus.fbreader.fbreader.FBReader fbreader =
(org.geometerplus.fbreader.fbreader.FBReader)ZLApplication.Instance();
myTextSearchControls.setVisibility(myTextSearchControls.Visible ? View.VISIBLE : View.GONE);
fbreader.registerButtonPanel(myTextSearchControls);
}
}
@Override
public void onStop() {
if (myTextSearchControls != null) {
ZLApplication.Instance().unregisterButtonPanel(myTextSearchControls);
myRestoreTextSearchControls = myTextSearchControls.Visible;
myTextSearchControls.hide(false);
myTextSearchControls = null;
}
super.onStop();
}
void showTextSearchControls(boolean show) {
if (myTextSearchControls != null) {
if (show) {
myTextSearchControls.show(true);
} else {
myTextSearchControls.hide(false);
}
}
}
protected ZLApplication createApplication(String fileName) {
@ -80,6 +123,18 @@ public class FBReader extends ZLAndroidActivity {
@Override
public boolean onSearchRequested() {
if (myTextSearchControls != null) {
final boolean visible = myTextSearchControls.Visible;
myTextSearchControls.hide(false);
SearchManager manager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);
manager.setOnCancelListener(new SearchManager.OnCancelListener() {
public void onCancel() {
if ((myTextSearchControls != null) && visible) {
myTextSearchControls.show(false);
}
}
});
}
final org.geometerplus.fbreader.fbreader.FBReader fbreader =
(org.geometerplus.fbreader.fbreader.FBReader)ZLApplication.Instance();
startSearch(fbreader.TextSearchPatternOption.getValue(), true, null, false);

View file

@ -57,6 +57,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
new LibraryAdapter(createTab("byAuthor", R.id.by_author), BookCollection.Instance().collectionByAuthor());
new LibraryAdapter(createTab("byTag", R.id.by_tag), BookCollection.Instance().collectionByTag());
new LibraryAdapter(createTab("recent", R.id.recent), BookCollection.Instance().recentBooks());
findViewById(R.id.search_results).setVisibility(View.GONE);
host.setCurrentTabByTag(mySelectedTabOption.getValue());
}

View file

@ -0,0 +1,86 @@
/*
* Copyright (C) 2009 Geometer Plus <contact@geometerplus.com>
*
* 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 android.os.*;
import android.app.*;
import android.content.Intent;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.dialogs.ZLDialogManager;
abstract class SearchActivity extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
final String pattern = intent.getStringExtra(SearchManager.QUERY);
final Handler successHandler = new Handler() {
public void handleMessage(Message message) {
onSuccess();
}
};
final Handler failureHandler = new Handler() {
private AlertDialog myAlertDialog;
public void handleMessage(Message message) {
switch (message.what) {
case 0:
myAlertDialog =
new AlertDialog.Builder(getParentActivity()).setMessage(
ZLResource.resource("errorMessage").getResource(getFailureMessageResourceKey()).getValue()
).create();
myAlertDialog.show();
break;
case 1:
myAlertDialog.dismiss();
break;
}
}
};
ZLDialogManager.Instance().wait(getWaitMessageResourceKey(), new Runnable() {
public void run() {
if (runSearch(pattern)) {
successHandler.sendEmptyMessage(0);
} else {
failureHandler.sendEmptyMessage(0);
new Thread(new Runnable() {
public synchronized void run() {
try {
wait(3000);
} catch (InterruptedException e) {
}
failureHandler.sendEmptyMessage(1);
}
}).start();
}
}
});
}
finish();
}
abstract boolean runSearch(String pattern);
abstract void onSuccess();
abstract String getWaitMessageResourceKey();
abstract String getFailureMessageResourceKey();
abstract Activity getParentActivity();
}

View file

@ -20,33 +20,33 @@
package org.geometerplus.android.fbreader;
import android.app.Activity;
import android.app.SearchManager;
import android.os.Bundle;
import android.content.Intent;
import org.geometerplus.zlibrary.core.dialogs.ZLDialogManager;
public class TextSearchActivity extends Activity {
public class TextSearchActivity extends SearchActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
void onSuccess() {
FBReader.Instance.showTextSearchControls(true);
}
final Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
final org.geometerplus.fbreader.fbreader.FBReader fbreader =
(org.geometerplus.fbreader.fbreader.FBReader)
org.geometerplus.fbreader.fbreader.FBReader.Instance();
final String pattern = intent.getStringExtra(SearchManager.QUERY);
fbreader.TextSearchPatternOption.setValue(pattern);
ZLDialogManager.Instance().wait("textSearch", new Runnable() {
public void run() {
int count = fbreader.getTextView().search(pattern, true, false, false, false);
if (count != 0) {
FBReader.Instance.showZoomControls();
}
}
});
}
finish();
@Override
String getFailureMessageResourceKey() {
return "textNotFound";
}
@Override
String getWaitMessageResourceKey() {
return "textSearch";
}
@Override
boolean runSearch(final String pattern) {
final org.geometerplus.fbreader.fbreader.FBReader fbreader =
(org.geometerplus.fbreader.fbreader.FBReader)org.geometerplus.fbreader.fbreader.FBReader.Instance();
fbreader.TextSearchPatternOption.setValue(pattern);
return fbreader.getTextView().search(pattern, true, false, false, false) != 0;
}
@Override
Activity getParentActivity() {
return FBReader.Instance;
}
}

View file

@ -0,0 +1,123 @@
/*
* Copyright (C) 2007-2009 Geometer Plus <contact@geometerplus.com>
*
* 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 android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.*;
import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.fbreader.fbreader.ActionCode;
public class TextSearchControls extends LinearLayout implements View.OnClickListener, ZLApplication.ButtonPanel {
private final ZoomButton myFindPreviousButton;
private final ZoomButton myFindNextButton;
private final ZoomButton myCloseButton;
boolean Visible;
public TextSearchControls(Context context) {
super(context);
setFocusable(false);
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);
myFindPreviousButton = (ZoomButton)findViewById(R.id.previous);
//myFindPreviousButton = new ZoomButton(context);
//myFindPreviousButton.setImageResource(R.drawable.text_search_previous);
myFindPreviousButton.setOnClickListener(this);
//addView(myFindPreviousButton);
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 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);
hide(true);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return true;
}
public void show(boolean animate) {
if (animate) {
fade(View.VISIBLE, 0.0f, 1.0f);
} else {
setVisibility(View.VISIBLE);
}
Visible = true;
}
public void hide(boolean animate) {
if (animate) {
fade(View.GONE, 1.0f, 0.0f);
} else {
setVisibility(View.GONE);
}
Visible = false;
}
private void fade(int visibility, float startAlpha, float endAlpha) {
final AlphaAnimation animation = new AlphaAnimation(startAlpha, endAlpha);
animation.setDuration(500);
startAnimation(animation);
setVisibility(visibility);
}
public void updateStates() {
final ZLApplication application = ZLApplication.Instance();
myFindNextButton.setEnabled(application.isActionEnabled(ActionCode.FIND_NEXT));
myFindPreviousButton.setEnabled(application.isActionEnabled(ActionCode.FIND_PREVIOUS));
}
@Override
public boolean hasFocus() {
return myFindPreviousButton.hasFocus() || myFindNextButton.hasFocus() || myCloseButton.hasFocus();
}
}

View file

@ -168,8 +168,6 @@ abstract class ZLTreeAdapter extends BaseAdapter implements AdapterView.OnItemCl
runTreeItem(getItem(position));
}
private boolean myContextMenuInProgress;
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
}

View file

@ -71,11 +71,11 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
public void buildMenu(Menu menu) {
new MenuBuilder(menu).processMenu(getApplication());
refresh();
refreshMenu();
}
protected void refresh() {
super.refresh();
@Override
protected void refreshMenu() {
for (Map.Entry<MenuItem,ZLApplication.Menubar.PlainItem> entry : myMenuItemMap.entrySet()) {
final String actionId = entry.getValue().ActionId;
final ZLApplication application = getApplication();
@ -94,14 +94,6 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
return viewWidget;
}
public void addToolbarItem(ZLApplication.Toolbar.Item item) {
// TODO: implement
}
public void setToolbarItemState(ZLApplication.Toolbar.Item item, boolean visible, boolean enabled) {
// TODO: implement
}
public void close() {
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).finish();
}

View file

@ -63,7 +63,7 @@ public abstract class ZLAndroidActivity extends Activity {
} else if (fileToOpen != null) {
ZLApplication.Instance().openFiles(new ZLPhysicalFile(new File(fileToOpen)));
}
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
}
@Override

View file

@ -103,6 +103,7 @@ public class ZLAndroidWidget extends View {
onDrawInScrolling(canvas);
} else {
onDrawStatic(canvas);
ZLApplication.Instance().onRepaintFinished();
}
}
@ -152,6 +153,7 @@ public class ZLAndroidWidget extends View {
mySecondaryBitmap = swap;
mySecondaryBitmapIsUpToDate = false;
view.onScrollingFinished(myViewPageToScroll);
ZLApplication.Instance().onRepaintFinished();
} else {
view.onScrollingFinished(ZLView.PAGE_CENTRAL);
}

View file

@ -116,7 +116,7 @@ public final class BookCollection {
dirQueue.offer(BookDirectory);
while (!dirQueue.isEmpty()) {
for (ZLFile file : dirQueue.poll().children()) {
if (file.getName(true).startsWith(".")) {
if (file.getName(false).startsWith(".")) {
continue;
}
if (file.isDirectory()) {

View file

@ -30,6 +30,7 @@ public interface ActionCode {
String SEARCH = "search";
String FIND_PREVIOUS = "findPrevious";
String FIND_NEXT = "findNext";
String CLEAR_FIND_RESULTS = "clearFindResults";
String VOLUME_KEY_SCROLL_FORWARD = "volumeKeyScrollForward";
String VOLUME_KEY_SCROLL_BACKWARD = "volumeKeyScrollBackward";
String TRACKBALL_SCROLL_FORWARD = "trackballScrollForward";

View file

@ -118,7 +118,7 @@ public class BookTextView extends FBView {
gotoPosition(0, 0, 0);
preparePaintInfo();
savePosition(position, 0, getStartCursor());
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
}
//TODO: remove
@ -276,13 +276,14 @@ public class BookTextView extends FBView {
void undoPageMove() {
gotoPosition((Position)myPositionStack.get(--myCurrentPointInStack));
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
/*
for (Object p : myPositionStack) {
System.out.print(((Position) p).ModelIndex + ","
+ ((Position) p).ParagraphIndex + "; ");
}
System.out.println("current position " + myCurrentPointInStack);
*/
}
boolean canRedoPageMove() {
@ -291,7 +292,7 @@ public class BookTextView extends FBView {
void redoPageMove() {
gotoPosition((Position)myPositionStack.get(++myCurrentPointInStack));
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
for (Object p : myPositionStack) {
System.out.print(((Position) p).ModelIndex + ","

View file

@ -35,6 +35,6 @@ class ChangeFontSizeAction extends FBAction {
ZLTextStyleCollection.Instance().getBaseStyle().FontSizeOption;
option.setValue(option.getValue() + myDelta);
Reader.clearTextCaches();
Reader.refreshWindow();
Reader.repaintView();
}
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (C) 2007-2009 Geometer Plus <contact@geometerplus.com>
*
* 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.fbreader.fbreader;
import org.geometerplus.zlibrary.text.view.ZLTextView;
class ClearFindResultsAction extends FBAction {
ClearFindResultsAction(FBReader fbreader) {
super(fbreader);
}
public void run() {
Reader.getTextView().clearFindResults();
}
}

View file

@ -92,6 +92,7 @@ public final class FBReader extends ZLApplication {
addAction(ActionCode.SEARCH, new SearchAction(this));
addAction(ActionCode.FIND_NEXT, new FindNextAction(this));
addAction(ActionCode.FIND_PREVIOUS, new FindPreviousAction(this));
addAction(ActionCode.CLEAR_FIND_RESULTS, new ClearFindResultsAction(this));
addAction(ActionCode.SCROLL_TO_HOME, new ScrollToHomeAction(this));
addAction(ActionCode.SCROLL_TO_START_OF_TEXT, new DummyAction(this));
@ -195,8 +196,7 @@ public final class FBReader extends ZLApplication {
setMode(ViewMode.FOOTNOTE);
FootnoteView.gotoParagraph(label.ParagraphIndex, false);
}
setHyperlinkCursor(false);
refreshWindow();
repaintView();
}
}
}
@ -224,8 +224,7 @@ public final class FBReader extends ZLApplication {
FootnoteView.setCaption(description.getTitle());
BookCollection.Instance().addBookToRecentList(description);
}
resetWindowCaption();
refreshWindow();
repaintView();
}
void showBookTextView() {
@ -257,7 +256,7 @@ main:
}
if (description != null) {
openBookInternal(description);
refreshWindow();
repaintView();
}
}
});

View file

@ -61,7 +61,7 @@ public abstract class FBView extends ZLTextViewImpl {
}
} else {
scrollPage(forward, ZLTextView.ScrollingMode.NO_OVERLAPPING, 0);
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
}
}
@ -167,7 +167,7 @@ public abstract class FBView extends ZLTextViewImpl {
} else {
scrollTo(PAGE_CENTRAL, 0);
onScrollingFinished(viewPage);
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
setScrollingActive(false);
}
}

View file

@ -36,6 +36,6 @@ class TrackballScrollingAction extends FBAction {
public void run() {
Reader.getTextView().scrollPage(myForward, ZLTextView.ScrollingMode.SCROLL_LINES, 1);
Reader.refreshWindow();
Reader.repaintView();
}
}

View file

@ -87,9 +87,8 @@ public class OptionsDialog {
}
public void run() {
myFBReader.grabAllKeys(myFBReader.KeyboardControlOption.getValue());
myFBReader.clearTextCaches();
myFBReader.refreshWindow();
myFBReader.repaintView();
}
}

View file

@ -47,8 +47,6 @@ public abstract class ZLApplication {
private static final String ROTATION = "Rotation";
private static final String ANGLE = "Angle";
private static final String STATE = "State";
private static final String KEYBOARD = "Keyboard";
private static final String FULL_CONTROL = "FullControl";
private static final String CONFIG = "Config";
private static final String AUTO_SAVE = "AutoSave";
private static final String TIMEOUT = "Timeout";
@ -60,9 +58,6 @@ public abstract class ZLApplication {
public final ZLIntegerOption AngleStateOption =
new ZLIntegerOption(STATE, ANGLE, ZLViewWidget.Angle.DEGREES0);
public final ZLBooleanOption KeyboardControlOption =
new ZLBooleanOption(KEYBOARD, FULL_CONTROL, false);
public final ZLBooleanOption ConfigAutoSavingOption =
new ZLBooleanOption(CONFIG, AUTO_SAVE, true);
public final ZLIntegerRangeOption ConfigAutoSaveTimeoutOption =
@ -76,10 +71,8 @@ public abstract class ZLApplication {
private ZLView myView;
private final HashMap myIdToActionMap = new HashMap();
private Toolbar myToolbar;
private Menubar myMenubar;
//private ZLTime myLastKeyActionTime;
//private ZLMessageHandler myPresentWindowHandler;
protected ZLApplication() {
ourInstance = this;
@ -88,16 +81,8 @@ public abstract class ZLApplication {
//ZLOption.startAutoSave(ConfigAutoSaveTimeoutOption.getValue());
}
//myPresentWindowHandler = new PresentWindowHandler(this);
//ZLCommunicationManager.instance().registerHandler("present", myPresentWindowHandler);
new ToolbarCreator().read(ZLResourceFile.createResourceFile("data/default/toolbar.xml"));
new MenubarCreator().read(ZLResourceFile.createResourceFile("data/default/menubar.xml"));
}
final Toolbar getToolbar() {
return myToolbar;
}
final Menubar getMenubar() {
return myMenubar;
@ -107,8 +92,7 @@ public abstract class ZLApplication {
if (view != null) {
myView = view;
if (myViewWidget != null) {
resetWindowCaption();
refreshWindow();
repaintView();
}
}
}
@ -127,41 +111,29 @@ public abstract class ZLApplication {
public void initWindow() {
setViewWidget(myWindow.createViewWidget());
if (KeyboardControlOption.getValue()) {
grabAllKeys(true);
}
myWindow.init();
setView(myView);
}
public final void refreshWindow() {
public final void repaintView() {
if (myViewWidget != null) {
myViewWidget.repaint();
}
}
public final void onRepaintFinished() {
if (myWindow != null) {
myWindow.refresh();
myWindow.refreshMenu();
}
for (ButtonPanel panel : myPanels) {
panel.updateStates();
}
}
protected final void resetWindowCaption() {
}
protected final void addAction(String actionId, ZLAction action) {
myIdToActionMap.put(actionId, action);
}
public final void grabAllKeys(boolean grab) {
if (myWindow != null) {
//myWindow.grabAllKeys(grab);
}
}
public final void setHyperlinkCursor(boolean hyperlink) {
if (myWindow != null) {
//myWindow.setHyperlinkCursor(hyperlink);
}
}
private final ZLAction getAction(String actionId) {
return (ZLAction)myIdToActionMap.get(actionId);
}
@ -208,20 +180,6 @@ public abstract class ZLApplication {
public abstract void openFiles(ZLFile ... files);
public final void presentWindow() {
if (myWindow != null) {
//myWindow.present();
}
}
//public String lastCaller() {
//return null;//((PresentWindowHandler)myPresentWindowHandler).lastCaller();
//}
//public void resetLastCaller() {
//((PresentWindowHandler)myPresentWindowHandler).resetLastCaller();
//}
final void setViewWidget(ZLViewWidget viewWidget) {
myViewWidget = viewWidget;
}
@ -273,134 +231,19 @@ public abstract class ZLApplication {
}
myViewWidget.rotate(newAngle);
AngleStateOption.setValue(newAngle);
refreshWindow();
repaintView();
}
}
//toolbar
static public final class Toolbar {
private final ArrayList myItems = new ArrayList();
private final ZLResource myResource = ZLResource.resource("toolbar");
private void addButton(String actionId/*, ButtonGroup group*/) {
ButtonItem button = new ButtonItem(actionId, myResource.getResource(actionId));
myItems.add(button);
//button.setButtonGroup(group);
}
/*
ButtonGroup createButtonGroup(int unselectAllButtonsActionId) {
return new ButtonGroup(unselectAllButtonsActionId);
}
public void addOptionEntry(ZLOptionEntry entry) {
if (entry != null) {
myItems.add(new OptionEntryItem(entry));
}
}
*/
public void addSeparator() {
myItems.add(new SeparatorItem());
}
int size() {
return myItems.size();
}
Item getItem(int index) {
return (Item)myItems.get(index);
}
public interface Item {
}
public final class ButtonItem implements Item {
private final String myActionId;
private final ZLResource myTooltip;
//private ButtonGroup myButtonGroup;
public ButtonItem(String actionId, ZLResource tooltip) {
myActionId = actionId;
myTooltip = tooltip;
}
public String getActionId() {
return myActionId;
}
public String getIconName() {
return myActionId;
}
public String getTooltip() {
return myTooltip.hasValue() ? myTooltip.getValue() : null;
}
/*
ButtonGroup getButtonGroup() {
return myButtonGroup;
}
boolean isToggleButton() {
return myButtonGroup != null;
}
void press() {
if (isToggleButton()) {
myButtonGroup.press(this);
}
}
boolean isPressed() {
return isToggleButton() && (this == myButtonGroup.PressedItem);
}
private void setButtonGroup(ButtonGroup bg) {
if (myButtonGroup != null) {
myButtonGroup.Items.remove(this);
}
myButtonGroup = bg;
if (myButtonGroup != null) {
myButtonGroup.Items.add(this);
}
}
*/
}
public class SeparatorItem implements Item {
}
/*
public class OptionEntryItem implements Item {
private ZLOptionEntry myOptionEntry;
public OptionEntryItem(ZLOptionEntry entry) {
myOptionEntry = entry;
}
public ZLOptionEntry entry() {
return myOptionEntry;
}
}
public final class ButtonGroup {
public final int UnselectAllButtonsActionId;
public final ArrayList<ButtonItem> Items = new ArrayList<ButtonItem>();
public ButtonItem PressedItem;
ButtonGroup(int unselectAllButtonsActionId) {
UnselectAllButtonsActionId = unselectAllButtonsActionId;
PressedItem = null;
}
void press(ButtonItem item) {
PressedItem = item;
}
}
*/
static public interface ButtonPanel {
void updateStates();
}
private final HashSet<ButtonPanel> myPanels = new HashSet<ButtonPanel>();
public final void registerButtonPanel(ButtonPanel panel) {
myPanels.add(panel);
}
public final void unregisterButtonPanel(ButtonPanel panel) {
myPanels.remove(panel);
}
//Menu
@ -503,40 +346,6 @@ public abstract class ZLApplication {
protected abstract void processSepartor(Menubar.Separator separator);
}
static public class PresentWindowHandler {//extends ZLMessageHandler {
private ZLApplication myApplication;
private String myLastCaller;
//public PresentWindowHandler(ZLApplication application);
//public void onMessageReceived(List<String> arguments);
//public String lastCaller();
//public void resetLastCaller();
}
private class ToolbarCreator extends ZLXMLReaderAdapter {
private static final String BUTTON = "button";
private static final String SEPARATOR = "separator";
public boolean dontCacheAttributeValues() {
return true;
}
public boolean startElementHandler(String tag, ZLStringMap attributes) {
if (myToolbar == null) {
myToolbar = new Toolbar();
}
if (BUTTON == tag) {
String id = attributes.getValue("id");
if (id != null) {
myToolbar.addButton(id);
}
} else if (SEPARATOR == tag) {
myToolbar.addSeparator();
}
return false;
}
}
private class MenubarCreator extends ZLXMLReaderAdapter {
private static final String ITEM = "item";
private static final String SUBMENU = "submenu";

View file

@ -41,120 +41,13 @@ abstract public class ZLApplicationWindow {
protected void init() {
myApplication.setViewWidget(createViewWidget());
final ZLApplication.Toolbar toolbar = myApplication.getToolbar();
if (toolbar != null) {
final int size = toolbar.size();
for (int i = 0; i < size; ++i) {
addToolbarItem(toolbar.getItem(i));
}
}
initMenu();
}
abstract protected void initMenu();
public void onButtonPress(ZLApplication.Toolbar.ButtonItem button) {
/*
if (myToggleButtonLock) {
return;
}
if (button.isToggleButton()) {
myToggleButtonLock = true;
if (button.isPressed()) {
setToggleButtonState(button);
myToggleButtonLock = false;
return;
} else {
button.press();
ZLApplication.Toolbar.ButtonGroup group = button.getButtonGroup();
final ArrayList<ZLApplication.Toolbar.ButtonItem> items = group.Items;
final int size = items.size();
for (int i = 0; i < size; ++i) {
setToggleButtonState(items.get(i));
}
}
myToggleButtonLock = false;
}
*/
getApplication().doAction(button.getActionId());
}
//public abstract void setToggleButtonState(ZLApplication.Toolbar.ButtonItem item);
public abstract void setToolbarItemState(ZLApplication.Toolbar.Item item, boolean visible, boolean enabled);
abstract protected void refreshMenu();
abstract protected ZLViewWidget createViewWidget();
abstract public void addToolbarItem(ZLApplication.Toolbar.Item item);
protected void refresh() {
final ZLApplication.Toolbar toolbar = myApplication.getToolbar();
if (toolbar != null) {
boolean enableToolbarSpace = false;
ZLApplication.Toolbar.Item lastSeparator = null;
final int size = toolbar.size();
for (int i = 0; i < size; ++i) {
final ZLApplication.Toolbar.Item item = toolbar.getItem(i);
/*
if (item instanceof ZLApplication.Toolbar.OptionEntryItem) {
case OPTION_ENTRY:
{
boolean visible = ((OptionEntryItem)item.entry().isVisible())//((Toolbar.OptionEntryItem)**it).entry()->isVisible();
if (visible) {
if (lastSeparator != null) {
setToolbarItemState(lastSeparator, true, true);
lastSeparator = null;
}
enableToolbarSpace = true;
}
setToolbarItemState(item, visible, true);
}
break;
} else */
if (item instanceof ZLApplication.Toolbar.ButtonItem) {
ZLApplication.Toolbar.ButtonItem button = (ZLApplication.Toolbar.ButtonItem)item;
final String id = button.getActionId();
final boolean visible = getApplication().isActionVisible(id);
final boolean enabled = getApplication().isActionEnabled(id);
if (visible) {
if (lastSeparator != null) {
setToolbarItemState(lastSeparator, true, true);
lastSeparator = null;
}
enableToolbarSpace = true;
}
/*
if (!enabled && button.isPressed()) {
ZLApplication.Toolbar.ButtonGroup group = button.getButtonGroup();
group.press(null);
getApplication().doAction(group.UnselectAllButtonsActionId);
myToggleButtonLock = true;
setToggleButtonState(button);
myToggleButtonLock = false;
}
*/
setToolbarItemState(item, visible, enabled);
} else if (item instanceof ZLApplication.Toolbar.SeparatorItem) {
if (enableToolbarSpace) {
lastSeparator = item;
enableToolbarSpace = false;
} else {
setToolbarItemState(item, false, true);
}
//break;
}
}
if (lastSeparator != null) {
setToolbarItemState(lastSeparator, false, true);
}
}
}
abstract protected void close();
}

View file

@ -50,11 +50,12 @@ public abstract class ZLTextView extends ZLView {
public abstract void scrollPage(boolean forward, int scrollingMode, int value);
public abstract int search(String text, boolean ignoreCase, boolean wholeText, boolean backward, boolean thisSectionOnly);
public abstract boolean canFindNext();
public abstract void findNext();
public abstract boolean canFindPrevious();
public abstract void findPrevious();
public abstract void clearFindResults();
public abstract boolean findResultsAreEmpty();
public abstract int getLeftMargin();
public abstract int getRightMargin();

View file

@ -279,7 +279,7 @@ final class ZLTextSelectionModel {
public void run() {
myView.scrollPage(forward, ZLTextView.ScrollingMode.SCROLL_LINES, 1);
myDoUpdate = true;
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
}
};
myTimer.schedule(myScrollingTask, 200, 400);

View file

@ -324,7 +324,7 @@ public abstract class ZLTextViewImpl extends ZLTextView {
}
*/
savePosition(position, myCurrentModelIndex, myCurrentPage.StartCursor);
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
}
}
@ -359,7 +359,7 @@ public abstract class ZLTextViewImpl extends ZLTextView {
(backward ? myModel.getLastMark() : myModel.getFirstMark()) :
(backward ? myModel.getPreviousMark(position) : myModel.getNextMark(position)));
}
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
}
return count;
}
@ -388,6 +388,18 @@ public abstract class ZLTextViewImpl extends ZLTextView {
}
}
public void clearFindResults() {
if (!findResultsAreEmpty()) {
myModel.removeAllMarks();
rebuildPaintInfo();
ZLApplication.Instance().repaintView();
}
}
public boolean findResultsAreEmpty() {
return (myModel == null) || myModel.getMarks().isEmpty();
}
private volatile boolean myScrollingIsActive;
protected boolean isScrollingActive() {
return myScrollingIsActive;
@ -1402,7 +1414,7 @@ public abstract class ZLTextViewImpl extends ZLTextView {
public boolean onStylusMovePressed(int x, int y) {
if (mySelectionModel.extendTo(x, y)) {
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
return true;
}
return false;
@ -1418,7 +1430,7 @@ public abstract class ZLTextViewImpl extends ZLTextView {
protected void activateSelection(int x, int y) {
if (isSelectionEnabled()) {
mySelectionModel.activate(x, y);
ZLApplication.Instance().refreshWindow();
ZLApplication.Instance().repaintView();
}
}
}