Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Yunitsky <yunik@mapswithme.com>2016-01-18 13:50:34 +0300
committerDmitry Yunitsky <yunik@mapswithme.com>2016-01-21 17:33:38 +0300
commitec3bf535340dffd49316b5594d798fdddbb02bdb (patch)
tree6ae249b729587c4b3d2272053da7170d3fb2eb40
parent0b73b104d1be69b0ffef348c1e32a63627f90403 (diff)
[android] Refactored MapObject.show
-rw-r--r--android/YoPme/jni/MapRenderer.cpp3
-rw-r--r--android/jni/Android.mk3
-rw-r--r--android/jni/com/mapswithme/core/ScopedLocalRef.hpp42
-rw-r--r--android/jni/com/mapswithme/core/jni_helper.cpp114
-rw-r--r--android/jni/com/mapswithme/core/jni_helper.hpp18
-rw-r--r--android/jni/com/mapswithme/maps/Framework.cpp256
-rw-r--r--android/jni/com/mapswithme/maps/Framework.hpp8
-rw-r--r--android/jni/com/mapswithme/maps/UserMarkHelper.cpp154
-rw-r--r--android/jni/com/mapswithme/maps/UserMarkHelper.hpp34
-rw-r--r--android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp18
-rw-r--r--android/jni/com/mapswithme/maps/bookmarks/data/BookmarkCategory.cpp190
-rw-r--r--android/jni/com/mapswithme/maps/editor/Editor.cpp75
-rw-r--r--android/res/layout/fragment_auth_editor.xml116
-rw-r--r--android/src/com/mapswithme/maps/Framework.java16
-rw-r--r--android/src/com/mapswithme/maps/MwmActivity.java118
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java134
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategory.java6
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/data/MapObject.java264
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/data/Metadata.java16
-rw-r--r--android/src/com/mapswithme/maps/editor/AuthFragment.java28
-rw-r--r--android/src/com/mapswithme/maps/editor/Editor.java35
-rw-r--r--android/src/com/mapswithme/maps/editor/EditorActivity.java9
-rw-r--r--android/src/com/mapswithme/maps/editor/EditorFragment.java152
-rw-r--r--android/src/com/mapswithme/maps/editor/EditorHostFragment.java110
-rw-r--r--android/src/com/mapswithme/maps/location/LocationHelper.java7
-rw-r--r--android/src/com/mapswithme/maps/routing/RoutingController.java10
-rw-r--r--android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java7
-rw-r--r--android/src/com/mapswithme/maps/routing/SlotFrame.java2
-rw-r--r--android/src/com/mapswithme/maps/search/SearchFragment.java2
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/BasePlacePageAnimationController.java4
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/HoursMinutesPickerFragment.java5
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/PlacePageLeftAnimationController.java4
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java93
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableAdapter.java2
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableFragment.java3
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/TimetableFragment.java35
-rw-r--r--android/src/com/mapswithme/util/sharing/MapObjectShareable.java4
-rw-r--r--android/src/com/mapswithme/util/sharing/ShareOption.java3
-rw-r--r--android/src/com/mapswithme/util/statistics/Statistics.java2
39 files changed, 1231 insertions, 871 deletions
diff --git a/android/YoPme/jni/MapRenderer.cpp b/android/YoPme/jni/MapRenderer.cpp
index 8c5f4601d9..a5a6ac80fe 100644
--- a/android/YoPme/jni/MapRenderer.cpp
+++ b/android/YoPme/jni/MapRenderer.cpp
@@ -10,9 +10,6 @@ namespace
static shared_ptr<yopme::Framework> s_framework;
}
-// @TODO refactor and remove that
-void InitNVEvent(JavaVM * jvm) {}
-
extern "C"
{
diff --git a/android/jni/Android.mk b/android/jni/Android.mk
index ac9d2963bf..08d1a387ad 100644
--- a/android/jni/Android.mk
+++ b/android/jni/Android.mk
@@ -61,6 +61,7 @@ TARGET_PLATFORM := android-15
LOCAL_HEADER_FILES := \
../../private.h \
com/mapswithme/core/jni_helper.hpp \
+ com/mapswithme/core/ScopedLocalRef.hpp \
com/mapswithme/core/logging.hpp \
com/mapswithme/maps/Framework.hpp \
com/mapswithme/maps/MapStorage.hpp \
@@ -92,6 +93,7 @@ LOCAL_SRC_FILES := \
com/mapswithme/maps/PrivateVariables.cpp \
com/mapswithme/maps/SearchEngine.cpp \
com/mapswithme/maps/SearchRecents.cpp \
+ com/mapswithme/maps/UserMarkHelper.cpp \
com/mapswithme/maps/settings/UnitLocale.cpp \
com/mapswithme/platform/Platform.cpp \
com/mapswithme/platform/HttpThread.cpp \
@@ -104,6 +106,7 @@ LOCAL_SRC_FILES := \
com/mapswithme/opengl/androidoglcontext.cpp \
com/mapswithme/opengl/androidoglcontextfactory.cpp \
com/mapswithme/maps/editor/OpeningHours.cpp \
+ com/mapswithme/maps/editor/Editor.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 -latomic -lz
diff --git a/android/jni/com/mapswithme/core/ScopedLocalRef.hpp b/android/jni/com/mapswithme/core/ScopedLocalRef.hpp
new file mode 100644
index 0000000000..735c1459e3
--- /dev/null
+++ b/android/jni/com/mapswithme/core/ScopedLocalRef.hpp
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <jni.h>
+
+namespace jni
+{
+
+// A smart pointer that deletes a JNI local reference when it goes out of scope.
+template<typename T>
+class ScopedLocalRef {
+public:
+ ScopedLocalRef(JNIEnv * env, T localRef) : m_env(env), m_localRef(localRef) { }
+
+ ~ScopedLocalRef()
+ {
+ reset();
+ }
+
+ void reset(T ptr = nullptr)
+ {
+ if (ptr == m_localRef)
+ return;
+
+ if (m_localRef != nullptr)
+ m_env->DeleteLocalRef(m_localRef);
+ m_localRef = ptr;
+ }
+
+ T get() const
+ {
+ return m_localRef;
+ }
+private:
+ JNIEnv * m_env;
+ T m_localRef;
+
+ // Disallow copy and assignment.
+ ScopedLocalRef(ScopedLocalRef const &) = delete;
+ void operator = (ScopedLocalRef const &) = delete;
+};
+
+} // namespace jni
diff --git a/android/jni/com/mapswithme/core/jni_helper.cpp b/android/jni/com/mapswithme/core/jni_helper.cpp
index 904b49224b..4a50ae16f5 100644
--- a/android/jni/com/mapswithme/core/jni_helper.cpp
+++ b/android/jni/com/mapswithme/core/jni_helper.cpp
@@ -1,7 +1,9 @@
#include "jni_helper.hpp"
#include "logging.hpp"
+#include "ScopedLocalRef.hpp"
#include "base/assert.hpp"
+#include "base/logging.hpp"
#include "std/vector.hpp"
static JavaVM * g_jvm = 0;
@@ -10,17 +12,10 @@ extern JavaVM * GetJVM()
return g_jvm;
}
-// TODO refactor cached jclass to smth more
-// TODO finish this logic after refactoring
-// cached classloader that can be used to find classes & methods from native threads.
-//static shared_ptr<jobject> g_classLoader;
-//static jmethodID g_findClassMethod;
-
// caching is necessary to create class from native threads
jclass g_indexClazz;
-
-// @TODO remove after refactoring. Needed for NVidia code
-void InitNVEvent(JavaVM * jvm);
+jclass g_mapObjectClazz;
+jclass g_bookmarkClazz;
extern "C"
{
@@ -32,20 +27,12 @@ extern "C"
jni::InitAssertLog();
JNIEnv * env = jni::GetEnv();
- // TODO
- // init classloader & findclass methodID.
-// auto randomClass = env->FindClass("com/mapswithme/maps/MapStorage");
-// jclass classClass = env->GetObjectClass(randomClass);
-// auto classLoaderClass = env->FindClass("java/lang/ClassLoader");
-// auto getClassLoaderMethod = env->GetMethodID(classClass, "getClassLoader",
-// "()Ljava/lang/ClassLoader;");
-// g_classLoader = jni::make_global_ref(env->CallObjectMethod(randomClass, getClassLoaderMethod));
-// ASSERT(*g_classLoader, ("Classloader can't be 0"));
-// g_findClassMethod = env->GetMethodID(classLoaderClass, "findClass",
-// "(Ljava/lang/String;)Ljava/lang/Class;");
-// ASSERT(g_findClassMethod, ("FindClass methodId can't be 0"));
- g_indexClazz = static_cast<jclass>(env->NewGlobalRef(env->FindClass("com/mapswithme/maps/MapStorage$Index")));
- ASSERT(g_indexClazz, ("Index class not found!"));
+ g_indexClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/MapStorage$Index");
+ ASSERT(g_indexClazz, (jni::DescribeException()));
+ g_mapObjectClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/MapObject");
+ ASSERT(g_mapObjectClazz, (jni::DescribeException()));
+ g_bookmarkClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/Bookmark");
+ ASSERT(g_bookmarkClazz, (jni::DescribeException()));
return JNI_VERSION_1_6;
}
@@ -55,37 +42,47 @@ extern "C"
{
g_jvm = 0;
jni::GetEnv()->DeleteGlobalRef(g_indexClazz);
+ jni::GetEnv()->DeleteGlobalRef(g_mapObjectClazz);
+ jni::GetEnv()->DeleteGlobalRef(g_bookmarkClazz);
}
} // extern "C"
namespace jni
{
- //
-// jclass FindClass(char const * name)
-// {
-// JNIEnv * env = GetEnv();
-// jstring className = env->NewStringUTF(name);
-// jclass clazz = static_cast<jclass>(GetEnv()->CallObjectMethod(*g_classLoader, g_findClassMethod, className));
-// env->DeleteLocalRef(className);
-// return clazz;
-// }
+ JNIEnv * GetEnv()
+ {
+ JNIEnv * env;
+ if (JNI_OK != g_jvm->GetEnv((void **)&env, JNI_VERSION_1_6))
+ {
+ ASSERT(false, ("Can't get JNIEnv. Was thread attached to JVM?"));
+ return 0;
+ }
+ return env;
+ }
- jmethodID GetJavaMethodID(JNIEnv * env, jobject obj, char const * fn, char const * sig)
+ JavaVM * GetJVM()
{
- ASSERT(env, ("JNIEnv can't be 0"));
- ASSERT(obj, ("jobject can't be 0"));
+ ASSERT(g_jvm, ("JVM is not initialized"));
+ return g_jvm;
+ }
- jclass cls = env->GetObjectClass(obj);
- ASSERT(cls, ("Can't get class: ", DescribeException()));
+ jmethodID GetJavaMethodID(JNIEnv * env, jobject obj, char const * fn, char const * sig)
+ {
+ TScopedLocalClassRef clazz(env, env->GetObjectClass(obj));
+ ASSERT(clazz.get(), ("Can't get class: ", DescribeException()));
- jmethodID mid = env->GetMethodID(cls, fn, sig);
+ jmethodID mid = env->GetMethodID(clazz.get(), fn, sig);
ASSERT(mid, ("Can't get methodID", fn, sig, DescribeException()));
-
- env->DeleteLocalRef(cls);
-
return mid;
}
+ jmethodID GetConstructorID(JNIEnv * env, jclass clazz, char const * sig)
+ {
+ jmethodID const ctorID = env->GetMethodID(clazz, "<init>", sig);
+ ASSERT(ctorID, (jni::DescribeException()));
+ return ctorID;
+ }
+
jclass GetGlobalClassRef(JNIEnv * env, char const * sig)
{
jclass klass = env->FindClass(sig);
@@ -128,23 +125,6 @@ namespace jni
return "java/lang/String";
}
- JNIEnv * GetEnv()
- {
- JNIEnv * env;
- if (JNI_OK != g_jvm->GetEnv((void **)&env, JNI_VERSION_1_6))
- {
- ASSERT(false, ("Can't get JNIEnv. Was thread attached to JVM?"));
- return 0;
- }
- return env;
- }
-
- JavaVM * GetJVM()
- {
- ASSERT(g_jvm, ("JVM is not initialized"));
- return g_jvm;
- }
-
struct global_ref_deleter
{
void operator()(jobject * ref)
@@ -188,14 +168,11 @@ namespace jni
{
jclass klass = env->FindClass("com/mapswithme/maps/bookmarks/data/ParcelablePointD");
ASSERT ( klass, () );
- jmethodID methodID = env->GetMethodID(
- klass, "<init>",
- "(DD)V");
- ASSERT ( methodID, () );
+ jmethodID methodID = GetConstructorID(env, klass, "(DD)V");
return env->NewObject(klass, methodID,
- static_cast<jdouble>(point.x),
- static_cast<jdouble>(point.y));
+ static_cast<jdouble>(point.x),
+ static_cast<jdouble>(point.y));
}
jobject GetNewPoint(JNIEnv * env, m2::PointD const & point)
@@ -207,20 +184,13 @@ namespace jni
{
jclass klass = env->FindClass("android/graphics/Point");
ASSERT ( klass, () );
- jmethodID methodID = env->GetMethodID(
- klass, "<init>",
- "(II)V");
- ASSERT ( methodID, () );
+ jmethodID methodID = GetConstructorID(env, klass, "(II)V");
return env->NewObject(klass, methodID,
static_cast<jint>(point.x),
static_cast<jint>(point.y));
}
- // TODO
- // make ScopedLocalRef wrapper similar to https://android.googlesource.com/platform/libnativehelper/+/jb-mr1.1-dev-plus-aosp/include/nativehelper/ScopedLocalRef.h
- // for localrefs automatically removed after going out of scope
-
// This util method dumps content of local and global reference jni tables to logcat for debug and testing purposes
void DumpDalvikReferenceTables()
{
diff --git a/android/jni/com/mapswithme/core/jni_helper.hpp b/android/jni/com/mapswithme/core/jni_helper.hpp
index e47082e4c2..aee47a7704 100644
--- a/android/jni/com/mapswithme/core/jni_helper.hpp
+++ b/android/jni/com/mapswithme/core/jni_helper.hpp
@@ -2,35 +2,33 @@
#include <jni.h>
+#include "ScopedLocalRef.hpp"
+
#include "geometry/point2d.hpp"
#include "std/string.hpp"
#include "std/shared_ptr.hpp"
-// cache MapIndex jclass
extern jclass g_indexClazz;
+extern jclass g_mapObjectClazz;
+extern jclass g_bookmarkClazz;
namespace jni
{
-// TODO yunitsky uncomment and use to load classes from native threads.
-// jclass FindClass(char const * name);
+ JNIEnv * GetEnv();
+ JavaVM * GetJVM();
jmethodID GetJavaMethodID(JNIEnv * env, jobject obj, char const * fn, char const * sig);
+ jmethodID GetConstructorID(JNIEnv * env, jclass clazz, char const * sig);
// Result value should be DeleteGlobalRef`ed by caller
jclass GetGlobalClassRef(JNIEnv * env, char const * s);
- JNIEnv * GetEnv();
- JavaVM * GetJVM();
-
string ToNativeString(JNIEnv * env, jstring str);
-
// Converts UTF-8 array to native UTF-8 string. Result differs from simple GetStringUTFChars call for characters greater than U+10000,
// since jni uses modified UTF (MUTF-8) for strings.
string ToNativeString(JNIEnv * env, jbyteArray const & utfBytes);
-
jstring ToJavaString(JNIEnv * env, char const * s);
-
inline jstring ToJavaString(JNIEnv * env, string const & s)
{
return ToJavaString(env, s.c_str());
@@ -42,6 +40,8 @@ namespace jni
string DescribeException();
shared_ptr<jobject> make_global_ref(jobject obj);
+ using TScopedLocalRef = ScopedLocalRef<jobject>;
+ using TScopedLocalClassRef = ScopedLocalRef<jclass>;
jobject GetNewParcelablePointD(JNIEnv * env, m2::PointD const & point);
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp
index 8ff06e82fb..21cc34ed89 100644
--- a/android/jni/com/mapswithme/maps/Framework.cpp
+++ b/android/jni/com/mapswithme/maps/Framework.cpp
@@ -1,13 +1,10 @@
#include "Framework.hpp"
#include "MapStorage.hpp"
-
-#include "../opengl/androidoglcontextfactory.hpp"
-
-#include "../core/jni_helper.hpp"
-
-#include "../country/country_helper.hpp"
-
-#include "../platform/Platform.hpp"
+#include "UserMarkHelper.hpp"
+#include "com/mapswithme/core/jni_helper.hpp"
+#include "com/mapswithme/country/country_helper.hpp"
+#include "com/mapswithme/opengl/androidoglcontextfactory.hpp"
+#include "com/mapswithme/platform/Platform.hpp"
#include "map/user_mark.hpp"
@@ -522,25 +519,6 @@ void Framework::DownloadingProgressUpdate(ActiveMapsLayout::TGroup const & group
}
}
-// Fills mapobject's metadata
-void Framework::InjectMetadata(JNIEnv * env, jclass const clazz, jobject const mapObject, feature::Metadata const & metadata)
-{
- static jmethodID const addId = env->GetMethodID(clazz, "addMetadata", "(ILjava/lang/String;)V");
- ASSERT ( addId, () );
-
- for (auto const t : metadata.GetPresentTypes())
- {
- // TODO: It is not a good idea to pass raw strings to UI. Calling separate getters should be a better way.
- // Upcoming change: how to pass opening hours (parsed) into Editor's UI? How to get edited changes back?
- jstring metaString = t == feature::Metadata::FMD_WIKIPEDIA ?
- jni::ToJavaString(env, metadata.GetWikiURL()) :
- jni::ToJavaString(env, metadata.Get(t));
- env->CallVoidMethod(mapObject, addId, t, metaString);
- // TODO use unique_ptrs for autoallocation of local refs
- env->DeleteLocalRef(metaString);
- }
-}
-
void Framework::PostDrapeTask(TDrapeTask && task)
{
ASSERT(task != nullptr, ());
@@ -558,14 +536,17 @@ void Framework::ExecuteDrapeTasks()
m_drapeTasksQueue.clear();
}
-} // namespace android
+void Framework::SetActiveUserMark(UserMark const * mark)
+{
+ m_activeUserMark = mark;
+}
-template <class T>
-T const * CastMark(UserMark const * data)
+UserMark const * Framework::GetActiveUserMark()
{
- return static_cast<T const *>(data);
+ return m_activeUserMark;
}
+} // namespace android
//============ GLUE CODE for com.mapswithme.maps.Framework class =============//
/* ____
@@ -576,124 +557,19 @@ T const * CastMark(UserMark const * data)
* \/
*/
-namespace
-{
-pair<jintArray, jobjectArray> NativeMetadataToJavaMetadata(JNIEnv * env, feature::Metadata const & metadata)
-{
- using feature::Metadata;
-
- auto const metaTypes = metadata.GetPresentTypes();
- // FIXME arrays, allocated through New<Type>Array should be deleted manually in the method.
- // refactor that to delete refs locally or pass arrays from outside context
- const jintArray j_metaTypes = env->NewIntArray(metadata.Size());
- jint * arr = env->GetIntArrayElements(j_metaTypes, 0);
- const jobjectArray j_metaValues = env->NewObjectArray(metadata.Size(), jni::GetStringClass(env), 0);
-
- for (size_t i = 0; i < metaTypes.size(); i++)
- {
- auto const type = metaTypes[i];
- arr[i] = type;
- // TODO: Refactor code to use separate getters for each metadata.
- jstring metaString = type == Metadata::FMD_WIKIPEDIA ?
- jni::ToJavaString(env, metadata.GetWikiURL()) :
- jni::ToJavaString(env, metadata.Get(type));
- env->SetObjectArrayElement(j_metaValues, i, metaString);
- env->DeleteLocalRef(metaString);
- }
- env->ReleaseIntArrayElements(j_metaTypes, arr, 0);
-
- return make_pair(j_metaTypes, j_metaValues);
-}
-} // namespace
-
extern "C"
{
- // API
- void CallOnApiPointActivatedListener(shared_ptr<jobject> obj, ApiMarkPoint const * data, double lat, double lon)
+ void CallOnMapObjectActivatedListener(shared_ptr<jobject> listener, jobject mapObject)
{
JNIEnv * env = jni::GetEnv();
- static jmethodID const methodID = jni::GetJavaMethodID(env,
- *obj.get(),
- "onApiPointActivated",
- "(DDLjava/lang/String;Ljava/lang/String;)V");
-
- jstring j_name = jni::ToJavaString(env, data->GetName());
- jstring j_id = jni::ToJavaString(env, data->GetID());
-
- env->CallVoidMethod(*obj.get(), methodID, lat, lon, j_name, j_id);
-
- // TODO use unique_ptrs for autoallocation of local refs
- env->DeleteLocalRef(j_id);
- env->DeleteLocalRef(j_name);
- }
-
- // Additional layer
- void CallOnAdditionalLayerActivatedListener(shared_ptr<jobject> obj, m2::PointD const & globalPoint,
- search::AddressInfo const & addrInfo, feature::Metadata const & metadata)
- {
- JNIEnv * env = jni::GetEnv();
-
- const jstring j_name = jni::ToJavaString(env, addrInfo.GetPinName());
- const jstring j_type = jni::ToJavaString(env, addrInfo.GetPinType());
- const double lon = MercatorBounds::XToLon(globalPoint.x);
- const double lat = MercatorBounds::YToLat(globalPoint.y);
-
- pair<jintArray, jobjectArray> const meta = NativeMetadataToJavaMetadata(env, metadata);
-
- const char * signature = "(Ljava/lang/String;Ljava/lang/String;DD[I[Ljava/lang/String;)V";
- static jmethodID const methodId = jni::GetJavaMethodID(env, *obj.get(),
- "onAdditionalLayerActivated", signature);
- env->CallVoidMethod(*obj.get(), methodId, j_name, j_type, lat, lon, meta.first, meta.second);
-
- env->DeleteLocalRef(j_type);
- env->DeleteLocalRef(j_name);
-
- env->DeleteLocalRef(meta.second);
- env->DeleteLocalRef(meta.first);
- }
-
- // POI
- void CallOnPoiActivatedListener(shared_ptr<jobject> obj, m2::PointD const & globalPoint,
- search::AddressInfo const & addrInfo, feature::Metadata const & metadata)
- {
- JNIEnv * env = jni::GetEnv();
-
- const jstring j_name = jni::ToJavaString(env, addrInfo.GetPinName());
- const jstring j_type = jni::ToJavaString(env, addrInfo.GetPinType());
- const jstring j_address = jni::ToJavaString(env, addrInfo.FormatAddress());
- const double lon = MercatorBounds::XToLon(globalPoint.x);
- const double lat = MercatorBounds::YToLat(globalPoint.y);
-
- pair<jintArray, jobjectArray> const meta = NativeMetadataToJavaMetadata(env, metadata);
-
- const char * signature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DD[I[Ljava/lang/String;)V";
- static jmethodID const methodId = jni::GetJavaMethodID(env, *obj.get(),
- "onPoiActivated", signature);
- env->CallVoidMethod(*obj.get(), methodId, j_name, j_type, j_address, lat, lon, meta.first, meta.second);
-
- env->DeleteLocalRef(meta.second);
- env->DeleteLocalRef(meta.first);
- }
-
- // Bookmark
- void CallOnBookmarkActivatedListener(shared_ptr<jobject> obj, BookmarkAndCategory const & bmkAndCat)
- {
- JNIEnv * env = jni::GetEnv();
- static jmethodID const methodId = jni::GetJavaMethodID(env, *obj.get(),
- "onBookmarkActivated", "(II)V");
- env->CallVoidMethod(*obj.get(), methodId, bmkAndCat.first, bmkAndCat.second);
- }
-
- // My position
- void CallOnMyPositionActivatedListener(shared_ptr<jobject> obj, double lat, double lon)
- {
- JNIEnv * env = jni::GetEnv();
- static jmethodID const methodId = jni::GetJavaMethodID(env, *obj.get(),
- "onMyPositionActivated", "(DD)V");
- env->CallVoidMethod(*obj.get(), methodId, lat, lon);
+ static jmethodID const methodId =
+ jni::GetJavaMethodID(env, *listener.get(), "onMapObjectActivated",
+ "(Lcom/mapswithme/maps/bookmarks/data/MapObject;)V");
+ ASSERT(methodId, ());
+ //public MapObject(@MapObjectType int mapObjectType, String name, double lat, double lon, String typeName)
+ env->CallVoidMethod(*listener.get(), methodId, mapObject);
}
- // Dismiss information box
void CallOnDismissListener(shared_ptr<jobject> obj)
{
JNIEnv * env = jni::GetEnv();
@@ -706,64 +582,15 @@ extern "C"
{
if (markCopy == nullptr)
{
+ g_framework->SetActiveUserMark(nullptr);
CallOnDismissListener(obj);
return;
}
- ::Framework * fm = frm();
UserMark const * mark = markCopy->GetUserMark();
- search::AddressInfo info;
- feature::Metadata metadata;
- auto const * feature = mark->GetFeature();
- if (feature)
- {
- info = fm->GetFeatureAddressInfo(*feature);
- metadata = feature->GetMetadata();
- }
- else
- {
- // Calculate at least country name for a point. Can we provide more address information?
- info.m_country = fm->GetCountryName(mark->GetPivot());
- }
- switch (mark->GetMarkType())
- {
- case UserMark::Type::API:
- {
- ms::LatLon const ll = mark->GetLatLon();
- CallOnApiPointActivatedListener(obj, CastMark<ApiMarkPoint>(mark), ll.lat, ll.lon);
- break;
- }
-
- case UserMark::Type::BOOKMARK:
- {
- BookmarkAndCategory bmAndCat = fm->FindBookmark(mark);
- if (IsValid(bmAndCat))
- CallOnBookmarkActivatedListener(obj, bmAndCat);
- break;
- }
-
- case UserMark::Type::POI:
- {
- CallOnPoiActivatedListener(obj, mark->GetPivot(), info, metadata);
- break;
- }
-
- case UserMark::Type::SEARCH:
- {
- CallOnAdditionalLayerActivatedListener(obj, mark->GetPivot(), info, metadata);
- break;
- }
-
- case UserMark::Type::MY_POSITION:
- {
- ms::LatLon const ll = mark->GetLatLon();
- CallOnMyPositionActivatedListener(obj, ll.lat, ll.lon);
- break;
- }
- case UserMark::Type::DEBUG_MARK:
- // Ignore clicks to debug marks.
- break;
- }
+ g_framework->SetActiveUserMark(mark);
+ jni::TScopedLocalRef mapObject(jni::GetEnv(), usermark_helper::CreateMapObject(mark));
+ CallOnMapObjectActivatedListener(obj, mapObject.get());
}
void CallRoutingListener(shared_ptr<jobject> obj, int errorCode, vector<storage::TIndex> const & absentCountries, vector<storage::TIndex> const & absentRoutes)
@@ -821,13 +648,13 @@ extern "C"
}
JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_Framework_nativeSetBalloonListener(JNIEnv * env, jclass clazz, jobject l)
+ Java_com_mapswithme_maps_Framework_nativeSetMapObjectListener(JNIEnv * env, jclass clazz, jobject l)
{
frm()->SetUserMarkActivationListener(bind(&CallOnUserMarkActivated, jni::make_global_ref(l), _1));
}
JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_Framework_nativeRemoveBalloonListener(JNIEnv * env, jobject thiz)
+ Java_com_mapswithme_maps_Framework_nativeRemoveMapObjectListener(JNIEnv * env, jobject thiz)
{
frm()->SetUserMarkActivationListener(::Framework::TActivateCallbackFn());
}
@@ -1146,33 +973,12 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_Framework_nativeGetMapObjectForPoint(JNIEnv * env, jclass clazz, jdouble lat, jdouble lon)
{
- PoiMarkPoint const * poiMark = frm()->GetAddressMark(MercatorBounds::FromLatLon(lat, lon));
- search::AddressInfo info;
- feature::Metadata metadata;
- auto const * feature = poiMark->GetFeature();
- if (feature)
- {
- metadata = feature->GetMetadata();
- info = frm()->GetFeatureAddressInfo(*feature);
- }
- // TODO(AlexZ): else case?
-
- static jclass const klass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/MapObject$Poi");
- // Java signature : Poi(String name, double lat, double lon, String typeName)
- static jmethodID const methodID = env->GetMethodID(klass, "<init>", "(Ljava/lang/String;DDLjava/lang/String;)V");
-
- jobject const mapObject = env->NewObject(klass, methodID, jni::ToJavaString(env, info.GetPinName()),
- lat, lon, jni::ToJavaString(env, info.GetPinType()));
- ASSERT(mapObject, ());
-
- g_framework->InjectMetadata(env, klass, mapObject, metadata);
-
- return mapObject;
+ return usermark_helper::CreateMapObject(frm()->GetAddressMark(MercatorBounds::FromLatLon(lat, lon)));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_Framework_nativeGetCountryNameIfAbsent(JNIEnv * env, jobject thiz,
- jdouble lat, jdouble lon)
+ jdouble lat, jdouble lon)
{
string const name = g_framework->GetCountryNameIfAbsent(MercatorBounds::FromLatLon(lat, lon));
@@ -1188,7 +994,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_Framework_nativeGetCountryIndex(JNIEnv * env, jobject thiz,
- jdouble lat, jdouble lon)
+ jdouble lat, jdouble lon)
{
TIndex const idx = g_framework->GetCountryIndex(lat, lon);
@@ -1334,4 +1140,10 @@ extern "C"
static jfieldID const buildingsField = env->GetFieldID(resultClass, "buildings", "Z");
env->SetBooleanField(result, buildingsField, buildings);
}
+
+ JNIEXPORT jobject JNICALL
+ Java_com_mapswithme_maps_Framework_nativeGetActiveMapObject(JNIEnv * env, jclass thiz)
+ {
+ return usermark_helper::CreateMapObject(g_framework->GetActiveUserMark());
+ }
} // extern "C"
diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp
index c91d9f60c9..509de6ee29 100644
--- a/android/jni/com/mapswithme/maps/Framework.hpp
+++ b/android/jni/com/mapswithme/maps/Framework.hpp
@@ -56,6 +56,8 @@ namespace android
location::EMyPositionMode m_currentMode;
bool m_isCurrentModeInitialized;
+ UserMark const * m_activeUserMark;
+
public:
Framework();
~Framework();
@@ -159,13 +161,13 @@ namespace android
void ApplyWidgets();
void CleanWidgets();
- // Fills mapobject's metadata from UserMark
- void InjectMetadata(JNIEnv * env, jclass clazz, jobject const mapObject, feature::Metadata const & metadata);
-
using TDrapeTask = function<void()>;
// Posts a task which must be executed when Drape Engine is alive.
void PostDrapeTask(TDrapeTask && task);
+ void SetActiveUserMark(UserMark const * mark);
+ UserMark const * GetActiveUserMark();
+
public:
virtual void ItemStatusChanged(int childPosition);
virtual void ItemProgressChanged(int childPosition, storage::LocalAndRemoteSizeT const & sizes);
diff --git a/android/jni/com/mapswithme/maps/UserMarkHelper.cpp b/android/jni/com/mapswithme/maps/UserMarkHelper.cpp
new file mode 100644
index 0000000000..372e93228e
--- /dev/null
+++ b/android/jni/com/mapswithme/maps/UserMarkHelper.cpp
@@ -0,0 +1,154 @@
+#include "UserMarkHelper.hpp"
+
+namespace usermark_helper
+{
+using search::AddressInfo;
+using feature::Metadata;
+
+template <class T>
+T const * CastMark(UserMark const * data)
+{
+ return static_cast<T const *>(data);
+}
+
+void InjectMetadata(JNIEnv * env, jclass const clazz, jobject const mapObject, feature::Metadata const & metadata)
+{
+ static jmethodID const addId = env->GetMethodID(clazz, "addMetadata", "(ILjava/lang/String;)V");
+ ASSERT(addId, ());
+
+ for (auto const t : metadata.GetPresentTypes())
+ {
+ // TODO: It is not a good idea to pass raw strings to UI. Calling separate getters should be a better way.
+ jni::TScopedLocalRef metaString(env, t == feature::Metadata::FMD_WIKIPEDIA ?
+ jni::ToJavaString(env, metadata.GetWikiURL()) :
+ jni::ToJavaString(env, metadata.Get(t)));
+ env->CallVoidMethod(mapObject, addId, t, metaString.get());
+ }
+}
+
+pair<jintArray, jobjectArray> NativeMetadataToJavaMetadata(JNIEnv * env, Metadata const & metadata)
+{
+ auto const metaTypes = metadata.GetPresentTypes();
+ const jintArray j_metaTypes = env->NewIntArray(metadata.Size());
+ jint * arr = env->GetIntArrayElements(j_metaTypes, 0);
+ const jobjectArray j_metaValues = env->NewObjectArray(metadata.Size(), jni::GetStringClass(env), 0);
+
+ for (size_t i = 0; i < metaTypes.size(); i++)
+ {
+ auto const type = metaTypes[i];
+ arr[i] = type;
+ // TODO: Refactor code to use separate getters for each metadata.
+ jni::TScopedLocalRef metaString(env, type == Metadata::FMD_WIKIPEDIA ?
+ jni::ToJavaString(env, metadata.GetWikiURL()) :
+ jni::ToJavaString(env, metadata.Get(type)));
+ env->SetObjectArrayElement(j_metaValues, i, metaString.get());
+ }
+ env->ReleaseIntArrayElements(j_metaTypes, arr, 0);
+
+ return make_pair(j_metaTypes, j_metaValues);
+}
+
+void FillAddressAndMetadata(UserMark const * mark, AddressInfo & info, Metadata & metadata)
+{
+ Framework * frm = g_framework->NativeFramework();
+ auto const * feature = mark->GetFeature();
+ if (feature)
+ {
+ info = frm->GetFeatureAddressInfo(*feature);
+ metadata = feature->GetMetadata();
+ }
+ else
+ {
+ // Calculate at least country name for a point. Can we provide more address information?
+ info.m_country = frm->GetCountryName(mark->GetPivot());
+ }
+}
+
+jobject CreateBookmark(int categoryId, int bookmarkId, string const & typeName, Metadata const & metadata)
+{
+ JNIEnv * env = jni::GetEnv();
+ // Java signature :
+ // public Bookmark(@IntRange(from = 0) int categoryId, @IntRange(from = 0) int bookmarkId, String name)
+ static jmethodID const ctorId = jni::GetConstructorID(env, g_bookmarkClazz, "(IILjava/lang/String;)V");
+ jni::TScopedLocalRef name(env, jni::ToJavaString(env, typeName));
+ jobject mapObject = env->NewObject(g_bookmarkClazz, ctorId,
+ static_cast<jint>(categoryId),
+ static_cast<jint>(bookmarkId),
+ name.get());
+
+ InjectMetadata(env, g_mapObjectClazz, mapObject, metadata);
+ return mapObject;
+}
+
+jobject CreateMapObject(int mapObjectType, string const & name, double lat, double lon, string const & typeName, string const & street, string const & house, Metadata const & metadata)
+{
+ JNIEnv * env = jni::GetEnv();
+ // Java signature :
+ // public MapObject(@MapObjectType int mapObjectType, String name, double lat, double lon, String typeName, String street, String house)
+ static jmethodID const ctorId =
+ jni::GetConstructorID(env, g_mapObjectClazz, "(ILjava/lang/String;DDLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
+
+ jobject mapObject = env->NewObject(g_mapObjectClazz, ctorId,
+ static_cast<jint>(mapObjectType),
+ jni::ToJavaString(env, name),
+ static_cast<jdouble>(lat),
+ static_cast<jdouble>(lon),
+ jni::ToJavaString(env, typeName),
+ jni::ToJavaString(env, street),
+ jni::ToJavaString(env, house));
+
+ InjectMetadata(env, g_mapObjectClazz, mapObject, metadata);
+ return mapObject;
+}
+
+jobject CreateMapObject(UserMark const * userMark)
+{
+ search::AddressInfo info;
+ feature::Metadata metadata;
+ FillAddressAndMetadata(userMark, info, metadata);
+ jobject mapObject = nullptr;
+ ms::LatLon ll;
+ switch (userMark->GetMarkType())
+ {
+ case UserMark::Type::API:
+ {
+ ll = userMark->GetLatLon();
+ ApiMarkPoint const * apiMark = CastMark<ApiMarkPoint>(userMark);
+ mapObject = CreateMapObject(kApiPoint, apiMark->GetName(), ll.lat, ll.lon, apiMark->GetID(), "", "", metadata);
+ break;
+ }
+ case UserMark::Type::BOOKMARK:
+ {
+ BookmarkAndCategory bmAndCat = g_framework->NativeFramework()->FindBookmark(userMark);
+ Bookmark const * bookmark = CastMark<Bookmark>(userMark);
+ if (IsValid(bmAndCat))
+ mapObject = CreateBookmark(bmAndCat.first, bmAndCat.second, bookmark->GetName(), metadata);
+ break;
+ }
+ case UserMark::Type::POI:
+ {
+ mapObject = CreateMapObject(kPoi, info.GetPinName(), userMark->GetPivot().x, userMark->GetPivot().y, info.GetPinType(), info.m_street, info.m_house, metadata);
+ break;
+ }
+ case UserMark::Type::SEARCH:
+ {
+ mapObject = CreateMapObject(kSearch, info.GetPinName(), userMark->GetPivot().x, userMark->GetPivot().y, info.GetPinType(), info.m_street, info.m_house, metadata);
+ break;
+ }
+ case UserMark::Type::MY_POSITION:
+ {
+ ll = userMark->GetLatLon();
+ mapObject = CreateMapObject(kMyPosition, "", ll.lat, ll.lon, "", "", "", metadata);
+ break;
+ }
+ case UserMark::Type::DEBUG_MARK:
+ {
+ // Ignore clicks to debug marks.
+ break;
+ }
+ }
+
+ return mapObject;
+}
+} // namespace usermark_helper
+
diff --git a/android/jni/com/mapswithme/maps/UserMarkHelper.hpp b/android/jni/com/mapswithme/maps/UserMarkHelper.hpp
new file mode 100644
index 0000000000..7757223a4e
--- /dev/null
+++ b/android/jni/com/mapswithme/maps/UserMarkHelper.hpp
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <jni.h>
+
+#include "com/mapswithme/core/jni_helper.hpp"
+#include "com/mapswithme/maps/Framework.hpp"
+
+#include "map/user_mark.hpp"
+
+namespace usermark_helper
+{
+// should be equal with definitions in MapObject.java
+static constexpr int kPoi = 0;
+static constexpr int kApiPoint = 1;
+static constexpr int kBookmark = 2;
+static constexpr int kMyPosition = 3;
+static constexpr int kSearch = 4;
+
+// Fills mapobject's metadata from UserMark
+void InjectMetadata(JNIEnv * env, jclass clazz, jobject const mapObject, feature::Metadata const & metadata);
+
+template <class T>
+T const * CastMark(UserMark const * data);
+
+pair<jintArray, jobjectArray> NativeMetadataToJavaMetadata(JNIEnv * env, feature::Metadata const & metadata);
+
+void FillAddressAndMetadata(UserMark const * mark, search::AddressInfo & info, feature::Metadata & metadata);
+
+jobject CreateBookmark(int categoryId, int bookmarkId, string const & typeName, feature::Metadata const & metadata);
+
+jobject CreateMapObject(int mapObjectType, string const & name, double lat, double lon, string const & typeName, feature::Metadata const & metadata);
+
+jobject CreateMapObject(UserMark const * userMark);
+} // namespace usermark
diff --git a/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp b/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp
index 9102e6fe56..c4d50022cf 100644
--- a/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp
+++ b/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp
@@ -19,28 +19,28 @@ namespace
extern "C"
{
JNIEXPORT jstring JNICALL
- Java_com_mapswithme_maps_bookmarks_data_Bookmark_getName(
+ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetName(
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
{
return jni::ToJavaString(env, getBookmark(cat, bmk)->GetName());
}
JNIEXPORT jstring JNICALL
- Java_com_mapswithme_maps_bookmarks_data_Bookmark_getBookmarkDescription(
+ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetBookmarkDescription(
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
{
return jni::ToJavaString(env, getBookmark(cat, bmk)->GetDescription());
}
JNIEXPORT jstring JNICALL
- Java_com_mapswithme_maps_bookmarks_data_Bookmark_getIcon(
+ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetIcon(
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
{
return jni::ToJavaString(env, getBookmark(cat, bmk)->GetType());
}
JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_bookmarks_data_Bookmark_setBookmarkParams(
+ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeSetBookmarkParams(
JNIEnv * env, jobject thiz, jint cat, jlong bmk,
jstring name, jstring type, jstring descr)
{
@@ -48,7 +48,7 @@ extern "C"
// initialize new bookmark
BookmarkData bm(jni::ToNativeString(env, name), jni::ToNativeString(env, type));
- if (descr != 0)
+ if (descr)
bm.SetDescription(jni::ToNativeString(env, descr));
else
bm.SetDescription(p->GetDescription());
@@ -57,28 +57,28 @@ extern "C"
}
JNIEXPORT jint JNICALL
- Java_com_mapswithme_maps_bookmarks_data_Bookmark_changeCategory(
+ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeChangeCategory(
JNIEnv * env, jobject thiz, jint oldCat, jint newCat, jlong bmk)
{
return g_framework->ChangeBookmarkCategory(BookmarkAndCategory(oldCat, bmk), newCat);
}
JNIEXPORT jobject JNICALL
- Java_com_mapswithme_maps_bookmarks_data_Bookmark_getXY(
+ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetXY(
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
{
return jni::GetNewParcelablePointD(env, getBookmark(cat, bmk)->GetPivot());
}
JNIEXPORT jdouble JNICALL
- Java_com_mapswithme_maps_bookmarks_data_Bookmark_getScale(
+ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetScale(
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
{
return getBookmark(cat, bmk)->GetScale();
}
JNIEXPORT jstring JNICALL
- Java_com_mapswithme_maps_bookmarks_data_Bookmark_encode2Ge0Url(
+ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeEncode2Ge0Url(
JNIEnv * env, jobject thiz, jint cat, jlong bmk, jboolean addName)
{
return jni::ToJavaString(env, frm()->CodeGe0url(getBookmark(cat, bmk), addName));
diff --git a/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkCategory.cpp b/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkCategory.cpp
index a7231e4a21..ee3bb1f534 100644
--- a/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkCategory.cpp
+++ b/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkCategory.cpp
@@ -1,132 +1,114 @@
-#include "../../Framework.hpp"
+#include "com/mapswithme/maps/Framework.hpp"
+#include "com/mapswithme/maps/UserMarkHelper.hpp"
+#include "com/mapswithme/core/jni_helper.hpp"
#include "platform/measurement_utils.hpp"
-#include "../../../core/jni_helper.hpp"
-
namespace
{
- ::Framework * frm() { return g_framework->NativeFramework(); }
+::Framework * frm() { return g_framework->NativeFramework(); }
- BookmarkCategory * getBmCategory(jint c)
- {
- BookmarkCategory * pCat = frm()->GetBmCategory(c);
- ASSERT(pCat, ("Category not found", c));
- return pCat;
- }
+BookmarkCategory * getBmCategory(jint c)
+{
+ BookmarkCategory * pCat = frm()->GetBmCategory(c);
+ ASSERT(pCat, ("Category not found", c));
+ return pCat;
+}
}
extern "C"
{
+JNIEXPORT jboolean JNICALL
+Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_isVisible(
+ JNIEnv * env, jobject thiz, jint id)
+{
+ return getBmCategory(id)->IsVisible();
+}
- JNIEXPORT jboolean JNICALL
- Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_isVisible(
- JNIEnv * env, jobject thiz, jint id)
- {
- return getBmCategory(id)->IsVisible();
- }
-
- JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_setVisibility(
- JNIEnv * env, jobject thiz, jint id, jboolean b)
- {
- BookmarkCategory * pCat = getBmCategory(id);
- {
- BookmarkCategory::Guard guard(*pCat);
- guard.m_controller.SetIsVisible(b);
- }
- pCat->SaveToKMLFile();
- }
-
- JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_setName(
- JNIEnv * env, jobject thiz, jint id, jstring n)
- {
- BookmarkCategory * pCat = getBmCategory(id);
- pCat->SetName(jni::ToNativeString(env, n));
- pCat->SaveToKMLFile();
- }
-
- JNIEXPORT jstring JNICALL
- Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getName(
- JNIEnv * env, jobject thiz, jint id)
- {
- return jni::ToJavaString(env, getBmCategory(id)->GetName());
- }
-
- JNIEXPORT jint JNICALL
- Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getSize(
- JNIEnv * env, jobject thiz, jint id)
- {
- BookmarkCategory * category = getBmCategory(id);
- return category->GetUserMarkCount() + category->GetTracksCount();
- }
-
- JNIEXPORT jint JNICALL
- Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getBookmarksCount(
- JNIEnv * env, jobject thiz, jint id)
+JNIEXPORT void JNICALL
+Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_setVisibility(
+ JNIEnv * env, jobject thiz, jint id, jboolean b)
+{
+ BookmarkCategory * pCat = getBmCategory(id);
{
- return getBmCategory(id)->GetUserMarkCount();
+ BookmarkCategory::Guard guard(*pCat);
+ guard.m_controller.SetIsVisible(b);
}
+ pCat->SaveToKMLFile();
+}
- JNIEXPORT jint JNICALL
- Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTracksCount(
- JNIEnv * env, jobject thiz, jint id)
- {
- return getBmCategory(id)->GetTracksCount();
- }
+JNIEXPORT void JNICALL
+Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_setName(
+ JNIEnv * env, jobject thiz, jint id, jstring n)
+{
+ BookmarkCategory * pCat = getBmCategory(id);
+ pCat->SetName(jni::ToNativeString(env, n));
+ pCat->SaveToKMLFile();
+}
- JNIEXPORT jobject JNICALL
- Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getBookmark(
- JNIEnv * env, jobject thiz, jint id, jint index, jclass bookmarkClazz)
- {
- // Bookmark(int categoryId, int bookmarkId, String name)
- jmethodID static const cId = env->GetMethodID(bookmarkClazz, "<init>", "(IILjava/lang/String;)V");
+JNIEXPORT jstring JNICALL
+Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getName(
+ JNIEnv * env, jobject thiz, jint id)
+{
+ return jni::ToJavaString(env, getBmCategory(id)->GetName());
+}
- BookmarkCategory * category = getBmCategory(id);
- Bookmark const * nBookmark = static_cast<Bookmark const *>(category->GetUserMark(index));
- feature::Metadata metadata;
- auto const * feature = nBookmark->GetFeature();
- if (feature)
- metadata = feature->GetMetadata();
- // TODO(AlexZ): else case?
+JNIEXPORT jint JNICALL
+Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getSize(
+ JNIEnv * env, jobject thiz, jint id)
+{
+ BookmarkCategory * category = getBmCategory(id);
+ return category->GetUserMarkCount() + category->GetTracksCount();
+}
- ASSERT(nBookmark, ("Bookmark must not be null with index:)", index));
+JNIEXPORT jint JNICALL
+Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getBookmarksCount(
+ JNIEnv * env, jobject thiz, jint id)
+{
+ return getBmCategory(id)->GetUserMarkCount();
+}
- jobject jBookmark = env->NewObject(bookmarkClazz, cId, id, index,
- jni::ToJavaString(env, nBookmark->GetName()));
- g_framework->InjectMetadata(env, bookmarkClazz, jBookmark, metadata);
+JNIEXPORT jint JNICALL
+Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTracksCount(
+ JNIEnv * env, jobject thiz, jint id)
+{
+ return getBmCategory(id)->GetTracksCount();
+}
- return jBookmark;
- }
+JNIEXPORT jobject JNICALL
+Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getBookmark(
+ JNIEnv * env, jobject thiz, jint id, jint index)
+{
+ return usermark_helper::CreateMapObject(getBmCategory(id)->GetUserMark(index));
+}
- static uint32_t shift(uint32_t v, uint8_t bitCount) { return v << bitCount; }
+static uint32_t shift(uint32_t v, uint8_t bitCount) { return v << bitCount; }
- JNIEXPORT jobject JNICALL
- Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTrack(
- JNIEnv * env, jobject thiz, jint id, jint index, jclass trackClazz)
- {
- // Track(int trackId, int categoryId, String name, String lengthString, int color)
- static jmethodID cId = env->GetMethodID(trackClazz, "<init>",
- "(IILjava/lang/String;Ljava/lang/String;I)V");
+JNIEXPORT jobject JNICALL
+Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTrack(
+ JNIEnv * env, jobject thiz, jint id, jint index, jclass trackClazz)
+{
+ // Track(int trackId, int categoryId, String name, String lengthString, int color)
+ static jmethodID cId = env->GetMethodID(trackClazz, "<init>",
+ "(IILjava/lang/String;Ljava/lang/String;I)V");
- BookmarkCategory * category = getBmCategory(id);
- Track const * nTrack = category->GetTrack(index);
+ BookmarkCategory * category = getBmCategory(id);
+ Track const * nTrack = category->GetTrack(index);
- ASSERT(nTrack, ("Track must not be null with index:)", index));
+ ASSERT(nTrack, ("Track must not be null with index:)", index));
- string formattedLenght;
- MeasurementUtils::FormatDistance(nTrack->GetLengthMeters(), formattedLenght);
+ string formattedLenght;
+ MeasurementUtils::FormatDistance(nTrack->GetLengthMeters(), formattedLenght);
- dp::Color nColor = nTrack->GetColor(0);
+ dp::Color nColor = nTrack->GetColor(0);
- jint androidColor = shift(nColor.GetAlfa(), 24) +
- shift(nColor.GetRed(), 16) +
- shift(nColor.GetGreen(), 8) +
- nColor.GetBlue();
+ jint androidColor = shift(nColor.GetAlfa(), 24) +
+ shift(nColor.GetRed(), 16) +
+ shift(nColor.GetGreen(), 8) +
+ nColor.GetBlue();
- return env->NewObject(trackClazz, cId,
- index, id, jni::ToJavaString(env, nTrack->GetName()),
- jni::ToJavaString(env, formattedLenght), androidColor);
- }
+ return env->NewObject(trackClazz, cId,
+ index, id, jni::ToJavaString(env, nTrack->GetName()),
+ jni::ToJavaString(env, formattedLenght), androidColor);
}
+} // extern "C"
diff --git a/android/jni/com/mapswithme/maps/editor/Editor.cpp b/android/jni/com/mapswithme/maps/editor/Editor.cpp
new file mode 100644
index 0000000000..7fc0e49889
--- /dev/null
+++ b/android/jni/com/mapswithme/maps/editor/Editor.cpp
@@ -0,0 +1,75 @@
+#include <jni.h>
+
+#include "com/mapswithme/core/jni_helper.hpp"
+#include "com/mapswithme/maps/Framework.hpp"
+
+#include "base/logging.hpp"
+#include "indexer/osm_editor.hpp"
+
+#include "std/algorithm.hpp"
+#include "std/set.hpp"
+#include "std/vector.hpp"
+
+namespace
+{
+using feature::Metadata;
+using osm::Editor;
+
+FeatureType * activeFeature()
+{
+ return g_framework->GetActiveUserMark()->GetFeature();
+}
+} // namespace
+
+extern "C"
+{
+using osm::Editor;
+
+JNIEXPORT void JNICALL
+Java_com_mapswithme_maps_editor_Editor_nativeSetMetadata(JNIEnv * env, jclass clazz, jint type, jstring value)
+{
+ auto & metadata = activeFeature()->GetMetadata();
+ metadata.Set(static_cast<Metadata::EType>(type), jni::ToNativeString(env, value));
+}
+
+JNIEXPORT void JNICALL
+Java_com_mapswithme_maps_editor_Editor_nativeEditFeature(JNIEnv * env, jclass clazz, jstring street, jstring houseNumber)
+{
+ Editor::Instance().EditFeature(*activeFeature(), jni::ToNativeString(env, street), jni::ToNativeString(env, houseNumber));
+}
+
+JNIEXPORT jintArray JNICALL
+Java_com_mapswithme_maps_editor_Editor_nativeGetEditableMetadata(JNIEnv * env, jclass clazz)
+{
+ auto const & editableTypes = Editor::Instance().EditableMetadataForType(*activeFeature());
+ int const size = editableTypes.size();
+ jintArray jEditableTypes = env->NewIntArray(size);
+ jint * arr = env->GetIntArrayElements(jEditableTypes, 0);
+ for (int i = 0; i < size; i++)
+ arr[i] = static_cast<jint>(editableTypes[i]);
+ env->ReleaseIntArrayElements(jEditableTypes, arr, 0);
+
+ return jEditableTypes;
+}
+
+JNIEXPORT jboolean JNICALL
+Java_com_mapswithme_maps_editor_Editor_nativeIsAddressEditable(JNIEnv * env, jclass clazz)
+{
+ return Editor::Instance().IsAddressEditable(*activeFeature());
+}
+
+JNIEXPORT jboolean JNICALL
+Java_com_mapswithme_maps_editor_Editor_nativeIsNameEditable(JNIEnv * env, jclass clazz)
+{
+ return Editor::Instance().IsNameEditable(*activeFeature());
+}
+
+JNIEXPORT void JNICALL
+Java_com_mapswithme_maps_editor_Editor_nativeSetName(JNIEnv * env, jclass clazz, jstring name)
+{
+ auto * feature = activeFeature();
+ auto names = feature->GetNames();
+ names.AddString(StringUtf8Multilang::DEFAULT_CODE, jni::ToNativeString(env, name));
+ feature->SetNames(names);
+}
+} // extern "C"
diff --git a/android/res/layout/fragment_auth_editor.xml b/android/res/layout/fragment_auth_editor.xml
new file mode 100644
index 0000000000..3cb3cba631
--- /dev/null
+++ b/android/res/layout/fragment_auth_editor.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/toolbar"
+ style="@style/MwmWidget.ToolbarStyle"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ android:gravity="end|center_vertical"
+ android:theme="@style/MwmWidget.ToolbarTheme"/>
+
+ <ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/toolbar"
+ android:fillViewport="true"
+ tools:ignore="DuplicateIds">
+
+ <RelativeLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="@dimen/margin_base">
+
+ <Button
+ android:id="@+id/login_google"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/editor_auth_btn_height"
+ android:layout_marginBottom="@dimen/margin_base"
+ android:background="@color/bg_editor_login_google"
+ android:text="Google"
+ android:textAllCaps="true"
+ android:textAppearance="@style/MwmTextAppearance.Body1"/>
+
+ <Button
+ android:id="@+id/login_facebook"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/editor_auth_btn_height"
+ android:layout_below="@id/login_google"
+ android:background="@color/bg_editor_login_fb"
+ android:text="Facebook"
+ android:textAllCaps="true"
+ android:textAppearance="@style/MwmTextAppearance.Body1.Light"/>
+
+ <com.mapswithme.maps.widget.CustomTextInputLayout
+ android:id="@+id/username"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/base_block_size"
+ android:layout_below="@id/facebook"
+ android:layout_marginTop="60dp">
+
+ <EditText
+ android:id="@+id/input"
+ style="@style/MwmWidget.Editor.FieldLayout.EditText"
+ android:hint="Email address or username"
+ android:textAppearance="@style/MwmTextAppearance.Body1"/>
+
+ </com.mapswithme.maps.widget.CustomTextInputLayout>
+
+ <com.mapswithme.maps.widget.CustomTextInputLayout
+ android:id="@+id/password"
+ style="@style/MwmWidget.Editor.FieldLayout"
+ android:layout_below="@id/facebook"
+ android:layout_marginTop="60dp">
+
+ <EditText
+ android:id="@+id/input"
+ style="@style/MwmWidget.Editor.FieldLayout.EditText"
+ android:hint="Password"
+ android:inputType="textPassword"
+ android:textAppearance="@style/MwmTextAppearance.Body1"/>
+
+ </com.mapswithme.maps.widget.CustomTextInputLayout>
+
+ <Button
+ android:id="@+id/login"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/editor_auth_btn_height"
+ android:layout_marginBottom="@dimen/margin_base"
+ android:background="?colorAccent"
+ android:text="Log in"
+ android:textAllCaps="true"
+ android:textAppearance="@style/MwmTextAppearance.Body1"/>
+
+ <TextView
+ android:id="@+id/lost_password"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentRight="true"
+ android:layout_below="@id/login"
+ android:layout_marginTop="@dimen/margin_base"
+ android:background="?clickableBackground"
+ android:text="Lost password"
+ android:textAllCaps="true"
+ android:textAppearance="@style/MwmTextAppearance.Body3"/>
+
+ <Button
+ android:id="@+id/register"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/editor_auth_btn_height"
+ android:layout_alignParentBottom="true"
+ android:layout_below="@id/lost_password"
+ android:layout_marginTop="@dimen/margin_base"
+ android:background="@color/bg_editor_login_google"
+ android:text="Login"
+ android:textAllCaps="true"
+ android:textAppearance="@style/MwmTextAppearance.Body1"/>
+
+ </RelativeLayout>
+
+ </ScrollView>
+
+</RelativeLayout> \ No newline at end of file
diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java
index 1a75c145ae..d7f5e2537f 100644
--- a/android/src/com/mapswithme/maps/Framework.java
+++ b/android/src/com/mapswithme/maps/Framework.java
@@ -20,17 +20,9 @@ public class Framework
public static final int ROUTER_TYPE_PEDESTRIAN = 1;
@SuppressWarnings("unused")
- public interface OnBalloonListener
+ public interface MapObjectListener
{
- void onApiPointActivated(double lat, double lon, String name, String id);
-
- void onPoiActivated(String name, String type, String address, double lat, double lon, int[] metaTypes, String[] metaValues);
-
- void onBookmarkActivated(int category, int bookmarkIndex);
-
- void onMyPositionActivated(double lat, double lon);
-
- void onAdditionalLayerActivated(String name, String type, double lat, double lon, int[] metaTypes, String[] metaValues);
+ void onMapObjectActivated(MapObject object);
void onDismiss();
}
@@ -85,9 +77,9 @@ public class Framework
public native static MapObject nativeGetMapObjectForPoint(double lat, double lon);
- public native static void nativeSetBalloonListener(OnBalloonListener listener);
+ public native static void nativeSetMapObjectListener(MapObjectListener listener);
- public native static void nativeRemoveBalloonListener();
+ public native static void nativeRemoveMapObjectListener();
public native static String nativeGetOutdatedCountriesString();
diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java
index 793687f277..84753f9c83 100644
--- a/android/src/com/mapswithme/maps/MwmActivity.java
+++ b/android/src/com/mapswithme/maps/MwmActivity.java
@@ -30,7 +30,7 @@ import java.util.Stack;
import com.mapswithme.country.ActiveCountryTree;
import com.mapswithme.country.DownloadActivity;
import com.mapswithme.country.DownloadFragment;
-import com.mapswithme.maps.Framework.OnBalloonListener;
+import com.mapswithme.maps.Framework.MapObjectListener;
import com.mapswithme.maps.MapStorage.Index;
import com.mapswithme.maps.activity.CustomNavigateUpListener;
import com.mapswithme.maps.ads.LikesManager;
@@ -41,7 +41,6 @@ import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
import com.mapswithme.maps.bookmarks.ChooseBookmarkCategoryFragment;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.MapObject;
-import com.mapswithme.maps.bookmarks.data.MapObject.ApiPoint;
import com.mapswithme.maps.editor.EditorActivity;
import com.mapswithme.maps.editor.EditorHostFragment;
import com.mapswithme.maps.location.LocationHelper;
@@ -83,7 +82,7 @@ import ru.mail.android.mytarget.nativeads.banners.NativeAppwallBanner;
public class MwmActivity extends BaseMwmFragmentActivity
implements LocationHelper.LocationListener,
- OnBalloonListener,
+ MapObjectListener,
View.OnTouchListener,
BasePlacePageAnimationController.OnVisibilityChangedListener,
OnClickListener,
@@ -331,7 +330,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
Statistics.INSTANCE.trackConnectionState();
- Framework.nativeSetBalloonListener(this);
+ Framework.nativeSetMapObjectListener(this);
mSearchController = new FloatingSearchToolbarController(this);
mLocationPredictor = new LocationPredictor(new Handler(), this);
@@ -362,9 +361,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
mFrame = findViewById(R.id.map_fragment_container);
mFadeView = (FadeView) findViewById(R.id.fade_view);
- mFadeView.setListener(new FadeView.Listener() {
+ mFadeView.setListener(new FadeView.Listener()
+ {
@Override
- public void onTouch() {
+ public void onTouch()
+ {
mMainMenu.close(true);
}
});
@@ -443,9 +444,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void startLocationToPoint(String statisticsEvent, String alohaEvent, final @Nullable MapObject endPoint)
{
- closeMenu(statisticsEvent, alohaEvent, new Runnable() {
+ closeMenu(statisticsEvent, alohaEvent, new Runnable()
+ {
@Override
- public void run() {
+ public void run()
+ {
RoutingController.get().prepare(endPoint);
if (mPlacePage.isDocked() || !mPlacePage.isFloating())
@@ -583,7 +586,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Override
public void onDestroy()
{
- Framework.nativeRemoveBalloonListener();
+ Framework.nativeRemoveMapObjectListener();
BottomSheetHelper.free();
RoutingController.get().detach();
super.onDestroy();
@@ -976,87 +979,42 @@ public class MwmActivity extends BaseMwmFragmentActivity
return true;
}
- // Callbacks from native touch events on map objects.
@Override
- public void onApiPointActivated(final double lat, final double lon, final String name, final String id)
+ public void onMapObjectActivated(MapObject object)
{
- final ParsedMwmRequest request = ParsedMwmRequest.getCurrentRequest();
- if (request == null)
- return;
-
- request.setPointData(lat, lon, name, id);
-
- runOnUiThread(new Runnable()
+ if (object.getMapObjectType() == MapObject.API_POINT)
{
- @Override
- public void run()
- {
- final String poiType = request.getCallerName(MwmApplication.get()).toString();
- activateMapObject(new ApiPoint(name, id, poiType, lat, lon));
- }
- });
- }
-
- @Override
- public void onPoiActivated(final String name, final String type, final String address, final double lat, final double lon,
- final int[] metaTypes, final String[] metaValues)
- {
- final MapObject poi = new MapObject.Poi(name, lat, lon, address);
- poi.addMetadata(metaTypes, metaValues);
- activateMapObject(poi);
- }
-
- @Override
- public void onBookmarkActivated(final int category, final int bookmarkIndex)
- {
- activateMapObject(BookmarkManager.INSTANCE.getBookmark(category, bookmarkIndex));
- }
+ final ParsedMwmRequest request = ParsedMwmRequest.getCurrentRequest();
+ if (request == null)
+ return;
- @Override
- public void onMyPositionActivated(final double lat, final double lon)
- {
- final MapObject mypos = new MapObject.MyPosition(lat, lon);
+ request.setPointData(object.getLat(), object.getLon(), object.getName(), object.getSearchId());
+ object.setType(request.getCallerName(MwmApplication.get()).toString());
- runOnUiThread(new Runnable()
+ }
+ else if (object.getMapObjectType() == MapObject.MY_POSITION)
{
- @Override
- public void run()
- {
- if (!Framework.nativeIsRoutingActive())
- {
- activateMapObject(mypos);
- }
- }
- });
- }
-
- @Override
- public void onAdditionalLayerActivated(final String name, final String type, final double lat, final double lon, final int[] metaTypes, final String[] metaValues)
- {
- final MapObject sr = new MapObject.SearchResult(name, type, lat, lon);
- sr.addMetadata(metaTypes, metaValues);
- activateMapObject(sr);
- }
+ if (Framework.nativeIsRoutingActive())
+ return;
+ }
- private void activateMapObject(MapObject object)
- {
setFullscreen(false);
- if (!mPlacePage.hasMapObject(object))
- {
- mPlacePage.setMapObject(object);
- mPlacePage.setState(State.PREVIEW);
+ if (mPlacePage.hasMapObject(object))
+ return;
- if (UiUtils.isVisible(mFadeView))
- mFadeView.fadeOut(false);
- }
+ mPlacePage.setMapObject(object);
+ mPlacePage.setState(State.PREVIEW);
+
+ if (UiUtils.isVisible(mFadeView))
+ mFadeView.fadeOut(false);
+ if (UiUtils.isVisible(mFadeView))
+ mFadeView.fadeOut(false);
}
@Override
public void onDismiss()
{
- if (!mPlacePage.hasMapObject(null))
- mPlacePage.hide();
- else
+ if (mPlacePage.hasMapObject(null))
{
if ((mPanelAnimator != null && mPanelAnimator.isVisible()) ||
UiUtils.isVisible(mSearchController.getToolbar()))
@@ -1064,6 +1022,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
setFullscreen(!mIsFullscreen);
}
+ else
+ {
+ mPlacePage.hide();
+ }
}
private void setFullscreen(boolean isFullscreen)
@@ -1319,7 +1281,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
if (mIsFragmentContainer)
{
- RoutingPlanFragment fragment = (RoutingPlanFragment)getFragment(RoutingPlanFragment.class);
+ RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
if (fragment != null)
fragment.updatePoints();
}
@@ -1334,7 +1296,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
if (mIsFragmentContainer)
{
- RoutingPlanFragment fragment = (RoutingPlanFragment)getFragment(RoutingPlanFragment.class);
+ RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
if (fragment != null)
fragment.updateBuildProgress(progress, router);
}
diff --git a/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java b/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java
index 36279c2bbf..58a10ddfe2 100644
--- a/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java
+++ b/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java
@@ -2,9 +2,10 @@ package com.mapswithme.maps.bookmarks.data;
import android.content.Context;
import android.os.Parcel;
+import android.support.annotation.IntRange;
+import android.support.annotation.Nullable;
import com.mapswithme.maps.Framework;
-import com.mapswithme.maps.R;
import com.mapswithme.util.Constants;
public class Bookmark extends MapObject
@@ -15,21 +16,30 @@ public class Bookmark extends MapObject
private double mMerX;
private double mMerY;
- Bookmark(int categoryId, int bookmarkId, String name)
+ Bookmark(@IntRange(from = 0) int categoryId, @IntRange(from = 0) int bookmarkId, String name)
{
- super(name, 0, 0, "");
+ super(BOOKMARK, name, 0, 0, "", "", "");
mCategoryId = categoryId;
mBookmarkId = bookmarkId;
mName = name;
mIcon = getIconInternal();
- getXY();
+ initXY();
+ }
+
+ private void initXY()
+ {
+ final ParcelablePointD ll = nativeGetXY(mCategoryId, mBookmarkId);
+ mMerX = ll.x;
+ mMerY = ll.y;
+
+ mLat = Math.toDegrees(2.0 * Math.atan(Math.exp(Math.toRadians(ll.y))) - Math.PI / 2.0);
+ mLon = ll.x;
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
- dest.writeString(getType().toString());
dest.writeInt(mCategoryId);
dest.writeInt(mBookmarkId);
dest.writeString(mName);
@@ -40,34 +50,24 @@ public class Bookmark extends MapObject
this(source.readInt(), source.readInt(), source.readString());
}
- private native ParcelablePointD getXY(int catId, long bookmarkId);
-
- private native String getIcon(int catId, long bookmarkId);
-
- private native double getScale(int catId, long bookmarkId);
-
- private native String encode2Ge0Url(int catId, long bookmarkId, boolean addName);
-
- private native void setBookmarkParams(int catId, long bookmarkId, String name, String type, String descr);
-
- private native int changeCategory(int oldCatId, int newCatId, long bookmarkId);
+ public final Creator<Bookmark> CREATOR = new Creator<Bookmark>() {
+ @Override
+ public Bookmark createFromParcel(Parcel source)
+ {
+ return new Bookmark(source);
+ }
- private native String getBookmarkDescription(int categoryId, long bookmarkId);
+ @Override
+ public Bookmark[] newArray(int size)
+ {
+ return new Bookmark[size];
+ }
+ };
@Override
public double getScale()
{
- return getScale(mCategoryId, mBookmarkId);
- }
-
- private void getXY()
- {
- final ParcelablePointD ll = getXY(mCategoryId, mBookmarkId);
- mMerX = ll.x;
- mMerY = ll.y;
-
- mLat = Math.toDegrees(2.0 * Math.atan(Math.exp(Math.toRadians(ll.y))) - Math.PI / 2.0);
- mLon = ll.x;
+ return nativeGetScale(mCategoryId, mBookmarkId);
}
public DistanceAndAzimut getDistanceAndAzimuth(double cLat, double cLon, double north)
@@ -75,15 +75,9 @@ public class Bookmark extends MapObject
return Framework.nativeGetDistanceAndAzimut(mMerX, mMerY, cLat, cLon, north);
}
- @Override
- public double getLat() { return mLat; }
-
- @Override
- public double getLon() { return mLon; }
-
private Icon getIconInternal()
{
- return BookmarkManager.getIconByType((mCategoryId >= 0) ? getIcon(mCategoryId, mBookmarkId) : "");
+ return BookmarkManager.getIconByType((mCategoryId >= 0) ? nativeGetIcon(mCategoryId, mBookmarkId) : "");
}
public Icon getIcon()
@@ -92,41 +86,45 @@ public class Bookmark extends MapObject
}
@Override
- public String getName()
+ @MapObjectType
+ public int getMapObjectType()
{
- return mName;
+ return MapObject.BOOKMARK;
+ }
+
+ @Override
+ public String getPoiTypeName()
+ {
+ return getCategory().getName();
}
public String getCategoryName(Context context)
{
- if (mCategoryId >= 0)
- {
- return BookmarkManager.INSTANCE.getCategoryById(mCategoryId).getName();
- }
- else
- {
- mCategoryId = 0;
- return context.getString(R.string.my_places);
- }
+ return getCategory().getName();
}
- public void setCategoryId(int catId)
+ private @Nullable BookmarkCategory getCategory()
{
- if (catId != mCategoryId)
- {
- mBookmarkId = changeCategory(mCategoryId, catId, mBookmarkId);
- mCategoryId = catId;
- }
+ return BookmarkManager.INSTANCE.getCategoryById(mCategoryId);
+ }
+
+ public void setCategoryId(@IntRange(from = 0) int catId)
+ {
+ if (catId == mCategoryId)
+ return;
+
+ mBookmarkId = nativeChangeCategory(mCategoryId, catId, mBookmarkId);
+ mCategoryId = catId;
}
- public void setParams(String name, Icon icon, String descr)
+ public void setParams(String name, Icon icon, String description)
{
if (icon == null)
icon = mIcon;
- if (!name.equals(getName()) || icon != mIcon || !descr.equals(getBookmarkDescription()))
+ if (!name.equals(getName()) || icon != mIcon || !description.equals(getBookmarkDescription()))
{
- setBookmarkParams(mCategoryId, mBookmarkId, name, icon.getType(), descr);
+ nativeSetBookmarkParams(mCategoryId, mBookmarkId, name, icon.getType(), description);
mName = name;
}
}
@@ -143,12 +141,12 @@ public class Bookmark extends MapObject
public String getBookmarkDescription()
{
- return getBookmarkDescription(mCategoryId, mBookmarkId);
+ return nativeGetBookmarkDescription(mCategoryId, mBookmarkId);
}
public String getGe0Url(boolean addName)
{
- return encode2Ge0Url(mCategoryId, mBookmarkId, addName);
+ return nativeEncode2Ge0Url(mCategoryId, mBookmarkId, addName);
}
public String getHttpGe0Url(boolean addName)
@@ -156,15 +154,17 @@ public class Bookmark extends MapObject
return getGe0Url(addName).replaceFirst(Constants.Url.GE0_PREFIX, Constants.Url.HTTP_GE0_PREFIX);
}
- @Override
- public MapObjectType getType()
- {
- return MapObjectType.BOOKMARK;
- }
+ private native String nativeGetBookmarkDescription(@IntRange(from = 0) int categoryId, @IntRange(from = 0) long bookmarkId);
- @Override
- public String getPoiTypeName()
- {
- return BookmarkManager.INSTANCE.getCategoryById(mCategoryId).getName();
- }
+ private native ParcelablePointD nativeGetXY(@IntRange(from = 0) int catId, @IntRange(from = 0) long bookmarkId);
+
+ private native String nativeGetIcon(@IntRange(from = 0) int catId, @IntRange(from = 0) long bookmarkId);
+
+ private native double nativeGetScale(@IntRange(from = 0) int catId, @IntRange(from = 0) long bookmarkId);
+
+ private native String nativeEncode2Ge0Url(@IntRange(from = 0) int catId, @IntRange(from = 0) long bookmarkId, boolean addName);
+
+ private native void nativeSetBookmarkParams(@IntRange(from = 0) int catId, @IntRange(from = 0) long bookmarkId, String name, String type, String descr);
+
+ private native int nativeChangeCategory(@IntRange(from = 0) int oldCatId, @IntRange(from = 0) int newCatId, @IntRange(from = 0) long bookmarkId);
}
diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategory.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategory.java
index 70c91ffd2f..19b0fa9743 100644
--- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategory.java
+++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkCategory.java
@@ -51,9 +51,9 @@ public class BookmarkCategory
return getTracksCount(mId);
}
- public Bookmark getBookmark(int index)
+ public Bookmark getBookmark(int bookmarkId)
{
- return getBookmark(mId, index, Bookmark.class);
+ return getBookmark(mId, bookmarkId);
}
public Track getTrack(int index)
@@ -67,7 +67,7 @@ public class BookmarkCategory
private native int getSize(int id);
- private native Bookmark getBookmark(int id, int index, Class<Bookmark> bookmarkClazz);
+ private native Bookmark getBookmark(int id, int index);
private native Track getTrack(int id, int index, Class<Track> trackClazz);
diff --git a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java
index 6394fb5bda..fddd98e654 100644
--- a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java
+++ b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java
@@ -1,49 +1,83 @@
package com.mapswithme.maps.bookmarks.data;
+import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
+import android.support.annotation.IntDef;
+import android.support.annotation.NonNull;
import android.text.TextUtils;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
-public abstract class MapObject implements Parcelable
+public class MapObject implements Parcelable
{
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({POI, API_POINT, BOOKMARK, MY_POSITION, SEARCH})
+ public @interface MapObjectType {}
+ public static final int POI = 0;
+ public static final int API_POINT = 1;
+ public static final int BOOKMARK = 2;
+ public static final int MY_POSITION = 3;
+ public static final int SEARCH = 4;
+
+ @MapObjectType protected final int mMapObjectType;
+
protected String mName;
protected double mLat;
protected double mLon;
protected String mTypeName;
+ protected String mStreet;
+ protected String mHouseNumber;
protected Metadata mMetadata;
- private final boolean mDroppedPin;
+ protected boolean mIsDroppedPin;
+ protected String mSearchId;
- public MapObject(String name, double lat, double lon, String typeName)
+ // TODO @yunikkk add static factory methods for different mapobject creation
+
+ public MapObject(@MapObjectType int mapObjectType, String name, double lat, double lon, String typeName, String street, String house)
{
- this(name, lat, lon, typeName, new Metadata());
+ this(mapObjectType, name, lat, lon, typeName, street, house, new Metadata());
}
- public MapObject(String name, double lat, double lon, String typeName, Metadata metadata)
+ public MapObject(@MapObjectType int mapObjectType, String name, double lat, double lon, String typeName, String street, String house, Metadata metadata)
{
+ mMapObjectType = mapObjectType;
mName = name;
mLat = lat;
mLon = lon;
mTypeName = typeName;
+ mStreet = street;
+ mHouseNumber = house;
mMetadata = metadata;
-
- mDroppedPin = TextUtils.isEmpty(mName);
+ mIsDroppedPin = TextUtils.isEmpty(mName);
}
protected MapObject(Parcel source)
{
- this(source.readString(), // Name
+ //noinspection ResourceType
+ this(source.readInt(), // MapObjectType
+ source.readString(), // Name
source.readDouble(), // Lat
source.readDouble(), // Lon
- source.readString(), // Type
- (Metadata)source.readParcelable(Metadata.class.getClassLoader()));
+ source.readString(), // TypeName
+ source.readString(), // Street
+ source.readString(), // HouseNumber
+ (Metadata) source.readParcelable(Metadata.class.getClassLoader()));
+
+ mIsDroppedPin = source.readByte() != 0;
+ mSearchId = source.readString();
}
public void setDefaultIfEmpty()
{
if (TextUtils.isEmpty(mName))
- mName = TextUtils.isEmpty(mTypeName) ? MwmApplication.get().getString(R.string.dropped_pin) : mTypeName;
+ mName = TextUtils.isEmpty(mTypeName) ? MwmApplication.get().getString(R.string.dropped_pin)
+ : mTypeName;
if (TextUtils.isEmpty(mTypeName))
mTypeName = MwmApplication.get().getString(R.string.placepage_unsorted);
@@ -89,6 +123,63 @@ public abstract class MapObject implements Parcelable
public double getLon() { return mLon; }
+ public String getPoiTypeName() { return mTypeName; }
+
+ public boolean getIsDroppedPin()
+ {
+ return mIsDroppedPin;
+ }
+
+ public String getMetadata(Metadata.MetadataType type)
+ {
+ return mMetadata.getMetadata(type);
+ }
+
+ /**
+ * @return properly formatted and translated cuisine string.
+ */
+ public @NonNull String getCuisine()
+ {
+ final String rawCuisine = mMetadata.getMetadata(Metadata.MetadataType.FMD_CUISINE);
+ if (TextUtils.isEmpty(rawCuisine))
+ return "";
+
+ // cuisines translations can contain unsupported symbols, and res ids
+ // replace them with supported "_"( so ', ' and ' ' are replaced with underlines)
+ final String[] cuisines = rawCuisine.split(";");
+ String result = "";
+ // search translations for each cuisine
+ final Resources resources = MwmApplication.get().getResources();
+ for (String cuisineRaw : cuisines)
+ {
+ final String cuisineKey = cuisineRaw.replace(", ", "_").replace(' ', '_').toLowerCase();
+ int resId = resources.getIdentifier("cuisine_" + cuisineKey, "string", BuildConfig.APPLICATION_ID);
+ result += resId == 0 ? cuisineRaw : resources.getString(resId);
+ }
+ return result;
+ }
+
+ public String getStreet()
+ {
+ return mStreet;
+ }
+
+ public String getHouseNumber()
+ {
+ return mHouseNumber;
+ }
+
+ @MapObjectType
+ public int getMapObjectType()
+ {
+ return mMapObjectType;
+ }
+
+ public String getSearchId()
+ {
+ return mSearchId;
+ }
+
public void setLat(double lat)
{
mLat = lat;
@@ -99,11 +190,9 @@ public abstract class MapObject implements Parcelable
mLon = lon;
}
- public String getPoiTypeName() { return mTypeName; }
-
- public boolean isDroppedPin()
+ public void setType(String type)
{
- return mDroppedPin;
+ mTypeName = type;
}
public void addMetadata(int type, String value)
@@ -117,13 +206,11 @@ public abstract class MapObject implements Parcelable
addMetadata(types[i], values[i]);
}
- public String getMetadata(Metadata.MetadataType type)
+ protected static MapObject readFromParcel(Parcel source)
{
- return mMetadata.getMetadata(type);
+ return new MapObject(source);
}
- public abstract MapObjectType getType();
-
@Override
public int describeContents()
{
@@ -133,12 +220,16 @@ public abstract class MapObject implements Parcelable
@Override
public void writeToParcel(Parcel dest, int flags)
{
- dest.writeString(getType().toString());
+ dest.writeInt(mMapObjectType);
dest.writeString(mName);
dest.writeDouble(mLat);
dest.writeDouble(mLon);
dest.writeString(mTypeName);
+ dest.writeString(mStreet);
+ dest.writeString(mHouseNumber);
dest.writeParcelable(mMetadata, 0);
+ dest.writeByte((byte) (mIsDroppedPin ? 1 : 0));
+ dest.writeString(mSearchId);
}
public static final Creator<MapObject> CREATOR = new Creator<MapObject>()
@@ -155,137 +246,4 @@ public abstract class MapObject implements Parcelable
return new MapObject[size];
}
};
-
- protected static MapObject readFromParcel(Parcel source)
- {
- final MapObjectType type = MapObjectType.valueOf(source.readString());
- switch (type)
- {
- case POI:
- return new Poi(source);
- case ADDITIONAL_LAYER:
- return new SearchResult(source);
- case MY_POSITION:
- return new MyPosition(source);
- case API_POINT:
- return new ApiPoint(source);
- case BOOKMARK:
- return new Bookmark(source);
- }
- return null;
- }
-
- public enum MapObjectType
- {
- POI,
- API_POINT,
- BOOKMARK,
- MY_POSITION,
- ADDITIONAL_LAYER
- }
-
- public static class Poi extends MapObject
- {
- public Poi(String name, double lat, double lon, String typeName)
- {
- super(name, lat, lon, typeName);
- }
-
- protected Poi(Parcel source)
- {
- super(source);
- }
-
- @Override
- public MapObjectType getType()
- {
- return MapObjectType.POI;
- }
- }
-
- public static class SearchResult extends MapObject
- {
- public SearchResult(String name, String type, double lat, double lon)
- {
- super(name, lat, lon, type);
- }
-
- protected SearchResult(Parcel source)
- {
- super(source);
- }
-
- @Override
- public MapObjectType getType()
- {
- return MapObjectType.ADDITIONAL_LAYER;
- }
- }
-
- public static class ApiPoint extends MapObject
- {
- private final String mId;
-
- public ApiPoint(String name, String id, String poiType, double lat, double lon)
- {
- super(name, lat, lon, poiType);
- mId = id;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags)
- {
- super.writeToParcel(dest, flags);
- dest.writeString(mId);
- }
-
- protected ApiPoint(Parcel source)
- {
- super(source);
- mId = source.readString();
- }
-
- @Override
- public MapObjectType getType()
- {
- return MapObjectType.API_POINT;
- }
-
- public String getId()
- {
- return mId;
- }
- }
-
- public static class MyPosition extends MapObject
- {
- public MyPosition(double lat, double lon)
- {
- super(MwmApplication.get().getString(R.string.my_position), lat, lon, "");
- }
-
- protected MyPosition(Parcel source)
- {
- super(source);
- }
-
- @Override
- public MapObjectType getType()
- {
- return MapObjectType.MY_POSITION;
- }
-
- @Override
- public void setDefaultIfEmpty()
- {
- if (TextUtils.isEmpty(mName))
- mName = MwmApplication.get().getString(R.string.my_position);
- }
-
- @Override
- public boolean sameAs(MapObject other)
- {
- return ((other instanceof MyPosition) || super.sameAs(other));
- }
- }
}
diff --git a/android/src/com/mapswithme/maps/bookmarks/data/Metadata.java b/android/src/com/mapswithme/maps/bookmarks/data/Metadata.java
index 4069fadb08..14261dbeec 100644
--- a/android/src/com/mapswithme/maps/bookmarks/data/Metadata.java
+++ b/android/src/com/mapswithme/maps/bookmarks/data/Metadata.java
@@ -2,6 +2,8 @@ package com.mapswithme.maps.bookmarks.data;
import android.os.Parcel;
import android.os.Parcelable;
+import android.support.annotation.IntRange;
+import android.support.annotation.NonNull;
import java.util.HashMap;
import java.util.Map;
@@ -42,13 +44,19 @@ public class Metadata implements Parcelable
mMetaType = metadataType;
}
- public static MetadataType fromInt(int metaType)
+ @NonNull
+ public static MetadataType fromInt(@IntRange(from = 1, to = 22) int metaType)
{
for (MetadataType type : values())
if (type.mMetaType == metaType)
return type;
- return null;
+ throw new IllegalArgumentException("Illegal metaType arg!");
+ }
+
+ public int toInt()
+ {
+ return mMetaType;
}
}
@@ -62,9 +70,6 @@ public class Metadata implements Parcelable
public boolean addMetadata(int metaType, String metaValue)
{
final MetadataType type = MetadataType.fromInt(metaType);
- if (type == null)
- return false;
-
mMetadataMap.put(type, metaValue);
return true;
}
@@ -81,7 +86,6 @@ public class Metadata implements Parcelable
}
/**
- * @param type
* @return null if metadata doesn't exist
*/
public String getMetadata(MetadataType type)
diff --git a/android/src/com/mapswithme/maps/editor/AuthFragment.java b/android/src/com/mapswithme/maps/editor/AuthFragment.java
new file mode 100644
index 0000000000..1983e3c4d6
--- /dev/null
+++ b/android/src/com/mapswithme/maps/editor/AuthFragment.java
@@ -0,0 +1,28 @@
+package com.mapswithme.maps.editor;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.mapswithme.maps.R;
+import com.mapswithme.maps.base.BaseMwmToolbarFragment;
+
+public class AuthFragment extends BaseMwmToolbarFragment
+{
+ @Nullable
+ @Override
+ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ return inflater.inflate(R.layout.fragment_auth_editor, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+
+ mToolbarController.setTitle("Log In");
+ }
+}
diff --git a/android/src/com/mapswithme/maps/editor/Editor.java b/android/src/com/mapswithme/maps/editor/Editor.java
new file mode 100644
index 0000000000..ad7b75aff2
--- /dev/null
+++ b/android/src/com/mapswithme/maps/editor/Editor.java
@@ -0,0 +1,35 @@
+package com.mapswithme.maps.editor;
+
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
+import com.mapswithme.maps.bookmarks.data.Metadata;
+
+
+/**
+ * Edits active(selected on the map) MapObjects(aka UserMark in core).
+ * All the methods apply to currently active objects.
+ */
+public final class Editor
+{
+ private Editor() {}
+
+ public static boolean hasEditableAttributes()
+ {
+ return Editor.nativeGetEditableMetadata().length != 0 ||
+ Editor.nativeIsAddressEditable() ||
+ Editor.nativeIsNameEditable();
+ }
+
+ public static native @NonNull int[] nativeGetEditableMetadata();
+
+ public static native void nativeSetMetadata(int type, String value);
+
+ public static native void nativeEditFeature(String street, String houseNumber);
+
+ public static native boolean nativeIsAddressEditable();
+
+ public static native boolean nativeIsNameEditable();
+
+ public static native void nativeSetName(String name);
+}
diff --git a/android/src/com/mapswithme/maps/editor/EditorActivity.java b/android/src/com/mapswithme/maps/editor/EditorActivity.java
index 08d4f59d7c..cdd4d81bc6 100644
--- a/android/src/com/mapswithme/maps/editor/EditorActivity.java
+++ b/android/src/com/mapswithme/maps/editor/EditorActivity.java
@@ -7,7 +7,6 @@ import android.support.v4.app.Fragment;
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
import com.mapswithme.maps.bookmarks.data.MapObject;
-import com.mapswithme.maps.widget.placepage.TimetableFragment;
public class EditorActivity extends BaseMwmFragmentActivity
{
@@ -17,14 +16,6 @@ public class EditorActivity extends BaseMwmFragmentActivity
return EditorHostFragment.class;
}
- @Override
- public void onBackPressed()
- {
- final TimetableFragment fragment = (TimetableFragment) getSupportFragmentManager().findFragmentByTag(getFragmentClass().getName());
- if ((fragment == null) || !fragment.isAdded() || !fragment.onBackPressed())
- super.onBackPressed();
- }
-
public static void start(@NonNull Activity activity, @NonNull MapObject point)
{
final Intent intent = new Intent(activity, EditorActivity.class);
diff --git a/android/src/com/mapswithme/maps/editor/EditorFragment.java b/android/src/com/mapswithme/maps/editor/EditorFragment.java
index 0bc0a5ad83..8b59201997 100644
--- a/android/src/com/mapswithme/maps/editor/EditorFragment.java
+++ b/android/src/com/mapswithme/maps/editor/EditorFragment.java
@@ -1,7 +1,6 @@
package com.mapswithme.maps.editor;
import android.os.Bundle;
-import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.SwitchCompat;
import android.text.TextUtils;
@@ -21,19 +20,31 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
{
private MapObject mEditedPoi;
+ private View mNameBlock;
+ private View mAddressBlock;
+ private View mMetadataBlock;
private EditText mEtName;
private TextView mTvLocalizedNames;
- private TextView mTvAddress;
+ private TextView mTvStreet;
+ private View mOpeningHours;
+ private View mEditOpeningHours;
private TextView mTvOpeningHours;
- private EditText mEtBuilding;
+ private EditText mEtHouseNumber;
+ private View mPhoneBlock;
private EditText mEtPhone;
+ private View mWebBlock;
private EditText mEtWebsite;
+ private View mEmailBlock;
private EditText mEtEmail;
+ private View mCuisineBlock;
private TextView mTvCuisine;
+ private View mWifiBlock;
private SwitchCompat mSwWifi;
private TextView mEmptyOpeningHours;
private TextView mTvSchedule;
+ protected EditorHostFragment mParent;
+
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
@@ -46,20 +57,119 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
{
super.onViewCreated(view, savedInstanceState);
+ mParent = (EditorHostFragment) getParentFragment();
+
initViews(view);
mEditedPoi = getArguments().getParcelable(EditorHostFragment.EXTRA_MAP_OBJECT);
if (mEditedPoi == null)
throw new IllegalStateException("Valid MapObject should be passed to edit it.");
mEtName.setText(mEditedPoi.getName());
+ // TODO read names
// mTvLocalizedNames.setText();
- // mTvAddress.setText();
+ mTvStreet.setText(mEditedPoi.getStreet());
+ mEtHouseNumber.setText(mEditedPoi.getHouseNumber());
mEtPhone.setText(mEditedPoi.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER));
mEtWebsite.setText(mEditedPoi.getMetadata(Metadata.MetadataType.FMD_WEBSITE));
mEtEmail.setText(mEditedPoi.getMetadata(Metadata.MetadataType.FMD_EMAIL));
mTvCuisine.setText(mEditedPoi.getMetadata(Metadata.MetadataType.FMD_CUISINE));
mSwWifi.setChecked(!TextUtils.isEmpty(mEditedPoi.getMetadata(Metadata.MetadataType.FMD_INTERNET)));
refreshOpeningTime();
+
+ refreshEditableFields();
+ }
+
+ public String getName()
+ {
+ // TODO add localized names
+ return mEtName.getText().toString();
+ }
+
+ public String getStreet()
+ {
+ return mTvStreet.getText().toString();
+ }
+
+ public String getHouseNumber()
+ {
+ return mEtHouseNumber.getText().toString();
+ }
+
+ public String getPhone()
+ {
+ return mEtPhone.getText().toString();
+ }
+
+ public String getWebsite()
+ {
+ return mEtWebsite.getText().toString();
+ }
+
+ public String getEmail()
+ {
+ return mEtEmail.getText().toString();
+ }
+
+ public String getCuisine()
+ {
+ return mTvCuisine.getText().toString();
+ }
+
+ public String getWifi()
+ {
+ return mSwWifi.isChecked() ? "Yes" : "";
+ }
+
+ public Metadata getMetadata()
+ {
+ final Metadata res = new Metadata();
+ res.addMetadata(Metadata.MetadataType.FMD_OPEN_HOURS, mTvOpeningHours.getText().toString());
+ res.addMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER, mEtPhone.getText().toString());
+ res.addMetadata(Metadata.MetadataType.FMD_WEBSITE, mEtWebsite.getText().toString());
+ res.addMetadata(Metadata.MetadataType.FMD_EMAIL, mEtEmail.getText().toString());
+ res.addMetadata(Metadata.MetadataType.FMD_CUISINE, mTvCuisine.getText().toString());
+ res.addMetadata(Metadata.MetadataType.FMD_INTERNET, mSwWifi.isChecked() ? "Yes" : "");
+ return res;
+ }
+
+ private void refreshEditableFields()
+ {
+ UiUtils.showIf(Editor.nativeIsNameEditable(), mNameBlock);
+ UiUtils.showIf(Editor.nativeIsAddressEditable(), mAddressBlock);
+
+ final int[] editableMeta = Editor.nativeGetEditableMetadata();
+ if (editableMeta.length == 0)
+ {
+ UiUtils.hide(mMetadataBlock);
+ return;
+ }
+
+ UiUtils.show(mMetadataBlock);
+ UiUtils.hide(mOpeningHours, mEditOpeningHours, mPhoneBlock, mWebBlock, mEmailBlock, mCuisineBlock, mWifiBlock);
+ for (int type : editableMeta)
+ {
+ switch (Metadata.MetadataType.fromInt(type))
+ {
+ case FMD_OPEN_HOURS:
+ UiUtils.show(mOpeningHours, mEditOpeningHours);
+ break;
+ case FMD_PHONE_NUMBER:
+ UiUtils.show(mPhoneBlock);
+ break;
+ case FMD_WEBSITE:
+ UiUtils.show(mWebBlock);
+ break;
+ case FMD_EMAIL:
+ UiUtils.show(mEmailBlock);
+ break;
+ case FMD_CUISINE:
+ UiUtils.show(mCuisineBlock);
+ break;
+ case FMD_INTERNET:
+ UiUtils.show(mWifiBlock);
+ break;
+ }
+ }
}
private void refreshOpeningTime()
@@ -85,22 +195,33 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
private void initViews(View view)
{
- mEtName = findInput(view, R.id.name);
- mEtBuilding = findInput(view, R.id.building);
- mEtPhone = findInput(view, R.id.phone);
- mEtWebsite = findInput(view, R.id.website);
- mEtEmail = findInput(view, R.id.email);
+ mNameBlock = view.findViewById(R.id.cv__name);
+ mAddressBlock = view.findViewById(R.id.cv__address);
+ mMetadataBlock = view.findViewById(R.id.cv__metadata);
+ mEtName = findInput(view.findViewById(R.id.name));
+ mTvStreet = (TextView) view.findViewById(R.id.street);
+ mEtHouseNumber = findInput(view.findViewById(R.id.building));
+ mPhoneBlock = view.findViewById(R.id.block_phone);
+ mEtPhone = findInput(mPhoneBlock);
+ mWebBlock = view.findViewById(R.id.block_website);
+ mEtWebsite = findInput(mWebBlock);
+ mEmailBlock = view.findViewById(R.id.block_email);
+ mEtEmail = findInput(mEmailBlock);
+ mCuisineBlock = view.findViewById(R.id.block_cuisine);
mTvCuisine = (TextView) view.findViewById(R.id.tv__cuisine);
+ mWifiBlock = view.findViewById(R.id.block_wifi);
mSwWifi = (SwitchCompat) view.findViewById(R.id.sw__wifi);
- view.findViewById(R.id.tv__edit_oh).setOnClickListener(this);
+ mWifiBlock.setOnClickListener(this);
+ mOpeningHours = view.findViewById(R.id.opening_hours);
+ mEditOpeningHours = view.findViewById(R.id.tv__edit_oh);
+ mEditOpeningHours.setOnClickListener(this);
mEmptyOpeningHours = (TextView) view.findViewById(R.id.et__empty_schedule);
mTvSchedule = (TextView) view.findViewById(R.id.tv__place_schedule);
- UiUtils.hide(view.findViewById(R.id.tv__today_schedule));
}
- private EditText findInput(View view, @IdRes int name)
+ private EditText findInput(View view)
{
- return (EditText) view.findViewById(name).findViewById(R.id.input);
+ return (EditText) view.findViewById(R.id.input);
}
@Override
@@ -111,11 +232,14 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
case R.id.tv__edit_oh:
editOpeningHours();
break;
+ case R.id.block_wifi:
+ mSwWifi.toggle();
+ break;
}
}
private void editOpeningHours()
{
-
+ mParent.editTimetable();
}
}
diff --git a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java
index 43369f0bf4..99cd73ee26 100644
--- a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java
+++ b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java
@@ -10,12 +10,28 @@ import android.view.ViewGroup;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
import com.mapswithme.maps.base.OnBackPressListener;
+import com.mapswithme.maps.bookmarks.data.MapObject;
+import com.mapswithme.maps.bookmarks.data.Metadata;
+import com.mapswithme.maps.widget.placepage.TimetableFragment;
+import com.mapswithme.util.Utils;
+
public class EditorHostFragment extends BaseMwmToolbarFragment
- implements OnBackPressListener
+ implements OnBackPressListener, View.OnClickListener
{
public static final String EXTRA_MAP_OBJECT = "MapObject";
+ enum Mode
+ {
+ MAP_OBJECT,
+ OPENING_HOURS,
+ STREET,
+ CUISINE;
+ }
+ private Mode mMode;
+
+ private MapObject mEditedObject;
+
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
@@ -27,18 +43,100 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
+ mEditedObject = getArguments().getParcelable(EditorHostFragment.EXTRA_MAP_OBJECT);
+ editMapObject();
+ mToolbarController.findViewById(R.id.save).setOnClickListener(this);
+ mToolbarController.getToolbar().setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v)
+ {
+ onBackPressed();
+ }
+ });
+ }
+
+ @Override
+ public boolean onBackPressed()
+ {
+ switch (mMode)
+ {
+ case OPENING_HOURS:
+ case STREET:
+ case CUISINE:
+ editMapObject();
+ return true;
+ }
+ return false;
+ }
- final Fragment editorFragment = Fragment.instantiate(getActivity(), EditorFragment.class.getName(), getArguments());
+ protected void editMapObject()
+ {
+ mMode = Mode.MAP_OBJECT;
+ mToolbarController.setTitle("Edit POI");
+ final Bundle args = new Bundle();
+ args.putParcelable(EXTRA_MAP_OBJECT, mEditedObject);
+ final Fragment editorFragment = Fragment.instantiate(getActivity(), EditorFragment.class.getName(), args);
getChildFragmentManager().beginTransaction()
- .replace(R.id.fragment_container, editorFragment)
+ .replace(R.id.fragment_container, editorFragment, EditorFragment.class.getName())
.commit();
+ }
- mToolbarController.setTitle("Edit POI");
+ protected void editTimetable()
+ {
+ mMode = Mode.OPENING_HOURS;
+ mToolbarController.setTitle("Opening hours");
+ final Bundle args = new Bundle();
+ args.putString(TimetableFragment.EXTRA_TIME, mEditedObject.getMetadata(Metadata.MetadataType.FMD_OPEN_HOURS));
+ final Fragment editorFragment = Fragment.instantiate(getActivity(), TimetableFragment.class.getName(), args);
+ getChildFragmentManager().beginTransaction()
+ .replace(R.id.fragment_container, editorFragment, TimetableFragment.class.getName())
+ .commit();
+ }
+
+ protected void editStreet()
+ {
+ mMode = Mode.STREET;
+ // TODO choose street
+ }
+
+ protected void editCuisine()
+ {
+ mMode = Mode.CUISINE;
+ // TODO choose cuisine
}
@Override
- public boolean onBackPressed()
+ public void onClick(View v)
{
- return false;
+ switch (v.getId())
+ {
+ case R.id.save:
+ switch (mMode)
+ {
+ case OPENING_HOURS:
+ final TimetableFragment fragment = (TimetableFragment) getChildFragmentManager().findFragmentByTag(TimetableFragment.class.getName());
+ mEditedObject.addMetadata(Metadata.MetadataType.FMD_OPEN_HOURS.toInt(), fragment.getTimetable());
+ editMapObject();
+ break;
+ case STREET:
+ // get street
+ break;
+ case CUISINE:
+ // get cuisine
+ break;
+ case MAP_OBJECT:
+ final EditorFragment editorFragment = (EditorFragment) getChildFragmentManager().findFragmentByTag(EditorFragment.class.getName());
+ Editor.nativeSetMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER.toInt(), editorFragment.getPhone());
+ Editor.nativeSetMetadata(Metadata.MetadataType.FMD_WEBSITE.toInt(), editorFragment.getWebsite());
+ Editor.nativeSetMetadata(Metadata.MetadataType.FMD_EMAIL.toInt(), editorFragment.getEmail());
+ Editor.nativeSetMetadata(Metadata.MetadataType.FMD_CUISINE.toInt(), editorFragment.getCuisine());
+ Editor.nativeSetMetadata(Metadata.MetadataType.FMD_INTERNET.toInt(), editorFragment.getWifi());
+ Editor.nativeSetName(editorFragment.getName());
+ Editor.nativeEditFeature(editorFragment.getStreet(), editorFragment.getHouseNumber());
+ Utils.navigateToParent(getActivity());
+ break;
+ }
+ break;
+ }
}
}
diff --git a/android/src/com/mapswithme/maps/location/LocationHelper.java b/android/src/com/mapswithme/maps/location/LocationHelper.java
index cf71fa6d7b..b5d74d3fd4 100644
--- a/android/src/com/mapswithme/maps/location/LocationHelper.java
+++ b/android/src/com/mapswithme/maps/location/LocationHelper.java
@@ -55,7 +55,7 @@ public enum LocationHelper implements SensorEventListener
private boolean mActive;
private Location mLastLocation;
- private MapObject.MyPosition mMyPosition;
+ private MapObject mMyPosition;
private long mLastLocationTime;
private final SensorManager mSensorManager;
@@ -151,7 +151,8 @@ public enum LocationHelper implements SensorEventListener
mLocationProvider.startUpdates();
}
- public @Nullable MapObject.MyPosition getMyPosition()
+ @Nullable
+ public MapObject getMyPosition()
{
if (!LocationState.isTurnedOn())
{
@@ -163,7 +164,7 @@ public enum LocationHelper implements SensorEventListener
return null;
if (mMyPosition == null)
- mMyPosition = new MapObject.MyPosition(mLastLocation.getLatitude(), mLastLocation.getLongitude());
+ mMyPosition = new MapObject(MapObject.MY_POSITION, "", mLastLocation.getLatitude(), mLastLocation.getLongitude(), "", "", "");
return mMyPosition;
}
diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java
index c2ecd2ea6b..9f1f7262ff 100644
--- a/android/src/com/mapswithme/maps/routing/RoutingController.java
+++ b/android/src/com/mapswithme/maps/routing/RoutingController.java
@@ -219,7 +219,7 @@ public class RoutingController
mBuildState = newState;
if (mBuildState == BuildState.BUILT &&
- !(mStartPoint instanceof MapObject.MyPosition))
+ mStartPoint.getMapObjectType() != MapObject.MY_POSITION)
Framework.nativeDisableFollowing();
}
@@ -353,7 +353,7 @@ public class RoutingController
{
Log.d(TAG, "start");
- if (!(mStartPoint instanceof MapObject.MyPosition))
+ if (mStartPoint.getMapObjectType() != MapObject.MY_POSITION)
{
Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_START_SUGGEST_REBUILD);
AlohaHelper.logClick(AlohaHelper.ROUTING_START_SUGGEST_REBUILD);
@@ -361,7 +361,7 @@ public class RoutingController
return;
}
- MapObject.MyPosition my = LocationHelper.INSTANCE.getMyPosition();
+ MapObject my = LocationHelper.INSTANCE.getMyPosition();
if (my == null)
{
mRoutingListener.onRoutingEvent(ResultCodesHelper.NO_POSITION, null, null);
@@ -389,7 +389,7 @@ public class RoutingController
titleView.setText(R.string.p2p_only_from_current);
builder.setCustomTitle(titleView);
- if (mEndPoint instanceof MapObject.MyPosition)
+ if (mEndPoint.getMapObjectType() == MapObject.MY_POSITION)
{
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener()
{
@@ -546,7 +546,7 @@ public class RoutingController
Framework.nativeSetRouteStartPoint(0.0, 0.0, false);
else
Framework.nativeSetRouteStartPoint(mStartPoint.getLat(), mStartPoint.getLon(),
- !(mStartPoint instanceof MapObject.MyPosition));
+ mStartPoint.getMapObjectType() != MapObject.MY_POSITION);
if (mEndPoint == null)
Framework.nativeSetRouteEndPoint(0.0, 0.0, false);
diff --git a/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java b/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java
index 744a2695ad..b4913481f4 100644
--- a/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java
+++ b/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java
@@ -39,9 +39,10 @@ public class RoutingPlanInplaceController extends RoutingPlanController
if (show)
{
- boolean open = (mSlotsRestoredState == null ? !(RoutingController.get().getStartPoint() instanceof MapObject.MyPosition) ||
- (RoutingController.get().getEndPoint() == null)
- : mSlotsRestoredState);
+ boolean open = (mSlotsRestoredState == null
+ ? (RoutingController.get().getStartPoint().getMapObjectType() != MapObject.MY_POSITION) ||
+ (RoutingController.get().getEndPoint() == null)
+ : mSlotsRestoredState);
showSlots(open, false);
mSlotsRestoredState = null;
}
diff --git a/android/src/com/mapswithme/maps/routing/SlotFrame.java b/android/src/com/mapswithme/maps/routing/SlotFrame.java
index a30a76825b..315e4f34e6 100644
--- a/android/src/com/mapswithme/maps/routing/SlotFrame.java
+++ b/android/src/com/mapswithme/maps/routing/SlotFrame.java
@@ -96,7 +96,7 @@ public class SlotFrame extends LinearLayout
return;
}
- if (mMapObject instanceof MapObject.MyPosition)
+ if (mMapObject.getMapObjectType() == MapObject.MY_POSITION)
mText.setText(R.string.p2p_your_location);
else
mText.setText(mMapObject.getName());
diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java
index e90e4ecc54..0482faf163 100644
--- a/android/src/com/mapswithme/maps/search/SearchFragment.java
+++ b/android/src/com/mapswithme/maps/search/SearchFragment.java
@@ -342,7 +342,7 @@ public class SearchFragment extends BaseMwmFragment
if (mFromRoutePlan)
{
//noinspection ConstantConditions
- final MapObject point = new MapObject.SearchResult(result.name, result.description.featureType, result.lat, result.lon);
+ final MapObject point = new MapObject(MapObject.SEARCH, result.name, result.lat, result.lon, result.description.featureType, "", "");
RoutingController.get().onPoiSelected(point);
}
diff --git a/android/src/com/mapswithme/maps/widget/placepage/BasePlacePageAnimationController.java b/android/src/com/mapswithme/maps/widget/placepage/BasePlacePageAnimationController.java
index fd093c4d7b..5a527be908 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/BasePlacePageAnimationController.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/BasePlacePageAnimationController.java
@@ -72,10 +72,10 @@ public abstract class BasePlacePageAnimationController
}
}
- public void setState(State state, MapObject.MapObjectType type)
+ public void setState(State state, @MapObject.MapObjectType int type)
{
State newState = state;
- if (type == MapObject.MapObjectType.BOOKMARK && state == State.DETAILS)
+ if (type == MapObject.BOOKMARK && state == State.DETAILS)
newState = State.BOOKMARK;
if (newState != mState)
diff --git a/android/src/com/mapswithme/maps/widget/placepage/HoursMinutesPickerFragment.java b/android/src/com/mapswithme/maps/widget/placepage/HoursMinutesPickerFragment.java
index a95573d7e8..7b4050530e 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/HoursMinutesPickerFragment.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/HoursMinutesPickerFragment.java
@@ -46,14 +46,15 @@ public class HoursMinutesPickerFragment extends BaseMwmDialogFragment
}
public static void pick(Context context, FragmentManager manager, @NonNull HoursMinutes from, @NonNull HoursMinutes to,
- @IntRange(from = 0, to = 1) int selectedPosition, int id)
+ @IntRange(from = 0, to = 1) int selectedPosition, int id)
{
final Bundle args = new Bundle();
args.putParcelable(EXTRA_FROM, from);
args.putParcelable(EXTRA_TO, to);
args.putInt(EXTRA_SELECT_FIRST, selectedPosition);
args.putInt(EXTRA_ID, id);
- final HoursMinutesPickerFragment fragment = (HoursMinutesPickerFragment) Fragment.instantiate(context, HoursMinutesPickerFragment.class.getName(), args);
+ final HoursMinutesPickerFragment fragment =
+ (HoursMinutesPickerFragment) Fragment.instantiate(context, HoursMinutesPickerFragment.class.getName(), args);
fragment.show(manager, null);
}
diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageLeftAnimationController.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageLeftAnimationController.java
index 1ff768bb20..3fa5fa4a8e 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageLeftAnimationController.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageLeftAnimationController.java
@@ -90,9 +90,9 @@ class PlacePageLeftAnimationController extends BasePlacePageAnimationController
}
@Override
- public void setState(State state, MapObject.MapObjectType type)
+ public void setState(State state, @MapObject.MapObjectType int type)
{
- if (state == State.PREVIEW && type == MapObject.MapObjectType.BOOKMARK)
+ if (state == State.PREVIEW && type == MapObject.BOOKMARK)
state = State.BOOKMARK;
super.setState(state, type);
diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
index e474724955..b60b785a3d 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
@@ -40,7 +40,6 @@ import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
-import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmActivity;
import com.mapswithme.maps.MwmApplication;
@@ -52,9 +51,8 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
import com.mapswithme.maps.bookmarks.data.Icon;
import com.mapswithme.maps.bookmarks.data.MapObject;
-import com.mapswithme.maps.bookmarks.data.MapObject.MapObjectType;
-import com.mapswithme.maps.bookmarks.data.MapObject.Poi;
import com.mapswithme.maps.bookmarks.data.Metadata;
+import com.mapswithme.maps.editor.Editor;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.widget.ArrowView;
@@ -177,14 +175,14 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
mTvElevation = (TextView) ppPreview.findViewById(R.id.tv__peak_elevation);
mPpDetails = (ScrollView) findViewById(R.id.pp__details);
- RelativeLayout address = (RelativeLayout)mPpDetails.findViewById(R.id.ll__place_name);
+ RelativeLayout address = (RelativeLayout) mPpDetails.findViewById(R.id.ll__place_name);
mPhone = mPpDetails.findViewById(R.id.ll__place_phone);
mPhone.setOnClickListener(this);
mTvPhone = (TextView) mPpDetails.findViewById(R.id.tv__place_phone);
mWebsite = mPpDetails.findViewById(R.id.ll__place_website);
mWebsite.setOnClickListener(this);
mTvWebsite = (TextView) mPpDetails.findViewById(R.id.tv__place_website);
- LinearLayout latlon = (LinearLayout)mPpDetails.findViewById(R.id.ll__place_latlon);
+ LinearLayout latlon = (LinearLayout) mPpDetails.findViewById(R.id.ll__place_latlon);
latlon.setOnClickListener(this);
mTvLatlon = (TextView) mPpDetails.findViewById(R.id.tv__place_latlon);
mSchedule = mPpDetails.findViewById(R.id.ll__place_schedule);
@@ -232,7 +230,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
}
});
- TextView tvNotes = (TextView)mPpDetails.findViewById(R.id.tv__bookmark_notes);
+ TextView tvNotes = (TextView) mPpDetails.findViewById(R.id.tv__bookmark_notes);
tvNotes.setOnClickListener(this);
mTvBookmarkGroup = (TextView) mPpDetails.findViewById(R.id.tv__bookmark_group);
@@ -337,7 +335,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
mPpDetails.scrollTo(0, 0);
if (mMapObject != null)
- mAnimationController.setState(state, mMapObject.getType());
+ mAnimationController.setState(state, mMapObject.getMapObjectType());
}
public MapObject getMapObject()
@@ -379,25 +377,25 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
refreshDetails();
final Location loc = LocationHelper.INSTANCE.getLastLocation();
- switch (mMapObject.getType())
+ switch (mMapObject.getMapObjectType())
{
- case BOOKMARK:
+ case MapObject.BOOKMARK:
refreshDistanceToObject(loc);
showBookmarkDetails();
refreshButtons(false, true);
break;
- case POI:
- case ADDITIONAL_LAYER:
+ case MapObject.POI:
+ case MapObject.SEARCH:
refreshDistanceToObject(loc);
hideBookmarkDetails();
refreshButtons(false, true);
break;
- case API_POINT:
+ case MapObject.API_POINT:
refreshDistanceToObject(loc);
hideBookmarkDetails();
refreshButtons(true, true);
break;
- case MY_POSITION:
+ case MapObject.MY_POSITION:
refreshMyPosition(loc);
hideBookmarkDetails();
refreshButtons(false, false);
@@ -420,32 +418,10 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
mTvTitle.setText(mMapObject.getName());
if (mToolbar != null)
mToolbar.setTitle(mMapObject.getName());
- String subtitle = mMapObject.getPoiTypeName();
- final String cuisine = mMapObject.getMetadata(Metadata.MetadataType.FMD_CUISINE);
- if (cuisine != null)
- subtitle += ", " + translateCuisine(cuisine);
+ String subtitle = mMapObject.getCuisine().isEmpty() ? mMapObject.getPoiTypeName()
+ : mMapObject.getPoiTypeName() + ", " + mMapObject.getCuisine();
mTvSubtitle.setText(subtitle);
mAvDirection.setVisibility(View.GONE);
- // TODO show/hide mTvOpened after schedule fill be parsed
- }
-
- public String translateCuisine(String cuisine)
- {
- if (TextUtils.isEmpty(cuisine))
- return cuisine;
-
- // cuisines translations can contain unsupported symbols, and res ids
- // replace them with supported "_"( so ', ' and ' ' are replaced with underlines)
- final String[] cuisines = cuisine.split(";");
- String result = "";
- // search translations for each cuisine
- for (String cuisineRaw : cuisines)
- {
- final String cuisineKey = cuisineRaw.replace(", ", "_").replace(' ', '_').toLowerCase();
- int resId = getResources().getIdentifier("cuisine_" + cuisineKey, "string", BuildConfig.APPLICATION_ID);
- result += resId == 0 ? cuisineRaw : getResources().getString(resId);
- }
- return result;
}
private void refreshDetails()
@@ -456,9 +432,9 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
refreshMetadataOrHide(mMapObject.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER), mPhone, mTvPhone);
refreshMetadataOrHide(mMapObject.getMetadata(Metadata.MetadataType.FMD_EMAIL), mEmail, mTvEmail);
refreshMetadataOrHide(mMapObject.getMetadata(Metadata.MetadataType.FMD_OPERATOR), mOperator, mTvOperator);
- refreshMetadataOrHide(translateCuisine(mMapObject.getMetadata(Metadata.MetadataType.FMD_CUISINE)), mCuisine, mTvCuisine);
+ refreshMetadataOrHide(mMapObject.getCuisine(), mCuisine, mTvCuisine);
// TODO @yunikkk uncomment wiki display when data with correct wiki representation(urlencoded once) will be ready
-// refreshMetadataOrHide(mMapObject.getMetadata(Metadata.MetadataType.FMD_WIKIPEDIA), mWiki, null);
+ // refreshMetadataOrHide(mMapObject.getMetadata(Metadata.MetadataType.FMD_WIKIPEDIA), mWiki, null);
refreshMetadataOrHide(mMapObject.getMetadata(Metadata.MetadataType.FMD_INTERNET), mWifi, null);
refreshMetadataOrHide(mMapObject.getMetadata(Metadata.MetadataType.FMD_FLATS), mEntrance, mTvEntrance);
// TODO throw away parsing hack when data will be parsed correctly in core
@@ -466,6 +442,17 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
refreshMetadataOrHide(TextUtils.isEmpty(rawSchedule) ? null : rawSchedule.replace("; ", "\n").replace(';', '\n'), mSchedule, mTvSchedule);
refreshMetadataStars(mMapObject.getMetadata(Metadata.MetadataType.FMD_STARS));
UiUtils.setTextAndHideIfEmpty(mTvElevation, mMapObject.getMetadata(Metadata.MetadataType.FMD_ELE));
+
+ if (hasMapObject(null) || !Editor.hasEditableAttributes())
+ {
+ UiUtils.hide(mEditor);
+ }
+ else
+ {
+ UiUtils.show(mEditor);
+ mTvEditor.setText(mMapObject.getIsDroppedPin() ? R.string.pp_place_add
+ : R.string.pp_place_edit);
+ }
}
private void hideBookmarkDetails()
@@ -506,13 +493,8 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
else
{
UiUtils.show(mGeneralButtonsFrame);
- UiUtils.showIf(!hasMapObject(null), mEditor);
UiUtils.hide(mRouteButtonsFrame);
- if (!hasMapObject(null))
- mTvEditor.setText(mMapObject.isDroppedPin() ? R.string.pp_place_add
- : R.string.pp_place_edit);
-
UiUtils.showIf(showBackButton || ParsedMwmRequest.isPickPointMode(), mApiBack);
UiUtils.showIf(showRoutingButton, mRoutingButton);
}
@@ -523,7 +505,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
if (mMapObject == null)
return;
- if (mMapObject.getType() == MapObjectType.MY_POSITION)
+ if (mMapObject.getMapObjectType() == MapObject.MY_POSITION)
refreshMyPosition(l);
else
refreshDistanceToObject(l);
@@ -604,7 +586,9 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
public void refreshAzimuth(double northAzimuth)
{
- if (getState() == State.HIDDEN || mMapObject == null || mMapObject.getType() == MapObjectType.MY_POSITION)
+ if (getState() == State.HIDDEN ||
+ mMapObject == null ||
+ mMapObject.getMapObjectType() == MapObject.MY_POSITION)
return;
final Location location = LocationHelper.INSTANCE.getLastLocation();
@@ -639,7 +623,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
// TODO remove that method completely. host activity should check that itself
private void checkApiWasCanceled()
{
- if ((mMapObject.getType() == MapObjectType.API_POINT) && !ParsedMwmRequest.hasRequest())
+ if (mMapObject.getMapObjectType() == MapObject.API_POINT && !ParsedMwmRequest.hasRequest())
setMapObject(null);
}
@@ -647,7 +631,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
private void checkBookmarkWasDeleted()
{
// We need to check, if content of body is still valid
- if (mMapObject.getType() == MapObjectType.BOOKMARK)
+ if (mMapObject.getMapObjectType() == MapObject.BOOKMARK)
{
final Bookmark bmk = (Bookmark) mMapObject;
boolean deleted = false;
@@ -663,7 +647,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
if (deleted)
{
// Make Poi from bookmark
- final MapObject p = new Poi(mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon(), null);
+ final MapObject p = new MapObject(MapObject.POI, mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon(), "", "", "");
setMapObject(p);
// TODO how to handle the case, when bookmark was moved to another group?
}
@@ -691,14 +675,15 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
/**
* Adds listener to {@link EditDescriptionFragment} to catch notification about bookmark description edit is complete.
* <br/>When the user rotates device screen the listener is lost, so we must re-subscribe again.
+ *
* @param fragment if specified - explicitely subscribe to this fragment. Otherwise try to find the fragment by hands.
*/
private void subscribeBookmarkEditFragment(@Nullable EditDescriptionFragment fragment)
{
if (fragment == null)
{
- FragmentManager fm = ((FragmentActivity)getContext()).getSupportFragmentManager();
- fragment = (EditDescriptionFragment)fm.findFragmentByTag(EditDescriptionFragment.class.getName());
+ FragmentManager fm = ((FragmentActivity) getContext()).getSupportFragmentManager();
+ fragment = (EditDescriptionFragment) fm.findFragmentByTag(EditDescriptionFragment.class.getName());
}
if (fragment == null)
@@ -718,7 +703,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
private void showEditor()
{
- ((MwmActivity)getContext()).showEditor(mMapObject);
+ ((MwmActivity) getContext()).showEditor(mMapObject);
}
@Override
@@ -828,7 +813,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
{
if (mMapObject == null)
return;
- if (mMapObject.getType() == MapObjectType.BOOKMARK)
+ if (mMapObject.getMapObjectType() == MapObject.BOOKMARK)
{
final Bookmark currentBookmark = (Bookmark) mMapObject;
MapObject p;
@@ -877,7 +862,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
final Bundle args = new Bundle();
args.putString(BookmarkColorDialogFragment.ICON_TYPE, ((Bookmark) mMapObject).getIcon().getType());
final BookmarkColorDialogFragment dialogFragment = (BookmarkColorDialogFragment) BookmarkColorDialogFragment.
- instantiate(getContext(), BookmarkColorDialogFragment.class.getName(), args);
+ instantiate(getContext(), BookmarkColorDialogFragment.class.getName(), args);
dialogFragment.setOnColorSetListener(new BookmarkColorDialogFragment.OnBookmarkColorChangeListener()
{
diff --git a/android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableAdapter.java b/android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableAdapter.java
index d0cd670b9c..e10d21d097 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableAdapter.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableAdapter.java
@@ -358,7 +358,7 @@ public class SimpleTimetableAdapter extends RecyclerView.Adapter<SimpleTimetable
{
final View day = itemView.findViewById(id);
final CheckBox checkBox = (CheckBox) day.findViewById(R.id.chb__day);
- // Save index of the day to get it back wheh checkbox will be toggled.
+ // Save index of the day to get it back when checkbox will be toggled.
checkBox.setTag(dayIndex);
days.put(dayIndex, checkBox);
day.setOnClickListener(new View.OnClickListener()
diff --git a/android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableFragment.java b/android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableFragment.java
index ddb8525c37..8ace08bdd2 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableFragment.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/SimpleTimetableFragment.java
@@ -27,7 +27,8 @@ public class SimpleTimetableFragment extends BaseMwmRecyclerFragment
@Override
protected RecyclerView.Adapter createAdapter()
{
- mAdapter = new SimpleTimetableAdapter(this);
+ if (mAdapter == null)
+ mAdapter = new SimpleTimetableAdapter(this);
return mAdapter;
}
diff --git a/android/src/com/mapswithme/maps/widget/placepage/TimetableFragment.java b/android/src/com/mapswithme/maps/widget/placepage/TimetableFragment.java
index 42ef62a08f..eebdeae152 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/TimetableFragment.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/TimetableFragment.java
@@ -10,13 +10,13 @@ import android.view.ViewGroup;
import android.widget.TextView;
import com.mapswithme.maps.R;
-import com.mapswithme.maps.base.BaseMwmToolbarFragment;
+import com.mapswithme.maps.base.BaseMwmFragment;
import com.mapswithme.maps.base.OnBackPressListener;
+import com.mapswithme.maps.editor.EditorHostFragment;
import com.mapswithme.maps.editor.OpeningHours;
import com.mapswithme.maps.editor.data.Timetable;
-import com.mapswithme.util.Utils;
-public class TimetableFragment extends BaseMwmToolbarFragment
+public class TimetableFragment extends BaseMwmFragment
implements View.OnClickListener,
OnBackPressListener
{
@@ -35,6 +35,8 @@ public class TimetableFragment extends BaseMwmToolbarFragment
private SimpleTimetableFragment mSimpleModeFragment;
private AdvancedTimetableFragment mAdvancedModeFragment;
+ protected EditorHostFragment mParent;
+
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
@@ -47,6 +49,8 @@ public class TimetableFragment extends BaseMwmToolbarFragment
{
super.onViewCreated(view, savedInstanceState);
+ mParent = (EditorHostFragment) getParentFragment();
+
initViews(view);
simpleMode();
@@ -55,10 +59,14 @@ public class TimetableFragment extends BaseMwmToolbarFragment
mSimpleModeFragment.setTimetables(OpeningHours.nativeTimetablesFromString(args.getString(EXTRA_TIME)));
}
+ public String getTimetable()
+ {
+ return OpeningHours.nativeTimetablesToString(mIsAdvancedMode ? mAdvancedModeFragment.getTimetables()
+ : mSimpleModeFragment.getTimetables());
+ }
+
private void initViews(View root)
{
- mToolbarController.setTitle(R.string.editor_time_title);
- mToolbarController.findViewById(R.id.iv__submit).setOnClickListener(this);
mSwitchMode = (TextView) root.findViewById(R.id.tv__mode_switch);
mSwitchMode.setOnClickListener(this);
}
@@ -71,8 +79,6 @@ public class TimetableFragment extends BaseMwmToolbarFragment
case R.id.tv__mode_switch:
switchMode();
break;
- case R.id.iv__submit:
- saveTimetable();
}
}
@@ -113,7 +119,7 @@ public class TimetableFragment extends BaseMwmToolbarFragment
return fragment != null && fragment.isAdded();
}
- private Timetable[] getFilledTimetables(Fragment fragment, TimetableProvider provider)
+ private @Nullable Timetable[] getFilledTimetables(Fragment fragment, TimetableProvider provider)
{
if (!hasFilledTimetables(fragment))
return null;
@@ -138,17 +144,4 @@ public class TimetableFragment extends BaseMwmToolbarFragment
getChildFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit();
return fragment;
}
-
- private void saveTimetable()
- {
- if (mIsAdvancedMode)
- mAdvancedModeFragment.getTimetables();
- else
- mSimpleModeFragment.getTimetables();
-
- final Timetable[] timetables = mIsAdvancedMode ? mAdvancedModeFragment.getTimetables() : mSimpleModeFragment.getTimetables();
- // TODO @yunikkk or @deathbaba save timetables to the core
-
- Utils.navigateToParent(getActivity());
- }
}
diff --git a/android/src/com/mapswithme/util/sharing/MapObjectShareable.java b/android/src/com/mapswithme/util/sharing/MapObjectShareable.java
index 37f24f5bf3..105b2a561e 100644
--- a/android/src/com/mapswithme/util/sharing/MapObjectShareable.java
+++ b/android/src/com/mapswithme/util/sharing/MapObjectShareable.java
@@ -20,9 +20,9 @@ public class MapObjectShareable extends BaseShareable
final String ge0Url = Framework.nativeGetGe0Url(mMapObject.getLat(), mMapObject.getLon(), mMapObject.getScale(), mMapObject.getName());
final String httpUrl = Framework.getHttpGe0Url(mMapObject.getLat(), mMapObject.getLon(), mMapObject.getScale(), mMapObject.getName());
final String address = Framework.nativeGetNameAndAddress4Point(mMapObject.getLat(), mMapObject.getLon());
- final int textId = mMapObject.getType() == MapObject.MapObjectType.MY_POSITION ?
+ final int textId = mMapObject.getMapObjectType() == MapObject.MY_POSITION ?
R.string.my_position_share_email : R.string.bookmark_share_email;
- final int subjectId = mMapObject.getType() == MapObject.MapObjectType.MY_POSITION ?
+ final int subjectId = mMapObject.getMapObjectType() == MapObject.MY_POSITION ?
R.string.my_position_share_email_subject : R.string.bookmark_share_email_subject;
setText(activity.getString(textId, address, ge0Url, httpUrl));
diff --git a/android/src/com/mapswithme/util/sharing/ShareOption.java b/android/src/com/mapswithme/util/sharing/ShareOption.java
index e99116feae..b3c42e0e3c 100644
--- a/android/src/com/mapswithme/util/sharing/ShareOption.java
+++ b/android/src/com/mapswithme/util/sharing/ShareOption.java
@@ -8,7 +8,6 @@ import android.support.annotation.StringRes;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.MapObject;
-import com.mapswithme.maps.bookmarks.data.MapObject.MapObjectType;
import com.mapswithme.util.Utils;
import com.mapswithme.util.statistics.Statistics;
@@ -59,7 +58,7 @@ public abstract class ShareOption
{
final String ge0Url = Framework.nativeGetGe0Url(mapObject.getLat(), mapObject.getLon(), mapObject.getScale(), "");
final String httpUrl = Framework.getHttpGe0Url(mapObject.getLat(), mapObject.getLon(), mapObject.getScale(), "");
- final int bodyId = mapObject.getType() == MapObjectType.MY_POSITION ? R.string.my_position_share_sms : R.string.bookmark_share_sms;
+ final int bodyId = mapObject.getMapObjectType() == MapObject.MY_POSITION ? R.string.my_position_share_sms : R.string.bookmark_share_sms;
final String body = activity.getString(bodyId, ge0Url, httpUrl);
shareWithText(activity, body);
diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java
index f6c473cc40..863e82fbf3 100644
--- a/android/src/com/mapswithme/util/statistics/Statistics.java
+++ b/android/src/com/mapswithme/util/statistics/Statistics.java
@@ -347,6 +347,6 @@ public enum Statistics
public static String getPointType(MapObject point)
{
- return point instanceof MapObject.MyPosition ? Statistics.EventParam.MY_POSITION : Statistics.EventParam.POINT;
+ return point.getMapObjectType() == MapObject.MY_POSITION ? Statistics.EventParam.MY_POSITION : Statistics.EventParam.POINT;
}
} \ No newline at end of file