Implement new Graphics. Introduce base class for layer instead of interface

This commit is contained in:
Victor Shcherb 2011-11-27 11:57:06 +01:00
parent 55ec5d50da
commit 75646d55b8
25 changed files with 108 additions and 103 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/box_free_pressed" />
<item android:state_focused="true" android:drawable="@drawable/box_free_pressed" />
<item android:drawable="@drawable/box_free_simple" />
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -161,7 +161,7 @@ public class MapVectorLayer extends BaseMapLayer {
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
return false;
}
}

View file

@ -1,6 +1,6 @@
package net.osmand.plus.views;
public abstract class BaseMapLayer implements OsmandMapLayer {
public abstract class BaseMapLayer extends OsmandMapLayer {
private int alpha = 255;
protected int warningToSwitchMapShown = 0;

View file

@ -14,15 +14,19 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.FrameLayout.LayoutParams;
public class ContextMenuLayer implements OsmandMapLayer {
public class ContextMenuLayer extends OsmandMapLayer {
public interface IContextMenuProvider {
@ -44,14 +48,14 @@ public class ContextMenuLayer implements OsmandMapLayer {
private DisplayMetrics dm;
private OsmandMapTileView view;
private static final int BASE_TEXT_SIZE = 170;
private static final int MARGIN_Y_TO_BOX = 12;
private int textSize = BASE_TEXT_SIZE;
private Paint paintLightBorder;
private Paint paintBlack;
private RectF textBorder;
private Paint paintBorder;
private final MapActivity activity;
private Rect padding = new Rect();
public ContextMenuLayer(MapActivity activity){
this.activity = activity;
@ -88,38 +92,43 @@ public class ContextMenuLayer implements OsmandMapLayer {
textView.setMinLines(1);
// textView.setMaxLines(15);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textBorder = new RectF(-2, -1, textSize + 2, 0);
textView.setClickable(true);
textView.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free));
}
@Override
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, boolean nightMode) {
if(latLon != null){
int x = view.getMapXForPoint(latLon.getLongitude());
int y = view.getMapYForPoint(latLon.getLatitude());
int x = view.getRotatedMapXForPoint(latLon.getLatitude(), latLon.getLongitude());
int y = view.getRotatedMapYForPoint(latLon.getLatitude(), latLon.getLongitude());
canvas.drawCircle(x, y, 5 * dm.density, paintBorder);
canvas.drawCircle(x, y, 5 * dm.density, paintBlack);
if (textView.getText().length() > 0) {
x = view.getRotatedMapXForPoint(latLon.getLatitude(), latLon.getLongitude());
y = view.getRotatedMapYForPoint(latLon.getLatitude(), latLon.getLongitude());
canvas.rotate(-view.getRotate(), view.getCenterPointX(), view.getCenterPointY());
canvas.translate(x - textView.getWidth() / 2, y - textView.getHeight() - 12);
canvas.translate(x - textView.getWidth() / 2, y - textView.getHeight() - MARGIN_Y_TO_BOX);
int c = textView.getLineCount();
textBorder.bottom = textView.getHeight() + 2;
canvas.drawRect(textBorder, paintLightBorder);
canvas.drawRect(textBorder, paintBlack);
textView.draw(canvas);
if (c == 0) {
// special case relayout after on draw method
textView.layout(0, 0, textSize, (int) ((textView.getPaint().getTextSize() + 4) * textView.getLineCount()));
layoutText();
view.refreshMap();
}
}
}
}
private void layoutText() {
if(textView.getLineCount() > 0) {
textView.getBackground().getPadding(padding);
}
int w = textSize;
int h = (int) ((textView.getPaint().getTextSize() +4) * textView.getLineCount()) +
padding.bottom + padding.top;
textView.layout(0, 0, w, h);
}
public void setLocation(LatLon loc, String description){
latLon = loc;
if(latLon != null){
@ -131,12 +140,13 @@ public class ContextMenuLayer implements OsmandMapLayer {
} else {
textView.setText(""); //$NON-NLS-1$
}
textView.layout(0, 0, textSize, (int) ((textView.getPaint().getTextSize()+4) * textView.getLineCount()));
layoutText();
}
@Override
public boolean onLongPressEvent(PointF point) {
if(pressedInTextView(point)){
if(pressedInTextView(point.x, point.y)){
setLocation(null, ""); //$NON-NLS-1$
view.refreshMap();
return true;
@ -171,14 +181,17 @@ public class ContextMenuLayer implements OsmandMapLayer {
@Override
public boolean drawInScreenPixels() {
return false;
return true;
}
public boolean pressedInTextView(PointF point){
if(latLon != null){
int x = view.getRotatedMapXForPoint(latLon.getLatitude(), latLon.getLongitude());
int y = view.getRotatedMapYForPoint(latLon.getLatitude(), latLon.getLongitude());
if (textBorder.contains(point.x - x + textView.getWidth() / 2, point.y - y + textView.getHeight() + 8)) {
public boolean pressedInTextView(float px, float py) {
if (latLon != null) {
Rect bs = textView.getBackground().getBounds();
int x = (int) (px - view.getRotatedMapXForPoint(latLon.getLatitude(), latLon.getLongitude()));
int y = (int) (py - view.getRotatedMapYForPoint(latLon.getLatitude(), latLon.getLongitude()));
x += bs.width() / 2;
y += bs.height() + MARGIN_Y_TO_BOX;
if (bs.contains(x, y)) {
return true;
}
}
@ -186,8 +199,8 @@ public class ContextMenuLayer implements OsmandMapLayer {
}
@Override
public boolean onTouchEvent(PointF point) {
if (pressedInTextView(point)) {
public boolean onSingleTap(PointF point) {
if (pressedInTextView(point.x, point.y)) {
if (selectedObject != null) {
ArrayList<String> l = new ArrayList<String>();
OnClickListener listener = selectedContextProvider.getActionListener(l, selectedObject);
@ -200,4 +213,23 @@ public class ContextMenuLayer implements OsmandMapLayer {
return false;
}
@Override
public void onTouchEvent(MotionEvent event) {
if (latLon != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if(pressedInTextView(event.getX(), event.getY())){
textView.setPressed(true);
view.refreshMap();
}
}
}
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
if(textView.isPressed()) {
textView.setPressed(false);
view.refreshMap();
}
}
}
}

View file

@ -20,7 +20,7 @@ import android.util.FloatMath;
import android.view.WindowManager;
import android.widget.Toast;
public class FavoritesLayer implements OsmandMapLayer, ContextMenuLayer.IContextMenuProvider {
public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private static final int startZoom = 6;
private static final int radius = 15;
@ -127,7 +127,7 @@ public class FavoritesLayer implements OsmandMapLayer, ContextMenuLayer.IContext
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
FavouritePoint fav = getFavoriteFromPoint(point);
if(fav != null){
String format = view.getContext().getString(R.string.favorite) + " : " + fav.getName(); //$NON-NLS-1$

View file

@ -17,7 +17,7 @@ import android.graphics.Paint.Cap;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
public class GPXLayer implements OsmandMapLayer {
public class GPXLayer extends OsmandMapLayer {
private OsmandMapTileView view;
@ -143,7 +143,7 @@ public class GPXLayer implements OsmandMapLayer {
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
return false;
}

View file

@ -28,7 +28,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.SeekBar;
public class MapControlsLayer implements OsmandMapLayer {
public class MapControlsLayer extends OsmandMapLayer {
private static final int SHOW_SEEKBAR_MSG_ID = 2;
private static final int SHOW_SEEKBAR_DELAY = 7000;
@ -215,13 +215,9 @@ public class MapControlsLayer implements OsmandMapLayer {
}
}
@Override
public boolean onLongPressEvent(PointF point) {
return false;
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
if (modeShadow.getBounds().contains((int) point.x, (int) point.y)) {
onApplicationModePress();
return true;

View file

@ -26,7 +26,7 @@ import android.util.DisplayMetrics;
import android.util.FloatMath;
import android.view.WindowManager;
public class MapInfoLayer implements OsmandMapLayer {
public class MapInfoLayer extends OsmandMapLayer {
private OsmandMapTileView view;
@ -349,13 +349,9 @@ public class MapInfoLayer implements OsmandMapLayer {
return true;
}
@Override
public boolean onLongPressEvent(PointF point) {
return false;
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
if (routeLayer != null && routeLayer.getHelper().isRouterEnabled()) {
if (boundsForMiniRoute.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) {
showMiniMap = !showMiniMap;

View file

@ -9,7 +9,6 @@ import net.osmand.plus.ResourceManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.FloatMath;
@ -257,15 +256,4 @@ public class MapTileLayer extends BaseMapLayer {
}
@Override
public boolean onLongPressEvent(PointF point) {
return false;
}
@Override
public boolean onTouchEvent(PointF point) {
return false;
}
}

View file

@ -42,7 +42,7 @@ import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;
public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMenuProvider, DialogProvider {
public class OsmBugsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, DialogProvider {
private static final Log log = LogUtil.getLog(OsmBugsLayer.class);
private final static int startZoom = 8;
@ -222,7 +222,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
OpenStreetBug bug = getBugFromPoint(point);
if(bug != null){
String format = activity.getString(R.string.osb_bug_name)+ " : " + bug.getName(); //$NON-NLS-1$

View file

@ -3,19 +3,26 @@ package net.osmand.plus.views;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.RectF;
import android.view.MotionEvent;
public interface OsmandMapLayer {
public abstract class OsmandMapLayer {
public void initLayer(OsmandMapTileView view);
public abstract void initLayer(OsmandMapTileView view);
public void onDraw(Canvas canvas, RectF latlonRect, RectF tilesRect, boolean nightMode);
public abstract void onDraw(Canvas canvas, RectF latlonRect, RectF tilesRect, boolean nightMode);
public void destroyLayer();
public abstract void destroyLayer();
public boolean onTouchEvent(PointF point);
public boolean onSingleTap(PointF point) {
return false;
}
public boolean onLongPressEvent(PointF point);
public boolean onLongPressEvent(PointF point) {
return false;
}
public void onTouchEvent(MotionEvent event) {}
/**
* This method returns whether canvas should be rotated as
@ -23,6 +30,7 @@ public interface OsmandMapLayer {
* If the layer draws simply layer over screen (not over map)
* it should return true.
*/
public boolean drawInScreenPixels();
public abstract boolean drawInScreenPixels();
}

View file

@ -672,6 +672,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
if (event.getAction() == MotionEvent.ACTION_DOWN) {
animatedDraggingThread.stopAnimating();
}
for(int i=layers.size() - 1; i >= 0; i--) {
layers.get(i).onTouchEvent(event);
}
if (!multiTouchSupport.onTouchEvent(event)) {
/* return */gestureDetector.onTouchEvent(event);
}
@ -765,19 +768,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
private class MapTileViewOnGestureListener implements OnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
// enable double tap animation
// animatedDraggingThread.stopAnimating();
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// if (Math.abs(e1.getX() - e2.getX()) + Math.abs(e1.getY() - e2.getY()) > 50 * dm.density) {
animatedDraggingThread.startDragging(velocityX, velocityY,
e1.getX(), e1.getY(), e2.getX(), e2.getY(), true);
// } else {
// onScroll(e1, e2, e1.getX() - e2.getX(), e1.getY() - e2.getY());
// }
return true;
}
@ -817,7 +814,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
log.debug("On click event " + point.x + " " + point.y); //$NON-NLS-1$ //$NON-NLS-2$
}
for (int i = layers.size() - 1; i >= 0; i--) {
if (layers.get(i).onTouchEvent(point)) {
if (layers.get(i).onSingleTap(point)) {
return true;
}
}

View file

@ -32,7 +32,7 @@ import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.Toast;
public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMenuProvider {
public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private static final int startZoom = 10;
public static final int TEXT_WRAP = 15;
public static final int TEXT_LINES = 3;
@ -55,10 +55,6 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen
this.activity = activity;
}
@Override
public boolean onLongPressEvent(PointF point) {
return false;
}
public PoiFilter getFilter() {
return filter;
@ -93,7 +89,7 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
Amenity n = getAmenityFromPoint(point);
if(n != null){
String format = OsmAndFormatter.getPoiSimpleFormat(n, view.getContext(),

View file

@ -16,7 +16,7 @@ import android.location.Location;
import android.util.DisplayMetrics;
import android.view.WindowManager;
public class PointLocationLayer implements OsmandMapLayer {
public class PointLocationLayer extends OsmandMapLayer {
protected final static int RADIUS = 7;
protected final static float HEADING_ANGLE = 60;
@ -172,15 +172,5 @@ public class PointLocationLayer implements OsmandMapLayer {
return false;
}
@Override
public boolean onLongPressEvent(PointF point) {
return false;
}
@Override
public boolean onTouchEvent(PointF point) {
return false;
}
}

View file

@ -15,7 +15,7 @@ import android.location.Location;
import android.util.DisplayMetrics;
import android.view.WindowManager;
public class PointNavigationLayer implements OsmandMapLayer {
public class PointNavigationLayer extends OsmandMapLayer {
protected final static int DIST_TO_SHOW = 80;
private Paint point;
@ -116,7 +116,7 @@ public class PointNavigationLayer implements OsmandMapLayer {
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
return false;
}

View file

@ -26,7 +26,7 @@ import android.widget.TextView;
import android.widget.FrameLayout.LayoutParams;
public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener {
public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationListener {
private static final int BASE_TEXT_SIZE = 150;
private int textSize = BASE_TEXT_SIZE;
@ -208,7 +208,7 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
return false;
}

View file

@ -19,7 +19,7 @@ import android.graphics.Paint.Style;
import android.location.Location;
import android.util.Log;
public class RouteLayer implements OsmandMapLayer {
public class RouteLayer extends OsmandMapLayer {
private OsmandMapTileView view;
@ -128,7 +128,7 @@ public class RouteLayer implements OsmandMapLayer {
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
return false;
}

View file

@ -17,7 +17,7 @@ import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.Toast;
public class TransportInfoLayer implements OsmandMapLayer {
public class TransportInfoLayer extends OsmandMapLayer {
private final TransportRouteHelper routeHelper;
private OsmandMapTileView view;
@ -109,13 +109,9 @@ public class TransportInfoLayer implements OsmandMapLayer {
return false;
}
@Override
public boolean onLongPressEvent(PointF point) {
return false;
}
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
int ex = (int) point.x;
int ey = (int) point.y;
if (visible && !routeHelper.getRoute().isEmpty()) {

View file

@ -18,7 +18,7 @@ import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.Toast;
public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMenuProvider {
public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private static final int startZoom = 12;
private Paint pointAltUI;
@ -68,7 +68,7 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo
@Override
public boolean onTouchEvent(PointF point) {
public boolean onSingleTap(PointF point) {
TransportStop n = getFromPoint(point);
if(n != null){
Toast.makeText(view.getContext(), getStopDescription(n, true), Toast.LENGTH_LONG).show();