mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
tap zones API implementation (not tested yet)
This commit is contained in:
parent
1e2aaf281d
commit
e2bb59de31
8 changed files with 118 additions and 73 deletions
|
@ -64,9 +64,10 @@ public interface Api {
|
|||
void setKeyAction(int key, boolean longPress, String action) throws ApiException;
|
||||
|
||||
List<String> listTapZones() throws ApiException;
|
||||
String getCurrentTapZone() throws ApiException;
|
||||
int getTapZoneHeight(String name) throws ApiException;
|
||||
int getTapZoneWidth(String name) throws ApiException;
|
||||
String getTapZoneAction(String name, int v, int h, boolean longPress) 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;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -346,6 +346,10 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
return requestStringList(LIST_TAPZONES, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public String getCurrentTapZone() throws ApiException {
|
||||
return requestString(GET_CURRENT_TAPZONE, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public int getTapZoneHeight(String name) throws ApiException {
|
||||
return requestInt(GET_TAPZONE_HEIGHT, envelope(name));
|
||||
}
|
||||
|
@ -354,29 +358,29 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
return requestInt(GET_TAPZONE_WIDTH, envelope(name));
|
||||
}
|
||||
|
||||
public String getTapZoneAction(String name, int v, int h, boolean longPress) throws ApiException {
|
||||
public String getTapZoneAction(String name, int h, int v, boolean singleTap) throws ApiException {
|
||||
return requestString(GET_TAPZONE_ACTION, new ApiObject[] {
|
||||
ApiObject.envelope(name),
|
||||
ApiObject.envelope(v),
|
||||
ApiObject.envelope(h),
|
||||
ApiObject.envelope(longPress)
|
||||
ApiObject.envelope(v),
|
||||
ApiObject.envelope(singleTap)
|
||||
});
|
||||
}
|
||||
|
||||
public void createTapZone(String name, int height, int width) throws ApiException {
|
||||
public void createTapZone(String name, int width, int height) throws ApiException {
|
||||
request(CREATE_TAPZONE, new ApiObject[] {
|
||||
ApiObject.envelope(name),
|
||||
ApiObject.envelope(height),
|
||||
ApiObject.envelope(width)
|
||||
ApiObject.envelope(width),
|
||||
ApiObject.envelope(height)
|
||||
});
|
||||
}
|
||||
|
||||
public void setTapZoneAction(String name, int v, int h, boolean longPress, String action) throws ApiException {
|
||||
public void setTapZoneAction(String name, int h, int v, boolean singleTap, String action) throws ApiException {
|
||||
request(SET_TAPZONE_ACTION, new ApiObject[] {
|
||||
ApiObject.envelope(name),
|
||||
ApiObject.envelope(v),
|
||||
ApiObject.envelope(h),
|
||||
ApiObject.envelope(longPress),
|
||||
ApiObject.envelope(v),
|
||||
ApiObject.envelope(singleTap),
|
||||
ApiObject.envelope(action)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -54,9 +54,10 @@ interface ApiMethods {
|
|||
int SET_KEY_ACTION = 912;
|
||||
|
||||
int LIST_TAPZONES = 921;
|
||||
int GET_TAPZONE_HEIGHT = 922;
|
||||
int GET_TAPZONE_WIDTH = 923;
|
||||
int GET_TAPZONE_ACTION = 924;
|
||||
int CREATE_TAPZONE = 925;
|
||||
int SET_TAPZONE_ACTION = 926;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.geometerplus.zlibrary.core.config.ZLConfig;
|
|||
|
||||
import org.geometerplus.zlibrary.text.view.*;
|
||||
|
||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||
import org.geometerplus.fbreader.fbreader.*;
|
||||
|
||||
public class ApiServerImplementation extends ApiInterface.Stub implements Api, ApiMethods {
|
||||
public static void sendEvent(ContextWrapper context, String eventType) {
|
||||
|
@ -143,6 +143,8 @@ 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_TAPZONE_ACTION:
|
||||
return ApiObject.envelope(getTapZoneAction(
|
||||
((ApiObject.String)parameters[0]).Value,
|
||||
|
@ -411,30 +413,32 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
}
|
||||
|
||||
public List<String> listTapZones() {
|
||||
// TODO: implement
|
||||
return Collections.emptyList();
|
||||
return TapZoneMap.zoneMapNames();
|
||||
}
|
||||
|
||||
public String getCurrentTapZone() {
|
||||
return ScrollingPreferences.Instance().TapZonesSchemeOption.getValue();
|
||||
}
|
||||
|
||||
public int getTapZoneHeight(String name) {
|
||||
// TODO: implement
|
||||
return -1;
|
||||
return TapZoneMap.zoneMap(name).getHeight();
|
||||
}
|
||||
|
||||
public int getTapZoneWidth(String name) {
|
||||
// TODO: implement
|
||||
return -1;
|
||||
return TapZoneMap.zoneMap(name).getWidth();
|
||||
}
|
||||
|
||||
public String getTapZoneAction(String name, int v, int h, boolean longPress) {
|
||||
// TODO: implement
|
||||
return null;
|
||||
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 height, int width) {
|
||||
// TODO: implement
|
||||
public void createTapZone(String name, int width, int height) {
|
||||
TapZoneMap.createZoneMap(name, width, height);
|
||||
}
|
||||
|
||||
public void setTapZoneAction(String name, int v, int h, boolean longPress, String action) {
|
||||
// TODO: implement
|
||||
public void setTapZoneAction(String name, int h, int v, boolean singleTap, String action) {
|
||||
TapZoneMap.zoneMap(name).setActionForZone(h, v, singleTap, action);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -343,9 +343,6 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
|||
|
||||
final ScrollingPreferences scrollingPreferences = ScrollingPreferences.Instance();
|
||||
|
||||
//final Screen tapZonesScreen = createPreferenceScreen("tapZones");
|
||||
//tapZonesScreen.addOption(scrollingPreferences.TapZonesSchemeOption, "tapZonesScheme");
|
||||
|
||||
final ZLKeyBindings keyBindings = fbReader.keyBindings();
|
||||
|
||||
final Screen scrollingScreen = createPreferenceScreen("scrolling");
|
||||
|
|
|
@ -53,18 +53,16 @@ public final class FBView extends ZLTextView {
|
|||
private boolean myIsBrightnessAdjustmentInProgress;
|
||||
private int myStartBrightness;
|
||||
|
||||
private String myZoneMapId;
|
||||
private TapZoneMap myZoneMap;
|
||||
|
||||
private TapZoneMap getZoneMap() {
|
||||
//final String id =
|
||||
// ScrollingPreferences.Instance().TapZonesSchemeOption.getValue().toString();
|
||||
final String id =
|
||||
ScrollingPreferences.Instance().HorizontalOption.getValue()
|
||||
? "right_to_left" : "up";
|
||||
if (!id.equals(myZoneMapId)) {
|
||||
myZoneMap = new TapZoneMap(id);
|
||||
myZoneMapId = id;
|
||||
final ScrollingPreferences prefs = ScrollingPreferences.Instance();
|
||||
String id = prefs.TapZonesSchemeOption.getValue();
|
||||
if ("".equals(id)) {
|
||||
id = ScrollingPreferences.Instance().HorizontalOption.getValue() ? "right_to_left" : "up";
|
||||
}
|
||||
if (myZoneMap == null || !id.equals(myZoneMap.Name)) {
|
||||
myZoneMap = TapZoneMap.zoneMap(id);
|
||||
}
|
||||
return myZoneMap;
|
||||
}
|
||||
|
|
|
@ -19,9 +19,7 @@
|
|||
|
||||
package org.geometerplus.fbreader.fbreader;
|
||||
|
||||
import org.geometerplus.zlibrary.core.options.ZLBooleanOption;
|
||||
import org.geometerplus.zlibrary.core.options.ZLEnumOption;
|
||||
import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption;
|
||||
import org.geometerplus.zlibrary.core.options.*;
|
||||
import org.geometerplus.zlibrary.core.view.ZLView;
|
||||
|
||||
public class ScrollingPreferences {
|
||||
|
@ -44,11 +42,8 @@ public class ScrollingPreferences {
|
|||
|
||||
public final ZLBooleanOption HorizontalOption =
|
||||
new ZLBooleanOption("Scrolling", "Horizontal", true);
|
||||
public static enum TapZonesScheme {
|
||||
left_to_right, right_to_left, up, down, custom
|
||||
}
|
||||
public final ZLEnumOption<TapZonesScheme> TapZonesSchemeOption =
|
||||
new ZLEnumOption<TapZonesScheme>("Scrolling", "TapZonesScheme", TapZonesScheme.right_to_left);
|
||||
public final ZLStringOption TapZonesSchemeOption =
|
||||
new ZLStringOption("Scrolling", "TapZonesScheme", "");
|
||||
|
||||
private ScrollingPreferences() {
|
||||
ourInstance = this;
|
||||
|
|
|
@ -19,46 +19,92 @@
|
|||
|
||||
package org.geometerplus.fbreader.fbreader;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.xml.ZLXMLReaderAdapter;
|
||||
import org.geometerplus.zlibrary.core.xml.ZLStringMap;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||
import org.geometerplus.zlibrary.core.options.*;
|
||||
|
||||
public class TapZoneMap {
|
||||
private static final ZLStringListOption ourMapsOption;
|
||||
static {
|
||||
final List<String> lst = new LinkedList<String>();
|
||||
// TODO: list files from default/tapzones
|
||||
lst.add("left_to_right");
|
||||
lst.add("up");
|
||||
ourMapsOption = new ZLStringListOption("TapZones", "List", lst, "\000");
|
||||
}
|
||||
private static final Map<String,TapZoneMap> ourMaps = new HashMap<String,TapZoneMap>();
|
||||
|
||||
public static List<String> zoneMapNames() {
|
||||
return ourMapsOption.getValue();
|
||||
}
|
||||
|
||||
public static TapZoneMap zoneMap(String name) {
|
||||
TapZoneMap map = ourMaps.get(name);
|
||||
if (map == null) {
|
||||
map = new TapZoneMap(name);
|
||||
ourMaps.put(name, map);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static TapZoneMap createZoneMap(String name, int width, int height) {
|
||||
if (ourMapsOption.getValue().contains(name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final TapZoneMap map = zoneMap(name);
|
||||
map.myWidth.setValue(width);
|
||||
map.myHeight.setValue(height);
|
||||
final List<String> lst = new LinkedList<String>(ourMapsOption.getValue());
|
||||
lst.add(name);
|
||||
ourMapsOption.setValue(lst);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static enum Tap {
|
||||
singleTap,
|
||||
singleNotDoubleTap,
|
||||
doubleTap
|
||||
};
|
||||
|
||||
private final String myName;
|
||||
private int myVerticalSize = 3;
|
||||
private int myHorizontalSize = 3;
|
||||
public final String Name;
|
||||
private final String myOptionGroupName;
|
||||
private ZLIntegerRangeOption myHeight;
|
||||
private ZLIntegerRangeOption myWidth;
|
||||
private final HashMap<Zone,ZLStringOption> myZoneMap = new HashMap<Zone,ZLStringOption>();
|
||||
private final HashMap<Zone,ZLStringOption> myZoneMap2 = new HashMap<Zone,ZLStringOption>();
|
||||
|
||||
TapZoneMap(String name, int v, int h) {
|
||||
myName = name;
|
||||
myVerticalSize = v;
|
||||
myHorizontalSize = h;
|
||||
}
|
||||
|
||||
TapZoneMap(String name) {
|
||||
myName = name;
|
||||
private TapZoneMap(String name) {
|
||||
Name = name;
|
||||
myOptionGroupName = "TapZones:" + name;
|
||||
myHeight = new ZLIntegerRangeOption(myOptionGroupName, "Height", 2, 5, 3);
|
||||
myWidth = new ZLIntegerRangeOption(myOptionGroupName, "Width", 2, 5, 3);
|
||||
final ZLFile mapFile = ZLFile.createFileByPath(
|
||||
"default/tapzones/" + name.toLowerCase() + ".xml"
|
||||
);
|
||||
new Reader().readQuietly(mapFile);
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return myHeight.getValue();
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return myWidth.getValue();
|
||||
}
|
||||
|
||||
public String getActionByCoordinates(int x, int y, int width, int height, Tap tap) {
|
||||
if (width == 0 || height == 0) {
|
||||
return null;
|
||||
}
|
||||
final Zone zone = new Zone(myHorizontalSize * x / width, myVerticalSize * y / height);
|
||||
final ZLStringOption option = getOptionByZone(zone, tap);
|
||||
return getActionByZone(myWidth.getValue() * x / width, myHeight.getValue() * y / height, tap);
|
||||
}
|
||||
|
||||
public String getActionByZone(int h, int v, Tap tap) {
|
||||
final ZLStringOption option = getOptionByZone(new Zone(h, v), tap);
|
||||
return option != null ? option.getValue() : null;
|
||||
}
|
||||
|
||||
|
@ -80,14 +126,14 @@ public class TapZoneMap {
|
|||
|
||||
private ZLStringOption createOptionForZone(Zone zone, boolean singleTap, String action) {
|
||||
return new ZLStringOption(
|
||||
"TapZones:" + (singleTap ? "Action" : "Action2"),
|
||||
myName + ":" + zone.HIndex + ":" + zone.VIndex,
|
||||
myOptionGroupName,
|
||||
(singleTap ? "Action" : "Action2") + ":" + zone.HIndex + ":" + zone.VIndex,
|
||||
action
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
public void setActionForZone(Zone zone, boolean singleTap, String action) {
|
||||
public void setActionForZone(int h, int v, boolean singleTap, String action) {
|
||||
final Zone zone = new Zone(h, v);
|
||||
final HashMap<Zone,ZLStringOption> map = singleTap ? myZoneMap : myZoneMap2;
|
||||
ZLStringOption option = map.get(zone);
|
||||
if (option == null) {
|
||||
|
@ -96,7 +142,6 @@ public class TapZoneMap {
|
|||
}
|
||||
option.setValue(action);
|
||||
}
|
||||
*/
|
||||
|
||||
private static class Zone {
|
||||
int HIndex;
|
||||
|
@ -153,11 +198,11 @@ public class TapZoneMap {
|
|||
} else if ("tapZones".equals(tag)) {
|
||||
final String v = attributes.getValue("v");
|
||||
if (v != null) {
|
||||
myVerticalSize = Integer.parseInt(v);
|
||||
myHeight.setValue(Integer.parseInt(v));
|
||||
}
|
||||
final String h = attributes.getValue("h");
|
||||
if (h != null) {
|
||||
myHorizontalSize = Integer.parseInt(h);
|
||||
myWidth.setValue(Integer.parseInt(h));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue