forked from organicmaps/organicmaps
[yota] Mwm files watching.
This commit is contained in:
parent
ef78f7f60a
commit
5d6a4b4a23
5 changed files with 88 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -439,7 +439,7 @@ public class BackscreenActivity extends BSActivity
|
|||
}
|
||||
}
|
||||
|
||||
public String getDataStoragePath()
|
||||
public static String getDataStoragePath()
|
||||
{
|
||||
return Environment.getExternalStorageDirectory().getAbsolutePath() + "/MapsWithMe/";
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue