mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
preferences API (stub implementation)
This commit is contained in:
parent
eb46450995
commit
47fc0d3be1
4 changed files with 168 additions and 34 deletions
|
@ -27,23 +27,41 @@ import org.geometerplus.zlibrary.text.view.*;
|
|||
|
||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||
|
||||
public class ApiServerImplementation extends ApiInterface.Stub implements ApiMethods {
|
||||
public class ApiServerImplementation extends ApiInterface.Stub implements Api, ApiMethods {
|
||||
private final FBReaderApp myReader = (FBReaderApp)FBReaderApp.Instance();
|
||||
|
||||
private ApiObject.Error unsupportedMethodError(int method) {
|
||||
return new ApiObject.Error("Unsupported method code: " + method);
|
||||
}
|
||||
|
||||
private ApiObject.Error exceptionInMethodError(int method, Throwable e) {
|
||||
return new ApiObject.Error("Exception in method " + method + ": " + e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiObject request(int method, ApiObject[] parameters) {
|
||||
try {
|
||||
switch (method) {
|
||||
case GET_FBREADER_VERSION:
|
||||
return ApiObject.envelope(ZLibrary.Instance().getVersionName());
|
||||
return ApiObject.envelope(getFBReaderVersion());
|
||||
case GET_OPTION_VALUE:
|
||||
return ApiObject.envelope(getOptionValue(
|
||||
((ApiObject.String)parameters[0]).Value,
|
||||
((ApiObject.String)parameters[1]).Value
|
||||
));
|
||||
case SET_OPTION_VALUE:
|
||||
setOptionValue(
|
||||
((ApiObject.String)parameters[0]).Value,
|
||||
((ApiObject.String)parameters[1]).Value,
|
||||
((ApiObject.String)parameters[2]).Value
|
||||
);
|
||||
return ApiObject.Void.Instance;
|
||||
case GET_BOOK_LANGUAGE:
|
||||
return ApiObject.envelope(myReader.Model.Book.getLanguage());
|
||||
return ApiObject.envelope(getBookLanguage());
|
||||
case GET_BOOK_TITLE:
|
||||
return ApiObject.envelope(myReader.Model.Book.getTitle());
|
||||
return ApiObject.envelope(getBookTitle());
|
||||
case GET_BOOK_FILE_NAME:
|
||||
return ApiObject.envelope(getBookFileName());
|
||||
case GET_PARAGRAPHS_NUMBER:
|
||||
return ApiObject.envelope(getParagraphsNumber());
|
||||
case GET_ELEMENTS_NUMBER:
|
||||
|
@ -55,9 +73,9 @@ public class ApiServerImplementation extends ApiInterface.Stub implements ApiMet
|
|||
((ApiObject.Integer)parameters[0]).Value
|
||||
));
|
||||
case GET_PAGE_START:
|
||||
return getTextPosition(myReader.getTextView().getStartCursor());
|
||||
return getPageStart();
|
||||
case GET_PAGE_END:
|
||||
return getTextPosition(myReader.getTextView().getEndCursor());
|
||||
return getPageEnd();
|
||||
case IS_PAGE_END_OF_SECTION:
|
||||
return ApiObject.envelope(isPageEndOfSection());
|
||||
case IS_PAGE_END_OF_TEXT:
|
||||
|
@ -67,14 +85,11 @@ public class ApiServerImplementation extends ApiInterface.Stub implements ApiMet
|
|||
return ApiObject.Void.Instance;
|
||||
case HIGHLIGHT_AREA:
|
||||
{
|
||||
myReader.getTextView().highlight(
|
||||
getZLTextPosition((TextPosition)parameters[0]),
|
||||
getZLTextPosition((TextPosition)parameters[1])
|
||||
);
|
||||
highlightArea((TextPosition)parameters[0], (TextPosition)parameters[1]);
|
||||
return ApiObject.Void.Instance;
|
||||
}
|
||||
case CLEAR_HIGHLIGHTING:
|
||||
myReader.getTextView().clearHighlighting();
|
||||
clearHighlighting();
|
||||
return ApiObject.Void.Instance;
|
||||
default:
|
||||
return unsupportedMethodError(method);
|
||||
|
@ -86,13 +101,95 @@ public class ApiServerImplementation extends ApiInterface.Stub implements ApiMet
|
|||
|
||||
@Override
|
||||
public List<ApiObject> requestList(int method, ApiObject[] parameters) {
|
||||
return Collections.<ApiObject>singletonList(unsupportedMethodError(method));
|
||||
try {
|
||||
switch (method) {
|
||||
case GET_OPTION_GROUPS:
|
||||
case GET_OPTION_NAMES:
|
||||
case GET_BOOK_TAGS:
|
||||
default:
|
||||
return Collections.<ApiObject>singletonList(unsupportedMethodError(method));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
return Collections.<ApiObject>singletonList(exceptionInMethodError(method, e));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<ApiObject,ApiObject> errorMap(ApiObject.Error error) {
|
||||
return Collections.<ApiObject,ApiObject>singletonMap(error, error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<ApiObject,ApiObject> requestMap(int method, ApiObject[] parameters) {
|
||||
final ApiObject error = unsupportedMethodError(method);
|
||||
return Collections.singletonMap(error, error);
|
||||
try {
|
||||
switch (method) {
|
||||
default:
|
||||
return errorMap(unsupportedMethodError(method));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
return errorMap(exceptionInMethodError(method, e));
|
||||
}
|
||||
}
|
||||
|
||||
// information about fbreader
|
||||
public String getFBReaderVersion() {
|
||||
return ZLibrary.Instance().getVersionName();
|
||||
}
|
||||
|
||||
// preferences information
|
||||
public List<String> getOptionGroups() {
|
||||
// TODO: implement
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<String> getOptionNames(String group) {
|
||||
// TODO: implement
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public String getOptionValue(String group, String name) {
|
||||
// TODO: implement
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setOptionValue(String group, String name, String value) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
public String getBookLanguage() {
|
||||
return myReader.Model.Book.getLanguage();
|
||||
}
|
||||
|
||||
public String getBookTitle() {
|
||||
return myReader.Model.Book.getTitle();
|
||||
}
|
||||
|
||||
public List<String> getBookTags() {
|
||||
// TODO: implement
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public String getBookFileName() {
|
||||
// TODO: implement
|
||||
return null;
|
||||
}
|
||||
|
||||
// page information
|
||||
public TextPosition getPageStart() {
|
||||
return getTextPosition(myReader.getTextView().getStartCursor());
|
||||
}
|
||||
|
||||
public TextPosition getPageEnd() {
|
||||
return getTextPosition(myReader.getTextView().getEndCursor());
|
||||
}
|
||||
|
||||
public boolean isPageEndOfSection() {
|
||||
final ZLTextWordCursor cursor = myReader.getTextView().getEndCursor();
|
||||
return cursor.isEndOfParagraph() && cursor.getParagraphCursor().isEndOfSection();
|
||||
}
|
||||
|
||||
public boolean isPageEndOfText() {
|
||||
final ZLTextWordCursor cursor = myReader.getTextView().getEndCursor();
|
||||
return cursor.isEndOfParagraph() && cursor.getParagraphCursor().isLast();
|
||||
}
|
||||
|
||||
private TextPosition getTextPosition(ZLTextWordCursor cursor) {
|
||||
|
@ -111,33 +208,35 @@ public class ApiServerImplementation extends ApiInterface.Stub implements ApiMet
|
|||
);
|
||||
}
|
||||
|
||||
private boolean isPageEndOfSection() {
|
||||
final ZLTextWordCursor cursor = myReader.getTextView().getEndCursor();
|
||||
return cursor.isEndOfParagraph() && cursor.getParagraphCursor().isEndOfSection();
|
||||
}
|
||||
|
||||
private boolean isPageEndOfText() {
|
||||
final ZLTextWordCursor cursor = myReader.getTextView().getEndCursor();
|
||||
return cursor.isEndOfParagraph() && cursor.getParagraphCursor().isLast();
|
||||
}
|
||||
|
||||
private void setPageStart(TextPosition position) {
|
||||
// manage view
|
||||
public void setPageStart(TextPosition position) {
|
||||
myReader.getTextView().gotoPosition(position.ParagraphIndex, position.ElementIndex, position.CharIndex);
|
||||
myReader.getViewWidget().repaint();
|
||||
}
|
||||
|
||||
private int getParagraphsNumber() {
|
||||
public void highlightArea(TextPosition start, TextPosition end) {
|
||||
myReader.getTextView().highlight(
|
||||
getZLTextPosition(start),
|
||||
getZLTextPosition(end)
|
||||
);
|
||||
}
|
||||
|
||||
public void clearHighlighting() {
|
||||
myReader.getTextView().clearHighlighting();
|
||||
}
|
||||
|
||||
public int getParagraphsNumber() {
|
||||
return myReader.Model.BookTextModel.getParagraphsNumber();
|
||||
}
|
||||
|
||||
private int getElementsNumber(int paragraphIndex) {
|
||||
public int getElementsNumber(int paragraphIndex) {
|
||||
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor());
|
||||
cursor.moveToParagraph(paragraphIndex);
|
||||
cursor.moveToParagraphEnd();
|
||||
return cursor.getElementIndex();
|
||||
}
|
||||
|
||||
private String getParagraphText(int paragraphIndex) {
|
||||
public String getParagraphText(int paragraphIndex) {
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor());
|
||||
cursor.moveToParagraph(paragraphIndex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue