1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 17:59:33 +02:00

very strange fix (idea by Greg Kochaniak)

This commit is contained in:
Nikolay Pultsin 2012-10-30 01:05:50 +04:00
parent 3c6fb84a0f
commit 6c739c6ccd

View file

@ -39,7 +39,13 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
); );
} }
private final FBReaderApp myReader = (FBReaderApp)FBReaderApp.Instance(); private volatile FBReaderApp myReader;
private synchronized FBReaderApp getReader() {
if (myReader == null) {
myReader = (FBReaderApp)FBReaderApp.Instance();
}
return myReader;
}
private ApiObject.Error unsupportedMethodError(int method) { private ApiObject.Error unsupportedMethodError(int method) {
return new ApiObject.Error("Unsupported method code: " + method); return new ApiObject.Error("Unsupported method code: " + method);
@ -287,11 +293,11 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
} }
public String getBookLanguage() { public String getBookLanguage() {
return myReader.Model.Book.getLanguage(); return getReader().Model.Book.getLanguage();
} }
public String getBookTitle() { public String getBookTitle() {
return myReader.Model.Book.getTitle(); return getReader().Model.Book.getTitle();
} }
public List<String> getBookTags() { public List<String> getBookTags() {
@ -300,11 +306,11 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
} }
public String getBookFilePath() { public String getBookFilePath() {
return myReader.Model.Book.File.getPath(); return getReader().Model.Book.File.getPath();
} }
public String getBookHash() { public String getBookHash() {
return myReader.Model.Book.getContentHashCode(); return getReader().Model.Book.getContentHashCode();
} }
public String getBookUniqueId() { public String getBookUniqueId() {
@ -354,20 +360,20 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
// page information // page information
public TextPosition getPageStart() { public TextPosition getPageStart() {
return getTextPosition(myReader.getTextView().getStartCursor()); return getTextPosition(getReader().getTextView().getStartCursor());
} }
public TextPosition getPageEnd() { public TextPosition getPageEnd() {
return getTextPosition(myReader.getTextView().getEndCursor()); return getTextPosition(getReader().getTextView().getEndCursor());
} }
public boolean isPageEndOfSection() { public boolean isPageEndOfSection() {
final ZLTextWordCursor cursor = myReader.getTextView().getEndCursor(); final ZLTextWordCursor cursor = getReader().getTextView().getEndCursor();
return cursor.isEndOfParagraph() && cursor.getParagraphCursor().isEndOfSection(); return cursor.isEndOfParagraph() && cursor.getParagraphCursor().isEndOfSection();
} }
public boolean isPageEndOfText() { public boolean isPageEndOfText() {
final ZLTextWordCursor cursor = myReader.getTextView().getEndCursor(); final ZLTextWordCursor cursor = getReader().getTextView().getEndCursor();
return cursor.isEndOfParagraph() && cursor.getParagraphCursor().isLast(); return cursor.isEndOfParagraph() && cursor.getParagraphCursor().isLast();
} }
@ -389,60 +395,60 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
// manage view // manage view
public void setPageStart(TextPosition position) { public void setPageStart(TextPosition position) {
myReader.getTextView().gotoPosition(position.ParagraphIndex, position.ElementIndex, position.CharIndex); getReader().getTextView().gotoPosition(position.ParagraphIndex, position.ElementIndex, position.CharIndex);
myReader.getViewWidget().repaint(); getReader().getViewWidget().repaint();
myReader.storePosition(); getReader().storePosition();
} }
public void highlightArea(TextPosition start, TextPosition end) { public void highlightArea(TextPosition start, TextPosition end) {
myReader.getTextView().highlight( getReader().getTextView().highlight(
getZLTextPosition(start), getZLTextPosition(start),
getZLTextPosition(end) getZLTextPosition(end)
); );
} }
public void clearHighlighting() { public void clearHighlighting() {
myReader.getTextView().clearHighlighting(); getReader().getTextView().clearHighlighting();
} }
public int getBottomMargin() { public int getBottomMargin() {
return myReader.BottomMarginOption.getValue(); return getReader().BottomMarginOption.getValue();
} }
public void setBottomMargin(int value) { public void setBottomMargin(int value) {
myReader.BottomMarginOption.setValue(value); getReader().BottomMarginOption.setValue(value);
} }
public int getTopMargin() { public int getTopMargin() {
return myReader.TopMarginOption.getValue(); return getReader().TopMarginOption.getValue();
} }
public void setTopMargin(int value) { public void setTopMargin(int value) {
myReader.TopMarginOption.setValue(value); getReader().TopMarginOption.setValue(value);
} }
public int getLeftMargin() { public int getLeftMargin() {
return myReader.LeftMarginOption.getValue(); return getReader().LeftMarginOption.getValue();
} }
public void setLeftMargin(int value) { public void setLeftMargin(int value) {
myReader.LeftMarginOption.setValue(value); getReader().LeftMarginOption.setValue(value);
} }
public int getRightMargin() { public int getRightMargin() {
return myReader.RightMarginOption.getValue(); return getReader().RightMarginOption.getValue();
} }
public void setRightMargin(int value) { public void setRightMargin(int value) {
myReader.RightMarginOption.setValue(value); getReader().RightMarginOption.setValue(value);
} }
public int getParagraphsNumber() { public int getParagraphsNumber() {
return myReader.Model.getTextModel().getParagraphsNumber(); return getReader().Model.getTextModel().getParagraphsNumber();
} }
public int getParagraphElementsCount(int paragraphIndex) { public int getParagraphElementsCount(int paragraphIndex) {
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor()); final ZLTextWordCursor cursor = new ZLTextWordCursor(getReader().getTextView().getStartCursor());
cursor.moveToParagraph(paragraphIndex); cursor.moveToParagraph(paragraphIndex);
cursor.moveToParagraphEnd(); cursor.moveToParagraphEnd();
return cursor.getElementIndex(); return cursor.getElementIndex();
@ -450,7 +456,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
public String getParagraphText(int paragraphIndex) { public String getParagraphText(int paragraphIndex) {
final StringBuffer sb = new StringBuffer(); final StringBuffer sb = new StringBuffer();
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor()); final ZLTextWordCursor cursor = new ZLTextWordCursor(getReader().getTextView().getStartCursor());
cursor.moveToParagraph(paragraphIndex); cursor.moveToParagraph(paragraphIndex);
cursor.moveToParagraphStart(); cursor.moveToParagraphStart();
while (!cursor.isEndOfParagraph()) { while (!cursor.isEndOfParagraph()) {
@ -465,7 +471,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
public List<String> getParagraphWords(int paragraphIndex) { public List<String> getParagraphWords(int paragraphIndex) {
final ArrayList<String> words = new ArrayList<String>(); final ArrayList<String> words = new ArrayList<String>();
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor()); final ZLTextWordCursor cursor = new ZLTextWordCursor(getReader().getTextView().getStartCursor());
cursor.moveToParagraph(paragraphIndex); cursor.moveToParagraph(paragraphIndex);
cursor.moveToParagraphStart(); cursor.moveToParagraphStart();
while (!cursor.isEndOfParagraph()) { while (!cursor.isEndOfParagraph()) {
@ -480,7 +486,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
public ArrayList<Integer> getParagraphWordIndices(int paragraphIndex) { public ArrayList<Integer> getParagraphWordIndices(int paragraphIndex) {
final ArrayList<Integer> indices = new ArrayList<Integer>(); final ArrayList<Integer> indices = new ArrayList<Integer>();
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor()); final ZLTextWordCursor cursor = new ZLTextWordCursor(getReader().getTextView().getStartCursor());
cursor.moveToParagraph(paragraphIndex); cursor.moveToParagraph(paragraphIndex);
cursor.moveToParagraphStart(); cursor.moveToParagraphStart();
while (!cursor.isEndOfParagraph()) { while (!cursor.isEndOfParagraph()) {