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

options: cleanup (category has been removed)

new view for TOC



git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@901 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Nikolay Pultsin 2009-03-31 20:21:35 +00:00
parent 738eb18e99
commit ef6680465d
55 changed files with 842 additions and 441 deletions

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<node name="libraryView">
<node name="byAuthor" value="By Author"/>
<node name="byTag" value="By Tag"/>
<node name="recent" value="Recent"/>
</node>
<node name="menu">
<node name="preferences" value="Preferences">
<node name="preferences" value="FBReader..."/>
@ -40,22 +45,6 @@
</node>
<node name="quit" value="Close"/>
</node>
<node name="toolbar">
<node name="showLibrary" value="Show Library Tree"/>
<node name="showRecent" value="Show Recent Books List"/>
<node name="addBook" value="Add File to Library"/>
<node name="gotoHome" value="Go to Start of Text"/>
<node name="undo" value="Go Back"/>
<node name="redo" value="Go Forward"/>
<node name="toc" value="Table of Contents"/>
<node name="search" value="Text Search"/>
<node name="findNext" value="Find Next"/>
<node name="findPrevious" value="Find Previous"/>
<node name="bookInfo" value="Show Book Info Dialog"/>
<node name="preferences" value="Show Preferences Dialog"/>
<node name="rotate" value="Rotate Text"/>
<node name="showHelp" value="About FBReader"/>
</node>
<node name="dialog">
<node name="button">
<node name="go" value="&amp;Go!"/>

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<node name="libraryView">
<node name="byAuthor" value="По автору"/>
<node name="byTag" value="По категории"/>
<node name="recent" value="Недавние"/>
</node>
<node name="menu">
<node name="bookInfo" value="Информация о книге..."/>
<node name="toc" value="Содержание"/>
@ -38,22 +43,6 @@
<node name="preferences" value="Настройки..."/>
<node name="quit" value="Закрыть"/>
</node>
<node name="toolbar">
<node name="showLibrary" value="Библиотека"/>
<node name="showRecent" value="Прочитанные книги"/>
<node name="addBook" value="Добавить файл в библиотеку"/>
<node name="gotoHome" value="В начало книги"/>
<node name="undo" value="Назад"/>
<node name="redo" value="Вперед"/>
<node name="toc" value="Оглавление"/>
<node name="search" value="Поиск"/>
<node name="findNext" value="Найти следующий"/>
<node name="findPrevious" value="Найти предыдущий"/>
<node name="bookInfo" value="Информация о книге"/>
<node name="preferences" value="Настройки"/>
<node name="rotate" value="Поворот текста"/>
<node name="showHelp" value="О программе"/>
</node>
<node name="dialog">
<node name="button">
<node name="go" value="&amp;Искать"/>

View file

@ -8,6 +8,7 @@ raw_res_dir = platform_dir + "/res/raw"
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"
data_dir_android = platform_dir + "/data"
print os.getcwd()
@ -35,3 +36,4 @@ clean_res_dir(drawable_res_dir)
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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="5dip"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/toc_tree_item_icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:singleLine="true"
/>
<TextView
android:id="@+id/toc_tree_item_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="5dip"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:gravity="center_vertical|left"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</LinearLayout>

View file

@ -0,0 +1,68 @@
/*
* 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 java.util.ArrayList;
import android.content.Context;
import android.widget.ListView;
import org.geometerplus.fbreader.description.Author;
import org.geometerplus.fbreader.collection.BookCollection;
final class AuthorListAdapter extends ZLListAdapter {
private final ArrayList<Author> myAuthors = new ArrayList(BookCollection.Instance().authors());
private final ZLListItem[] myItems = new ZLListItem[myAuthors.size()];
private final ListView myView;
private final Author mySelectedAuthor;
AuthorListAdapter(ListView view, Author selectedAuthor) {
super(view.getContext(), null);
myView = view;
mySelectedAuthor = selectedAuthor;
}
public int getCount() {
return myItems.length;
}
public ZLListItem getItem(final int position) {
ZLListItem item = myItems[position];
if (item == null) {
item = new AuthorItem(myView, myAuthors.get(position));
myItems[position] = item;
}
return item;
}
public int getSelectedIndex() {
if (mySelectedAuthor == null) {
return -1;
}
int count = 0;
for (Author author : myAuthors) {
if (author.equals(mySelectedAuthor)) {
return count;
}
++count;
}
return -1;
}
}

View file

@ -28,13 +28,25 @@ import android.widget.ListView;
import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.fbreader.description.Author;
import org.geometerplus.fbreader.description.BookDescription;
import org.geometerplus.fbreader.collection.BookCollection;
public class LibraryTabActivity extends TabActivity {
static LibraryTabActivity ourActivity;
final ZLStringOption mySelectedTabOption = new ZLStringOption("TabActivity", "SelectedTab", "");
private ListView createTab(String tag, int id) {
final TabHost host = getTabHost();
final String label = ZLResource.resource("libraryView").getResource(tag).getValue();
host.addTab(host.newTabSpec(tag).setIndicator(label).setContent(id));
return (ListView)findViewById(id);
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@ -42,14 +54,13 @@ public class LibraryTabActivity extends TabActivity {
final TabHost host = getTabHost();
LayoutInflater.from(this).inflate(R.layout.library, host.getTabContentView(), true);
host.addTab(host.newTabSpec("By Author").setIndicator("By Author").setContent(R.id.by_author));
host.addTab(host.newTabSpec("By Tag").setIndicator("By Tag").setContent(R.id.by_tag));
host.addTab(host.newTabSpec("Recent").setIndicator("Recent").setContent(R.id.recent));
//host.addTab(host.newTabSpec("Network").setIndicator("Network").setContent(R.id.network));
LibraryTabUtil.setAuthorList((ListView)findViewById(R.id.by_author), null);
LibraryTabUtil.setTagList((ListView)findViewById(R.id.by_tag), "");
LibraryTabUtil.setRecentBooksList((ListView)findViewById(R.id.recent));
LibraryTabUtil.setAuthorList(createTab("byAuthor", R.id.by_author), null);
LibraryTabUtil.setTagList(createTab("byTag", R.id.by_tag), "");
LibraryTabUtil.setRecentBooksList(createTab("recent", R.id.recent));
host.setCurrentTabByTag(mySelectedTabOption.getValue());
}
@Override
@ -63,4 +74,10 @@ public class LibraryTabActivity extends TabActivity {
ourActivity = null;
super.onPause();
}
@Override
public void onStop() {
mySelectedTabOption.setValue(getTabHost().getCurrentTabTag());
super.onStop();
}
}

View file

@ -24,53 +24,19 @@ import android.widget.ListView;
import org.geometerplus.fbreader.description.Author;
import org.geometerplus.fbreader.description.BookDescription;
import org.geometerplus.fbreader.collection.BookCollection;
import org.geometerplus.fbreader.collection.RecentBooks;
class LibraryTabUtil {
static void setAuthorList(ListView view, Author selectedAuthor) {
final ZLListAdapter adapter = new ZLListAdapter(view.getContext());
int selectedIndex = -1;
int count = 0;
for (final Author author : BookCollection.Instance().authors()) {
adapter.addItem(new AuthorItem(view, author));
if (author.equals(selectedAuthor)) {
selectedIndex = count;
}
++count;
}
setAdapter(view, adapter);
if (selectedIndex >= 0) {
view.setSelection(selectedIndex);
}
setAdapter(view, new AuthorListAdapter(view, selectedAuthor));
}
static void setTagList(ListView view, String selectedTag) {
final ZLListAdapter adapter = new ZLListAdapter(view.getContext());
int selectedIndex = -1;
int count = 0;
if (!BookCollection.Instance().booksByTag(null).isEmpty()) {
adapter.addItem(new TagItem(view, null));
if (selectedTag == null) {
selectedIndex = count;
}
++count;
}
for (final String tag : BookCollection.Instance().tags()) {
adapter.addItem(new TagItem(view, tag));
if (tag.equals(selectedTag)) {
selectedIndex = count;
}
++count;
}
setAdapter(view, adapter);
if (selectedIndex >= 0) {
view.setSelection(selectedIndex);
}
setAdapter(view, new TagListAdapter(view, selectedTag));
}
static void setBookList(final ListView view, final Author author, String selectedSeries) {
ZLListAdapter adapter =
new ZLListAdapter(
ZLListAdapterImpl adapter =
new ZLListAdapterImpl(
view.getContext(),
new Runnable() {
public void run() {
@ -106,8 +72,8 @@ class LibraryTabUtil {
}
static void setBookList(final ListView view, final String tag) {
ZLListAdapter adapter =
new ZLListAdapter(
ZLListAdapterImpl adapter =
new ZLListAdapterImpl(
view.getContext(),
new Runnable() {
public void run() {
@ -122,16 +88,12 @@ class LibraryTabUtil {
}
static void setRecentBooksList(final ListView view) {
ZLListAdapter adapter = new ZLListAdapter(view.getContext());
for (BookDescription book : RecentBooks.Instance().books()) {
adapter.addItem(new BookItem(book));
}
setAdapter(view, adapter);
setAdapter(view, new RecentBooksListAdapter(view.getContext()));
}
static void setSeriesBookList(final ListView view, final Author author, final String series) {
ZLListAdapter adapter =
new ZLListAdapter(
ZLListAdapterImpl adapter =
new ZLListAdapterImpl(
view.getContext(),
new Runnable() {
public void run() {
@ -151,5 +113,9 @@ class LibraryTabUtil {
view.setAdapter(adapter);
view.setOnKeyListener(adapter);
view.setOnItemClickListener(adapter);
int selectedIndex = adapter.getSelectedIndex();
if (selectedIndex >= 0) {
view.setSelection(selectedIndex);
}
}
}

View file

@ -0,0 +1,53 @@
/*
* 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 java.util.ArrayList;
import android.content.Context;
import org.geometerplus.fbreader.description.BookDescription;
import org.geometerplus.fbreader.collection.RecentBooks;
final class RecentBooksListAdapter extends ZLListAdapter {
final ArrayList<BookDescription> myBooks = RecentBooks.Instance().books();
final ZLListItem[] myItems = new ZLListItem[myBooks.size()];
RecentBooksListAdapter(Context context) {
super(context, null);
}
public int getCount() {
return myItems.length;
}
public ZLListItem getItem(final int position) {
ZLListItem item = myItems[position];
if (item == null) {
item = new BookItem(myBooks.get(position));
myItems[position] = item;
}
return item;
}
public int getSelectedIndex() {
return -1;
}
}

View file

@ -1,7 +1,33 @@
package org.geometerplus.android.fbreader;
import android.os.Bundle;
import android.view.View;
import android.content.Context;
import android.app.ListActivity;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import org.geometerplus.zlibrary.core.tree.ZLTextTree;
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
public class TOCActivity extends ListActivity {
public final static Object DATA_KEY = new Object();
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
ZLTextTree tree = (ZLTextTree)((ZLAndroidApplication)getApplication()).getData(DATA_KEY);
ZLTreeAdapter adapter = new ZLTreeAdapter(getListView(), tree);
getListView().setAdapter(adapter);
getListView().setOnKeyListener(adapter);
getListView().setOnItemClickListener(adapter);
/*
int selectedIndex = adapter.getSelectedIndex();
if (selectedIndex >= 0) {
view.setSelection(selectedIndex);
}
*/
}
}

