refactor: rename MapView -> Map, MapViewPosition -> Viewport

This commit is contained in:
Hannes Janetzek
2013-09-03 04:17:49 +02:00
parent 07db32f394
commit 870363bf2f
39 changed files with 560 additions and 442 deletions

View File

@@ -18,14 +18,14 @@ import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import org.oscim.renderer.GLRenderer;
import org.oscim.view.MapView;
import org.oscim.view.Map;
import android.opengl.GLSurfaceView;
public class AndroidGLRenderer extends GLRenderer implements GLSurfaceView.Renderer{
public AndroidGLRenderer(MapView mapView) {
super(mapView);
public AndroidGLRenderer(Map map) {
super(map);
}
@Override

View File

@@ -14,7 +14,7 @@
*/
package org.oscim.android;
import org.oscim.view.MapView;
import org.oscim.view.Map;
import android.content.Context;
import android.hardware.Sensor;
@@ -30,9 +30,9 @@ public class Compass {
if (Math.abs(event.values[0] - mAngle) > 0.25) {
mAngle = event.values[0];
if (mMapView != null) {
mMapView.getMapViewPosition().setRotation(-mAngle);
mMapView.updateMap(true);
if (mMap != null) {
mMap.getViewport().setRotation(-mAngle);
mMap.updateMap(true);
}
}
}
@@ -43,13 +43,13 @@ public class Compass {
};
/* package */float mAngle = 0;
/* package */MapView mMapView;
/* package */Map mMap;
private final SensorManager mSensorManager;
private final Sensor mSensor;
public Compass(MapActivity mapActivity, MapView mapView) {
mMapView = mapView;
public Compass(MapActivity mapActivity, Map map) {
mMap = map;
mSensorManager = (SensorManager) mapActivity
.getSystemService(Context.SENSOR_SERVICE);
@@ -63,6 +63,6 @@ public class Compass {
public void disable() {
mSensorManager.unregisterListener(mListener);
mMapView.getMapViewPosition().setRotation(0);
mMap.getViewport().setRotation(0);
}
}

View File

@@ -14,25 +14,25 @@
*/
package org.oscim.android;
import org.oscim.view.MapView;
import org.oscim.view.Map;
import android.content.Context;
import android.opengl.GLSurfaceView;
public class GLView extends GLSurfaceView {
MapView mMapView;
Map mMap;
private final AndroidGLRenderer mRenderer;
public GLView(Context context, MapView mapView) {
public GLView(Context context, Map map) {
super(context);
mMapView = mapView;
mMap = map;
// Log.d(TAG, "init GLSurfaceLayer");
setEGLConfigChooser(new GlConfigChooser());
setEGLContextClientVersion(2);
setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);
mRenderer = new AndroidGLRenderer(mMapView);
mRenderer = new AndroidGLRenderer(mMap);
setRenderer(mRenderer);
//if (!MapView.debugFrameTime)

View File

@@ -16,7 +16,7 @@ package org.oscim.android;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.view.MapView;
import org.oscim.view.Map;
import android.app.Activity;
import android.content.SharedPreferences;
@@ -24,7 +24,7 @@ import android.content.SharedPreferences.Editor;
/**
* MapActivity is the abstract base class which must be extended in order to use
* a {@link MapView}. There are no abstract methods in this implementation which
* a {@link Map}. There are no abstract methods in this implementation which
* subclasses need to override and no API key or registration is required.
* <p>
* A subclass may create a MapView either via one of the MapView constructors or
@@ -43,18 +43,18 @@ public abstract class MapActivity extends Activity {
private static final String PREFERENCES_FILE = "MapActivity";
//private static final String KEY_THEME = "Theme";
private static boolean containsMapViewPosition(SharedPreferences sharedPreferences) {
private static boolean containsViewport(SharedPreferences sharedPreferences) {
return sharedPreferences.contains(KEY_LATITUDE)
&& sharedPreferences.contains(KEY_LONGITUDE)
&& sharedPreferences.contains(KEY_MAP_SCALE);
}
protected MapView mMapView;
protected Map mMap;
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.destroy();
mMap.destroy();
}
@Override
@@ -67,7 +67,7 @@ public abstract class MapActivity extends Activity {
// save the map position
MapPosition mapPosition = new MapPosition();
mMapView.getMapViewPosition().getMapPosition(mapPosition);
mMap.getViewport().getMapPosition(mapPosition);
GeoPoint geoPoint = mapPosition.getGeoPoint();
@@ -75,7 +75,7 @@ public abstract class MapActivity extends Activity {
editor.putInt(KEY_LONGITUDE, geoPoint.longitudeE6);
editor.putFloat(KEY_MAP_SCALE, (float)mapPosition.scale);
//editor.putString(KEY_THEME, mMapView.getRenderTheme());
//editor.putString(KEY_THEME, mMap.getRenderTheme());
editor.commit();
}
@@ -93,16 +93,16 @@ public abstract class MapActivity extends Activity {
/**
* This method is called once by each MapView during its setup process.
*
* @param mapView
* @param map
* the calling MapView.
*/
public final void registerMapView(MapView mapView) {
mMapView = mapView;
public final void registerMapView(Map map) {
mMap = map;
SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE,
MODE_PRIVATE);
if (containsMapViewPosition(sharedPreferences)) {
if (containsViewport(sharedPreferences)) {
// get and set the map position and zoom level
int latitudeE6 = sharedPreferences.getInt(KEY_LATITUDE, 0);
int longitudeE6 = sharedPreferences.getInt(KEY_LONGITUDE, 0);
@@ -113,7 +113,7 @@ public abstract class MapActivity extends Activity {
mapPosition.setPosition(latitudeE6 / 1E6, longitudeE6 / 1E6);
mapPosition.setScale(scale);
mMapView.setMapPosition(mapPosition);
mMap.setMapPosition(mapPosition);
}
//String theme = sharedPreferences.getString(KEY_THEME,
@@ -121,15 +121,15 @@ public abstract class MapActivity extends Activity {
// if (theme.startsWith("/")) {
// try {
// mapView.setRenderTheme(theme);
// map.setRenderTheme(theme);
// } catch (FileNotFoundException e) {
// mapView.setRenderTheme(InternalRenderTheme.DEFAULT);
// map.setRenderTheme(InternalRenderTheme.DEFAULT);
// }
// } else {
// try {
// mapView.setRenderTheme(InternalRenderTheme.valueOf(theme));
// map.setRenderTheme(InternalRenderTheme.valueOf(theme));
// } catch (IllegalArgumentException e) {
// mapView.setRenderTheme(InternalRenderTheme.DEFAULT);
// map.setRenderTheme(InternalRenderTheme.DEFAULT);
// }
// }
}

View File

@@ -75,8 +75,8 @@ package org.oscim.android;
// private final Bitmap mMapScaleBitmap;
// private final BitmapRenderLayer mBitmapLayer;
//
// public MapScaleBar(MapView mapView) {
// super(mapView);
// public MapScaleBar(MapView map) {
// super(map);
//
// mMapScaleBitmap = Bitmap.createBitmap(
// BITMAP_WIDTH, BITMAP_HEIGHT,
@@ -89,7 +89,7 @@ package org.oscim.android;
// configurePaints();
//
// mRedrawNeeded = true;
// mLayer = mBitmapLayer = new BitmapRenderLayer(mapView);
// mLayer = mBitmapLayer = new BitmapRenderLayer(map);
// mBitmapLayer.setBitmap(mMapScaleBitmap, 0, 0,
// (int)(BITMAP_WIDTH * 1.2f),
// (int)(BITMAP_HEIGHT * 1.2f));

View File

@@ -23,7 +23,7 @@ import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.GLAdapter;
import org.oscim.backend.Log;
import org.oscim.core.Tile;
import org.oscim.view.MapView;
import org.oscim.view.Map;
import android.content.Context;
import android.util.AttributeSet;
@@ -35,9 +35,9 @@ import android.widget.RelativeLayout;
* A MapView shows a map on the display of the device. It handles all user input
* and touch gestures to move and zoom the map.
*/
public class AndroidMapView extends RelativeLayout {
public class MapView extends RelativeLayout {
final static String TAG = AndroidMapView.class.getName();
final static String TAG = MapView.class.getName();
public static final boolean debugFrameTime = false;
public static final boolean testRegionZoom = false;
@@ -52,7 +52,7 @@ public class AndroidMapView extends RelativeLayout {
private int mHeight;
private final MapView mMapView;
private final Map mMap;
final GLView mGLView;
boolean mPausing = false;
@@ -61,10 +61,6 @@ public class AndroidMapView extends RelativeLayout {
static {
System.loadLibrary("vtm-jni");
//System.loadLibrary("tessellate");
CanvasAdapter.g = AndroidGraphics.INSTANCE;
GLAdapter.g = new AndroidGL();
Log.logger = new AndroidLog();
}
/**
@@ -74,7 +70,7 @@ public class AndroidMapView extends RelativeLayout {
* if the context object is not an instance of
* {@link MapActivity} .
*/
public AndroidMapView(Context context) {
public MapView(Context context) {
this(context, null);
}
@@ -88,7 +84,7 @@ public class AndroidMapView extends RelativeLayout {
* {@link MapActivity} .
*/
public AndroidMapView(Context context, AttributeSet attributeSet) {
public MapView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
if (!(context instanceof MapActivity)) {
@@ -96,7 +92,10 @@ public class AndroidMapView extends RelativeLayout {
"context is not an instance of MapActivity");
}
Log.logger = new AndroidLog();
CanvasAdapter.g = AndroidGraphics.INSTANCE;
AssetAdapter.g = new AndroidAssetAdapter(context);
GLAdapter.g = new AndroidGL();
this.setWillNotDraw(true);
@@ -108,9 +107,9 @@ public class AndroidMapView extends RelativeLayout {
MapActivity mapActivity = (MapActivity) context;
final AndroidMapView m = this;
final MapView m = this;
mMapView = new MapView(){
mMap = new Map(){
boolean mWaitRedraw;
@@ -176,10 +175,10 @@ public class AndroidMapView extends RelativeLayout {
}
};
mGLView = new GLView(context, mMapView);
mCompass = new Compass(mapActivity, mMapView);
mGLView = new GLView(context, mMap);
mCompass = new Compass(mapActivity, mMap);
mapActivity.registerMapView(mMapView);
mapActivity.registerMapView(mMap);
LayoutParams params = new LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT,
@@ -187,21 +186,21 @@ public class AndroidMapView extends RelativeLayout {
addView(mGLView, params);
mMapView.clearMap();
mMapView.updateMap(false);
mMap.clearMap();
mMap.updateMap(false);
}
View getView(){
return this;
}
public MapView getMap() {
return mMapView;
public Map getMap() {
return mMap;
}
public void onStop() {
Log.d(TAG, "onStop");
//mLayerManager.destroy();
//mMap.destroy();
}
@@ -230,7 +229,7 @@ public class AndroidMapView extends RelativeLayout {
mMotionEvent.wrap(motionEvent);
return mMapView.getLayerManager().handleMotionEvent(mMotionEvent);
return mMap.getLayers().handleMotionEvent(mMotionEvent);
}
// synchronized ???
@@ -247,7 +246,7 @@ public class AndroidMapView extends RelativeLayout {
mInitialized = (mWidth > 0 && mHeight > 0);
if (mInitialized)
mMapView.getMapViewPosition().setViewport(width, height);
mMap.getViewport().setViewport(width, height);
}

View File

@@ -55,7 +55,7 @@ package org.oscim.android;
// @Override
// public void onClick(View view) {
// // if (MapView.testRegionZoom)
// // mMapView.mRegionLookup.updateRegion(1, null);
// // mMap.mRegionLookup.updateRegion(1, null);
// // else
// // MapZoomControls.this.zoom((byte) 1);
// mMapZoomControls.zoom((byte) 1);
@@ -72,7 +72,7 @@ package org.oscim.android;
// @Override
// public void onClick(View view) {
// // if (MapView.testRegionZoom)
// // mMapView.mRegionLookup.updateRegion(-1, null);
// // mMap.mRegionLookup.updateRegion(-1, null);
// // else
// mMapZoomControls.zoom((byte) -1);
// }
@@ -117,10 +117,10 @@ package org.oscim.android;
// private final Handler mZoomControlsHideHandler;
// private byte mZoomLevelMax;
// private byte mZoomLevelMin;
// private final MapView mMapView;
// private final MapView mMap;
//
// MapZoomControls(Context context, final MapView mapView) {
// mMapView = mapView;
// MapZoomControls(Context context, final MapView map) {
// mMap = map;
// mZoomControls = new ZoomControls(context);
// mShowMapZoomControls = true;
// mZoomLevelMax = DEFAULT_ZOOM_LEVEL_MAX;
@@ -135,7 +135,7 @@ package org.oscim.android;
//
// int wrapContent = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
// LayoutParams layoutParams = new LayoutParams(wrapContent, wrapContent);
// mapView.addView(mZoomControls, layoutParams);
// map.addView(mZoomControls, layoutParams);
// }
//
// /**
@@ -146,8 +146,8 @@ package org.oscim.android;
// * @return true if the zoom level was changed, false otherwise.
// */
// boolean zoom(byte zoomLevelDiff) {
// MapViewPosition mapViewPosition = mMapView.getMapViewPosition();
// int z = mapViewPosition.getZoomLevel() + zoomLevelDiff;
// Viewport mapPosition = mMap.getViewport();
// int z = mapPosition.getZoomLevel() + zoomLevelDiff;
// if (zoomLevelDiff > 0) {
// // check if zoom in is possible
// if (z > mZoomLevelMax) {
@@ -161,8 +161,8 @@ package org.oscim.android;
// }
// }
//
// mapViewPosition.setZoomLevel((byte) z);
// mMapView.redrawMap(true);
// mapPosition.setZoomLevel((byte) z);
// mMap.redrawMap(true);
//
// return true;
// }