mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
synchronyzation with Greg's branch + code style
This commit is contained in:
parent
33f47b668a
commit
cbd74279ac
5 changed files with 186 additions and 18 deletions
|
@ -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;
|
||||
int getParagraphWordsCount(int paragraphIndex) throws ApiException;
|
||||
String 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<String> listActions() throws ApiException;
|
||||
|
|
|
@ -171,6 +171,18 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
return stringList;
|
||||
}
|
||||
|
||||
private List<Integer> requestIntegerList(int method, ApiObject[] params) throws ApiException {
|
||||
final List<ApiObject> list = requestList(method, params);
|
||||
final ArrayList<Integer> intList = new ArrayList<Integer>(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 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
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 class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
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<String> getParagraphWordsCount(int paragraphIndex) throws ApiException {
|
||||
return requestStringList(GET_PARAGRAPH_WORDS_COUNT, envelope(paragraphIndex));
|
||||
}
|
||||
|
||||
public ArrayList<Integer> 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 class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
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 class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
}
|
||||
|
||||
public List<String> listActions() throws ApiException {
|
||||
return requestStringList(LIST_ACTIONS, EMPTY_PARAMETERS);
|
||||
return requestStringList(LIST_ACTIONS, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public List<String> listActionNames(List<String> actions) throws ApiException {
|
||||
return requestStringList(LIST_ACTION_NAMES, envelope(actions));
|
||||
return requestStringList(LIST_ACTION_NAMES, envelope(actions));
|
||||
}
|
||||
|
||||
public List<String> 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 {
|
||||
|
|
|
@ -32,7 +32,7 @@ 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_COUNT = 604;
|
||||
int GET_PARAGRAPH_WORD_INDICES = 605;
|
||||
|
@ -47,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;
|
||||
|
|
|
@ -176,6 +176,14 @@ public abstract class ApiObject implements Parcelable {
|
|||
return objects;
|
||||
}
|
||||
|
||||
static List<ApiObject> envelope(List<java.lang.Integer> values) {
|
||||
final ArrayList<ApiObject> objects = new ArrayList<ApiObject>(values.size());
|
||||
for (java.lang.Integer v : values) {
|
||||
objects.add(new Integer(v));
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
abstract protected int type();
|
||||
|
||||
public int describeContents() {
|
||||
|
|
|
@ -104,8 +104,8 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
}
|
||||
case GET_PARAGRAPHS_NUMBER:
|
||||
return ApiObject.envelope(getParagraphsNumber());
|
||||
case GET_ELEMENTS_NUMBER:
|
||||
return ApiObject.envelope(getElementsNumber(
|
||||
case GET_PARAGRAPH_ELEMENTS_COUNT:
|
||||
return ApiObject.envelope(getParagraphElementsCount(
|
||||
((ApiObject.Integer)parameters[0]).Value
|
||||
));
|
||||
case GET_PARAGRAPH_TEXT:
|
||||
|
@ -131,6 +131,26 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
case CLEAR_HIGHLIGHTING:
|
||||
clearHighlighting();
|
||||
return ApiObject.Void.Instance;
|
||||
case GET_BOTTOM_MARGIN:
|
||||
return ApiObject.envelope(getBottomMargin());
|
||||
case SET_BOTTOM_MARGIN:
|
||||
setBottomMargin(((ApiObject.Integer)parameters[0]).Value);
|
||||
return ApiObject.Void.Instance;
|
||||
case GET_TOP_MARGIN:
|
||||
return ApiObject.envelope(getTopMargin());
|
||||
case SET_TOP_MARGIN:
|
||||
setTopMargin(((ApiObject.Integer)parameters[0]).Value);
|
||||
return ApiObject.Void.Instance;
|
||||
case GET_LEFT_MARGIN:
|
||||
return ApiObject.envelope(getLeftMargin());
|
||||
case SET_LEFT_MARGIN:
|
||||
setLeftMargin(((ApiObject.Integer)parameters[0]).Value);
|
||||
return ApiObject.Void.Instance;
|
||||
case GET_RIGHT_MARGIN:
|
||||
return ApiObject.envelope(getRightMargin());
|
||||
case SET_RIGHT_MARGIN:
|
||||
setRightMargin(((ApiObject.Integer)parameters[0]).Value);
|
||||
return ApiObject.Void.Instance;
|
||||
case GET_KEY_ACTION:
|
||||
return ApiObject.envelope(getKeyAction(
|
||||
((ApiObject.Integer)parameters[0]).Value,
|
||||
|
@ -144,9 +164,9 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
);
|
||||
return ApiObject.Void.Instance;
|
||||
case GET_ZONEMAP:
|
||||
return ApiObject.envelope(getZoneMap());
|
||||
return ApiObject.envelope(getZoneMap());
|
||||
case SET_ZONEMAP:
|
||||
setZoneMap(((ApiObject.String)parameters[0]).Value);
|
||||
setZoneMap(((ApiObject.String)parameters[0]).Value);
|
||||
return ApiObject.Void.Instance;
|
||||
case GET_ZONEMAP_HEIGHT:
|
||||
return ApiObject.envelope(getZoneMapHeight(((ApiObject.String)parameters[0]).Value));
|
||||
|
@ -207,12 +227,20 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
{
|
||||
final ArrayList<String> actions = new ArrayList<String>(parameters.length);
|
||||
for (ApiObject o : parameters) {
|
||||
actions.add(((ApiObject.String)o).Value);
|
||||
actions.add(((ApiObject.String)o).Value);
|
||||
}
|
||||
return ApiObject.envelope(listActionNames(actions));
|
||||
}
|
||||
case LIST_ZONEMAPS:
|
||||
return ApiObject.envelope(listZoneMaps());
|
||||
case GET_PARAGRAPH_WORDS_COUNT:
|
||||
return ApiObject.envelope(getParagraphWordsCount(
|
||||
((ApiObject.Integer)parameters[0]).Value
|
||||
));
|
||||
case GET_PARAGRAPH_WORD_INDICES:
|
||||
return ApiObject.envelope(getParagraphWordIndices(
|
||||
((ApiObject.Integer)parameters[0]).Value
|
||||
));
|
||||
default:
|
||||
return Collections.<ApiObject>singletonList(unsupportedMethodError(method));
|
||||
}
|
||||
|
@ -376,11 +404,43 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
myReader.getTextView().clearHighlighting();
|
||||
}
|
||||
|
||||
public int getBottomMargin() {
|
||||
return myReader.BottomMarginOption.getValue();
|
||||
}
|
||||
|
||||
public void setBottomMargin(int value) {
|
||||
myReader.BottomMarginOption.setValue(value);
|
||||
}
|
||||
|
||||
public int getTopMargin() {
|
||||
return myReader.TopMarginOption.getValue();
|
||||
}
|
||||
|
||||
public void setTopMargin(int value) {
|
||||
myReader.TopMarginOption.setValue(value);
|
||||
}
|
||||
|
||||
public int getLeftMargin() {
|
||||
return myReader.LeftMarginOption.getValue();
|
||||
}
|
||||
|
||||
public void setLeftMargin(int value) {
|
||||
myReader.LeftMarginOption.setValue(value);
|
||||
}
|
||||
|
||||
public int getRightMargin() {
|
||||
return myReader.RightMarginOption.getValue();
|
||||
}
|
||||
|
||||
public void setRightMargin(int value) {
|
||||
myReader.RightMarginOption.setValue(value);
|
||||
}
|
||||
|
||||
public int getParagraphsNumber() {
|
||||
return myReader.Model.getTextModel().getParagraphsNumber();
|
||||
}
|
||||
|
||||
public int getElementsNumber(int paragraphIndex) {
|
||||
public int getParagraphElementsCount(int paragraphIndex) {
|
||||
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor());
|
||||
cursor.moveToParagraph(paragraphIndex);
|
||||
cursor.moveToParagraphEnd();
|
||||
|
@ -402,6 +462,36 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
public List<String> getParagraphWordsCount(int paragraphIndex) {
|
||||
final ArrayList<String> words = new ArrayList<String>();
|
||||
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor());
|
||||
cursor.moveToParagraph(paragraphIndex);
|
||||
cursor.moveToParagraphStart();
|
||||
while (!cursor.isEndOfParagraph()) {
|
||||
ZLTextElement element = cursor.getElement();
|
||||
if (element instanceof ZLTextWord) {
|
||||
words.add(element.toString());
|
||||
}
|
||||
cursor.nextWord();
|
||||
}
|
||||
return words;
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getParagraphWordIndices(int paragraphIndex) {
|
||||
final ArrayList<Integer> indices = new ArrayList<Integer>();
|
||||
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor());
|
||||
cursor.moveToParagraph(paragraphIndex);
|
||||
cursor.moveToParagraphStart();
|
||||
while (!cursor.isEndOfParagraph()) {
|
||||
ZLTextElement element = cursor.getElement();
|
||||
if (element instanceof ZLTextWord) {
|
||||
indices.add(cursor.getElementIndex());
|
||||
}
|
||||
cursor.nextWord();
|
||||
}
|
||||
return indices;
|
||||
}
|
||||
|
||||
// action control
|
||||
public List<String> listActions() {
|
||||
// TODO: implement
|
||||
|
@ -427,11 +517,11 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
}
|
||||
|
||||
public String getZoneMap() {
|
||||
return ScrollingPreferences.Instance().TapZoneMapOption.getValue();
|
||||
return ScrollingPreferences.Instance().TapZoneMapOption.getValue();
|
||||
}
|
||||
|
||||
public void setZoneMap(String name) {
|
||||
ScrollingPreferences.Instance().TapZoneMapOption.setValue(name);
|
||||
ScrollingPreferences.Instance().TapZoneMapOption.setValue(name);
|
||||
}
|
||||
|
||||
public int getZoneMapHeight(String name) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue