1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

API implementation (in progress)

This commit is contained in:
Nikolay Pultsin 2012-05-23 03:50:24 +01:00
parent 45dfb63382
commit 1e2aaf281d
5 changed files with 89 additions and 31 deletions

View file

@ -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;
}

View file

@ -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<String> 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<String> getOptionGroups() throws ApiException {
return requestStringList(GET_OPTION_GROUPS, EMPTY_PARAMETERS);
return requestStringList(LIST_OPTION_GROUPS, EMPTY_PARAMETERS);
}
public List<String> 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<String> 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<String> 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)

View file

@ -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;

View file

@ -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);
}

View file

@ -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<ApiObject> 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<String> actions = new ArrayList<String>(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.<ApiObject>singletonList(unsupportedMethodError(method));
}
@ -340,51 +391,50 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
}
// action control
public List<String> listActions() throws ApiException {
public List<String> listActions() {
// TODO: implement
return Collections.emptyList();
}
public List<String> listActionNames(List<String> actions) throws ApiException {
public List<String> listActionNames(List<String> 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<String> listTapZones() throws ApiException {
public List<String> 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
}
}