View file

@ -0,0 +1,87 @@
/*
* 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 java.util.ArrayList;
import android.content.Context;
import android.widget.ListView;
import org.geometerplus.fbreader.collection.BookCollection;
final class TagListAdapter extends ZLListAdapter {
private final ArrayList<String> myTags = new ArrayList<String>(BookCollection.Instance().tags());
private final ZLListItem[] myItems;
private final ListView myView;
private final String mySelectedTag;
private final boolean myHasBooksWithNoTags;
TagListAdapter(ListView view, String selectedTag) {
super(view.getContext(), null);
myView = view;
mySelectedTag = selectedTag;
myHasBooksWithNoTags = !BookCollection.Instance().booksByTag(null).isEmpty();
int count = myTags.size();
if (myHasBooksWithNoTags) {
++count;
}
myItems = new ZLListItem[count];
}
public int getCount() {
return myItems.length;
}
public ZLListItem getItem(final int position) {
ZLListItem item = myItems[position];
if (item == null) {
int pos = position;
if (myHasBooksWithNoTags) {
if (pos == 0) {
item = new TagItem(myView, null);
} else {
--pos;
}
}
if (item == null) {
item = new TagItem(myView, myTags.get(pos));
}
myItems[position] = item;
}
return item;
}
public int getSelectedIndex() {
if (mySelectedTag == null) {
return 0;
}
if (mySelectedTag.length() == 0) {
return -1;
}
int count = myHasBooksWithNoTags ? 1 : 0;
for (String tag : myTags) {
if (tag.equals(mySelectedTag)) {
return count;
}
++count;
}
return -1;
}
}

View file

@ -19,8 +19,6 @@
package org.geometerplus.android.fbreader;
import java.util.ArrayList;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
@ -33,9 +31,8 @@ import android.widget.TextView;
import org.geometerplus.zlibrary.ui.android.R;
final class ZLListAdapter extends BaseAdapter implements AdapterView.OnItemClickListener, View.OnKeyListener {
abstract class ZLListAdapter extends BaseAdapter implements AdapterView.OnItemClickListener, View.OnKeyListener {
private final Context myContext;
private final ArrayList<ZLListItem> myItems = new ArrayList<ZLListItem>();
private final Runnable myCancelAction;
ZLListAdapter(Context context, Runnable cancelAction) {
@ -43,17 +40,9 @@ final class ZLListAdapter extends BaseAdapter implements AdapterView.OnItemClick
myCancelAction = cancelAction;
}
ZLListAdapter(Context context) {
this(context, null);
}
void addItem(ZLListItem item) {
myItems.add(item);
}
public int getCount() {
return myItems.size();
}
public abstract int getCount();
public abstract ZLListItem getItem(final int position);
public abstract int getSelectedIndex();
public boolean areAllItemsEnabled() {
return true;
@ -63,10 +52,6 @@ final class ZLListAdapter extends BaseAdapter implements AdapterView.OnItemClick
return true;
}
public ZLListItem getItem(final int position) {
return myItems.get(position);
}
public long getItemId(int position) {
return position;
}

View file

@ -0,0 +1,54 @@
/*
* 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 java.util.ArrayList;
import android.content.Context;
import org.geometerplus.zlibrary.ui.android.R;
final class ZLListAdapterImpl extends ZLListAdapter {
private final ArrayList<ZLListItem> myItems = new ArrayList<ZLListItem>();
ZLListAdapterImpl(Context context, Runnable cancelAction) {
super(context, cancelAction);
}
ZLListAdapterImpl(Context context) {
this(context, null);
}
void addItem(ZLListItem item) {
myItems.add(item);
}
public int getCount() {
return myItems.size();
}
public ZLListItem getItem(final int position) {
return myItems.get(position);
}
public int getSelectedIndex() {
return -1;
}
}

View file

@ -0,0 +1,163 @@
/*
* 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 java.util.HashSet;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.view.KeyEvent;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ImageView;
import org.geometerplus.zlibrary.core.tree.ZLTextTree;
import org.geometerplus.zlibrary.ui.android.R;
final class ZLTreeAdapter extends BaseAdapter implements AdapterView.OnItemClickListener, View.OnKeyListener {
private final ListView myParent;
private final ZLTextTree myTree;
private final ZLTreeItem[] myItems;
private final HashSet<ZLTextTree> myOpenItems = new HashSet<ZLTextTree>();
ZLTreeAdapter(ListView parent, ZLTextTree tree) {
myParent = parent;
myTree = tree;
myItems = new ZLTreeItem[tree.getSize() - 1];
myOpenItems.add(tree);
}
private int getCount(ZLTextTree tree) {
int count = 1;
if (myOpenItems.contains(tree)) {
for (ZLTextTree subtree : tree.subTrees()) {
count += getCount(subtree);
}
}
return count;
}
public int getCount() {
return getCount(myTree) - 1;
}
private int indexByPosition(int position, ZLTextTree tree) {
if (position == 0) {
return 0;
}
--position;
int index = 1;
for (ZLTextTree subtree : tree.subTrees()) {
int count = getCount(subtree);
if (count <= position) {
position -= count;
index += subtree.getSize();
} else {
return index + indexByPosition(position, subtree);
}
}
throw new RuntimeException("That's impossible!!!");
}
public ZLTreeItem getItem(int position) {
final int index = indexByPosition(position + 1, myTree) - 1;
ZLTreeItem item = myItems[index];
if (item == null) {
item = new ZLTreeItem(myTree.getTree(index + 1));
myItems[index] = item;
}
return item;
}
public boolean areAllItemsEnabled() {
return true;
}
public boolean isEnabled(int position) {
return true;
}
public long getItemId(int position) {
return indexByPosition(position + 1, myTree);
}
public View getView(int position, View convertView, ViewGroup parent) {
final View view = (convertView != null) ? convertView :
LayoutInflater.from(myParent.getContext()).inflate(R.layout.toc_tree_item, parent, false);
final ZLTextTree tree = getItem(position).Tree;
ImageView image = (ImageView)view.findViewById(R.id.toc_tree_item_icon);
if (tree.subTrees().isEmpty()) {
image.setImageResource(R.drawable.tree_icon_group_empty);
} else {
if (myOpenItems.contains(tree)) {
image.setImageResource(R.drawable.tree_icon_group_open);
} else {
image.setImageResource(R.drawable.tree_icon_group_closed);
}
}
image.setPadding(25 * (tree.getLevel() - 1), image.getPaddingTop(), 0, image.getPaddingBottom());
TextView text = (TextView)view.findViewById(R.id.toc_tree_item_text);
text.setText(tree.getText());
return view;
}
private boolean runTreeItem(ZLTreeItem item) {
return runTree(item.Tree);
}
private boolean runTree(ZLTextTree tree) {
if (tree.subTrees().isEmpty()) {
return false;
}
if (myOpenItems.contains(tree)) {
myOpenItems.remove(tree);
} else {
myOpenItems.add(tree);
}
myParent.invalidateViews();
myParent.requestLayout();
return true;
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
runTreeItem((ZLTreeItem)getItem(position));
}
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
switch (keyEvent.getAction()) {
case KeyEvent.ACTION_UP:
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
runTreeItem((ZLTreeItem)((ListView)view).getSelectedItem());
return true;
case KeyEvent.KEYCODE_BACK:
return true;
}
break;
}
return false;
}
}

View file

@ -17,10 +17,14 @@
* 02110-1301, USA.
*/
package org.geometerplus.fbreader.option;
package org.geometerplus.android.fbreader;
public interface FBOptions {
String BOOKS_CATEGORY = "books";
String SEARCH_CATEGORY = "search";
String EXTERNAL_CATEGORY = "external";
import org.geometerplus.zlibrary.core.tree.ZLTextTree;
final class ZLTreeItem {
final ZLTextTree Tree;
ZLTreeItem(ZLTextTree tree) {
Tree = tree;
}
}

View file

@ -71,7 +71,7 @@ public final class ZLSQLiteConfig extends ZLConfig {
return answer;
}
public void setValue(String group, String name, String value, String category) {
public void setValue(String group, String name, String value) {
database().execSQL(
"INSERT OR REPLACE INTO config (groupName, name, value) VALUES (?, ?, ?)",
new String[] { group, name, value });

View file

@ -55,6 +55,17 @@ public class ZLAndroidDialogManager extends ZLDialogManager {
myActivity.startActivity(new Intent(myActivity, activityClass));
}
public void runActivity(Class activityClass, Object key, Object data) {
((ZLAndroidApplication)myActivity.getApplication()).putData(key, data);
myActivity.startActivity(new Intent(myActivity, activityClass));
}
/*
public void runActivity(Intent intent) {
myActivity.startActivity(intent);
}
*/
public void showInformationBox(String key, String message) {
showAlert(0, key, message);
}

View file

@ -25,6 +25,7 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.image.*;
import org.geometerplus.zlibrary.text.model.*;
import org.geometerplus.zlibrary.core.tree.ZLTextTree;
import org.geometerplus.fbreader.description.BookDescription;
import org.geometerplus.fbreader.formats.*;
@ -32,7 +33,7 @@ import org.geometerplus.fbreader.formats.*;
public final class BookModel {
public final BookDescription Description;
public final ZLTextPlainModel BookTextModel = new ZLTextPlainModel(65536, "/sdcard/Books/.FBReader", "cache");
public final ContentsModel ContentsModel = new ContentsModel();
public final ContentsTree ContentsTree = new ContentsTree();
private final HashMap<String,ZLTextPlainModel> myFootnotes = new HashMap<String,ZLTextPlainModel>();
private final HashMap myInternalHyperlinks = new HashMap();

View file

@ -24,6 +24,7 @@ import org.geometerplus.zlibrary.core.util.*;
import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.text.model.*;
import org.geometerplus.zlibrary.core.tree.ZLTextTree;
public class BookReader {
public final BookModel Model;
@ -45,14 +46,11 @@ public class BookReader {
private boolean myInsideTitle = false;
private boolean mySectionContainsRegularContents = false;
private boolean myContentsParagraphExists = false;
private final ArrayList myTOCStack = new ArrayList();
private boolean myLastTOCParagraphIsEmpty = false;
private ZLTextTree myCurrentContentsTree;
private final char[] PERIOD = "...".toCharArray();
public BookReader(BookModel model) {
Model = model;
myCurrentContentsTree = model.ContentsTree;
}
private final void flushTextBufferToParagraph() {
@ -220,8 +218,8 @@ public class BookReader {
}
}
public final void addHyperlinkLabel(String label, int paragraphNumber) {
Model.addHyperlinkLabel(label, myCurrentTextModel, paragraphNumber);
public final void addHyperlinkLabel(String label, int paragraphIndex) {
Model.addHyperlinkLabel(label, myCurrentTextModel, paragraphIndex);
}
public final void addContentsData(char[] data) {
@ -229,7 +227,7 @@ public class BookReader {
}
public final void addContentsData(char[] data, int offset, int length) {
if ((length != 0) && !myTOCStack.isEmpty()) {
if ((length != 0) && (myCurrentContentsTree != null)) {
myContentsBuffer.append(data, offset, length);
}
}
@ -240,47 +238,42 @@ public class BookReader {
public final void beginContentsParagraph(ZLTextModel bookTextModel, int referenceNumber) {
final ZLTextPlainModel textModel = myCurrentTextModel;
final ArrayList tocStack = myTOCStack;
if (textModel == bookTextModel) {
ContentsModel contentsModel = Model.ContentsModel;
if (referenceNumber == -1) {
referenceNumber = textModel.getParagraphsNumber();
}
int size = tocStack.size();
ZLTextTreeParagraph peek = (size != 0) ? (ZLTextTreeParagraph)tocStack.get(size - 1) : null;
final ZLTextBuffer contentsBuffer = myContentsBuffer;
if (!contentsBuffer.isEmpty()) {
contentsModel.addText(contentsBuffer);
contentsBuffer.clear();
myLastTOCParagraphIsEmpty = false;
} else if (myLastTOCParagraphIsEmpty) {
contentsModel.addText(PERIOD);
ZLTextTree parentTree = myCurrentContentsTree;
if (parentTree.getLevel() > 0) {
final ZLTextBuffer contentsBuffer = myContentsBuffer;
if (!contentsBuffer.isEmpty()) {
parentTree.setText(contentsBuffer.toString());
contentsBuffer.clear();
} else if (parentTree.getText() == null) {
parentTree.setText("...");
}
} else {
myContentsBuffer.clear();
}
ZLTextTreeParagraph para = contentsModel.createParagraph(peek);
contentsModel.addControl(FBTextKind.CONTENTS_TABLE_ENTRY, true);
contentsModel.setReference(para, myCurrentTextModel, referenceNumber);
tocStack.add(para);
myLastTOCParagraphIsEmpty = true;
myContentsParagraphExists = true;
ZLTextTree tree = parentTree.createSubTree();
Model.ContentsTree.setReference(tree, myCurrentTextModel, referenceNumber);
myCurrentContentsTree = tree;
}
}
public final void endContentsParagraph() {
final ArrayList tocStack = myTOCStack;
if (!tocStack.isEmpty()) {
final ContentsModel contentsModel = Model.ContentsModel;
final ZLTextBuffer contentsBuffer = myContentsBuffer;
if (!contentsBuffer.isEmpty()) {
contentsModel.addText(contentsBuffer);
contentsBuffer.clear();
myLastTOCParagraphIsEmpty = false;
} else if (myLastTOCParagraphIsEmpty) {
contentsModel.addText(PERIOD);
myLastTOCParagraphIsEmpty = false;
}
tocStack.remove(tocStack.size() - 1);
final ZLTextTree tree = myCurrentContentsTree;
final ZLTextBuffer contentsBuffer = myContentsBuffer;
if (tree.getLevel() == 0) {
contentsBuffer.clear();
return;
}
myContentsParagraphExists = false;
if (!contentsBuffer.isEmpty()) {
tree.setText(contentsBuffer.toString());
contentsBuffer.clear();
} else if (tree.getText() == null) {
tree.setText("...");
}
myCurrentContentsTree = tree.getParent();
}
public final void setReference(int contentsParagraphNumber, int referenceNumber) {
@ -288,10 +281,10 @@ public class BookReader {
}
public final void setReference(int contentsParagraphNumber, ZLTextModel textModel, int referenceNumber) {
final ContentsModel contentsModel = Model.ContentsModel;
if (contentsParagraphNumber < contentsModel.getParagraphsNumber()) {
contentsModel.setReference(
contentsModel.getTreeParagraph(contentsParagraphNumber), textModel, referenceNumber
final ContentsTree contentsTree = Model.ContentsTree;
if (contentsParagraphNumber < contentsTree.getSize()) {
contentsTree.setReference(
contentsTree.getTree(contentsParagraphNumber), textModel, referenceNumber
);
}
}
@ -301,7 +294,7 @@ public class BookReader {
}
public final boolean contentsParagraphIsOpen() {
return myContentsParagraphExists;
return myCurrentContentsTree.getLevel() > 0;
}
public final void beginContentsParagraph() {

View file

@ -22,18 +22,18 @@ package org.geometerplus.fbreader.bookmodel;
import java.util.*;
import org.geometerplus.zlibrary.core.util.*;
import org.geometerplus.zlibrary.text.model.*;
import org.geometerplus.zlibrary.text.model.ZLTextModel;
import org.geometerplus.zlibrary.core.tree.ZLTextTree;
public class ContentsModel extends ZLTextTreeModel {
private final HashMap myReferenceByParagraph = new HashMap();
public class ContentsTree extends ZLTextTree {
private final HashMap<ZLTextTree,Reference> myReferenceByTree = new HashMap<ZLTextTree,Reference>();
public Reference getReference(ZLTextTreeParagraph paragraph) {
return (Reference) myReferenceByParagraph.get(paragraph);
// return (num != null) ? num.intValue() : -1;
public Reference getReference(ZLTextTree tree) {
return myReferenceByTree.get(tree);
}
public void setReference(ZLTextTreeParagraph paragraph, ZLTextModel model, int reference) {
myReferenceByParagraph.put(paragraph, new Reference(reference, model));
public void setReference(ZLTextTree tree, ZLTextModel model, int reference) {
myReferenceByTree.put(tree, new Reference(reference, model));
}
public static class Reference {
@ -45,5 +45,4 @@ public class ContentsModel extends ZLTextTreeModel {
Model = model;
}
}
}

View file

@ -22,7 +22,7 @@ package org.geometerplus.fbreader.collection;
import java.util.*;
import org.geometerplus.zlibrary.core.util.*;
import org.geometerplus.zlibrary.core.options.*;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.fbreader.description.*;
import org.geometerplus.fbreader.formats.PluginCollection;
@ -42,9 +42,11 @@ public final class RecentBooks {
}
private final ArrayList<String> myFileNames = new ArrayList<String>();
private final ArrayList<BookDescription> myBooks = new ArrayList<BookDescription>();
private boolean myIsFullySynchronized;
private RecentBooks() {
final ZLStringOption option = new ZLStringOption(ZLOption.STATE_CATEGORY, GROUP, "", "");
final ZLStringOption option = new ZLStringOption(GROUP, "", "");
for (int count = 0; ; ++count) {
option.changeName(BOOK + count);
String name = option.getValue();
@ -55,29 +57,45 @@ public final class RecentBooks {
}
}
public void addBook(String fileName) {
public void addBook(String fileName) {
myFileNames.remove(fileName);
myFileNames.add(0, fileName);
myBooks.clear();
save();
}
public ArrayList<BookDescription> books() {
final ArrayList<BookDescription> bookList = new ArrayList<BookDescription>();
public void rebuild() {
if (!myIsFullySynchronized) {
myBooks.clear();
}
}
public void synchronize() {
if (!myBooks.isEmpty()) {
return;
}
int count = 0;
myIsFullySynchronized = true;
for (String fileName : myFileNames) {
BookDescription description = BookDescription.getDescription(fileName);
if (description != null) {
bookList.add(description);
myBooks.add(description);
} else {
myIsFullySynchronized = false;
}
if (++count >= LIST_SIZE) {
break;
}
}
return bookList;
}
public ArrayList<BookDescription> books() {
synchronize();
return myBooks;
}
public void save() {
final ZLStringOption option = new ZLStringOption(ZLOption.STATE_CATEGORY, GROUP, "", "");
final ZLStringOption option = new ZLStringOption(GROUP, "", "");
int count = 0;
for (String fileName : myFileNames) {
option.changeName(BOOK + count);

View file

@ -26,7 +26,6 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.options.*;
import org.geometerplus.fbreader.formats.*;
import org.geometerplus.fbreader.option.FBOptions;
public class BookDescription implements Comparable {
private static final String EMPTY = "";
@ -169,7 +168,7 @@ public class BookDescription implements Comparable {
}
private void saveTags() {
saveTags(new ZLStringOption(FBOptions.BOOKS_CATEGORY, FileName, "TagList", EMPTY));
saveTags(new ZLStringOption(FileName, "TagList", EMPTY));
}
private void saveTags(ZLStringOption tagsOption) {
@ -199,15 +198,14 @@ public class BookDescription implements Comparable {
public final ZLStringOption TagsOption;
public BookInfo(String fileName) {
final String category = FBOptions.BOOKS_CATEGORY;
AuthorDisplayNameOption = new ZLStringOption(category, fileName, "AuthorDisplayName", EMPTY);
AuthorSortKeyOption = new ZLStringOption(category, fileName, "AuthorSortKey", EMPTY);
TitleOption = new ZLStringOption(category, fileName, "Title", EMPTY);
SeriesNameOption = new ZLStringOption(category, fileName, "Sequence", EMPTY);
NumberInSeriesOption = new ZLIntegerRangeOption(category, fileName, "Number in seq", 0, 100, 0);
LanguageOption = new ZLStringOption(category, fileName, "Language", UNKNOWN);
EncodingOption = new ZLStringOption(category, fileName, "Encoding", EMPTY);
TagsOption = new ZLStringOption(category, fileName, "TagList", EMPTY);
AuthorDisplayNameOption = new ZLStringOption(fileName, "AuthorDisplayName", EMPTY);
AuthorSortKeyOption = new ZLStringOption(fileName, "AuthorSortKey", EMPTY);
TitleOption = new ZLStringOption(fileName, "Title", EMPTY);
SeriesNameOption = new ZLStringOption(fileName, "Sequence", EMPTY);
NumberInSeriesOption = new ZLIntegerRangeOption(fileName, "Number in seq", 0, 100, 0);
LanguageOption = new ZLStringOption(fileName, "Language", UNKNOWN);
EncodingOption = new ZLStringOption(fileName, "Encoding", EMPTY);
TagsOption = new ZLStringOption(fileName, "TagList", EMPTY);
}
public boolean isFull() {

View file

@ -24,7 +24,6 @@ import org.geometerplus.zlibrary.core.util.*;
import org.geometerplus.fbreader.description.BookDescription.BookInfo;
import org.geometerplus.fbreader.formats.PluginCollection;
import org.geometerplus.fbreader.option.FBOptions;
import org.geometerplus.zlibrary.core.filesystem.ZLDir;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.options.ZLIntegerOption;
@ -36,24 +35,24 @@ public class BookDescriptionUtil {
private static final String ENTRIES_NUMBER = "EntriesNumber";
public static boolean checkInfo(ZLFile file) {
ZLIntegerOption op = new ZLIntegerOption(FBOptions.BOOKS_CATEGORY, file.getPath(), SIZE, -1);
ZLIntegerOption op = new ZLIntegerOption(file.getPath(), SIZE, -1);
return op.getValue() == (int)file.size();
}
public static void saveInfo(ZLFile file) {
new ZLIntegerOption(FBOptions.BOOKS_CATEGORY, file.getPath(), SIZE, -1).setValue((int)file.size());
new ZLIntegerOption(file.getPath(), SIZE, -1).setValue((int)file.size());
}
public static void listZipEntries(ZLFile zipFile, ArrayList entries) {
int entriesNumber = new ZLIntegerOption(FBOptions.BOOKS_CATEGORY, zipFile.getPath(), ENTRIES_NUMBER, -1).getValue();
int entriesNumber = new ZLIntegerOption(zipFile.getPath(), ENTRIES_NUMBER, -1).getValue();
if (entriesNumber == -1) {
//??? why so??resetZipInfo(zipFile.path());
resetZipInfo(zipFile);
entriesNumber = new ZLIntegerOption(FBOptions.BOOKS_CATEGORY, zipFile.getPath(), ENTRIES_NUMBER, -1).getValue();
entriesNumber = new ZLIntegerOption(zipFile.getPath(), ENTRIES_NUMBER, -1).getValue();
}
final ZLStringOption entryOption =
new ZLStringOption(FBOptions.BOOKS_CATEGORY, zipFile.getPath(), "", "");
new ZLStringOption(zipFile.getPath(), "", "");
for (int i = 0; i < entriesNumber; ++i) {
entryOption.changeName(ENTRY + i);
final String entry = entryOption.getValue();
@ -76,7 +75,7 @@ public class BookDescriptionUtil {
for (int i = 0; i < size; ++i) {
String entry = (String)entries.get(i);
final ZLStringOption entryOption =
new ZLStringOption(FBOptions.BOOKS_CATEGORY, zipFile.getPath(), "", "");
new ZLStringOption(zipFile.getPath(), "", "");
if (PluginCollection.instance().getPlugin(new ZLFile(entry), true) != null) {
final String fullName = zipPrefix + entry;
entryOption.changeName(ENTRY + counter);
@ -85,7 +84,7 @@ public class BookDescriptionUtil {
++counter;
}
}
new ZLIntegerOption(FBOptions.BOOKS_CATEGORY, zipFile.getPath(), ENTRIES_NUMBER, -1).setValue(counter);
new ZLIntegerOption(zipFile.getPath(), ENTRIES_NUMBER, -1).setValue(counter);
}
}

View file

@ -27,13 +27,11 @@ import org.geometerplus.zlibrary.core.util.*;
import org.geometerplus.zlibrary.core.config.ZLConfig;
import org.geometerplus.zlibrary.core.library.ZLibrary;
import org.geometerplus.zlibrary.core.options.ZLBooleanOption;
import org.geometerplus.zlibrary.core.options.ZLOption;
import org.geometerplus.zlibrary.core.xml.ZLStringMap;
import org.geometerplus.zlibrary.core.xml.ZLXMLReaderAdapter;
public class ZLEncodingCollection {
private static ZLEncodingCollection ourInstance;
private static ZLBooleanOption ourUseWindows1252HackOption;
private final ArrayList/*<ZLEncodingSet>*/ mySets = new ArrayList();
private final HashMap/*<String,ZLEncodingConverterInfo>*/ myInfosByName = new HashMap();
@ -54,19 +52,6 @@ public class ZLEncodingCollection {
return ZLibrary.JAR_DATA_PREFIX + "data/encodings/Encodings.xml";
}
public static ZLBooleanOption useWindows1252HackOption() {
if (ourUseWindows1252HackOption == null) {
ourUseWindows1252HackOption =
new ZLBooleanOption(ZLOption.CONFIG_CATEGORY, "Encoding", "UseWindows1252Hack", true);
}
return ourUseWindows1252HackOption;
}
public static boolean useWindows1252Hack() {
return ZLConfig.Instance() != null/*.isInitialised()*/ && useWindows1252HackOption().getValue();
}
public ArrayList<ZLEncodingSet> sets() {
init();
return mySets;
@ -74,7 +59,7 @@ public class ZLEncodingCollection {
public ZLEncodingConverterInfo info(String name) {
init();
String lowerCaseName = name.toLowerCase();
if (useWindows1252Hack() && (lowerCaseName == "iso-8859-1")) {
if (lowerCaseName == "iso-8859-1") {
lowerCaseName = "windows-1252";
}
return (ZLEncodingConverterInfo)myInfosByName.get(lowerCaseName);

View file

@ -43,7 +43,6 @@ public class BookTextView extends FBView {
private ZLIntegerOption myParagraphIndexOption;
private ZLIntegerOption myWordIndexOption;
private ZLIntegerOption myCharIndexOption;
private ZLTextModel myContentsModel;
private ArrayList myPositionStack = new ArrayList();
private int myCurrentPointInStack;
@ -53,27 +52,23 @@ public class BookTextView extends FBView {
public ZLBooleanOption ShowTOCMarksOption;
public final ZLBooleanOption OpenInBrowserOption =
new ZLBooleanOption(ZLOption.CONFIG_CATEGORY, "Web Browser", "Enabled", true);
new ZLBooleanOption("Web Browser", "Enabled", true);
BookTextView(ZLPaintContext context) {
super(context);
ShowTOCMarksOption = new ZLBooleanOption(ZLOption.LOOK_AND_FEEL_CATEGORY, "Indicator", "ShowTOCMarks", false);
ShowTOCMarksOption = new ZLBooleanOption("Indicator", "ShowTOCMarks", false);
}
public void setContentsModel(ZLTextModel contentsModel) {
myContentsModel = contentsModel;
}
public void setModels(ArrayList/*<ZLTextModel>*/ models, String fileName) {
myFileName = fileName;
myPositionStack.clear();
final int stackSize = new ZLIntegerRangeOption(ZLOption.STATE_CATEGORY, fileName, BUFFER_SIZE, 0, MAX_UNDO_STACK_SIZE, 0).getValue();
myCurrentPointInStack = new ZLIntegerRangeOption(ZLOption.STATE_CATEGORY, fileName, POSITION_IN_BUFFER, 0, (stackSize == 0) ? 0 : (stackSize - 1), 0).getValue();
final int stackSize = new ZLIntegerRangeOption(fileName, BUFFER_SIZE, 0, MAX_UNDO_STACK_SIZE, 0).getValue();
myCurrentPointInStack = new ZLIntegerRangeOption(fileName, POSITION_IN_BUFFER, 0, (stackSize == 0) ? 0 : (stackSize - 1), 0).getValue();
if (models != null) {
final ZLIntegerOption option = new ZLIntegerOption(ZLOption.STATE_CATEGORY, fileName, "", 0);
final ZLIntegerOption option = new ZLIntegerOption(fileName, "", 0);
final int size = models.size();
for (int i = 0; i < stackSize; ++i) {
// option.changeName(MODEL_PREFIX + i);
@ -250,10 +245,10 @@ public class BookTextView extends FBView {
final String group = getFileName();
new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, BUFFER_SIZE, 0).setValue(myPositionStack.size());
new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, POSITION_IN_BUFFER, 0).setValue(myCurrentPointInStack);
new ZLIntegerOption(group, BUFFER_SIZE, 0).setValue(myPositionStack.size());
new ZLIntegerOption(group, POSITION_IN_BUFFER, 0).setValue(myCurrentPointInStack);
final ZLIntegerOption option = new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, "", 0);
final ZLIntegerOption option = new ZLIntegerOption(group, "", 0);
for (int i = 0; i < myPositionStack.size(); ++i) {
Position position = (Position)myPositionStack.get(i);
option.changeName(PARAGRAPH_PREFIX + i);

View file

@ -1,97 +0,0 @@
/*
* 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.core.options.*;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
import org.geometerplus.zlibrary.text.model.*;
import org.geometerplus.zlibrary.text.view.impl.ZLTextWordCursor;
import org.geometerplus.fbreader.bookmodel.ContentsModel;
class ContentsView extends FBView {
ContentsView(ZLPaintContext context) {
super(context);
}
public boolean onStylusRelease(int x, int y) {
if (super.onStylusRelease(x, y)) {
return false;
}
final int index = getParagraphIndexByCoordinate(y);
if (index == -1) {
return false;
}
final ContentsModel contentsModel = (ContentsModel)getModel();
final ZLTextTreeParagraph paragraph = contentsModel.getTreeParagraph(index);
final ContentsModel.Reference reference = contentsModel.getReference(paragraph);
final FBReader fbreader = (FBReader)ZLApplication.Instance();
// fbreader.BookTextView.gotoPosition(reference, 0, 0);
fbreader.BookTextView.gotoParagraphSafe(reference.Model, reference.ParagraphIndex);
fbreader.setMode(FBReader.ViewMode.BOOK_TEXT);
return true;
}
boolean isEmpty() {
final ContentsModel contentsModel = (ContentsModel)getModel();
return (contentsModel == null) || (contentsModel.getParagraphsNumber() == 0);
}
int currentTextViewParagraph(boolean includeStart) {
final FBReader fbreader = (FBReader)ZLApplication.Instance();
final ZLTextWordCursor cursor = fbreader.BookTextView.StartCursor;
if (!cursor.isNull()) {
int reference = cursor.getParagraphCursor().Index;
boolean startOfParagraph = cursor.getWordIndex() == 0;
if (cursor.isEndOfParagraph()) {
++reference;
startOfParagraph = true;
}
final int length = getModel().getParagraphsNumber();
final ContentsModel contentsModel = (ContentsModel)getModel();
final ZLTextModel currentModel = (ZLTextModel) fbreader.BookTextView.getModel();
for (int i = 1; i < length; ++i) {
final ContentsModel.Reference contentsReference =
contentsModel.getReference(contentsModel.getTreeParagraph(i));
if ((contentsReference.Model == currentModel)
&& ((contentsReference.ParagraphIndex > reference) ||
(!includeStart && startOfParagraph
&& (contentsReference.ParagraphIndex == reference)))) {
return i - 1;
}
}
return length - 1;
}
return -1;
}
void gotoReference() {
getModel().removeAllMarks();
final int selected = currentTextViewParagraph(true);
highlightParagraph(selected);
gotoParagraph(selected, false);
scrollPage(false, ScrollingMode.SCROLL_PERCENTAGE, 40);
}
}

View file

@ -45,11 +45,10 @@ public final class FBReader extends ZLApplication {
int UNDEFINED = 0;
int BOOK_TEXT = 1 << 0;
int FOOTNOTE = 1 << 1;
int CONTENTS = 1 << 2;
};
public final ZLBooleanOption UseSeparateBindingsOption =
new ZLBooleanOption(ZLOption.CONFIG_CATEGORY, "KeysOptions", "UseSeparateBindings", false);
new ZLBooleanOption("KeysOptions", "UseSeparateBindings", false);
public final ScrollingOptions TouchScrollingOptions =
new ScrollingOptions("TouchScrolling", ZLTextView.ScrollingMode.NO_OVERLAPPING);
@ -75,7 +74,7 @@ public final class FBReader extends ZLApplication {
}
private final ZLStringOption myBookNameOption =
new ZLStringOption(ZLOption.STATE_CATEGORY, "State", "Book", "");
new ZLStringOption("State", "Book", "");
private final ZLKeyBindings myBindings0 = new ZLKeyBindings("Keys");
private final ZLKeyBindings myBindings90 = new ZLKeyBindings("Keys90");
@ -86,10 +85,9 @@ public final class FBReader extends ZLApplication {
private int myPreviousMode = ViewMode.BOOK_TEXT;
public final BookTextView BookTextView;
public final ContentsView ContentsView;
public final FootnoteView FootnoteView;
private BookModel myBookModel;
BookModel myBookModel;
private final String myArg0;
public FBReader(String[] args) {
@ -132,7 +130,6 @@ public final class FBReader extends ZLApplication {
ZLPaintContext context = ZLibrary.Instance().getPaintContext();
BookTextView = new BookTextView(context);
ContentsView = new ContentsView(context);
FootnoteView = new FootnoteView(context);
setMode(ViewMode.BOOK_TEXT);
@ -197,10 +194,6 @@ public final class FBReader extends ZLApplication {
case ViewMode.BOOK_TEXT:
setView(BookTextView);
break;
case ViewMode.CONTENTS:
ContentsView.gotoReference();
setView(ContentsView);
break;
case ViewMode.FOOTNOTE:
setView(FootnoteView);
break;
@ -234,7 +227,6 @@ public final class FBReader extends ZLApplication {
public void clearTextCaches() {
BookTextView.clearCaches();
ContentsView.clearCaches();
FootnoteView.clearCaches();
}
@ -244,8 +236,6 @@ public final class FBReader extends ZLApplication {
if (description != null) {
BookTextView.saveState();
BookTextView.setModels(null, "");
BookTextView.setContentsModel(null);
ContentsView.setModel(null);
myBookModel = null;
//android.os.Debug.startMethodTracing("/data/anr/loading");
@ -257,11 +247,8 @@ public final class FBReader extends ZLApplication {
// BookTextView.setModel(myBookModel.BookTextModel, fileName);
BookTextView.setModels(myBookModel.getBookTextModels(), fileName);
BookTextView.setCaption(description.getTitle());
BookTextView.setContentsModel(myBookModel.ContentsModel);
FootnoteView.setModel(null);
FootnoteView.setCaption(description.getTitle());
ContentsView.setModel(myBookModel.ContentsModel);
ContentsView.setCaption(description.getTitle());
RecentBooks.Instance().addBook(fileName);
}
resetWindowCaption();

View file

@ -37,7 +37,7 @@ public abstract class FBView extends ZLTextViewImpl {
private static ZLIntegerRangeOption createMarginOption(String name, int defaultValue) {
return new ZLIntegerRangeOption(
ZLOption.LOOK_AND_FEEL_CATEGORY, "Options", name, 0, 1000, defaultValue
"Options", name, 0, 1000, defaultValue
);
}
@ -149,7 +149,7 @@ public abstract class FBView extends ZLTextViewImpl {
public static ZLBooleanOption selectionOption() {
if (ourSelectionOption == null) {
ourSelectionOption = new ZLBooleanOption(ZLOption.LOOK_AND_FEEL_CATEGORY, "Options", "IsSelectionEnabled", true);
ourSelectionOption = new ZLBooleanOption("Options", "IsSelectionEnabled", true);
}
return ourSelectionOption;
}

View file

@ -28,10 +28,9 @@ public final class ScrollingOptions {
public final ZLIntegerRangeOption PercentToScrollOption;
public ScrollingOptions(String group, int mode) {
final String category = ZLOption.CONFIG_CATEGORY;
ModeOption = new ZLIntegerOption(category, group, "Mode", mode);
LinesToKeepOption = new ZLIntegerRangeOption(category, group, "LinesToKeep", 1, 100, 1);
LinesToScrollOption = new ZLIntegerRangeOption(category, group, "LinesToScroll", 1, 100, 1);
PercentToScrollOption = new ZLIntegerRangeOption(category, group, "PercentToScrollOption", 1, 100, 50);
ModeOption = new ZLIntegerOption(group, "Mode", mode);
LinesToKeepOption = new ZLIntegerRangeOption(group, "LinesToKeep", 1, 100, 1);
LinesToScrollOption = new ZLIntegerRangeOption(group, "LinesToScroll", 1, 100, 1);
PercentToScrollOption = new ZLIntegerRangeOption(group, "PercentToScrollOption", 1, 100, 50);
}
}

View file

@ -19,7 +19,6 @@
package org.geometerplus.fbreader.fbreader;
import org.geometerplus.fbreader.option.FBOptions;
import org.geometerplus.zlibrary.core.options.*;
import org.geometerplus.zlibrary.core.dialogs.*;
import org.geometerplus.zlibrary.core.resources.ZLResource;
@ -37,11 +36,11 @@ class SearchAction extends FBAction {
SearchAction(FBReader fbreader) {
super(fbreader);
SearchBackwardOption = new ZLBooleanOption(FBOptions.SEARCH_CATEGORY, SEARCH, "Backward", false);
SearchIgnoreCaseOption = new ZLBooleanOption(FBOptions.SEARCH_CATEGORY, SEARCH, "IgnoreCase", true);
SearchInWholeTextOption = new ZLBooleanOption(FBOptions.SEARCH_CATEGORY, SEARCH, "WholeText", false);
SearchThisSectionOnlyOption = new ZLBooleanOption(FBOptions.SEARCH_CATEGORY, SEARCH, "ThisSectionOnly", false);
SearchPatternOption = new ZLStringOption(FBOptions.SEARCH_CATEGORY, SEARCH, PATTERN, "");
SearchBackwardOption = new ZLBooleanOption(SEARCH, "Backward", false);
SearchIgnoreCaseOption = new ZLBooleanOption(SEARCH, "IgnoreCase", true);
SearchInWholeTextOption = new ZLBooleanOption(SEARCH, "WholeText", false);
SearchThisSectionOnlyOption = new ZLBooleanOption(SEARCH, "ThisSectionOnly", false);
SearchPatternOption = new ZLStringOption(SEARCH, PATTERN, "");
}
public boolean isVisible() {

View file

@ -21,7 +21,6 @@ package org.geometerplus.fbreader.fbreader;
import java.util.ArrayList;
import org.geometerplus.fbreader.option.FBOptions;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.dialogs.ZLComboOptionEntry;
@ -42,7 +41,7 @@ class SearchPatternEntry extends ZLComboOptionEntry {
int index = 1;
for (int i = 0; (index < 6) && (i < myValues.size()); i++) {
if (!myValues.get(i).equals(v)) {
(new ZLStringOption(FBOptions.SEARCH_CATEGORY, SearchAction.SEARCH, SearchAction.PATTERN + index, "")).
(new ZLStringOption(SearchAction.SEARCH, SearchAction.PATTERN + index, "")).
setValue((String) myValues.get(i));
index++;
}
@ -54,8 +53,7 @@ class SearchPatternEntry extends ZLComboOptionEntry {
if (myValues.isEmpty()) {
myValues.add(myAction.SearchPatternOption.getValue());
for (int i = 1; i < 6; i++) {
String value = (new ZLStringOption(FBOptions.SEARCH_CATEGORY,
SearchAction.SEARCH, SearchAction.PATTERN + i, "")).getValue();
String value = (new ZLStringOption(SearchAction.SEARCH, SearchAction.PATTERN + i, "")).getValue();
if (value != "") {
myValues.add(value);
}

View file

@ -20,6 +20,7 @@
package org.geometerplus.fbreader.fbreader;
import org.geometerplus.fbreader.collection.BookCollection;
import org.geometerplus.fbreader.collection.RecentBooks;
import org.geometerplus.android.fbreader.LibraryTabActivity;
@ -38,6 +39,9 @@ class ShowLibrary extends FBAction {
BookCollection collection = BookCollection.Instance();
collection.rebuild();
collection.synchronize();
RecentBooks recentBooks = RecentBooks.Instance();
recentBooks.rebuild();
recentBooks.synchronize();
// TODO: select current book (author?)
/*
if (myBookModel != null) {

View file

@ -19,6 +19,9 @@
package org.geometerplus.fbreader.fbreader;
//import android.net.Uri;
//import android.content.Intent;
import org.geometerplus.android.fbreader.TOCActivity;
import org.geometerplus.zlibrary.ui.android.dialogs.ZLAndroidDialogManager;
@ -29,19 +32,20 @@ class ShowTOCAction extends FBAction {
}
public boolean isVisible() {
switch (Reader.getMode()) {
case FBReader.ViewMode.BOOK_TEXT:
case FBReader.ViewMode.FOOTNOTE:
return !Reader.ContentsView.isEmpty();
default:
return false;
}
// TODO: check if contents model is empty
//return !Reader.ContentsView.isEmpty();
return Reader.myBookModel.ContentsTree.getSize() > 1;
}
public void run() {
final ZLAndroidDialogManager dialogManager =
(ZLAndroidDialogManager)ZLAndroidDialogManager.getInstance();
dialogManager.runActivity(TOCActivity.class);
//Reader.setMode(FBReader.ViewMode.CONTENTS);
/*
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
dialogManager.runActivity(intent);
*/
// TODO: open tree
dialogManager.runActivity(TOCActivity.class, TOCActivity.DATA_KEY, Reader.myBookModel.ContentsTree);
}
}

View file

@ -64,9 +64,9 @@ public class PluginCollection {
}
private PluginCollection() {
LanguageAutoDetectOption = new ZLBooleanOption(ZLOption.CONFIG_CATEGORY, "Format", "AutoDetect", true);
DefaultLanguageOption = new ZLStringOption(ZLOption.CONFIG_CATEGORY, "Format", "DefaultLanguage", "en");
DefaultEncodingOption = new ZLStringOption(ZLOption.CONFIG_CATEGORY, "Format", "DefaultEncoding", "windows-1252");
LanguageAutoDetectOption = new ZLBooleanOption("Format", "AutoDetect", true);
DefaultLanguageOption = new ZLStringOption("Format", "DefaultLanguage", "en");
DefaultEncodingOption = new ZLStringOption("Format", "DefaultEncoding", "windows-1252");
}
public FormatPlugin getPlugin(ZLFile file, boolean strong) {

View file

@ -25,7 +25,6 @@ import java.io.InputStream;
import org.geometerplus.fbreader.description.BookDescriptionUtil;
import org.geometerplus.fbreader.formats.FormatPlugin;
import org.geometerplus.fbreader.formats.plucker.PluckerTextStream;
import org.geometerplus.fbreader.option.FBOptions;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
@ -41,7 +40,7 @@ public abstract class PdbPlugin extends FormatPlugin {
ZLFile baseFile = (index == -1) ? file : new ZLFile(fileName.substring(0, index));
boolean upToDate = BookDescriptionUtil.checkInfo(baseFile);
ZLStringOption palmTypeOption = new ZLStringOption(FBOptions.BOOKS_CATEGORY, file.getPath(), "PalmType", "");
ZLStringOption palmTypeOption = new ZLStringOption(file.getPath(), "PalmType", "");
String palmType = palmTypeOption.getValue();
if ((palmType.length() != 8) || !upToDate) {
byte[] id = new byte[8];

View file

@ -33,7 +33,7 @@ import org.geometerplus.fbreader.fbreader.*;
public class KeyBindingsPage {
public KeyBindingsPage(FBReader fbreader, ZLDialogContent dialogTab) {
if (new ZLBooleanOption(ZLOption.EMPTY, ZLOption.PLATFORM_GROUP, "FullKeyboardControlSupported", false).getValue()) {
if (new ZLBooleanOption(ZLOption.PLATFORM_GROUP, "FullKeyboardControlSupported", false).getValue()) {
dialogTab.addOption("grabSystemKeys", new KeyboardControlEntry(fbreader));
}
MultiKeyOptionEntry keyEntry = new MultiKeyOptionEntry(dialogTab.getResource("action"), fbreader);

View file

@ -48,7 +48,6 @@ public class OptionsDialog {
// EncodingSetEntry encodingSetEntry = new EncodingSetEntry(encodingEntry);
// encodingTab.addOption("defaultEncodingSet", encodingSetEntry);
// encodingTab.addOption("defaultEncoding", encodingEntry);
encodingTab.addOption("useWindows1252Hack", new ZLSimpleBooleanOptionEntry(ZLEncodingCollection.useWindows1252HackOption()));
new ScrollingOptionsPage(myDialog.createTab("Scrolling"), fbreader);

View file

@ -26,7 +26,6 @@ import org.geometerplus.zlibrary.core.library.ZLibrary;
import org.geometerplus.zlibrary.core.options.ZLBooleanOption;
import org.geometerplus.zlibrary.core.options.ZLIntegerOption;
import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption;
import org.geometerplus.zlibrary.core.options.ZLOption;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.view.ZLView;
import org.geometerplus.zlibrary.core.view.ZLViewWidget;
@ -55,21 +54,21 @@ public abstract class ZLApplication {
public final ZLIntegerOption RotationAngleOption =
// temporary commented while we have no options dialog
//new ZLIntegerOption(ZLOption.CONFIG_CATEGORY, ROTATION, ANGLE, ZLViewWidget.Angle.DEGREES90);
new ZLIntegerOption(ZLOption.CONFIG_CATEGORY, ROTATION, ANGLE, -1);
//new ZLIntegerOption(ROTATION, ANGLE, ZLViewWidget.Angle.DEGREES90);
new ZLIntegerOption(ROTATION, ANGLE, -1);
public final ZLIntegerOption AngleStateOption =
new ZLIntegerOption(ZLOption.CONFIG_CATEGORY, STATE, ANGLE, ZLViewWidget.Angle.DEGREES0);
new ZLIntegerOption(STATE, ANGLE, ZLViewWidget.Angle.DEGREES0);
public final ZLBooleanOption KeyboardControlOption =
new ZLBooleanOption(ZLOption.CONFIG_CATEGORY, KEYBOARD, FULL_CONTROL, false);
new ZLBooleanOption(KEYBOARD, FULL_CONTROL, false);
public final ZLBooleanOption ConfigAutoSavingOption =
new ZLBooleanOption(ZLOption.CONFIG_CATEGORY, CONFIG, AUTO_SAVE, true);
new ZLBooleanOption(CONFIG, AUTO_SAVE, true);
public final ZLIntegerRangeOption ConfigAutoSaveTimeoutOption =
new ZLIntegerRangeOption(ZLOption.CONFIG_CATEGORY, CONFIG, TIMEOUT, 1, 6000, 30);
new ZLIntegerRangeOption(CONFIG, TIMEOUT, 1, 6000, 30);
public final ZLIntegerRangeOption KeyDelayOption =
new ZLIntegerRangeOption(ZLOption.CONFIG_CATEGORY, "Options", "KeyDelay", 0, 5000, 250);
new ZLIntegerRangeOption("Options", "KeyDelay", 0, 5000, 250);
protected ZLViewWidget myViewWidget;
private ZLApplicationWindow myWindow;

View file

@ -26,7 +26,6 @@ import org.geometerplus.zlibrary.core.util.*;
import org.geometerplus.zlibrary.core.options.ZLIntegerOption;
import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption;
import org.geometerplus.zlibrary.core.options.ZLOption;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
public final class ZLKeyBindings {
@ -62,11 +61,11 @@ public final class ZLKeyBindings {
private void loadCustomBindings() {
final int size =
new ZLIntegerRangeOption(ZLOption.CONFIG_CATEGORY, myName, BINDINGS_NUMBER, 0, 256, 0).getValue();
new ZLIntegerRangeOption(myName, BINDINGS_NUMBER, 0, 256, 0).getValue();
final ZLStringOption keyOption =
new ZLStringOption(ZLOption.CONFIG_CATEGORY, myName, "", "");
new ZLStringOption(myName, "", "");
final ZLStringOption actionOption =
new ZLStringOption(ZLOption.CONFIG_CATEGORY, myName, "", "");
new ZLStringOption(myName, "", "");
for (int i = 0; i < size; ++i) {
keyOption.changeName(BINDED_KEY + i);
final String keyValue = keyOption.getValue();
@ -90,9 +89,9 @@ public final class ZLKeyBindings {
int counter = 0;
final ZLStringOption keyOption =
new ZLStringOption(ZLOption.CONFIG_CATEGORY, myName, "", "");
new ZLStringOption(myName, "", "");
final ZLStringOption actionOption =
new ZLStringOption(ZLOption.CONFIG_CATEGORY, myName, "", "");
new ZLStringOption(myName, "", "");
for (Iterator it = myBindingsMap.keySet().iterator(); it.hasNext(); ) {
final String key = (String)it.next();
final String originalValue = (String)keymap.get(key);
@ -105,6 +104,6 @@ public final class ZLKeyBindings {
++counter;
}
}
new ZLIntegerRangeOption(ZLOption.CONFIG_CATEGORY, myName, BINDINGS_NUMBER, 0, 256, 0).setValue(counter);
new ZLIntegerRangeOption(myName, BINDINGS_NUMBER, 0, 256, 0).setValue(counter);
}
}

View file

@ -32,7 +32,7 @@ public abstract class ZLConfig {
public abstract void shutdown();
public abstract String getValue(String group, String name, String defaultValue);
public abstract void setValue(String group, String name, String value, String category);
public abstract void setValue(String group, String name, String value);
public abstract void unsetValue(String group, String name);
public abstract void removeGroup(String name);
}

View file

@ -36,7 +36,7 @@ public abstract class ZLOptionsDialog {
myResource = resource;
myExitAction = exitAction;
myApplyAction = applyAction;
myTabOption = new ZLStringOption(ZLOption.LOOK_AND_FEEL_CATEGORY, resource.Name, "SelectedTab", "");
myTabOption = new ZLStringOption(resource.Name, "SelectedTab", "");
}
protected void acceptTab(ZLDialogContent tab) {

View file

@ -25,8 +25,8 @@ public final class ZLBoolean3Option extends ZLOption implements ZLSimpleOption {
private int myValue;
private final int myDefaultValue;
public ZLBoolean3Option(String category, String group, String optionName, int defaultValue) {
super(category, group, optionName);
public ZLBoolean3Option(String group, String optionName, int defaultValue) {
super(group, optionName);
myDefaultValue = defaultValue;
myValue = myDefaultValue;
}

View file

@ -23,8 +23,8 @@ public final class ZLBooleanOption extends ZLOption implements ZLSimpleOption {
private final boolean myDefaultValue;
private boolean myValue;
public ZLBooleanOption(String category, String group, String optionName, boolean defaultValue) {
super(category, group, optionName);
public ZLBooleanOption(String group, String optionName, boolean defaultValue) {
super(group, optionName);
myDefaultValue = defaultValue;
myValue = defaultValue;
}

View file

@ -34,8 +34,8 @@ public final class ZLColorOption extends ZLOption {
private final ZLColor myDefaultValue;
private ZLColor myValue;
public ZLColorOption(String category, String group, String optionName, ZLColor defaultValue) {
super(category, group, optionName);
public ZLColorOption(String group, String optionName, ZLColor defaultValue) {
super(group, optionName);
myDefaultValue = (defaultValue != null) ? defaultValue : new ZLColor(0);
myValue = myDefaultValue;
}

View file

@ -23,8 +23,8 @@ public final class ZLIntegerOption extends ZLOption {
private final int myDefaultValue;
private int myValue;
public ZLIntegerOption(String category, String group, String optionName, int defaultValue) {
super(category, group, optionName);
public ZLIntegerOption(String group, String optionName, int defaultValue) {
super(group, optionName);
myDefaultValue = defaultValue;
myValue = defaultValue;
}

View file

@ -26,8 +26,8 @@ public final class ZLIntegerRangeOption extends ZLOption {
private final int myDefaultValue;
private int myValue;
public ZLIntegerRangeOption(String category, String group, String optionName, int minValue, int maxValue, int defaultValue) {
super(category, group, optionName);
public ZLIntegerRangeOption(String group, String optionName, int minValue, int maxValue, int defaultValue) {
super(group, optionName);
MinValue = minValue;
MaxValue = maxValue;
if (defaultValue < MinValue) {

View file

@ -22,27 +22,13 @@ package org.geometerplus.zlibrary.core.options;
import org.geometerplus.zlibrary.core.config.ZLConfig;
public abstract class ZLOption {
public static final String LOOK_AND_FEEL_CATEGORY = "ui";
public static final String CONFIG_CATEGORY = "options";
public static final String STATE_CATEGORY = "state";
public static final String EMPTY = "";
public static final String PLATFORM_GROUP = "PlatformOptions";
private final String myCategory;
private final String myGroup;
private String myOptionName;
protected boolean myIsSynchronized;
/**
* êîíñòðóêòîð
*
* @param config
* @param category
* @param group
* @param optionName
*/
protected ZLOption(String category, String group, String optionName) {
myCategory = category.intern();
protected ZLOption(String group, String optionName) {
myGroup = group.intern();
myOptionName = optionName.intern();
myIsSynchronized = false;
@ -62,7 +48,7 @@ public abstract class ZLOption {
protected final void setConfigValue(String value) {
ZLConfig config = ZLConfig.Instance();
if (config != null) {
config.setValue(myGroup, myOptionName, value, myCategory);
config.setValue(myGroup, myOptionName, value);
}
}

View file

@ -23,8 +23,8 @@ public final class ZLStringOption extends ZLOption implements ZLSimpleOption {
private final String myDefaultValue;
private String myValue;
public ZLStringOption(String category, String group, String optionName, String defaultValue) {
super(category, group, optionName);
public ZLStringOption(String group, String optionName, String defaultValue) {
super(group, optionName);
myDefaultValue = (defaultValue != null) ? defaultValue.intern() : "";
myValue = myDefaultValue;
}

View file

@ -0,0 +1,97 @@
/*
* 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.zlibrary.core.tree;
import java.util.ArrayList;
public class ZLTextTree {
private static final ArrayList<ZLTextTree> ourEmptyList = new ArrayList<ZLTextTree>();
private int mySize = 1;
private String myText;
private final ZLTextTree myParent;
private final int myLevel;
private ArrayList<ZLTextTree> mySubTrees;
protected ZLTextTree() {
myParent = null;
myLevel = 0;
}
private ZLTextTree(ZLTextTree parent) {
myParent = parent;
myLevel = parent.myLevel + 1;
}
public final ZLTextTree getParent() {
return myParent;
}
public final int getLevel() {
return myLevel;
}
public final int getSize() {
return mySize;
}
public final String getText() {
return myText;
}
public final ArrayList<ZLTextTree> subTrees() {
return (mySubTrees != null) ? mySubTrees : ourEmptyList;
}
public final ZLTextTree getTree(int index) {
if ((index < 0) || (index >= mySize)) {
// TODO: throw exception?
return null;
}
if (index == 0) {
return this;
}
--index;
for (ZLTextTree subtree : mySubTrees) {
if (subtree.mySize <= index) {
index -= subtree.mySize;
} else {
return subtree.getTree(index);
}
}
return null;
}
public final void setText(String text) {
myText = text;
}
public final ZLTextTree createSubTree() {
if (mySubTrees == null) {
mySubTrees = new ArrayList<ZLTextTree>();
}
ZLTextTree tree = new ZLTextTree(this);
mySubTrees.add(tree);
for (ZLTextTree parent = this; parent != null; parent = parent.myParent) {
++parent.mySize;
}
return tree;
}
}

View file

@ -74,4 +74,8 @@ public final class ZLTextBuffer {
public void clear() {
myDataLength = 0;
}
public String toString() {
return new String(myData, 0, myDataLength);
}
}

View file

@ -26,44 +26,43 @@ import org.geometerplus.zlibrary.text.view.ZLTextStyle;
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
public class ZLTextBaseStyle implements ZLTextStyle {
private static final String CATEGORY = ZLOption.LOOK_AND_FEEL_CATEGORY;
private static final String COLORS = "Colors";
private static final String GROUP = "Style";
private static final String OPTIONS = "Options";
public final ZLColorOption BackgroundColorOption =
new ZLColorOption(CATEGORY, COLORS, "Background", new ZLColor(255, 255, 255));
new ZLColorOption(COLORS, "Background", new ZLColor(255, 255, 255));
public final ZLColorOption SelectionBackgroundColorOption =
new ZLColorOption(CATEGORY, COLORS, "SelectionBackground", new ZLColor(82, 131, 194));
new ZLColorOption(COLORS, "SelectionBackground", new ZLColor(82, 131, 194));
public final ZLColorOption HighlightedTextColorOption =
new ZLColorOption(CATEGORY, COLORS, "SelectedText", new ZLColor(60, 139, 255));
new ZLColorOption(COLORS, "SelectedText", new ZLColor(60, 139, 255));
public final ZLColorOption RegularTextColorOption =
new ZLColorOption(CATEGORY, COLORS, "Text", new ZLColor(0, 0, 0));
new ZLColorOption(COLORS, "Text", new ZLColor(0, 0, 0));
public final ZLColorOption InternalHyperlinkTextColorOption =
new ZLColorOption(CATEGORY, COLORS, "Hyperlink", new ZLColor(33, 96, 180));
new ZLColorOption(COLORS, "Hyperlink", new ZLColor(33, 96, 180));
public final ZLColorOption ExternalHyperlinkTextColorOption =
new ZLColorOption(CATEGORY, COLORS, "ExternalHyperlink", new ZLColor(98, 174, 26));
new ZLColorOption(COLORS, "ExternalHyperlink", new ZLColor(98, 174, 26));
public final ZLColorOption TreeLinesColorOption =
new ZLColorOption(CATEGORY, COLORS, "TreeLines", new ZLColor(127, 127, 127));
new ZLColorOption(COLORS, "TreeLines", new ZLColor(127, 127, 127));
public final ZLBooleanOption AutoHyphenationOption =
new ZLBooleanOption(CATEGORY, OPTIONS, "AutoHyphenation", true);
new ZLBooleanOption(OPTIONS, "AutoHyphenation", true);
public final ZLBooleanOption BoldOption =
new ZLBooleanOption(CATEGORY, GROUP, "Base:bold", false);
new ZLBooleanOption(GROUP, "Base:bold", false);
public final ZLBooleanOption ItalicOption =
new ZLBooleanOption(CATEGORY, GROUP, "Base:italic", false);
new ZLBooleanOption(GROUP, "Base:italic", false);
public final ZLIntegerOption AlignmentOption =
new ZLIntegerOption(CATEGORY, GROUP, "Base:alignment", ZLTextAlignmentType.ALIGN_JUSTIFY);
new ZLIntegerOption(GROUP, "Base:alignment", ZLTextAlignmentType.ALIGN_JUSTIFY);
public final ZLIntegerOption LineSpacePercentOption =
new ZLIntegerOption(CATEGORY, GROUP, "Base:lineSpacingPercent", 120);
new ZLIntegerOption(GROUP, "Base:lineSpacingPercent", 120);
public final ZLStringOption FontFamilyOption;
public final ZLIntegerRangeOption FontSizeOption;
public ZLTextBaseStyle(String fontFamily, int fontSize) {
FontFamilyOption = new ZLStringOption(CATEGORY, GROUP, "Base:fontFamily", fontFamily);
FontSizeOption = new ZLIntegerRangeOption(CATEGORY, GROUP, "Base:fontSize", 0, 72, fontSize);
FontFamilyOption = new ZLStringOption(GROUP, "Base:fontFamily", fontFamily);
FontSizeOption = new ZLIntegerRangeOption(GROUP, "Base:fontSize", 0, 72, fontSize);
}
public String getFontFamily() {

View file

@ -39,14 +39,13 @@ public class ZLTextFullStyleDecoration extends ZLTextStyleDecoration {
public ZLTextFullStyleDecoration(String name, int fontSizeDelta, int bold, int italic, int spaceBefore, int spaceAfter, int leftIndent,int rightIndent, int firstLineIndentDelta, int verticalShift, byte alignment, int lineSpace, int allowHyphenations) {
super(name, fontSizeDelta, bold, italic, verticalShift, allowHyphenations);
final String category = ZLOption.LOOK_AND_FEEL_CATEGORY;
SpaceBeforeOption = new ZLIntegerRangeOption(category, STYLE, name + ":spaceBefore", -10, 100, spaceBefore);
SpaceAfterOption = new ZLIntegerRangeOption(category, STYLE, name + ":spaceAfter", -10, 100, spaceAfter);
LeftIndentOption = new ZLIntegerRangeOption(category, STYLE, name + ":leftIndent", -300, 300, leftIndent);
RightIndentOption = new ZLIntegerRangeOption(category, STYLE, name + ":rightIndent", -300, 300, rightIndent);
FirstLineIndentDeltaOption = new ZLIntegerRangeOption(category, STYLE, name + ":firstLineIndentDelta", -300, 300, firstLineIndentDelta);
AlignmentOption = new ZLIntegerOption(category, STYLE, name + ":alignment", alignment);
LineSpacePercentOption = new ZLIntegerOption(category, STYLE, name + ":lineSpacePercent", lineSpace);
SpaceBeforeOption = new ZLIntegerRangeOption(STYLE, name + ":spaceBefore", -10, 100, spaceBefore);
SpaceAfterOption = new ZLIntegerRangeOption(STYLE, name + ":spaceAfter", -10, 100, spaceAfter);
LeftIndentOption = new ZLIntegerRangeOption(STYLE, name + ":leftIndent", -300, 300, leftIndent);
RightIndentOption = new ZLIntegerRangeOption(STYLE, name + ":rightIndent", -300, 300, rightIndent);
FirstLineIndentDeltaOption = new ZLIntegerRangeOption(STYLE, name + ":firstLineIndentDelta", -300, 300, firstLineIndentDelta);
AlignmentOption = new ZLIntegerOption(STYLE, name + ":alignment", alignment);
LineSpacePercentOption = new ZLIntegerOption(STYLE, name + ":lineSpacePercent", lineSpace);
}
public boolean isFullDecoration() {

View file

@ -39,13 +39,12 @@ public class ZLTextStyleDecoration {
public ZLTextStyleDecoration(String name, int fontSizeDelta, int bold, int italic, int verticalShift, int allowHyphenations) {
myName = name;
final String category = ZLOption.LOOK_AND_FEEL_CATEGORY;
FontFamilyOption = new ZLStringOption(category, STYLE, name + ":fontFamily", "");
FontSizeDeltaOption = new ZLIntegerRangeOption(category, STYLE, name + ":fontSize", -16, 16, fontSizeDelta);
BoldOption = new ZLBoolean3Option(category, STYLE, name + ":bold", bold);
ItalicOption = new ZLBoolean3Option(category, STYLE, name + ":italic", italic);
VerticalShiftOption = new ZLIntegerOption(category, STYLE, name + ":vShift", verticalShift);
AllowHyphenationsOption = new ZLBoolean3Option(category, STYLE, name + ":allowHyphenations", allowHyphenations);
FontFamilyOption = new ZLStringOption(STYLE, name + ":fontFamily", "");
FontSizeDeltaOption = new ZLIntegerRangeOption(STYLE, name + ":fontSize", -16, 16, fontSizeDelta);
BoldOption = new ZLBoolean3Option(STYLE, name + ":bold", bold);
ItalicOption = new ZLBoolean3Option(STYLE, name + ":italic", italic);
VerticalShiftOption = new ZLIntegerOption(STYLE, name + ":vShift", verticalShift);
AllowHyphenationsOption = new ZLBoolean3Option(STYLE, name + ":allowHyphenations", allowHyphenations);
}
public ZLTextStyle createDecoratedStyle(ZLTextStyle base) {