diff --git a/src/org/geometerplus/android/fbreader/api/Api.java b/src/org/geometerplus/android/fbreader/api/Api.java index 41b19f3..45bf4ff 100644 --- a/src/org/geometerplus/android/fbreader/api/Api.java +++ b/src/org/geometerplus/android/fbreader/api/Api.java @@ -42,8 +42,10 @@ public interface Api { // text information int getParagraphsNumber() throws ApiException; - int getElementsNumber(int paragraphIndex) throws ApiException; + int getParagraphElementsCount(int paragraphIndex) throws ApiException; String getParagraphText(int paragraphIndex) throws ApiException; + List getParagraphWords(int paragraphIndex) throws ApiException; + List getParagraphWordIndices(int paragraphIndex) throws ApiException; // page information TextPosition getPageStart() throws ApiException; @@ -55,6 +57,14 @@ public interface Api { void setPageStart(TextPosition position) throws ApiException; void highlightArea(TextPosition start, TextPosition end) throws ApiException; void clearHighlighting() throws ApiException; + int getBottomMargin() throws ApiException; + void setBottomMargin(int value) throws ApiException; + int getTopMargin() throws ApiException; + void setTopMargin(int value) throws ApiException; + int getLeftMargin() throws ApiException; + void setLeftMargin(int value) throws ApiException; + int getRightMargin() throws ApiException; + void setRightMargin(int value) throws ApiException; // action control List listActions() throws ApiException; diff --git a/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java b/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java index 059ed82..bf5cb5b 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java +++ b/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java @@ -171,6 +171,18 @@ private List requestStringList(int method, ApiObject[] params) throws Ap return stringList; } + private List requestIntegerList(int method, ApiObject[] params) throws ApiException { + final List list = requestList(method, params); + final ArrayList intList = new ArrayList(list.size()); + for (ApiObject object : list) { + if (!(object instanceof ApiObject.Integer)) { + throw new ApiException("Cannot cast an element returned from method " + method + " to Integer"); + } + intList.add(((ApiObject.Integer)object).Value); + } + return intList; + } + private static final ApiObject[] EMPTY_PARAMETERS = new ApiObject[0]; private static ApiObject[] envelope(String value) { @@ -189,7 +201,7 @@ private static ApiObject[] envelope(List value) { final ApiObject[] objects = new ApiObject[value.size()]; int index = 0; for (String s : value) { - objects[index++] = ApiObject.envelope(s); + objects[index++] = ApiObject.envelope(s); } return objects; } @@ -302,8 +314,16 @@ public String getParagraphText(int paragraphIndex) throws ApiException { return requestString(GET_PARAGRAPH_TEXT, envelope(paragraphIndex)); } - public int getElementsNumber(int paragraphIndex) throws ApiException { - return requestInt(GET_ELEMENTS_NUMBER, envelope(paragraphIndex)); + public int getParagraphElementsCount(int paragraphIndex) throws ApiException { + return requestInt(GET_PARAGRAPH_ELEMENTS_COUNT, envelope(paragraphIndex)); + } + + public List getParagraphWords(int paragraphIndex) throws ApiException { + return requestStringList(GET_PARAGRAPH_WORDS, envelope(paragraphIndex)); + } + + public List getParagraphWordIndices(int paragraphIndex) throws ApiException { + return requestIntegerList(GET_PARAGRAPH_WORD_INDICES, envelope(paragraphIndex)); } public void setPageStart(TextPosition position) throws ApiException { @@ -318,6 +338,38 @@ public void clearHighlighting() throws ApiException { request(CLEAR_HIGHLIGHTING, EMPTY_PARAMETERS); } + public int getBottomMargin() throws ApiException { + return requestInt(GET_BOTTOM_MARGIN, EMPTY_PARAMETERS); + } + + public void setBottomMargin(int value) throws ApiException { + request(SET_BOTTOM_MARGIN, new ApiObject[] { ApiObject.envelope(value) }); + } + + public int getTopMargin() throws ApiException { + return requestInt(GET_TOP_MARGIN, EMPTY_PARAMETERS); + } + + public void setTopMargin(int value) throws ApiException { + request(SET_TOP_MARGIN, new ApiObject[] { ApiObject.envelope(value) }); + } + + public int getLeftMargin() throws ApiException { + return requestInt(GET_LEFT_MARGIN, EMPTY_PARAMETERS); + } + + public void setLeftMargin(int value) throws ApiException { + request(SET_LEFT_MARGIN, new ApiObject[] { ApiObject.envelope(value) }); + } + + public int getRightMargin() throws ApiException { + return requestInt(GET_RIGHT_MARGIN, EMPTY_PARAMETERS); + } + + public void setRightMargin(int value) throws ApiException { + request(SET_RIGHT_MARGIN, new ApiObject[] { ApiObject.envelope(value) }); + } + // action control public String getKeyAction(int key, boolean longPress) throws ApiException { return requestString(GET_KEY_ACTION, new ApiObject[] { @@ -335,23 +387,23 @@ public void setKeyAction(int key, boolean longPress, String action) throws ApiEx } public List listActions() throws ApiException { - return requestStringList(LIST_ACTIONS, EMPTY_PARAMETERS); + return requestStringList(LIST_ACTIONS, EMPTY_PARAMETERS); } public List listActionNames(List actions) throws ApiException { - return requestStringList(LIST_ACTION_NAMES, envelope(actions)); + return requestStringList(LIST_ACTION_NAMES, envelope(actions)); } public List listZoneMaps() throws ApiException { - return requestStringList(LIST_ZONEMAPS, EMPTY_PARAMETERS); + return requestStringList(LIST_ZONEMAPS, EMPTY_PARAMETERS); } public String getZoneMap() throws ApiException { - return requestString(GET_ZONEMAP, EMPTY_PARAMETERS); + return requestString(GET_ZONEMAP, EMPTY_PARAMETERS); } public void setZoneMap(String name) throws ApiException { - request(SET_ZONEMAP, envelope(name)); + request(SET_ZONEMAP, envelope(name)); } public int getZoneMapHeight(String name) throws ApiException { diff --git a/src/org/geometerplus/android/fbreader/api/ApiMethods.java b/src/org/geometerplus/android/fbreader/api/ApiMethods.java index 5fc0282..d358c4e 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiMethods.java +++ b/src/org/geometerplus/android/fbreader/api/ApiMethods.java @@ -32,8 +32,10 @@ interface ApiMethods { // text information int GET_PARAGRAPHS_NUMBER = 601; - int GET_ELEMENTS_NUMBER = 602; + int GET_PARAGRAPH_ELEMENTS_COUNT = 602; int GET_PARAGRAPH_TEXT = 603; + int GET_PARAGRAPH_WORDS = 604; + int GET_PARAGRAPH_WORD_INDICES = 605; // page information int GET_PAGE_START = 701; @@ -45,6 +47,14 @@ interface ApiMethods { int SET_PAGE_START = 801; int HIGHLIGHT_AREA = 802; int CLEAR_HIGHLIGHTING = 803; + int GET_BOTTOM_MARGIN = 804; + int SET_BOTTOM_MARGIN = 805; + int GET_TOP_MARGIN = 806; + int SET_TOP_MARGIN = 807; + int GET_LEFT_MARGIN = 808; + int SET_LEFT_MARGIN = 809; + int GET_RIGHT_MARGIN = 810; + int SET_RIGHT_MARGIN = 811; // action control int LIST_ACTIONS = 901; diff --git a/src/org/geometerplus/android/fbreader/api/ApiObject.java b/src/org/geometerplus/android/fbreader/api/ApiObject.java index 18438aa..0d927cc 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiObject.java +++ b/src/org/geometerplus/android/fbreader/api/ApiObject.java @@ -168,7 +168,7 @@ static ApiObject envelope(java.util.Date value) { return new Date(value); } - static List envelope(List values) { + static List envelopeStringList(List values) { final ArrayList objects = new ArrayList(values.size()); for (java.lang.String v : values) { objects.add(new String(v)); @@ -176,6 +176,14 @@ static List envelope(List values) { return objects; } + static List envelopeIntegerList(List values) { + final ArrayList objects = new ArrayList(values.size()); + for (java.lang.Integer v : values) { + objects.add(new Integer(v)); + } + return objects; + } + abstract protected int type(); public int describeContents() {