mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
footnote text in the toast
This commit is contained in:
parent
67217c4264
commit
e06804dda1
8 changed files with 90 additions and 32 deletions
|
@ -255,6 +255,9 @@
|
||||||
<node name="saveText" value="Save text"/>
|
<node name="saveText" value="Save text"/>
|
||||||
<node name="editStyle" value="Edit style…"/>
|
<node name="editStyle" value="Edit style…"/>
|
||||||
</node>
|
</node>
|
||||||
|
<node name="footnoteToast">
|
||||||
|
<node name="more" value="More"/>
|
||||||
|
</node>
|
||||||
<node name="cancelMenu">
|
<node name="cancelMenu">
|
||||||
<node name="library" value="Open library"/>
|
<node name="library" value="Open library"/>
|
||||||
<node name="networkLibrary" value="Open network library"/>
|
<node name="networkLibrary" value="Open network library"/>
|
||||||
|
|
|
@ -30,6 +30,8 @@ import com.github.johnpersano.supertoasts.SuperToast;
|
||||||
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
|
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
import org.geometerplus.zlibrary.text.util.AutoTextSnippet;
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
@ -70,16 +72,18 @@ class ProcessHyperlinkAction extends FBAndroidAction {
|
||||||
case FBHyperlinkType.INTERNAL:
|
case FBHyperlinkType.INTERNAL:
|
||||||
Reader.Collection.markHyperlinkAsVisited(Reader.getCurrentBook(), hyperlink.Id);
|
Reader.Collection.markHyperlinkAsVisited(Reader.getCurrentBook(), hyperlink.Id);
|
||||||
{
|
{
|
||||||
final FBReaderApp.FootnoteData data = Reader.getFootnoteData(hyperlink.Id);
|
final AutoTextSnippet snippet = Reader.getFootnoteData(hyperlink.Id);
|
||||||
if (data != null) {
|
if (snippet == null) {
|
||||||
final SuperActivityToast toast =
|
break;
|
||||||
new SuperActivityToast(BaseActivity, SuperToast.Type.BUTTON);
|
}
|
||||||
toast.setText(data.Text);
|
final SuperActivityToast toast;
|
||||||
toast.setDuration(SuperToast.Duration.LONG);
|
if (snippet.IsEndOfText) {
|
||||||
|
toast = new SuperActivityToast(BaseActivity, SuperToast.Type.STANDARD);
|
||||||
|
} else {
|
||||||
|
toast = new SuperActivityToast(BaseActivity, SuperToast.Type.BUTTON);
|
||||||
toast.setButtonIcon(
|
toast.setButtonIcon(
|
||||||
android.R.drawable.ic_menu_more,
|
android.R.drawable.ic_menu_more,
|
||||||
"More"
|
ZLResource.resource("footnoteToast").getResource("more").getValue()
|
||||||
//ZLResource.resource("dialog").getResource("button").getResource("edit").getValue()
|
|
||||||
);
|
);
|
||||||
toast.setOnClickWrapper(new OnClickWrapper("ftnt", new SuperToast.OnClickListener() {
|
toast.setOnClickWrapper(new OnClickWrapper("ftnt", new SuperToast.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,8 +91,10 @@ class ProcessHyperlinkAction extends FBAndroidAction {
|
||||||
Reader.tryOpenFootnote(hyperlink.Id);
|
Reader.tryOpenFootnote(hyperlink.Id);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
toast.show();
|
|
||||||
}
|
}
|
||||||
|
toast.setText(snippet.getText());
|
||||||
|
toast.setDuration(SuperToast.Duration.LONG);
|
||||||
|
toast.show();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
import org.geometerplus.zlibrary.text.util.AutoTextSnippet;
|
||||||
import org.geometerplus.zlibrary.text.util.TextSnippet;
|
import org.geometerplus.zlibrary.text.util.TextSnippet;
|
||||||
import org.geometerplus.zlibrary.text.util.TextSnippetImpl;
|
|
||||||
|
|
||||||
public final class Bookmark extends ZLTextFixedPosition {
|
public final class Bookmark extends ZLTextFixedPosition {
|
||||||
public enum DateType {
|
public enum DateType {
|
||||||
|
@ -35,7 +35,7 @@ public final class Bookmark extends ZLTextFixedPosition {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bookmark createBookmark(Book book, String modelId, ZLTextWordCursor startCursor, int maxWords, boolean isVisible) {
|
public static Bookmark createBookmark(Book book, String modelId, ZLTextWordCursor startCursor, int maxWords, boolean isVisible) {
|
||||||
return new Bookmark(book, modelId, new TextSnippetImpl(startCursor, maxWords), isVisible);
|
return new Bookmark(book, modelId, new AutoTextSnippet(startCursor, maxWords), isVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long myId;
|
private long myId;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.geometerplus.zlibrary.core.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
||||||
|
import org.geometerplus.zlibrary.text.util.AutoTextSnippet;
|
||||||
import org.geometerplus.zlibrary.text.util.EmptyTextSnippet;
|
import org.geometerplus.zlibrary.text.util.EmptyTextSnippet;
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
|
||||||
|
@ -211,17 +212,7 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
return (FBView)getCurrentView();
|
return (FBView)getCurrentView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FootnoteData {
|
public AutoTextSnippet getFootnoteData(String id) {
|
||||||
public final String Text;
|
|
||||||
public final boolean IsFull;
|
|
||||||
|
|
||||||
private FootnoteData(String text, boolean isFull) {
|
|
||||||
Text = text;
|
|
||||||
IsFull = isFull;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FootnoteData getFootnoteData(String id) {
|
|
||||||
if (Model == null) {
|
if (Model == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +220,18 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
if (label == null) {
|
if (label == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new FootnoteData("Here will be the footnote text", false);
|
final ZLTextModel model;
|
||||||
|
if (label.ModelId != null) {
|
||||||
|
model = Model.getFootnoteModel(label.ModelId);
|
||||||
|
} else {
|
||||||
|
model = Model.getTextModel();
|
||||||
|
}
|
||||||
|
if (model == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final ZLTextWordCursor cursor =
|
||||||
|
new ZLTextWordCursor(new ZLTextParagraphCursor(model, label.ParagraphIndex));
|
||||||
|
return new AutoTextSnippet(cursor, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tryOpenFootnote(String id) {
|
public void tryOpenFootnote(String id) {
|
||||||
|
|
|
@ -29,8 +29,8 @@ import org.geometerplus.zlibrary.core.util.ZLColor;
|
||||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
||||||
|
import org.geometerplus.zlibrary.text.util.FixedTextSnippet;
|
||||||
import org.geometerplus.zlibrary.text.util.TextSnippet;
|
import org.geometerplus.zlibrary.text.util.TextSnippet;
|
||||||
import org.geometerplus.zlibrary.text.util.TextSnippetImpl;
|
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection;
|
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection;
|
||||||
|
|
||||||
|
@ -747,7 +747,7 @@ public final class FBView extends ZLTextView {
|
||||||
if (!isSelectionEmpty()) {
|
if (!isSelectionEmpty()) {
|
||||||
traverser.traverse(start, end);
|
traverser.traverse(start, end);
|
||||||
}
|
}
|
||||||
return new TextSnippetImpl(start, end, traverser.getText());
|
return new FixedTextSnippet(start, end, traverser.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCountOfSelectedWords() {
|
public int getCountOfSelectedWords() {
|
||||||
|
|
|
@ -23,18 +23,14 @@ import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
|
||||||
public class TextSnippetImpl implements TextSnippet {
|
public final class AutoTextSnippet implements TextSnippet {
|
||||||
private final ZLTextPosition myStart;
|
private final ZLTextPosition myStart;
|
||||||
private final ZLTextPosition myEnd;
|
private final ZLTextPosition myEnd;
|
||||||
private final String myText;
|
private final String myText;
|
||||||
|
|
||||||
public TextSnippetImpl(ZLTextPosition start, ZLTextPosition end, String text) {
|
public final boolean IsEndOfText;
|
||||||
myStart = start;
|
|
||||||
myEnd = end;
|
|
||||||
myText = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextSnippetImpl(ZLTextWordCursor start, int maxWords) {
|
public AutoTextSnippet(ZLTextWordCursor start, int maxWords) {
|
||||||
final ZLTextWordCursor cursor = new ZLTextWordCursor(start);
|
final ZLTextWordCursor cursor = new ZLTextWordCursor(start);
|
||||||
|
|
||||||
final Buffer buffer = new Buffer(cursor);
|
final Buffer buffer = new Buffer(cursor);
|
||||||
|
@ -118,6 +114,7 @@ mainLoop:
|
||||||
myStart = new ZLTextFixedPosition(start);
|
myStart = new ZLTextFixedPosition(start);
|
||||||
myEnd = buffer.Cursor;
|
myEnd = buffer.Cursor;
|
||||||
myText = buffer.Builder.toString();
|
myText = buffer.Builder.toString();
|
||||||
|
IsEndOfText = cursor.isEndOfText() && sentenceBuffer.isEmpty() && phraseBuffer.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Buffer {
|
private static class Buffer {
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2009-2015 FBReader.ORG Limited <contact@fbreader.org>
|
||||||
|
*
|
||||||
|
* 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.text.util;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||||
|
|
||||||
|
public final class FixedTextSnippet implements TextSnippet {
|
||||||
|
private final ZLTextPosition myStart;
|
||||||
|
private final ZLTextPosition myEnd;
|
||||||
|
private final String myText;
|
||||||
|
|
||||||
|
public FixedTextSnippet(ZLTextPosition start, ZLTextPosition end, String text) {
|
||||||
|
myStart = start;
|
||||||
|
myEnd = end;
|
||||||
|
myText = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZLTextPosition getStart() {
|
||||||
|
return myStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZLTextPosition getEnd() {
|
||||||
|
return myEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return myText;
|
||||||
|
}
|
||||||
|
}
|
|
@ -210,6 +210,10 @@ public final class ZLTextParagraphCursor {
|
||||||
public final ZLTextModel Model;
|
public final ZLTextModel Model;
|
||||||
private final ArrayList<ZLTextElement> myElements = new ArrayList<ZLTextElement>();
|
private final ArrayList<ZLTextElement> myElements = new ArrayList<ZLTextElement>();
|
||||||
|
|
||||||
|
public ZLTextParagraphCursor(ZLTextModel model, int index) {
|
||||||
|
this(new CursorManager(model, null), model, index);
|
||||||
|
}
|
||||||
|
|
||||||
ZLTextParagraphCursor(CursorManager cManager, ZLTextModel model, int index) {
|
ZLTextParagraphCursor(CursorManager cManager, ZLTextModel model, int index) {
|
||||||
CursorManager = cManager;
|
CursorManager = cManager;
|
||||||
Model = model;
|
Model = model;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue