In accessibility mode special actions bound to Click and LongClick

events on the map view.
This commit is contained in:
Igor B. Poretsky 2013-03-01 05:19:29 +04:00
parent c9d52283e3
commit a22f9c4fc8
4 changed files with 62 additions and 2 deletions

View file

@ -0,0 +1,9 @@
package net.osmand.access;
// This interface is intended for defining prioritized actions
// to be performed in touch exploration mode. Implementations
// should do nothing and return false when accessibility is disabled.
public interface AccessibilityActionsProvider {
public boolean onClick();
public boolean onLongClick();
}

View file

@ -0,0 +1,36 @@
package net.osmand.access;
import net.osmand.access.AccessibilityActionsProvider;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapTileView;
import android.os.Build;
// Accessibility actions for map view.
public class MapAccessibilityActions implements AccessibilityActionsProvider {
private final MapActivity activity;
public MapAccessibilityActions(final MapActivity activity) {
this.activity = activity;
}
@Override
public boolean onClick() {
if ((Build.VERSION.SDK_INT >= 14) && activity.getMyApplication().getInternalAPI().accessibilityEnabled()) {
activity.emitNavigationHint();
return true;
}
return false;
}
@Override
public boolean onLongClick() {
if ((Build.VERSION.SDK_INT >= 14) && activity.getMyApplication().getInternalAPI().accessibilityEnabled()) {
final OsmandMapTileView mapView = activity.getMapView();
activity.getMapActions().contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
return true;
}
return false;
}
}

View file

@ -13,6 +13,7 @@ import net.osmand.access.AccessibilityPlugin;
import net.osmand.access.AccessibleActivity;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.access.MapAccessibilityActions;
import net.osmand.access.NavigationInfo;
import net.osmand.binary.RouteDataObject;
import net.osmand.map.IMapLocationListener;
@ -192,7 +193,8 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
return MapActivity.this.onTrackballEvent(e);
}
});
mapView.setAccessibilityActions(new MapAccessibilityActions(this));
// Do some action on close
startProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
@ -710,7 +712,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
return hint;
}
private void emitNavigationHint() {
public void emitNavigationHint() {
final LatLon point = getTargetPoints().getPointToNavigate();
if (point != null) {
if (routingHelper.isRouteCalculated()) {

View file

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityActionsProvider;
import net.osmand.access.AccessibleToast;
import net.osmand.access.MapExplorer;
import net.osmand.map.IMapLocationListener;
@ -96,6 +97,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
private OnTrackBallListener trackBallDelegate;
private AccessibilityActionsProvider accessibilityActions;
private List<OsmandMapLayer> layers = new ArrayList<OsmandMapLayer>();
private BaseMapLayer mainLayer;
@ -776,6 +779,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
this.onClickListener = l;
}
public void setAccessibilityActions(AccessibilityActionsProvider actions) {
accessibilityActions = actions;
}
public LatLon getLatLonFromScreenPoint(float x, float y) {
float dx = x - getCenterPointX();
@ -892,6 +899,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
if (log.isDebugEnabled()) {
log.debug("On long click event " + e.getX() + " " + e.getY()); //$NON-NLS-1$ //$NON-NLS-2$
}
if ((accessibilityActions != null) && accessibilityActions.onLongClick()) {
return;
}
PointF point = new PointF(e.getX(), e.getY());
for (int i = layers.size() - 1; i >= 0; i--) {
if (layers.get(i).onLongPressEvent(point)) {
@ -919,6 +929,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
if (log.isDebugEnabled()) {
log.debug("On click event " + point.x + " " + point.y); //$NON-NLS-1$ //$NON-NLS-2$
}
if ((accessibilityActions != null) && accessibilityActions.onClick()) {
return true;
}
for (int i = layers.size() - 1; i >= 0; i--) {
if (layers.get(i).onSingleTap(point)) {
return true;