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;
|
void setKeyAction(int key, boolean longPress, String action) throws ApiException;
|
||||||
|
|
||||||
List<String> listTapZones() throws ApiException;
|
List<String> listTapZones() throws ApiException;
|
||||||
|
String getCurrentTapZone() throws ApiException;
|
||||||
int getTapZoneHeight(String name) throws ApiException;
|
int getTapZoneHeight(String name) throws ApiException;
|
||||||
int getTapZoneWidth(String name) throws ApiException;
|
int getTapZoneWidth(String name) throws ApiException;
|
||||||
String getTapZoneAction(String name, int v, int h, boolean longPress) throws ApiException;
|
String getTapZoneAction(String name, int h, int v, boolean singleTap) throws ApiException;
|
||||||
void createTapZone(String name, int height, int width) throws ApiException;
|
void createTapZone(String name, int width, int height) throws ApiException;
|
||||||
void setTapZoneAction(String name, int v, int h, boolean longPress, String action) 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);
|
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 {
|
public int getTapZoneHeight(String name) throws ApiException {
|
||||||
return requestInt(GET_TAPZONE_HEIGHT, envelope(name));
|
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));
|
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[] {
|
return requestString(GET_TAPZONE_ACTION, new ApiObject[] {
|
||||||
ApiObject.envelope(name),
|
ApiObject.envelope(name),
|
||||||
ApiObject.envelope(v),
|
|
||||||
ApiObject.envelope(h),
|
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[] {
|
request(CREATE_TAPZONE, new ApiObject[] {
|
||||||
ApiObject.envelope(name),
|
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[] {
|
request(SET_TAPZONE_ACTION, new ApiObject[] {
|
||||||
ApiObject.envelope(name),
|
ApiObject.envelope(name),
|
||||||
ApiObject.envelope(v),
|
|
||||||
ApiObject.envelope(h),
|
ApiObject.envelope(h),
|
||||||
ApiObject.envelope(longPress),
|
ApiObject.envelope(v),
|
||||||
|
ApiObject.envelope(singleTap),
|
||||||
ApiObject.envelope(action)
|
ApiObject.envelope(action)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,10 @@ interface ApiMethods {
|
||||||
int SET_KEY_ACTION = 912;
|
int SET_KEY_ACTION = 912;
|
||||||
|
|
||||||
int LIST_TAPZONES = 921;
|
int LIST_TAPZONES = 921;
|
||||||
int GET_TAPZONE_HEIGHT = 922;
|
int GET_CURRENT_TAPZONE = 922;
|
||||||
int GET_TAPZONE_WIDTH = 923;
|
int GET_TAPZONE_HEIGHT = 923;
|
||||||
int GET_TAPZONE_ACTION = 924;
|
int GET_TAPZONE_WIDTH = 924;
|
||||||
int CREATE_TAPZONE = 925;
|
int GET_TAPZONE_ACTION = 925;
|
||||||
int SET_TAPZONE_ACTION = 926;
|
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.zlibrary.text.view.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.*;
|
||||||
|
|
||||||
public class ApiServerImplementation extends ApiInterface.Stub implements Api, ApiMethods {
|
public class ApiServerImplementation extends ApiInterface.Stub implements Api, ApiMethods {
|
||||||
public static void sendEvent(ContextWrapper context, String eventType) {
|
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
|
((ApiObject.String)parameters[2]).Value
|
||||||
);
|
);
|
||||||
return ApiObject.Void.Instance;
|
return ApiObject.Void.Instance;
|
||||||
|
case GET_CURRENT_TAPZONE:
|
||||||
|
return ApiObject.envelope(getCurrentTapZone());
|
||||||
case GET_TAPZONE_ACTION:
|
case GET_TAPZONE_ACTION:
|
||||||
return ApiObject.envelope(getTapZoneAction(
|
return ApiObject.envelope(getTapZoneAction(
|
||||||
((ApiObject.String)parameters[0]).Value,
|
((ApiObject.String)parameters[0]).Value,
|
||||||
|
@ -411,30 +413,32 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> listTapZones() {
|
public List<String> listTapZones() {
|
||||||
// TODO: implement
|
return TapZoneMap.zoneMapNames();
|
||||||
return Collections.emptyList();
|
}
|
||||||
|
|
||||||
|
public String getCurrentTapZone() {
|
||||||
|
return ScrollingPreferences.Instance().TapZonesSchemeOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTapZoneHeight(String name) {
|
public int getTapZoneHeight(String name) {
|
||||||
// TODO: implement
|
return TapZoneMap.zoneMap(name).getHeight();
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTapZoneWidth(String name) {
|
public int getTapZoneWidth(String name) {
|
||||||
// TODO: implement
|
return TapZoneMap.zoneMap(name).getWidth();
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTapZoneAction(String name, int v, int h, boolean longPress) {
|
public String getTapZoneAction(String name, int h, int v, boolean singleTap) {
|
||||||
// TODO: implement
|
return TapZoneMap.zoneMap(name).getActionByZone(
|
||||||
return null;
|
h, v, singleTap ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.doubleTap
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createTapZone(String name, int height, int width) {
|
public void createTapZone(String name, int width, int height) {
|
||||||
// TODO: implement
|
TapZoneMap.createZoneMap(name, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTapZoneAction(String name, int v, int h, boolean longPress, String action) {
|
public void setTapZoneAction(String name, int h, int v, boolean singleTap, String action) {
|
||||||
// TODO: implement
|
TapZoneMap.zoneMap(name).setActionForZone(h, v, singleTap, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -343,9 +343,6 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
|
|
||||||
final ScrollingPreferences scrollingPreferences = ScrollingPreferences.Instance();
|
final ScrollingPreferences scrollingPreferences = ScrollingPreferences.Instance();
|
||||||
|
|
||||||
//final Screen tapZonesScreen = createPreferenceScreen("tapZones");
|
|
||||||
//tapZonesScreen.addOption(scrollingPreferences.TapZonesSchemeOption, "tapZonesScheme");
|
|
||||||
|
|
||||||
final ZLKeyBindings keyBindings = fbReader.keyBindings();
|
final ZLKeyBindings keyBindings = fbReader.keyBindings();
|
||||||
|
|
||||||
final Screen scrollingScreen = createPreferenceScreen("scrolling");
|
final Screen scrollingScreen = createPreferenceScreen("scrolling");
|
||||||
|
|
|
@ -53,18 +53,16 @@ public final class FBView extends ZLTextView {
|
||||||
private boolean myIsBrightnessAdjustmentInProgress;
|
private boolean myIsBrightnessAdjustmentInProgress;
|
||||||
private int myStartBrightness;
|
private int myStartBrightness;
|
||||||
|
|
||||||
private String myZoneMapId;
|
|
||||||
private TapZoneMap myZoneMap;
|
private TapZoneMap myZoneMap;
|
||||||
|
|
||||||
private TapZoneMap getZoneMap() {
|
private TapZoneMap getZoneMap() {
|
||||||
//final String id =
|
final ScrollingPreferences prefs = ScrollingPreferences.Instance();
|
||||||
// ScrollingPreferences.Instance().TapZonesSchemeOption.getValue().toString();
|
String id = prefs.TapZonesSchemeOption.getValue();
|
||||||
final String id =
|
if ("".equals(id)) {
|
||||||
ScrollingPreferences.Instance().HorizontalOption.getValue()
|
id = ScrollingPreferences.Instance().HorizontalOption.getValue() ? "right_to_left" : "up";
|
||||||
? "right_to_left" : "up";
|
}
|
||||||
if (!id.equals(myZoneMapId)) {
|
if (myZoneMap == null || !id.equals(myZoneMap.Name)) {
|
||||||
myZoneMap = new TapZoneMap(id);
|
myZoneMap = TapZoneMap.zoneMap(id);
|
||||||
myZoneMapId = id;
|
|
||||||
}
|
}
|
||||||
return myZoneMap;
|
return myZoneMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,7 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.fbreader;
|
package org.geometerplus.fbreader.fbreader;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.options.ZLBooleanOption;
|
import org.geometerplus.zlibrary.core.options.*;
|
||||||
import org.geometerplus.zlibrary.core.options.ZLEnumOption;
|
|
||||||
import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption;
|
|
||||||
import org.geometerplus.zlibrary.core.view.ZLView;
|
import org.geometerplus.zlibrary.core.view.ZLView;
|
||||||
|
|
||||||
public class ScrollingPreferences {
|
public class ScrollingPreferences {
|
||||||
|
@ -44,11 +42,8 @@ public class ScrollingPreferences {
|
||||||
|
|
||||||
public final ZLBooleanOption HorizontalOption =
|
public final ZLBooleanOption HorizontalOption =
|
||||||
new ZLBooleanOption("Scrolling", "Horizontal", true);
|
new ZLBooleanOption("Scrolling", "Horizontal", true);
|
||||||
public static enum TapZonesScheme {
|
public final ZLStringOption TapZonesSchemeOption =
|
||||||
left_to_right, right_to_left, up, down, custom
|
new ZLStringOption("Scrolling", "TapZonesScheme", "");
|
||||||
}
|
|
||||||
public final ZLEnumOption<TapZonesScheme> TapZonesSchemeOption =
|
|
||||||
new ZLEnumOption<TapZonesScheme>("Scrolling", "TapZonesScheme", TapZonesScheme.right_to_left);
|
|
||||||
|
|
||||||
private ScrollingPreferences() {
|
private ScrollingPreferences() {
|
||||||
ourInstance = this;
|
ourInstance = this;
|
||||||
|
|
|
@ -19,46 +19,92 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.fbreader;
|
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.ZLXMLReaderAdapter;
|
||||||
import org.geometerplus.zlibrary.core.xml.ZLStringMap;
|
import org.geometerplus.zlibrary.core.xml.ZLStringMap;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
import org.geometerplus.zlibrary.core.options.*;
|
||||||
|
|
||||||
public class TapZoneMap {
|
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 {
|
public static enum Tap {
|
||||||
singleTap,
|
singleTap,
|
||||||
singleNotDoubleTap,
|
singleNotDoubleTap,
|
||||||
doubleTap
|
doubleTap
|
||||||
};
|
};
|
||||||
|
|
||||||
private final String myName;
|
public final String Name;
|
||||||
private int myVerticalSize = 3;
|
private final String myOptionGroupName;
|
||||||
private int myHorizontalSize = 3;
|
private ZLIntegerRangeOption myHeight;
|
||||||
|
private ZLIntegerRangeOption myWidth;
|
||||||
private final HashMap<Zone,ZLStringOption> myZoneMap = new HashMap<Zone,ZLStringOption>();
|
private final HashMap<Zone,ZLStringOption> myZoneMap = new HashMap<Zone,ZLStringOption>();
|
||||||
private final HashMap<Zone,ZLStringOption> myZoneMap2 = new HashMap<Zone,ZLStringOption>();
|
private final HashMap<Zone,ZLStringOption> myZoneMap2 = new HashMap<Zone,ZLStringOption>();
|
||||||
|
|
||||||
TapZoneMap(String name, int v, int h) {
|
private TapZoneMap(String name) {
|
||||||
myName = name;
|
Name = name;
|
||||||
myVerticalSize = v;
|
myOptionGroupName = "TapZones:" + name;
|
||||||
myHorizontalSize = h;
|
myHeight = new ZLIntegerRangeOption(myOptionGroupName, "Height", 2, 5, 3);
|
||||||
}
|
myWidth = new ZLIntegerRangeOption(myOptionGroupName, "Width", 2, 5, 3);
|
||||||
|
|
||||||
TapZoneMap(String name) {
|
|
||||||
myName = name;
|
|
||||||
final ZLFile mapFile = ZLFile.createFileByPath(
|
final ZLFile mapFile = ZLFile.createFileByPath(
|
||||||
"default/tapzones/" + name.toLowerCase() + ".xml"
|
"default/tapzones/" + name.toLowerCase() + ".xml"
|
||||||
);
|
);
|
||||||
new Reader().readQuietly(mapFile);
|
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) {
|
public String getActionByCoordinates(int x, int y, int width, int height, Tap tap) {
|
||||||
if (width == 0 || height == 0) {
|
if (width == 0 || height == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Zone zone = new Zone(myHorizontalSize * x / width, myVerticalSize * y / height);
|
return getActionByZone(myWidth.getValue() * x / width, myHeight.getValue() * y / height, tap);
|
||||||
final ZLStringOption option = getOptionByZone(zone, 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;
|
return option != null ? option.getValue() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,14 +126,14 @@ public class TapZoneMap {
|
||||||
|
|
||||||
private ZLStringOption createOptionForZone(Zone zone, boolean singleTap, String action) {
|
private ZLStringOption createOptionForZone(Zone zone, boolean singleTap, String action) {
|
||||||
return new ZLStringOption(
|
return new ZLStringOption(
|
||||||
"TapZones:" + (singleTap ? "Action" : "Action2"),
|
myOptionGroupName,
|
||||||
myName + ":" + zone.HIndex + ":" + zone.VIndex,
|
(singleTap ? "Action" : "Action2") + ":" + zone.HIndex + ":" + zone.VIndex,
|
||||||
action
|
action
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
public void setActionForZone(int h, int v, boolean singleTap, String action) {
|
||||||
public void setActionForZone(Zone zone, boolean singleTap, String action) {
|
final Zone zone = new Zone(h, v);
|
||||||
final HashMap<Zone,ZLStringOption> map = singleTap ? myZoneMap : myZoneMap2;
|
final HashMap<Zone,ZLStringOption> map = singleTap ? myZoneMap : myZoneMap2;
|
||||||
ZLStringOption option = map.get(zone);
|
ZLStringOption option = map.get(zone);
|
||||||
if (option == null) {
|
if (option == null) {
|
||||||
|
@ -96,7 +142,6 @@ public class TapZoneMap {
|
||||||
}
|
}
|
||||||
option.setValue(action);
|
option.setValue(action);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
private static class Zone {
|
private static class Zone {
|
||||||
int HIndex;
|
int HIndex;
|
||||||
|
@ -153,11 +198,11 @@ public class TapZoneMap {
|
||||||
} else if ("tapZones".equals(tag)) {
|
} else if ("tapZones".equals(tag)) {
|
||||||
final String v = attributes.getValue("v");
|
final String v = attributes.getValue("v");
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
myVerticalSize = Integer.parseInt(v);
|
myHeight.setValue(Integer.parseInt(v));
|
||||||
}
|
}
|
||||||
final String h = attributes.getValue("h");
|
final String h = attributes.getValue("h");
|
||||||
if (h != null) {
|
if (h != null) {
|
||||||
myHorizontalSize = Integer.parseInt(h);
|
myWidth.setValue(Integer.parseInt(h));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue