From f78bb5ee9670ca150ec245a17829813dd3d3b745 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 2 Oct 2014 12:05:16 +0300 Subject: [PATCH 1/3] naming refactor --- .../controllers/NativeViewController.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java b/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java index d08026427e..aaf9c66f2c 100644 --- a/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java +++ b/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java @@ -67,7 +67,7 @@ public class NativeViewController extends MapViewBaseController { private QIODeviceLogSink fileLogSink; private RotatedTileBox currentViewport = null; - private boolean offlineMap = true; + private boolean offlineMap = false; private GestureDetector gestureDetector; @@ -252,8 +252,8 @@ public class NativeViewController extends MapViewBaseController { } private class EGLContextFactory implements GLSurfaceView.EGLContextFactory { - private EGLContext _gpuWorkerContext; - private EGLSurface _gpuWorkerFakeSurface; + private EGLContext gpuWorkerContext; + private EGLSurface gpuWorkerFakeSurface; public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) { final String eglExtensions = egl.eglQueryString(display, EGL10.EGL_EXTENSIONS); @@ -280,7 +280,7 @@ public class NativeViewController extends MapViewBaseController { Log.i(NATIVE_TAG, "Creating GPU worker context..."); try { - _gpuWorkerContext = egl.eglCreateContext( + gpuWorkerContext = egl.eglCreateContext( display, eglConfig, mainContext, @@ -288,13 +288,13 @@ public class NativeViewController extends MapViewBaseController { } catch (Exception e) { Log.e(NATIVE_TAG, "Failed to create GPU worker context", e); } - if (_gpuWorkerContext == null || _gpuWorkerContext == EGL10.EGL_NO_CONTEXT) + if (gpuWorkerContext == null || gpuWorkerContext == EGL10.EGL_NO_CONTEXT) { Log.e(NATIVE_TAG, "Failed to create GPU worker context: " + egl.eglGetError()); - _gpuWorkerContext = null; + gpuWorkerContext = null; } - if (_gpuWorkerContext != null) + if (gpuWorkerContext != null) { Log.i(NATIVE_TAG, "Creating GPU worker fake surface..."); try { @@ -302,21 +302,21 @@ public class NativeViewController extends MapViewBaseController { EGL10.EGL_WIDTH, 1, EGL10.EGL_HEIGHT, 1, EGL10.EGL_NONE }; - _gpuWorkerFakeSurface = egl.eglCreatePbufferSurface(display, eglConfig, surfaceAttribList); + gpuWorkerFakeSurface = egl.eglCreatePbufferSurface(display, eglConfig, surfaceAttribList); } catch (Exception e) { Log.e(NATIVE_TAG, "Failed to create GPU worker fake surface", e); } - if (_gpuWorkerFakeSurface == null || _gpuWorkerFakeSurface == EGL10.EGL_NO_SURFACE) + if (gpuWorkerFakeSurface == null || gpuWorkerFakeSurface == EGL10.EGL_NO_SURFACE) { Log.e(NATIVE_TAG, "Failed to create GPU worker fake surface: " + egl.eglGetError()); - _gpuWorkerFakeSurface = null; + gpuWorkerFakeSurface = null; } } MapRendererSetupOptions rendererSetupOptions = new MapRendererSetupOptions(); - if (_gpuWorkerContext != null && _gpuWorkerFakeSurface != null) { + if (gpuWorkerContext != null && gpuWorkerFakeSurface != null) { rendererSetupOptions.setGpuWorkerThreadEnabled(true); - gpuWorkerThreadPrologue = new GpuWorkerThreadPrologue(egl, display, _gpuWorkerContext, _gpuWorkerFakeSurface); + gpuWorkerThreadPrologue = new GpuWorkerThreadPrologue(egl, display, gpuWorkerContext, gpuWorkerFakeSurface); rendererSetupOptions.setGpuWorkerThreadPrologue(gpuWorkerThreadPrologue.getBinding()); gpuWorkerThreadEpilogue = new GpuWorkerThreadEpilogue(egl); rendererSetupOptions.setGpuWorkerThreadEpilogue(gpuWorkerThreadEpilogue.getBinding()); @@ -333,14 +333,14 @@ public class NativeViewController extends MapViewBaseController { public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) { egl.eglDestroyContext(display, context); - if (_gpuWorkerContext != null) { - egl.eglDestroyContext(display, _gpuWorkerContext); - _gpuWorkerContext = null; + if (gpuWorkerContext != null) { + egl.eglDestroyContext(display, gpuWorkerContext); + gpuWorkerContext = null; } - if (_gpuWorkerFakeSurface != null) { - egl.eglDestroySurface(display, _gpuWorkerFakeSurface); - _gpuWorkerFakeSurface = null; + if (gpuWorkerFakeSurface != null) { + egl.eglDestroySurface(display, gpuWorkerFakeSurface); + gpuWorkerFakeSurface = null; } } } From c004d93891d3176f7d6f4d7cb6b44d813fc0b12f Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 2 Oct 2014 14:33:09 +0300 Subject: [PATCH 2/3] Added support for simple gestures on map --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 5 +++++ .../osmand/plus/views/controllers/NativeViewController.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index f9c34ddd02..df484a8c15 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -733,4 +733,9 @@ public class MapActivity extends AccessibleActivity { public View getLayout() { return getWindow().getDecorView().findViewById(android.R.id.content); } + + @Override + public boolean onTouchEvent(MotionEvent event) { + return mapViewController.onTouchEvent(event); + } } diff --git a/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java b/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java index aaf9c66f2c..708c5e6c2d 100644 --- a/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java +++ b/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java @@ -67,7 +67,7 @@ public class NativeViewController extends MapViewBaseController { private QIODeviceLogSink fileLogSink; private RotatedTileBox currentViewport = null; - private boolean offlineMap = false; + private boolean offlineMap = true; private GestureDetector gestureDetector; From 6cc5a576fe15a983e9e150c848322a0edf8d74a6 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 2 Oct 2014 15:22:50 +0300 Subject: [PATCH 3/3] Little refactor to class names. Created class for native cpp libaries. --- .../net/osmand/core/android/GLActivity.java | 4 ++-- ...etector.java => TwoFingerTapDetector.java} | 2 +- .../osmand/plus/render/NativeCppLibrary.java | 23 +++++++++++++++++++ .../osmand/plus/views/OsmandMapTileView.java | 7 ++---- .../views/controllers/JavaViewController.java | 1 - .../controllers/NativeViewController.java | 22 ++++++++++-------- 6 files changed, 40 insertions(+), 19 deletions(-) rename OsmAnd/src/net/osmand/plus/helpers/{SimpleTwoFingerTapDetector.java => TwoFingerTapDetector.java} (96%) create mode 100644 OsmAnd/src/net/osmand/plus/render/NativeCppLibrary.java diff --git a/OsmAnd/src/net/osmand/core/android/GLActivity.java b/OsmAnd/src/net/osmand/core/android/GLActivity.java index e58b7c8dd5..c084602cbf 100644 --- a/OsmAnd/src/net/osmand/core/android/GLActivity.java +++ b/OsmAnd/src/net/osmand/core/android/GLActivity.java @@ -14,7 +14,7 @@ import net.osmand.data.RotatedTileBox; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; -import net.osmand.plus.helpers.SimpleTwoFingerTapDetector; +import net.osmand.plus.helpers.TwoFingerTapDetector; import net.osmand.plus.render.NativeOsmandLibrary; import android.app.Activity; import android.content.Context; @@ -75,7 +75,7 @@ public class GLActivity extends Activity { } private boolean afterTwoFingerTap = false; - SimpleTwoFingerTapDetector twoFingerTapDetector = new SimpleTwoFingerTapDetector() { + TwoFingerTapDetector twoFingerTapDetector = new TwoFingerTapDetector() { @Override public void onTwoFingerTap() { afterTwoFingerTap = true; diff --git a/OsmAnd/src/net/osmand/plus/helpers/SimpleTwoFingerTapDetector.java b/OsmAnd/src/net/osmand/plus/helpers/TwoFingerTapDetector.java similarity index 96% rename from OsmAnd/src/net/osmand/plus/helpers/SimpleTwoFingerTapDetector.java rename to OsmAnd/src/net/osmand/plus/helpers/TwoFingerTapDetector.java index b5a7cfec73..f31fb4d8f9 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/SimpleTwoFingerTapDetector.java +++ b/OsmAnd/src/net/osmand/plus/helpers/TwoFingerTapDetector.java @@ -6,7 +6,7 @@ import android.view.ViewConfiguration; /** * Created by Barsik on 24.06.2014. */ -public abstract class SimpleTwoFingerTapDetector { +public abstract class TwoFingerTapDetector { private static final int TIMEOUT = ViewConfiguration.getTapTimeout() + 100; private long mFirstDownTime = 0; private byte mTwoFingerTapCount = 0; diff --git a/OsmAnd/src/net/osmand/plus/render/NativeCppLibrary.java b/OsmAnd/src/net/osmand/plus/render/NativeCppLibrary.java new file mode 100644 index 0000000000..20cbb7662d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/render/NativeCppLibrary.java @@ -0,0 +1,23 @@ +package net.osmand.plus.render; + +import net.osmand.NativeLibrary; + +/** + * Created by Denis on 02.10.2014. + */ +public class NativeCppLibrary extends NativeLibrary { + + public NativeCppLibrary(boolean newLibrary) { + super(newLibrary); + } + + public static void loadLibrary(String name) { + try { + System.out.println("Loading " + name); + System.loadLibrary(name); + } catch( UnsatisfiedLinkError e ) { + System.err.println("Failed to load '"+name + "':" + e); + throw e; + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index adf8a9176d..e093344e93 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -23,7 +23,7 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; -import net.osmand.plus.helpers.SimpleTwoFingerTapDetector; +import net.osmand.plus.helpers.TwoFingerTapDetector; import net.osmand.plus.views.MultiTouchSupport.MultiTouchZoomListener; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.controllers.JavaViewController; @@ -81,9 +81,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall protected static final int emptyTileDivisor = 16; - - - public interface OnLongClickListener { public boolean onLongPressEvent(PointF point); } @@ -148,7 +145,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall private Paint paintImg; private boolean afterTwoFingerTap = false; - SimpleTwoFingerTapDetector twoFingerTapDetector = new SimpleTwoFingerTapDetector() { + TwoFingerTapDetector twoFingerTapDetector = new TwoFingerTapDetector() { @Override public void onTwoFingerTap() { afterTwoFingerTap = true; diff --git a/OsmAnd/src/net/osmand/plus/views/controllers/JavaViewController.java b/OsmAnd/src/net/osmand/plus/views/controllers/JavaViewController.java index 191b4217e2..d21e61674c 100644 --- a/OsmAnd/src/net/osmand/plus/views/controllers/JavaViewController.java +++ b/OsmAnd/src/net/osmand/plus/views/controllers/JavaViewController.java @@ -24,7 +24,6 @@ import java.util.List; * Created by Натали on 29.09.2014. */ public class JavaViewController extends MapViewBaseController { - private GLSurfaceView glSurfaceView; private OsmandMapTileView mapTileView; private OsmandSettings settings; private MapActivity mapActivity; diff --git a/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java b/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java index 708c5e6c2d..e4e5fdf807 100644 --- a/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java +++ b/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java @@ -22,7 +22,8 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.base.MapViewTrackingUtilities; -import net.osmand.plus.helpers.SimpleTwoFingerTapDetector; +import net.osmand.plus.helpers.TwoFingerTapDetector; +import net.osmand.plus.render.NativeCppLibrary; import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; @@ -36,14 +37,6 @@ import java.util.List; */ public class NativeViewController extends MapViewBaseController { - static { - NativeOsmandLibrary.loadLibrary("gnustl_shared"); - NativeOsmandLibrary.loadLibrary("Qt5Core"); - NativeOsmandLibrary.loadLibrary("Qt5Network"); - NativeOsmandLibrary.loadLibrary("Qt5Sql"); - NativeOsmandLibrary.loadLibrary("OsmAndCoreWithJNI"); - } - private GLSurfaceView glSurfaceView; private OsmandSettings settings; private MapActivity mapActivity; @@ -74,7 +67,7 @@ public class NativeViewController extends MapViewBaseController { public static final String NATIVE_TAG = "NativeRender"; private CoreResourcesFromAndroidAssets coreResources; - SimpleTwoFingerTapDetector twoFingerTapDetector = new SimpleTwoFingerTapDetector() { + TwoFingerTapDetector twoFingerTapDetector = new TwoFingerTapDetector() { @Override public void onTwoFingerTap() { currentViewport.setZoom(currentViewport.getZoom() - 1); @@ -87,9 +80,18 @@ public class NativeViewController extends MapViewBaseController { this.glSurfaceView = surfaceView; this.settings = activity.getMyApplication().getSettings(); this.mapActivity = activity; + loadLibraries(); setupView(); } + private void loadLibraries() { + NativeCppLibrary.loadLibrary("gnustl_shared"); + NativeCppLibrary.loadLibrary("Qt5Core"); + NativeCppLibrary.loadLibrary("Qt5Network"); + NativeCppLibrary.loadLibrary("Qt5Sql"); + NativeCppLibrary.loadLibrary("OsmAndCoreWithJNI"); + } + private void setupView() { WindowManager mgr = (WindowManager)mapActivity.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics();