mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +02:00
updated API
This commit is contained in:
parent
3ea71a1efc
commit
d2dfafccf8
5 changed files with 93 additions and 17 deletions
|
@ -20,24 +20,30 @@
|
|||
package org.geometerplus.android.fbreader.api;
|
||||
|
||||
public interface Api {
|
||||
public void connect();
|
||||
public void disconnect();
|
||||
void connect();
|
||||
void disconnect();
|
||||
|
||||
// fbreader information
|
||||
public String getFBReaderVersion() throws ApiException;
|
||||
String getFBReaderVersion() throws ApiException;
|
||||
|
||||
// book information
|
||||
public String getBookLanguage() throws ApiException;
|
||||
String getBookLanguage() throws ApiException;
|
||||
String getBookTitle() throws ApiException;
|
||||
//String getBookAuthors() throws ApiException;
|
||||
//String getBookTags() throws ApiException;
|
||||
String getBookFileName() throws ApiException;
|
||||
|
||||
// text information
|
||||
public int getParagraphsNumber() throws ApiException;
|
||||
public int getElementsNumber(int paragraphIndex) throws ApiException;
|
||||
public String getParagraphText(int paragraphIndex) throws ApiException;
|
||||
int getParagraphsNumber() throws ApiException;
|
||||
int getElementsNumber(int paragraphIndex) throws ApiException;
|
||||
String getParagraphText(int paragraphIndex) throws ApiException;
|
||||
|
||||
// page information
|
||||
public TextPosition getPageStart() throws ApiException;
|
||||
public TextPosition getPageEnd() throws ApiException;
|
||||
TextPosition getPageStart() throws ApiException;
|
||||
TextPosition getPageEnd() throws ApiException;
|
||||
boolean isPageEndOfSection() throws ApiException;
|
||||
boolean isPageEndOfText() throws ApiException;
|
||||
|
||||
// manage view
|
||||
public void setPageStart(TextPosition position) throws ApiException;
|
||||
void setPageStart(TextPosition position) throws ApiException;
|
||||
}
|
||||
|
|
|
@ -52,6 +52,10 @@ public class ApiImplementation extends ApiInterface.Stub implements ApiMethods {
|
|||
return getTextPosition(myReader.getTextView().getStartCursor());
|
||||
case GET_PAGE_END:
|
||||
return getTextPosition(myReader.getTextView().getEndCursor());
|
||||
case IS_PAGE_END_OF_SECTION:
|
||||
return ApiObject.envelope(isPageEndOfSection());
|
||||
case IS_PAGE_END_OF_TEXT:
|
||||
return ApiObject.envelope(isPageEndOfText());
|
||||
case SET_PAGE_START:
|
||||
setPageStart(
|
||||
(TextPosition)parameters[0]
|
||||
|
@ -77,6 +81,16 @@ public class ApiImplementation extends ApiInterface.Stub implements ApiMethods {
|
|||
);
|
||||
}
|
||||
|
||||
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) {
|
||||
myReader.getTextView().gotoPosition(position.ParagraphIndex, position.ElementIndex, position.CharIndex);
|
||||
myReader.getViewWidget().repaint();
|
||||
|
|
|
@ -33,6 +33,10 @@ interface ApiMethods {
|
|||
|
||||
// book information
|
||||
int GET_BOOK_LANGUAGE = 501;
|
||||
int GET_BOOK_TITLE = 502;
|
||||
int GET_BOOK_AUTHORS = 503;
|
||||
int GET_BOOK_TAGS = 504;
|
||||
int GET_BOOK_FILENAME = 505;
|
||||
|
||||
// text information
|
||||
int GET_PARAGRAPHS_NUMBER = 601;
|
||||
|
@ -42,6 +46,8 @@ interface ApiMethods {
|
|||
// page information
|
||||
int GET_PAGE_START = 701;
|
||||
int GET_PAGE_END = 702;
|
||||
int IS_PAGE_END_OF_TEXT = 703;
|
||||
int IS_PAGE_END_OF_SECTION = 704;
|
||||
|
||||
// view change
|
||||
int SET_PAGE_START = 801;
|
||||
|
|
|
@ -28,7 +28,8 @@ public abstract class ApiObject implements Parcelable {
|
|||
int VOID = 0;
|
||||
int INT = 1;
|
||||
int STRING = 2;
|
||||
int TEXT_POSITION = 3;
|
||||
int BOOLEAN = 3;
|
||||
int TEXT_POSITION = 10;
|
||||
}
|
||||
|
||||
static class Void extends ApiObject {
|
||||
|
@ -62,22 +63,22 @@ public abstract class ApiObject implements Parcelable {
|
|||
}
|
||||
}
|
||||
|
||||
static class Error extends ApiObject {
|
||||
final java.lang.String Message;
|
||||
static class Boolean extends ApiObject {
|
||||
final boolean Value;
|
||||
|
||||
Error(java.lang.String message) {
|
||||
Message = message;
|
||||
Boolean(boolean value) {
|
||||
Value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int type() {
|
||||
return Type.ERROR;
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int flags) {
|
||||
super.writeToParcel(parcel, flags);
|
||||
parcel.writeString(Message);
|
||||
parcel.writeByte((byte)(Value ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,10 +101,33 @@ public abstract class ApiObject implements Parcelable {
|
|||
}
|
||||
}
|
||||
|
||||
static class Error extends ApiObject {
|
||||
final java.lang.String Message;
|
||||
|
||||
Error(java.lang.String message) {
|
||||
Message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int type() {
|
||||
return Type.ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int flags) {
|
||||
super.writeToParcel(parcel, flags);
|
||||
parcel.writeString(Message);
|
||||
}
|
||||
}
|
||||
|
||||
static ApiObject envelope(int value) {
|
||||
return new Integer(value);
|
||||
}
|
||||
|
||||
static ApiObject envelope(boolean value) {
|
||||
return new Boolean(value);
|
||||
}
|
||||
|
||||
static ApiObject envelope(java.lang.String value) {
|
||||
return new String(value);
|
||||
}
|
||||
|
@ -131,6 +155,8 @@ public abstract class ApiObject implements Parcelable {
|
|||
return Void.Instance;
|
||||
case Type.INT:
|
||||
return new Integer(parcel.readInt());
|
||||
case Type.BOOLEAN:
|
||||
return new Boolean(parcel.readByte() == 1);
|
||||
case Type.STRING:
|
||||
return new String(parcel.readString());
|
||||
case Type.TEXT_POSITION:
|
||||
|
|
|
@ -91,6 +91,14 @@ public class ApiServiceConnection implements ServiceConnection, Api, ApiMethods
|
|||
return ((ApiObject.Integer)object).Value;
|
||||
}
|
||||
|
||||
private boolean requestBoolean(int method, ApiObject[] params) throws ApiException {
|
||||
final ApiObject object = request(method, params);
|
||||
if (!(object instanceof ApiObject.Boolean)) {
|
||||
throw new ApiException("Cannot cast return type of method " + method + " to boolean");
|
||||
}
|
||||
return ((ApiObject.Boolean)object).Value;
|
||||
}
|
||||
|
||||
private TextPosition requestTextPosition(int method, ApiObject[] params) throws ApiException {
|
||||
final ApiObject object = request(method, params);
|
||||
if (!(object instanceof TextPosition)) {
|
||||
|
@ -113,6 +121,14 @@ public class ApiServiceConnection implements ServiceConnection, Api, ApiMethods
|
|||
return requestString(GET_BOOK_LANGUAGE, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public String getBookTitle() throws ApiException {
|
||||
return requestString(GET_BOOK_TITLE, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public String getBookFileName() throws ApiException {
|
||||
return requestString(GET_BOOK_FILENAME, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public TextPosition getPageStart() throws ApiException {
|
||||
return requestTextPosition(GET_PAGE_START, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
@ -121,6 +137,14 @@ public class ApiServiceConnection implements ServiceConnection, Api, ApiMethods
|
|||
return requestTextPosition(GET_PAGE_END, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public boolean isPageEndOfSection() throws ApiException {
|
||||
return requestBoolean(IS_PAGE_END_OF_SECTION, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public boolean isPageEndOfText() throws ApiException {
|
||||
return requestBoolean(IS_PAGE_END_OF_TEXT, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public void setPageStart(TextPosition position) throws ApiException {
|
||||
request(SET_PAGE_START, new ApiObject[] { position });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue