diff options
author | Dmitry Kunin <dkunin@mapswith.me> | 2013-09-18 16:06:47 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:02:17 +0300 |
commit | 5d6a4b4a237674c4d549783e1ddc159b552ad215 (patch) | |
tree | 37bb6b0ee8ba742ff14f81ab450f6dcebe9a8dbc | |
parent | ef78f7f60a076aa4f7b4098e4d319f4ca9ee8b78 (diff) |
[yota] Mwm files watching.
5 files changed, 88 insertions, 5 deletions
diff --git a/android/YoPme/jni/Framework.hpp b/android/YoPme/jni/Framework.hpp index 3ee117d845..6ac6c65bec 100644 --- a/android/YoPme/jni/Framework.hpp +++ b/android/YoPme/jni/Framework.hpp @@ -14,6 +14,8 @@ namespace yopme bool ShowMyPosition(double lat, double lon, double zoom); bool ShowPoi(double lat, double lon, bool needMyLoc, double myLat, double myLoc, double zoom); + ::Framework & NativeFramework() { return m_framework; } + private: void ShowRect(bool needApiPin, m2::PointD const & apiPinPoint, bool needMyLoc, m2::PointD const & myLocPoint); diff --git a/android/YoPme/jni/MapRenderer.cpp b/android/YoPme/jni/MapRenderer.cpp index f98fbf2be0..b7e1a14b29 100644 --- a/android/YoPme/jni/MapRenderer.cpp +++ b/android/YoPme/jni/MapRenderer.cpp @@ -10,6 +10,8 @@ namespace static shared_ptr<yopme::Framework> s_framework; } +#define FRAMEWORK_CHECK() ASSERT(s_framework != NULL, ()) + // @TODO refactor and remove that void InitNVEvent(JavaVM * jvm) {} @@ -26,7 +28,8 @@ JNIEXPORT bool JNICALL Java_com_mapswithme_yopme_map_MapRenderer_nativeRenderMyPosition(JNIEnv * env, jobject obj, double lat, double lon, double zoom) { - ASSERT(s_framework != NULL, ()); +// ASSERT(s_framework != NULL, ()); + FRAMEWORK_CHECK(); return s_framework->ShowMyPosition(lat, lon, zoom); } @@ -36,8 +39,24 @@ Java_com_mapswithme_yopme_map_MapRenderer_nativeRenderPoiMap(JNIEnv * env, jobje bool needMyLoc, double myLat, double myLon, double zoom) { - ASSERT(s_framework != NULL, ()); +// ASSERT(s_framework != NULL, ()); + FRAMEWORK_CHECK(); return s_framework->ShowPoi(lat, lon, needMyLoc, myLat, myLon, zoom); } +JNIEXPORT void JNICALL +Java_com_mapswithme_yopme_map_MapRenderer_nativeOnMapFileUpdate(JNIEnv * env, jobject thiz) +{ + FRAMEWORK_CHECK(); + s_framework->NativeFramework().RemoveLocalMaps(); + s_framework->NativeFramework().AddLocalMaps(); +} + +JNIEXPORT void JNICALL +Java_com_mapswithme_yopme_map_MapRenderer_nativeOnKmlFileUpdate(JNIEnv * env, jobject thiz) +{ + FRAMEWORK_CHECK(); + s_framework->NativeFramework().LoadBookmarks(); +} + } // extern "C" diff --git a/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java b/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java index 37e401674d..c70a325e01 100644 --- a/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java +++ b/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java @@ -439,7 +439,7 @@ public class BackscreenActivity extends BSActivity } } - public String getDataStoragePath() + public static String getDataStoragePath() { return Environment.getExternalStorageDirectory().getAbsolutePath() + "/MapsWithMe/"; } diff --git a/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java b/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java index fce6c2e9e9..c814c717ee 100644 --- a/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java +++ b/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java @@ -1,20 +1,26 @@ package com.mapswithme.yopme.map; import android.graphics.Bitmap; - import com.mapswithme.yopme.PoiPoint; +import com.mapswithme.yopme.map.MwmFilesObserver.EventType; +import com.mapswithme.yopme.map.MwmFilesObserver.MwmFilesListener; import com.mapswithme.yopme.util.PixelBuffer; -public class MapRenderer implements MapDataProvider +public class MapRenderer implements MapDataProvider, MwmFilesListener { private final static String TAG = "MapRenderer"; PixelBuffer mPixelBuffer = null; + private final MwmFilesObserver mFilesObserver; + public MapRenderer(int width, int height) { mPixelBuffer = new PixelBuffer(width, height); mPixelBuffer.init(); nativeCreateFramework(width, height); + + mFilesObserver = new MwmFilesObserver(this); + mFilesObserver.startWatching(); } public void terminate() @@ -68,4 +74,19 @@ public class MapRenderer implements MapDataProvider private native boolean nativeRenderPoiMap(double lat, double lon, boolean needMyLocation, double myLat, double myLon, double zoom); + + private native void nativeOnKmlFileUpdate(); + private native void nativeOnMapFileUpdate(); + + @Override + public void onFileEvent(String path, EventType event) + { + synchronized (MapRenderer.class) + { + if (EventType.KML_FILE_EVENT == event) + nativeOnKmlFileUpdate(); + else if (EventType.MAP_FILE_EVENT == event) + nativeOnMapFileUpdate(); + } + } } diff --git a/android/YoPme/src/com/mapswithme/yopme/map/MwmFilesObserver.java b/android/YoPme/src/com/mapswithme/yopme/map/MwmFilesObserver.java new file mode 100644 index 0000000000..53a1fbd7bd --- /dev/null +++ b/android/YoPme/src/com/mapswithme/yopme/map/MwmFilesObserver.java @@ -0,0 +1,41 @@ +package com.mapswithme.yopme.map; + +import com.mapswithme.yopme.BackscreenActivity; + +import android.os.FileObserver; + +public class MwmFilesObserver extends FileObserver +{ + private final MwmFilesListener mListener; + + public enum EventType + { + MAP_FILE_EVENT, + KML_FILE_EVENT, + } + + public interface MwmFilesListener + { + void onFileEvent(String path, EventType event); + } + + private final static int MASK = + MODIFY | CREATE | DELETE | MOVED_FROM | MOVED_TO; + + + public MwmFilesObserver(MwmFilesListener listener) + { + super(BackscreenActivity.getDataStoragePath(), MASK); + mListener = listener; + } + + @Override + public void onEvent(int event, String path) + { + if (path.endsWith(".mwm")) + mListener.onFileEvent(path, EventType.MAP_FILE_EVENT); + else if (path.endsWith(".kml")) + mListener.onFileEvent(path, EventType.KML_FILE_EVENT); + } + +} |