diff --git a/src/org/geometerplus/android/fbreader/api/Api.java b/src/org/geometerplus/android/fbreader/api/Api.java index d9857b721..3d86ce219 100644 --- a/src/org/geometerplus/android/fbreader/api/Api.java +++ b/src/org/geometerplus/android/fbreader/api/Api.java @@ -67,6 +67,6 @@ public interface Api { int getTapZoneHeight(String name) throws ApiException; int getTapZoneWidth(String name) throws ApiException; String getTapZoneAction(String name, int v, int h, boolean longPress) throws ApiException; - boolean createTapZone(String name, int height, int width) throws ApiException; + void createTapZone(String name, int height, int width) throws ApiException; void setTapZoneAction(String name, int v, int h, boolean longPress, String action) throws ApiException; } diff --git a/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java b/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java index 9b1d897f9..0fa325d34 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java +++ b/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java @@ -181,6 +181,10 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho return new ApiObject[] { ApiObject.envelope(value) }; } + private static ApiObject[] envelope(long value) { + return new ApiObject[] { ApiObject.envelope(value) }; + } + private static ApiObject[] envelope(List value) { final ApiObject[] objects = new ApiObject[value.size()]; int index = 0; @@ -197,11 +201,11 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho // preferences information public List getOptionGroups() throws ApiException { - return requestStringList(GET_OPTION_GROUPS, EMPTY_PARAMETERS); + return requestStringList(LIST_OPTION_GROUPS, EMPTY_PARAMETERS); } public List getOptionNames(String group) throws ApiException { - return requestStringList(GET_OPTION_NAMES, envelope(group)); + return requestStringList(LIST_OPTION_NAMES, envelope(group)); } public String getOptionValue(String group, String name) throws ApiException { @@ -227,7 +231,7 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho } public List getBookTags() throws ApiException { - return requestStringList(GET_BOOK_TAGS, EMPTY_PARAMETERS); + return requestStringList(LIST_BOOK_TAGS, EMPTY_PARAMETERS); } public String getBookFilePath() throws ApiException { @@ -247,31 +251,31 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho } public String getBookLanguage(long id) throws ApiException { - return requestString(GET_BOOK_LANGUAGE, EMPTY_PARAMETERS); + return requestString(GET_BOOK_LANGUAGE, envelope(id)); } public String getBookTitle(long id) throws ApiException { - return requestString(GET_BOOK_TITLE, EMPTY_PARAMETERS); + return requestString(GET_BOOK_TITLE, envelope(id)); } public List getBookTags(long id) throws ApiException { - return requestStringList(GET_BOOK_TAGS, EMPTY_PARAMETERS); + return requestStringList(LIST_BOOK_TAGS, envelope(id)); } public String getBookFilePath(long id) throws ApiException { - return requestString(GET_BOOK_FILE_PATH, EMPTY_PARAMETERS); + return requestString(GET_BOOK_FILE_PATH, envelope(id)); } public String getBookHash(long id) throws ApiException { - return requestString(GET_BOOK_HASH, EMPTY_PARAMETERS); + return requestString(GET_BOOK_HASH, envelope(id)); } public String getBookUniqueId(long id) throws ApiException { - return requestString(GET_BOOK_UNIQUE_ID, EMPTY_PARAMETERS); + return requestString(GET_BOOK_UNIQUE_ID, envelope(id)); } public Date getBookLastTurningTime(long id) throws ApiException { - return requestDate(GET_BOOK_LAST_TURNING_TIME, EMPTY_PARAMETERS); + return requestDate(GET_BOOK_LAST_TURNING_TIME, envelope(id)); } public TextPosition getPageStart() throws ApiException { @@ -359,8 +363,8 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho }); } - public boolean createTapZone(String name, int height, int width) throws ApiException { - return requestBoolean(CREATE_TAPZONE, new ApiObject[] { + public void createTapZone(String name, int height, int width) throws ApiException { + request(CREATE_TAPZONE, new ApiObject[] { ApiObject.envelope(name), ApiObject.envelope(height), ApiObject.envelope(width) diff --git a/src/org/geometerplus/android/fbreader/api/ApiMethods.java b/src/org/geometerplus/android/fbreader/api/ApiMethods.java index ce5101087..7b4d079fa 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiMethods.java +++ b/src/org/geometerplus/android/fbreader/api/ApiMethods.java @@ -15,16 +15,16 @@ interface ApiMethods { // bookmarks information // preferences - int GET_OPTION_GROUPS = 401; - int GET_OPTION_NAMES = 402; + int LIST_OPTION_GROUPS = 401; + int LIST_OPTION_NAMES = 402; int GET_OPTION_VALUE = 403; int SET_OPTION_VALUE = 404; // book information int GET_BOOK_LANGUAGE = 501; int GET_BOOK_TITLE = 502; - int GET_BOOK_AUTHORS = 503; - int GET_BOOK_TAGS = 504; + int LIST_BOOK_AUTHORS = 503; + int LIST_BOOK_TAGS = 504; int GET_BOOK_FILE_PATH = 505; int GET_BOOK_HASH = 506; int GET_BOOK_UNIQUE_ID = 507; diff --git a/src/org/geometerplus/android/fbreader/api/ApiObject.java b/src/org/geometerplus/android/fbreader/api/ApiObject.java index 8d6623f65..18438aae5 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiObject.java +++ b/src/org/geometerplus/android/fbreader/api/ApiObject.java @@ -152,6 +152,10 @@ public abstract class ApiObject implements Parcelable { return new Integer(value); } + static ApiObject envelope(long value) { + return new Long(value); + } + static ApiObject envelope(boolean value) { return new Boolean(value); } diff --git a/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java b/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java index d7edbcf46..95de8607d 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java +++ b/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java @@ -131,6 +131,45 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A case CLEAR_HIGHLIGHTING: clearHighlighting(); return ApiObject.Void.Instance; + case GET_KEY_ACTION: + return ApiObject.envelope(getKeyAction( + ((ApiObject.Integer)parameters[0]).Value, + ((ApiObject.Boolean)parameters[1]).Value + )); + case SET_KEY_ACTION: + setKeyAction( + ((ApiObject.Integer)parameters[0]).Value, + ((ApiObject.Boolean)parameters[1]).Value, + ((ApiObject.String)parameters[2]).Value + ); + return ApiObject.Void.Instance; + case GET_TAPZONE_ACTION: + return ApiObject.envelope(getTapZoneAction( + ((ApiObject.String)parameters[0]).Value, + ((ApiObject.Integer)parameters[1]).Value, + ((ApiObject.Integer)parameters[2]).Value, + ((ApiObject.Boolean)parameters[3]).Value + )); + case GET_TAPZONE_HEIGHT: + return ApiObject.envelope(getTapZoneHeight(((ApiObject.String)parameters[0]).Value)); + case GET_TAPZONE_WIDTH: + return ApiObject.envelope(getTapZoneWidth(((ApiObject.String)parameters[0]).Value)); + case SET_TAPZONE_ACTION: + setTapZoneAction( + ((ApiObject.String)parameters[0]).Value, + ((ApiObject.Integer)parameters[1]).Value, + ((ApiObject.Integer)parameters[2]).Value, + ((ApiObject.Boolean)parameters[3]).Value, + ((ApiObject.String)parameters[4]).Value + ); + return ApiObject.Void.Instance; + case CREATE_TAPZONE: + createTapZone( + ((ApiObject.String)parameters[0]).Value, + ((ApiObject.Integer)parameters[1]).Value, + ((ApiObject.Integer)parameters[2]).Value + ); + return ApiObject.Void.Instance; default: return unsupportedMethodError(method); } @@ -142,14 +181,26 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A public List requestList(int method, ApiObject[] parameters) { try { switch (method) { - case GET_OPTION_GROUPS: + case LIST_OPTION_GROUPS: return ApiObject.envelope(getOptionGroups()); - case GET_OPTION_NAMES: + case LIST_OPTION_NAMES: return ApiObject.envelope(getOptionNames( ((ApiObject.String)parameters[0]).Value )); - case GET_BOOK_TAGS: + case LIST_BOOK_TAGS: return ApiObject.envelope(getBookTags()); + case LIST_ACTIONS: + return ApiObject.envelope(listActions()); + case LIST_ACTION_NAMES: + { + final ArrayList actions = new ArrayList(parameters.length); + for (ApiObject o : parameters) { + actions.add(((ApiObject.String)o).Value); + } + return ApiObject.envelope(listActionNames(actions)); + } + case LIST_TAPZONES: + return ApiObject.envelope(listTapZones()); default: return Collections.singletonList(unsupportedMethodError(method)); } @@ -340,51 +391,50 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A } // action control - public List listActions() throws ApiException { + public List listActions() { // TODO: implement return Collections.emptyList(); } - public List listActionNames(List actions) throws ApiException { + public List listActionNames(List actions) { // TODO: implement return Collections.emptyList(); } - public String getKeyAction(int key, boolean longPress) throws ApiException { + public String getKeyAction(int key, boolean longPress) { // TODO: implement return null; } - public void setKeyAction(int key, boolean longPress, String action) throws ApiException { + public void setKeyAction(int key, boolean longPress, String action) { // TODO: implement } - public List listTapZones() throws ApiException { + public List listTapZones() { // TODO: implement return Collections.emptyList(); } - public int getTapZoneHeight(String name) throws ApiException { + public int getTapZoneHeight(String name) { // TODO: implement return -1; } - public int getTapZoneWidth(String name) throws ApiException { + public int getTapZoneWidth(String name) { // TODO: implement return -1; } - public String getTapZoneAction(String name, int v, int h, boolean longPress) throws ApiException { + public String getTapZoneAction(String name, int v, int h, boolean longPress) { // TODO: implement return null; } - public boolean createTapZone(String name, int height, int width) throws ApiException { + public void createTapZone(String name, int height, int width) { // TODO: implement - return false; } - public void setTapZoneAction(String name, int v, int h, boolean longPress, String action) throws ApiException { + public void setTapZoneAction(String name, int v, int h, boolean longPress, String action) { // TODO: implement } }