From 6175f96a8f18c7a4c0276397d8e86a50d97139c3 Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Wed, 23 May 2012 05:48:51 +0100 Subject: [PATCH] more API methods --- TODO.1.5 | 1 + .../android/fbreader/api/Api.java | 14 +++-- .../fbreader/api/ApiClientImplementation.java | 44 ++++++++----- .../android/fbreader/api/ApiMethods.java | 18 +++--- .../fbreader/api/ApiServerImplementation.java | 61 +++++++++++++------ .../fbreader/fbreader/FBView.java | 2 +- .../fbreader/ScrollingPreferences.java | 4 +- 7 files changed, 94 insertions(+), 50 deletions(-) diff --git a/TODO.1.5 b/TODO.1.5 index 0339eef46..b9a6e013a 100644 --- a/TODO.1.5 +++ b/TODO.1.5 @@ -5,6 +5,7 @@ litres: author photos 1.5.*: +* Advanced settings plugin does not run * Autogeneration for ApiMethods & ApiImplementations * Footnotes on the same page * Chinese books (mail from Eric) diff --git a/src/org/geometerplus/android/fbreader/api/Api.java b/src/org/geometerplus/android/fbreader/api/Api.java index 5c27df1b0..41b19f396 100644 --- a/src/org/geometerplus/android/fbreader/api/Api.java +++ b/src/org/geometerplus/android/fbreader/api/Api.java @@ -63,11 +63,15 @@ public interface Api { String getKeyAction(int key, boolean longPress) throws ApiException; void setKeyAction(int key, boolean longPress, String action) throws ApiException; - List listTapZones() throws ApiException; - String getCurrentTapZone() throws ApiException; - int getTapZoneHeight(String name) throws ApiException; - int getTapZoneWidth(String name) throws ApiException; + List listZoneMaps() throws ApiException; + String getZoneMap() throws ApiException; + void setZoneMap(String name) throws ApiException; + int getZoneMapHeight(String name) throws ApiException; + int getZoneMapWidth(String name) throws ApiException; + void createZoneMap(String name, int width, int height) throws ApiException; + boolean isZoneMapCustom(String name) throws ApiException; + void deleteZoneMap(String name) throws ApiException; + String getTapZoneAction(String name, int h, int v, boolean singleTap) throws ApiException; - void createTapZone(String name, int width, int height) throws ApiException; void setTapZoneAction(String name, int h, int v, boolean singleTap, 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 0104ecb7d..059ed825d 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java +++ b/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java @@ -342,20 +342,40 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho return requestStringList(LIST_ACTION_NAMES, envelope(actions)); } - public List listTapZones() throws ApiException { - return requestStringList(LIST_TAPZONES, EMPTY_PARAMETERS); + public List listZoneMaps() throws ApiException { + return requestStringList(LIST_ZONEMAPS, EMPTY_PARAMETERS); } - public String getCurrentTapZone() throws ApiException { - return requestString(GET_CURRENT_TAPZONE, EMPTY_PARAMETERS); + public String getZoneMap() throws ApiException { + return requestString(GET_ZONEMAP, EMPTY_PARAMETERS); } - public int getTapZoneHeight(String name) throws ApiException { - return requestInt(GET_TAPZONE_HEIGHT, envelope(name)); + public void setZoneMap(String name) throws ApiException { + request(SET_ZONEMAP, envelope(name)); } - public int getTapZoneWidth(String name) throws ApiException { - return requestInt(GET_TAPZONE_WIDTH, envelope(name)); + public int getZoneMapHeight(String name) throws ApiException { + return requestInt(GET_ZONEMAP_HEIGHT, envelope(name)); + } + + public int getZoneMapWidth(String name) throws ApiException { + return requestInt(GET_ZONEMAP_WIDTH, envelope(name)); + } + + public void createZoneMap(String name, int width, int height) throws ApiException { + request(CREATE_ZONEMAP, new ApiObject[] { + ApiObject.envelope(name), + ApiObject.envelope(width), + ApiObject.envelope(height) + }); + } + + public boolean isZoneMapCustom(String name) throws ApiException { + return requestBoolean(IS_ZONEMAP_CUSTOM, envelope(name)); + } + + public void deleteZoneMap(String name) throws ApiException { + request(DELETE_ZONEMAP, envelope(name)); } public String getTapZoneAction(String name, int h, int v, boolean singleTap) throws ApiException { @@ -367,14 +387,6 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho }); } - public void createTapZone(String name, int width, int height) throws ApiException { - request(CREATE_TAPZONE, new ApiObject[] { - ApiObject.envelope(name), - ApiObject.envelope(width), - ApiObject.envelope(height) - }); - } - public void setTapZoneAction(String name, int h, int v, boolean singleTap, String action) throws ApiException { request(SET_TAPZONE_ACTION, new ApiObject[] { ApiObject.envelope(name), diff --git a/src/org/geometerplus/android/fbreader/api/ApiMethods.java b/src/org/geometerplus/android/fbreader/api/ApiMethods.java index 5368bc637..5fc028271 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiMethods.java +++ b/src/org/geometerplus/android/fbreader/api/ApiMethods.java @@ -53,11 +53,15 @@ interface ApiMethods { int GET_KEY_ACTION = 911; int SET_KEY_ACTION = 912; - int LIST_TAPZONES = 921; - int GET_CURRENT_TAPZONE = 922; - int GET_TAPZONE_HEIGHT = 923; - int GET_TAPZONE_WIDTH = 924; - int GET_TAPZONE_ACTION = 925; - int CREATE_TAPZONE = 926; - int SET_TAPZONE_ACTION = 927; + int LIST_ZONEMAPS = 921; + int GET_ZONEMAP = 922; + int SET_ZONEMAP = 923; + int GET_ZONEMAP_HEIGHT = 924; + int GET_ZONEMAP_WIDTH = 925; + int CREATE_ZONEMAP = 926; + int IS_ZONEMAP_CUSTOM = 927; + int DELETE_ZONEMAP = 928; + + int GET_TAPZONE_ACTION = 931; + int SET_TAPZONE_ACTION = 932; } diff --git a/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java b/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java index 5b3527ed3..78dbfee31 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java +++ b/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java @@ -143,8 +143,15 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A ((ApiObject.String)parameters[2]).Value ); return ApiObject.Void.Instance; - case GET_CURRENT_TAPZONE: - return ApiObject.envelope(getCurrentTapZone()); + case GET_ZONEMAP: + return ApiObject.envelope(getZoneMap()); + case SET_ZONEMAP: + setZoneMap(((ApiObject.String)parameters[0]).Value); + return ApiObject.Void.Instance; + case GET_ZONEMAP_HEIGHT: + return ApiObject.envelope(getZoneMapHeight(((ApiObject.String)parameters[0]).Value)); + case GET_ZONEMAP_WIDTH: + return ApiObject.envelope(getZoneMapWidth(((ApiObject.String)parameters[0]).Value)); case GET_TAPZONE_ACTION: return ApiObject.envelope(getTapZoneAction( ((ApiObject.String)parameters[0]).Value, @@ -152,10 +159,6 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A ((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, @@ -165,13 +168,20 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A ((ApiObject.String)parameters[4]).Value ); return ApiObject.Void.Instance; - case CREATE_TAPZONE: - createTapZone( + case CREATE_ZONEMAP: + createZoneMap( ((ApiObject.String)parameters[0]).Value, ((ApiObject.Integer)parameters[1]).Value, ((ApiObject.Integer)parameters[2]).Value ); return ApiObject.Void.Instance; + case IS_ZONEMAP_CUSTOM: + return ApiObject.envelope(isZoneMapCustom( + ((ApiObject.String)parameters[0]).Value + )); + case DELETE_ZONEMAP: + deleteZoneMap(((ApiObject.String)parameters[0]).Value); + return ApiObject.Void.Instance; default: return unsupportedMethodError(method); } @@ -201,8 +211,8 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A } return ApiObject.envelope(listActionNames(actions)); } - case LIST_TAPZONES: - return ApiObject.envelope(listTapZones()); + case LIST_ZONEMAPS: + return ApiObject.envelope(listZoneMaps()); default: return Collections.singletonList(unsupportedMethodError(method)); } @@ -412,32 +422,45 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A // TODO: implement } - public List listTapZones() { + public List listZoneMaps() { return TapZoneMap.zoneMapNames(); } - public String getCurrentTapZone() { - return ScrollingPreferences.Instance().TapZonesSchemeOption.getValue(); + public String getZoneMap() { + return ScrollingPreferences.Instance().TapZoneMapOption.getValue(); } - public int getTapZoneHeight(String name) { + public void setZoneMap(String name) { + ScrollingPreferences.Instance().TapZoneMapOption.setValue(name); + } + + public int getZoneMapHeight(String name) { return TapZoneMap.zoneMap(name).getHeight(); } - public int getTapZoneWidth(String name) { + public int getZoneMapWidth(String name) { return TapZoneMap.zoneMap(name).getWidth(); } + public void createZoneMap(String name, int width, int height) { + TapZoneMap.createZoneMap(name, width, height); + } + + public boolean isZoneMapCustom(String name) throws ApiException { + // TODO: implement + return false; + } + + public void deleteZoneMap(String name) throws ApiException { + // TODO: implement + } + public String getTapZoneAction(String name, int h, int v, boolean singleTap) { return TapZoneMap.zoneMap(name).getActionByZone( h, v, singleTap ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.doubleTap ); } - public void createTapZone(String name, int width, int height) { - TapZoneMap.createZoneMap(name, width, height); - } - public void setTapZoneAction(String name, int h, int v, boolean singleTap, String action) { TapZoneMap.zoneMap(name).setActionForZone(h, v, singleTap, action); } diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java index c3b712417..3ec122a9f 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBView.java +++ b/src/org/geometerplus/fbreader/fbreader/FBView.java @@ -57,7 +57,7 @@ public final class FBView extends ZLTextView { private TapZoneMap getZoneMap() { final ScrollingPreferences prefs = ScrollingPreferences.Instance(); - String id = prefs.TapZonesSchemeOption.getValue(); + String id = prefs.TapZoneMapOption.getValue(); if ("".equals(id)) { id = ScrollingPreferences.Instance().HorizontalOption.getValue() ? "right_to_left" : "up"; } diff --git a/src/org/geometerplus/fbreader/fbreader/ScrollingPreferences.java b/src/org/geometerplus/fbreader/fbreader/ScrollingPreferences.java index a37555c9d..5195f8c91 100644 --- a/src/org/geometerplus/fbreader/fbreader/ScrollingPreferences.java +++ b/src/org/geometerplus/fbreader/fbreader/ScrollingPreferences.java @@ -42,8 +42,8 @@ public class ScrollingPreferences { public final ZLBooleanOption HorizontalOption = new ZLBooleanOption("Scrolling", "Horizontal", true); - public final ZLStringOption TapZonesSchemeOption = - new ZLStringOption("Scrolling", "TapZonesScheme", ""); + public final ZLStringOption TapZoneMapOption = + new ZLStringOption("Scrolling", "TapZoneMap", ""); private ScrollingPreferences() { ourInstance = this;