- get rid of some osmdroid cruft
- move default marker to 'res'
This commit is contained in:
parent
ebcd923025
commit
449b2b4709
1
res/.gitignore
vendored
1
res/.gitignore
vendored
@ -1 +0,0 @@
|
||||
!.gitignore
|
||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 664 B After Width: | Height: | Size: 664 B |
BIN
res/drawable/pin.png
Normal file
BIN
res/drawable/pin.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 osmdroid
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.overlay;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
public class DefaultResourceProxyImpl implements ResourceProxy, MapViewConstants {
|
||||
// private static final String TAG = DefaultResourceProxyImpl.class.getSimpleName();
|
||||
|
||||
private DisplayMetrics mDisplayMetrics;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pContext
|
||||
* Used to get the display metrics that are used for scaling the
|
||||
* bitmaps returned by {@@link getBitmap}. Can be null,
|
||||
* in which case the bitmaps are not scaled.
|
||||
*/
|
||||
public DefaultResourceProxyImpl(final Context pContext) {
|
||||
if (pContext != null) {
|
||||
mDisplayMetrics = pContext.getResources().getDisplayMetrics();
|
||||
// if (DEBUGMODE) {
|
||||
// logger.debug("mDisplayMetrics=" + mDisplayMetrics);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(final string pResId) {
|
||||
switch (pResId) {
|
||||
case mapnik:
|
||||
return "Mapnik";
|
||||
case cyclemap:
|
||||
return "Cycle Map";
|
||||
case public_transport:
|
||||
return "Public transport";
|
||||
case base:
|
||||
return "OSM base layer";
|
||||
case topo:
|
||||
return "Topographic";
|
||||
case hills:
|
||||
return "Hills";
|
||||
case cloudmade_standard:
|
||||
return "CloudMade (Standard tiles)";
|
||||
case cloudmade_small:
|
||||
return "CloudMade (small tiles)";
|
||||
case mapquest_osm:
|
||||
return "Mapquest";
|
||||
case mapquest_aerial:
|
||||
return "Mapquest Aerial";
|
||||
case bing:
|
||||
return "Bing";
|
||||
case fiets_nl:
|
||||
return "OpenFietsKaart overlay";
|
||||
case base_nl:
|
||||
return "Netherlands base overlay";
|
||||
case roads_nl:
|
||||
return "Netherlands roads overlay";
|
||||
case unknown:
|
||||
return "Unknown";
|
||||
case format_distance_meters:
|
||||
return "%s m";
|
||||
case format_distance_kilometers:
|
||||
return "%s km";
|
||||
case format_distance_miles:
|
||||
return "%s mi";
|
||||
case format_distance_nautical_miles:
|
||||
return "%s nm";
|
||||
case format_distance_feet:
|
||||
return "%s ft";
|
||||
case online_mode:
|
||||
return "Online mode";
|
||||
case offline_mode:
|
||||
return "Offline mode";
|
||||
case my_location:
|
||||
return "My location";
|
||||
case compass:
|
||||
return "Compass";
|
||||
case map_mode:
|
||||
return "Map mode";
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(final string pResId, final Object... formatArgs) {
|
||||
return String.format(getString(pResId), formatArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getBitmap(final bitmap pResId) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
final String resName = pResId.name() + ".png";
|
||||
is = getClass().getResourceAsStream(resName);
|
||||
if (is == null) {
|
||||
throw new IllegalArgumentException("Resource not found: " + resName);
|
||||
}
|
||||
BitmapFactory.Options options = null;
|
||||
if (mDisplayMetrics != null) {
|
||||
options = getBitmapOptions();
|
||||
}
|
||||
return BitmapFactory.decodeStream(is, null, options);
|
||||
} catch (final OutOfMemoryError e) {
|
||||
// logger.error("OutOfMemoryError getting bitmap resource: " +
|
||||
// pResId);
|
||||
System.gc();
|
||||
// there's not much we can do here
|
||||
// - when we load a bitmap from resources we expect it to be found
|
||||
throw e;
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (final IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BitmapFactory.Options getBitmapOptions() {
|
||||
try {
|
||||
final Field density = DisplayMetrics.class.getDeclaredField("DENSITY_DEFAULT");
|
||||
final Field inDensity = BitmapFactory.Options.class.getDeclaredField("inDensity");
|
||||
final Field inTargetDensity = BitmapFactory.Options.class
|
||||
.getDeclaredField("inTargetDensity");
|
||||
final Field targetDensity = DisplayMetrics.class.getDeclaredField("densityDpi");
|
||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
inDensity.setInt(options, density.getInt(null));
|
||||
inTargetDensity.setInt(options, targetDensity.getInt(mDisplayMetrics));
|
||||
return options;
|
||||
} catch (final IllegalAccessException ex) {
|
||||
// ignore
|
||||
} catch (final NoSuchFieldException ex) {
|
||||
// ignore
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getDrawable(final bitmap pResId) {
|
||||
return new BitmapDrawable(getBitmap(pResId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDisplayMetricsDensity() {
|
||||
return mDisplayMetrics.density;
|
||||
}
|
||||
|
||||
}
|
||||
@ -17,8 +17,8 @@ package org.oscim.overlay;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.oscim.app.R;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.overlay.ResourceProxy.bitmap;
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.view.MapViewPosition;
|
||||
|
||||
@ -42,35 +42,22 @@ public class ItemizedIconOverlay<Item extends OverlayItem> extends ItemizedOverl
|
||||
final MapView mapView,
|
||||
final List<Item> pList,
|
||||
final Drawable pDefaultMarker,
|
||||
final ItemizedIconOverlay.OnItemGestureListener<Item> pOnItemGestureListener,
|
||||
final ResourceProxy pResourceProxy) {
|
||||
final ItemizedIconOverlay.OnItemGestureListener<Item> pOnItemGestureListener) {
|
||||
|
||||
super(mapView, pDefaultMarker, pResourceProxy);
|
||||
super(mapView, pDefaultMarker);
|
||||
|
||||
this.mItemList = pList;
|
||||
this.mOnItemGestureListener = pOnItemGestureListener;
|
||||
populate();
|
||||
}
|
||||
|
||||
public ItemizedIconOverlay(
|
||||
final MapView mapView,
|
||||
final List<Item> pList,
|
||||
final ItemizedIconOverlay.OnItemGestureListener<Item> pOnItemGestureListener,
|
||||
final ResourceProxy pResourceProxy) {
|
||||
|
||||
this(mapView, pList, pResourceProxy.getDrawable(bitmap.marker_default),
|
||||
pOnItemGestureListener,
|
||||
pResourceProxy);
|
||||
}
|
||||
|
||||
public ItemizedIconOverlay(
|
||||
final MapView mapView,
|
||||
final Context pContext,
|
||||
final List<Item> pList,
|
||||
final ItemizedIconOverlay.OnItemGestureListener<Item> pOnItemGestureListener) {
|
||||
this(mapView, pList, new DefaultResourceProxyImpl(pContext)
|
||||
.getDrawable(bitmap.marker_default),
|
||||
pOnItemGestureListener, new DefaultResourceProxyImpl(pContext));
|
||||
this(mapView, pList, pContext.getResources().getDrawable(R.drawable.marker_default),
|
||||
pOnItemGestureListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -84,7 +84,7 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
|
||||
|
||||
// note: this is called from GL-Thread. so check your syncs!
|
||||
@Override
|
||||
public synchronized void update(MapPosition curPos,
|
||||
public synchronized void update(MapPosition curPos,
|
||||
boolean positionChanged,
|
||||
boolean tilesChanged) {
|
||||
|
||||
@ -236,10 +236,9 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
|
||||
*/
|
||||
public abstract int size();
|
||||
|
||||
public ItemizedOverlay(MapView mapView, final Drawable pDefaultMarker, final ResourceProxy
|
||||
pResourceProxy) {
|
||||
public ItemizedOverlay(MapView mapView, final Drawable pDefaultMarker) {
|
||||
|
||||
super(pResourceProxy);
|
||||
super();
|
||||
|
||||
if (pDefaultMarker == null) {
|
||||
throw new IllegalArgumentException("You must pass a default marker to ItemizedOverlay.");
|
||||
@ -247,8 +246,6 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
|
||||
|
||||
this.mDefaultMarker = pDefaultMarker;
|
||||
|
||||
// mInternalItemList = new ArrayList<Item>();
|
||||
|
||||
mMapView = mapView;
|
||||
mLayer = new ItemOverlay(mapView);
|
||||
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 osmdroid
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Created by plusminus on 18:00:24 - 25.09.2008
|
||||
package org.oscim.overlay;
|
||||
|
||||
/**
|
||||
* This class contains constants used by the map view.
|
||||
*
|
||||
* @author Nicolas Gramlich
|
||||
*/
|
||||
public interface MapViewConstants {
|
||||
// ===========================================================
|
||||
// Final Fields
|
||||
// ===========================================================
|
||||
|
||||
public static final boolean DEBUGMODE = false;
|
||||
|
||||
public static final int NOT_SET = Integer.MIN_VALUE;
|
||||
|
||||
public static final int ANIMATION_SMOOTHNESS_LOW = 4;
|
||||
public static final int ANIMATION_SMOOTHNESS_DEFAULT = 10;
|
||||
public static final int ANIMATION_SMOOTHNESS_HIGH = 20;
|
||||
|
||||
public static final int ANIMATION_DURATION_SHORT = 500;
|
||||
public static final int ANIMATION_DURATION_DEFAULT = 1000;
|
||||
public static final int ANIMATION_DURATION_LONG = 2000;
|
||||
|
||||
/** Minimum Zoom Level */
|
||||
public static final int MINIMUM_ZOOMLEVEL = 0;
|
||||
|
||||
/**
|
||||
* Maximum Zoom Level - we use Integers to store zoom levels so overflow
|
||||
* happens at 2^32 - 1,
|
||||
* but we also have a tile size that is typically 2^8, so (32-1)-8-1 = 22
|
||||
*/
|
||||
public static final int MAXIMUM_ZOOMLEVEL = 22;
|
||||
}
|
||||
@ -23,7 +23,6 @@ import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.overlays.RenderOverlay;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
@ -39,7 +38,7 @@ import android.view.MotionEvent;
|
||||
*
|
||||
* @author Nicolas Gramlich
|
||||
*/
|
||||
public abstract class Overlay implements OverlayConstants {
|
||||
public abstract class Overlay {
|
||||
|
||||
// ===========================================================
|
||||
// Constants
|
||||
@ -55,8 +54,8 @@ public abstract class Overlay implements OverlayConstants {
|
||||
// Fields
|
||||
// ===========================================================
|
||||
|
||||
protected final ResourceProxy mResourceProxy;
|
||||
protected final float mScale;
|
||||
//protected final ResourceProxy mResourceProxy;
|
||||
//protected final float mScale;
|
||||
|
||||
// private static final Rect mRect = new Rect();
|
||||
private boolean mEnabled = true;
|
||||
@ -72,20 +71,6 @@ public abstract class Overlay implements OverlayConstants {
|
||||
// ===========================================================
|
||||
|
||||
public Overlay() {
|
||||
mResourceProxy = null;
|
||||
mScale = 1;
|
||||
// mResourceProxy = new DefaultResourceProxyImpl(ctx);
|
||||
// mScale = ctx.getResources().getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
public Overlay(final Context ctx) {
|
||||
mResourceProxy = new DefaultResourceProxyImpl(ctx);
|
||||
mScale = ctx.getResources().getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
public Overlay(final ResourceProxy pResourceProxy) {
|
||||
mResourceProxy = pResourceProxy;
|
||||
mScale = mResourceProxy.getDisplayMetricsDensity();
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 osmdroid
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.overlay;
|
||||
|
||||
/**
|
||||
* This class contains constants used by the overlays.
|
||||
*/
|
||||
public interface OverlayConstants {
|
||||
// ===========================================================
|
||||
// Final Fields
|
||||
// ===========================================================
|
||||
|
||||
public static final boolean DEBUGMODE = false;
|
||||
|
||||
public static final int NOT_SET = Integer.MIN_VALUE;
|
||||
|
||||
public static final int DEFAULT_ZOOMLEVEL_MINIMAP_DIFFERENCE = 3;
|
||||
}
|
||||
@ -163,7 +163,7 @@ public class PathOverlay extends Overlay {
|
||||
}
|
||||
|
||||
public PathOverlay(MapView mapView, final int color, final Context ctx) {
|
||||
super(ctx);
|
||||
super();
|
||||
this.mPaint.setColor(color);
|
||||
this.mPaint.setStrokeWidth(2.0f);
|
||||
this.mPaint.setStyle(Paint.Style.STROKE);
|
||||
|
||||
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 osmdroid
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.overlay;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public interface ResourceProxy {
|
||||
|
||||
public static enum string {
|
||||
|
||||
// tile sources
|
||||
mapnik, cyclemap, public_transport, base, topo, hills, cloudmade_small, cloudmade_standard, mapquest_osm, mapquest_aerial, bing,
|
||||
|
||||
// overlays
|
||||
fiets_nl, base_nl, roads_nl,
|
||||
|
||||
// other stuff
|
||||
unknown, format_distance_meters, format_distance_kilometers, format_distance_miles, format_distance_nautical_miles, format_distance_feet, online_mode, offline_mode, my_location, compass, map_mode,
|
||||
|
||||
}
|
||||
|
||||
public static enum bitmap {
|
||||
|
||||
/**
|
||||
* For testing - the image doesn't exist.
|
||||
*/
|
||||
unknown,
|
||||
|
||||
center, direction_arrow, marker_default, marker_default_focused_base, navto_small, next, previous, person,
|
||||
|
||||
/**
|
||||
* Menu icons
|
||||
*/
|
||||
ic_menu_offline, ic_menu_mylocation, ic_menu_compass, ic_menu_mapmode
|
||||
}
|
||||
|
||||
String getString(string pResId);
|
||||
|
||||
/**
|
||||
* Use a string resource as a format definition, and format using the
|
||||
* supplied format arguments.
|
||||
*
|
||||
* @param pResId
|
||||
* ...
|
||||
* @param formatArgs
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
String getString(string pResId, Object... formatArgs);
|
||||
|
||||
Bitmap getBitmap(bitmap pResId);
|
||||
|
||||
/**
|
||||
* Get a bitmap as a {@link Drawable}
|
||||
*
|
||||
* @param pResId
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
Drawable getDrawable(bitmap pResId);
|
||||
|
||||
/**
|
||||
* Gets the density from the current screen's DisplayMetrics
|
||||
*
|
||||
* @return the screen's density
|
||||
*/
|
||||
float getDisplayMetricsDensity();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user