diff --git a/vtm-android/src/org/oscim/android/AndroidMap.java b/vtm-android/src/org/oscim/android/AndroidMap.java
deleted file mode 100644
index 0a130a6f..00000000
--- a/vtm-android/src/org/oscim/android/AndroidMap.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2013 Hannes Janetzek
- *
- * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
- *
- * 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 .
- */
-package org.oscim.android;
-
-import org.oscim.android.gl.GLView;
-import org.oscim.map.Map;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import android.widget.RelativeLayout.LayoutParams;
-
-public class AndroidMap extends Map {
- static final Logger log = LoggerFactory.getLogger(AndroidMap.class);
-
- private final MapView mMapView;
- final GLView mGLView;
-
- private boolean mRenderRequest;
- private boolean mRenderWait;
- private boolean mPausing;
-
- public AndroidMap(MapView mapView) {
- super();
-
- mMapView = mapView;
- mGLView = new GLView(mapView.getContext(), this);
-
- LayoutParams params =
- new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
- android.view.ViewGroup.LayoutParams.MATCH_PARENT);
-
- mapView.addView(mGLView, params);
- }
-
- @Override
- public int getWidth() {
- return mMapView.getWidth();
- }
-
- @Override
- public int getHeight() {
- return mMapView.getHeight();
- }
-
- private final Runnable mRedrawCb = new Runnable() {
- @Override
- public void run() {
- prepareFrame();
- mGLView.requestRender();
- }
- };
-
- @Override
- public void updateMap(boolean redraw) {
- if (mPausing)
- return;
-
- if (!mRenderRequest) {
- mRenderRequest = true;
- mMapView.post(mRedrawCb);
- } else {
- mRenderWait = true;
- }
- }
-
- @Override
- public void render() {
- if (mPausing)
- return;
-
- updateMap(true);
- }
-
- @Override
- public void beginFrame() {
- }
-
- @Override
- public void doneFrame() {
- mRenderRequest = false;
-
- if (mRenderWait) {
- //log.debug("redraw");
- mRenderWait = false;
- updateMap(true);
- //prepareFrame();
- //mGLView.requestRender();
- }
- }
-
- @Override
- public boolean post(Runnable runnable) {
- return mMapView.post(runnable);
- }
-
- @Override
- public boolean postDelayed(Runnable action, long delay) {
- return mMapView.postDelayed(action, delay);
- }
-
- public void pause(boolean pause) {
- log.debug("pause... {}", pause);
- mPausing = pause;
- }
-}
diff --git a/vtm-android/src/org/oscim/android/MapView.java b/vtm-android/src/org/oscim/android/MapView.java
index 2847a2cc..5c603ad2 100644
--- a/vtm-android/src/org/oscim/android/MapView.java
+++ b/vtm-android/src/org/oscim/android/MapView.java
@@ -16,8 +16,12 @@
*/
package org.oscim.android;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
import org.oscim.android.canvas.AndroidGraphics;
import org.oscim.android.gl.AndroidGL;
+import org.oscim.android.gl.GlConfigChooser;
import org.oscim.android.input.AndroidMotionEvent;
import org.oscim.android.input.GestureHandler;
import org.oscim.backend.CanvasAdapter;
@@ -28,19 +32,26 @@ import org.slf4j.LoggerFactory;
import android.annotation.SuppressLint;
import android.content.Context;
+import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.GestureDetector;
-import android.widget.RelativeLayout;
-public class MapView extends RelativeLayout {
+/**
+ * The MapView,
+ *
+ * add it your App, have a map!
+ *
+ * Dont forget to call onPause / onResume!
+ */
+public class MapView extends GLSurfaceView {
+
+ static final Logger log = LoggerFactory.getLogger(MapView.class);
static {
System.loadLibrary("vtm-jni");
}
- static final Logger log = LoggerFactory.getLogger(MapView.class);
-
protected final AndroidMap mMap;
protected final GestureDetector mGestureDetector;
protected final AndroidMotionEvent mMotionEvent;
@@ -49,12 +60,17 @@ public class MapView extends RelativeLayout {
this(context, null);
}
+ @SuppressWarnings("deprecation")
public MapView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
+
+ /* Not sure if this makes sense */
this.setWillNotDraw(true);
this.setClickable(true);
this.setFocusable(true);
+ this.setFocusableInTouchMode(true);
+ /* Setup android backedn */
AndroidGraphics.init();
AndroidAssets.init(context);
GLAdapter.init(new AndroidGL());
@@ -62,8 +78,21 @@ public class MapView extends RelativeLayout {
DisplayMetrics metrics = getResources().getDisplayMetrics();
CanvasAdapter.dpi = (int) Math.max(metrics.xdpi, metrics.ydpi);
+ /* Initialize the Map */
mMap = new AndroidMap(this);
+ /* Initialize Renderer */
+ setEGLConfigChooser(new GlConfigChooser());
+ setEGLContextClientVersion(2);
+
+ if (GLAdapter.debug)
+ setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR
+ | GLSurfaceView.DEBUG_LOG_GL_CALLS);
+
+ setRenderer(new GLRenderer(mMap));
+ setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
+
+ /* to be removed */
if (context instanceof MapActivity)
((MapActivity) context).registerMapView(this);
@@ -81,11 +110,11 @@ public class MapView extends RelativeLayout {
}
- void onPause() {
+ public void onPause() {
mMap.pause(true);
}
- void onResume() {
+ public void onResume() {
mMap.pause(false);
}
@@ -116,4 +145,113 @@ public class MapView extends RelativeLayout {
public Map map() {
return mMap;
}
+
+ static class AndroidMap extends Map {
+
+ private final MapView mMapView;
+
+ private boolean mRenderRequest;
+ private boolean mRenderWait;
+ private boolean mPausing;
+
+ public AndroidMap(MapView mapView) {
+ super();
+ mMapView = mapView;
+ }
+
+ @Override
+ public int getWidth() {
+ return mMapView.getWidth();
+ }
+
+ @Override
+ public int getHeight() {
+ return mMapView.getHeight();
+ }
+
+ private final Runnable mRedrawCb = new Runnable() {
+ @Override
+ public void run() {
+ prepareFrame();
+ mMapView.requestRender();
+ }
+ };
+
+ @Override
+ public void updateMap(boolean redraw) {
+ if (mPausing)
+ return;
+
+ if (!mRenderRequest) {
+ mRenderRequest = true;
+ mMapView.post(mRedrawCb);
+ } else {
+ mRenderWait = true;
+ }
+ }
+
+ @Override
+ public void render() {
+ if (mPausing)
+ return;
+
+ updateMap(true);
+ }
+
+ @Override
+ public void beginFrame() {
+ }
+
+ @Override
+ public void doneFrame() {
+ mRenderRequest = false;
+
+ if (mRenderWait) {
+ //log.debug("redraw");
+ mRenderWait = false;
+ updateMap(true);
+ //prepareFrame();
+ //mGLView.requestRender();
+ }
+ }
+
+ @Override
+ public boolean post(Runnable runnable) {
+ return mMapView.post(runnable);
+ }
+
+ @Override
+ public boolean postDelayed(Runnable action, long delay) {
+ return mMapView.postDelayed(action, delay);
+ }
+
+ public void pause(boolean pause) {
+ log.debug("pause... {}", pause);
+ mPausing = pause;
+ }
+ }
+
+ static class GLRenderer extends org.oscim.renderer.MapRenderer
+ implements GLSurfaceView.Renderer {
+
+ public GLRenderer(Map map) {
+ super(map);
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ super.onSurfaceCreated();
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ super.onSurfaceChanged(width, height);
+
+ }
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+ super.onDrawFrame();
+ }
+ }
}
diff --git a/vtm-android/src/org/oscim/android/gl/GLView.java b/vtm-android/src/org/oscim/android/gl/GLView.java
deleted file mode 100644
index fcecb62d..00000000
--- a/vtm-android/src/org/oscim/android/gl/GLView.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2012 Hannes Janetzek
- *
- * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
- *
- * 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 .
- */
-package org.oscim.android.gl;
-
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.opengles.GL10;
-
-import org.oscim.backend.GLAdapter;
-import org.oscim.map.Map;
-
-import android.content.Context;
-import android.opengl.GLSurfaceView;
-
-public class GLView extends GLSurfaceView {
-
- class GLRenderer extends org.oscim.renderer.MapRenderer implements GLSurfaceView.Renderer {
-
- public GLRenderer(Map map) {
- super(map);
- }
-
- @Override
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
- super.onSurfaceCreated();
- }
-
- @Override
- public void onSurfaceChanged(GL10 gl, int width, int height) {
- super.onSurfaceChanged(width, height);
-
- }
-
- @Override
- public void onDrawFrame(GL10 gl) {
- super.onDrawFrame();
- }
- }
-
- public GLView(Context context, Map map) {
- super(context);
- setEGLConfigChooser(new GlConfigChooser());
- setEGLContextClientVersion(2);
-
- if (GLAdapter.debug)
- setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR | GLSurfaceView.DEBUG_LOG_GL_CALLS);
-
- setRenderer(new GLRenderer(map));
-
- setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
- }
-}