forked from organicmaps/organicmaps
[android] Refactored MapObject.
This commit is contained in:
parent
58112d07dd
commit
b973c417d4
46 changed files with 1307 additions and 949 deletions
|
@ -10,9 +10,6 @@ namespace
|
|||
static shared_ptr<yopme::Framework> s_framework;
|
||||
}
|
||||
|
||||
// @TODO refactor and remove that
|
||||
void InitNVEvent(JavaVM * jvm) {}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
42
android/jni/com/mapswithme/core/ScopedLocalRef.hpp
Normal file
42
android/jni/com/mapswithme/core/ScopedLocalRef.hpp
Normal file
|
@ -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
|
|
@ -1,7 +1,10 @@
|
|||
#include "jni_helper.hpp"
|
||||
#include "logging.hpp"
|
||||
#include "ScopedLocalRef.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
#include "base/exception.hpp"
|
||||
#include "base/logging.hpp"
|
||||
#include "std/vector.hpp"
|
||||
|
||||
static JavaVM * g_jvm = 0;
|
||||
|
@ -10,17 +13,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 +28,9 @@ 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");
|
||||
g_mapObjectClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/MapObject");
|
||||
g_bookmarkClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/Bookmark");
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
@ -54,38 +39,47 @@ extern "C"
|
|||
JNI_OnUnload(JavaVM *, void *)
|
||||
{
|
||||
g_jvm = 0;
|
||||
jni::GetEnv()->DeleteGlobalRef(g_indexClazz);
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
env->DeleteGlobalRef(g_indexClazz);
|
||||
env->DeleteGlobalRef(g_mapObjectClazz);
|
||||
env->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;
|
||||
// }
|
||||
|
||||
jmethodID GetJavaMethodID(JNIEnv * env, jobject obj, char const * fn, char const * sig)
|
||||
JNIEnv * GetEnv()
|
||||
{
|
||||
ASSERT(env, ("JNIEnv can't be 0"));
|
||||
ASSERT(obj, ("jobject can't be 0"));
|
||||
JNIEnv * env;
|
||||
if (JNI_OK != g_jvm->GetEnv((void **)&env, JNI_VERSION_1_6))
|
||||
MYTHROW(RootException, ("Can't get JNIEnv. Was thread attached to JVM?"));
|
||||
|
||||
jclass cls = env->GetObjectClass(obj);
|
||||
ASSERT(cls, ("Can't get class: ", DescribeException()));
|
||||
return env;
|
||||
}
|
||||
|
||||
jmethodID mid = env->GetMethodID(cls, fn, sig);
|
||||
JavaVM * GetJVM()
|
||||
{
|
||||
ASSERT(g_jvm, ("JVM is not initialized"));
|
||||
return g_jvm;
|
||||
}
|
||||
|
||||
jmethodID GetMethodID(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(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, (DescribeException()));
|
||||
return ctorID;
|
||||
}
|
||||
|
||||
jclass GetGlobalClassRef(JNIEnv * env, char const * sig)
|
||||
{
|
||||
jclass klass = env->FindClass(sig);
|
||||
|
@ -128,28 +122,11 @@ 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)
|
||||
{
|
||||
jni::GetEnv()->DeleteGlobalRef(*ref);
|
||||
GetEnv()->DeleteGlobalRef(*ref);
|
||||
delete ref;
|
||||
}
|
||||
};
|
||||
|
@ -157,13 +134,13 @@ namespace jni
|
|||
shared_ptr<jobject> make_global_ref(jobject obj)
|
||||
{
|
||||
jobject * ref = new jobject;
|
||||
*ref = jni::GetEnv()->NewGlobalRef(obj);
|
||||
*ref = GetEnv()->NewGlobalRef(obj);
|
||||
return shared_ptr<jobject>(ref, global_ref_deleter());
|
||||
}
|
||||
|
||||
string DescribeException()
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
JNIEnv * env = GetEnv();
|
||||
|
||||
if (env->ExceptionCheck())
|
||||
{
|
||||
|
@ -188,14 +165,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,24 +181,17 @@ 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()
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
JNIEnv * env = GetEnv();
|
||||
jclass vm_class = env->FindClass("dalvik/system/VMDebug");
|
||||
jmethodID dump_mid = env->GetStaticMethodID(vm_class, "dumpReferenceTables", "()V");
|
||||
env->CallStaticVoidMethod(vm_class, dump_mid);
|
||||
|
|
|
@ -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 GetMethodID(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);
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ extern "C"
|
|||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
|
||||
jmethodID methodID = jni::GetJavaMethodID(env, *obj.get(), "onDownloadFinished", "(I)V");
|
||||
jmethodID methodID = jni::GetMethodID(env, *obj.get(), "onDownloadFinished", "(I)V");
|
||||
env->CallVoidMethod(*obj.get(), methodID, errorCode);
|
||||
}
|
||||
|
||||
|
@ -180,10 +180,10 @@ extern "C"
|
|||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
|
||||
jmethodID methodID = jni::GetJavaMethodID(env, *obj.get(), "onDownloadProgress", "(IIII)V");
|
||||
jmethodID methodID = jni::GetMethodID(env, *obj.get(), "onDownloadProgress", "(IIII)V");
|
||||
env->CallVoidMethod(*obj.get(), methodID,
|
||||
curTotal, curProgress,
|
||||
glbTotal, glbProgress);
|
||||
curTotal, curProgress,
|
||||
glbTotal, glbProgress);
|
||||
}
|
||||
|
||||
typedef HttpRequest::CallbackT CallbackT;
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -449,10 +446,8 @@ void Framework::ItemStatusChanged(int childPosition)
|
|||
return;
|
||||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
static jmethodID const methodID = jni::GetJavaMethodID(env,
|
||||
*m_javaCountryListener,
|
||||
"onItemStatusChanged",
|
||||
"(I)V");
|
||||
static jmethodID const methodID = jni::GetMethodID(env, *m_javaCountryListener,
|
||||
"onItemStatusChanged", "(I)V");
|
||||
ASSERT ( methodID, () );
|
||||
|
||||
env->CallVoidMethod(*m_javaCountryListener, methodID, childPosition);
|
||||
|
@ -464,10 +459,8 @@ void Framework::ItemProgressChanged(int childPosition, LocalAndRemoteSizeT const
|
|||
return;
|
||||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
static jmethodID const methodID = jni::GetJavaMethodID(env,
|
||||
*m_javaCountryListener,
|
||||
"onItemProgressChanged",
|
||||
"(I[J)V");
|
||||
static jmethodID const methodID = jni::GetMethodID(env, *m_javaCountryListener,
|
||||
"onItemProgressChanged", "(I[J)V");
|
||||
ASSERT ( methodID, () );
|
||||
|
||||
env->CallVoidMethod(*m_javaCountryListener, methodID, childPosition, storage_utils::ToArray(env, sizes));
|
||||
|
@ -479,7 +472,7 @@ void Framework::CountryGroupChanged(ActiveMapsLayout::TGroup const & oldGroup, i
|
|||
JNIEnv * env = jni::GetEnv();
|
||||
for (TListenerMap::const_iterator it = m_javaActiveMapListeners.begin(); it != m_javaActiveMapListeners.end(); ++it)
|
||||
{
|
||||
jmethodID const methodID = jni::GetJavaMethodID(env, *(it->second), "onCountryGroupChanged", "(IIII)V");
|
||||
jmethodID const methodID = jni::GetMethodID(env, *(it->second), "onCountryGroupChanged", "(IIII)V");
|
||||
ASSERT ( methodID, () );
|
||||
|
||||
env->CallVoidMethod(*(it->second), methodID, oldGroup, oldPosition, newGroup, newPosition);
|
||||
|
@ -492,7 +485,7 @@ void Framework::CountryStatusChanged(ActiveMapsLayout::TGroup const & group, int
|
|||
JNIEnv * env = jni::GetEnv();
|
||||
for (TListenerMap::const_iterator it = m_javaActiveMapListeners.begin(); it != m_javaActiveMapListeners.end(); ++it)
|
||||
{
|
||||
jmethodID const methodID = jni::GetJavaMethodID(env, *(it->second), "onCountryStatusChanged", "(IIII)V");
|
||||
jmethodID const methodID = jni::GetMethodID(env, *(it->second), "onCountryStatusChanged", "(IIII)V");
|
||||
ASSERT ( methodID, () );
|
||||
|
||||
env->CallVoidMethod(*(it->second), methodID, group, position,
|
||||
|
@ -506,7 +499,7 @@ void Framework::CountryOptionsChanged(ActiveMapsLayout::TGroup const & group, in
|
|||
JNIEnv * env = jni::GetEnv();
|
||||
for (TListenerMap::const_iterator it = m_javaActiveMapListeners.begin(); it != m_javaActiveMapListeners.end(); ++it)
|
||||
{
|
||||
jmethodID const methodID = jni::GetJavaMethodID(env, *(it->second), "onCountryOptionsChanged", "(IIII)V");
|
||||
jmethodID const methodID = jni::GetMethodID(env, *(it->second), "onCountryOptionsChanged", "(IIII)V");
|
||||
ASSERT ( methodID, () );
|
||||
|
||||
env->CallVoidMethod(*(it->second), methodID, group, position,
|
||||
|
@ -520,32 +513,13 @@ void Framework::DownloadingProgressUpdate(ActiveMapsLayout::TGroup const & group
|
|||
JNIEnv * env = jni::GetEnv();
|
||||
for (TListenerMap::const_iterator it = m_javaActiveMapListeners.begin(); it != m_javaActiveMapListeners.end(); ++it)
|
||||
{
|
||||
jmethodID const methodID = jni::GetJavaMethodID(env, *(it->second), "onCountryProgressChanged", "(II[J)V");
|
||||
jmethodID const methodID = jni::GetMethodID(env, *(it->second), "onCountryProgressChanged", "(II[J)V");
|
||||
ASSERT ( methodID, () );
|
||||
|
||||
env->CallVoidMethod(*(it->second), methodID, group, position, storage_utils::ToArray(env, progress));
|
||||
}
|
||||
}
|
||||
|
||||
// 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, ());
|
||||
|
@ -563,14 +537,17 @@ void Framework::ExecuteDrapeTasks()
|
|||
m_drapeTasksQueue.clear();
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
template <class T>
|
||||
T const * CastMark(UserMark const * data)
|
||||
void Framework::SetActiveUserMark(UserMark const * mark)
|
||||
{
|
||||
return static_cast<T const *>(data);
|
||||
m_activeUserMark = mark;
|
||||
}
|
||||
|
||||
UserMark const * Framework::GetActiveUserMark()
|
||||
{
|
||||
return m_activeUserMark;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
//============ GLUE CODE for com.mapswithme.maps.Framework class =============//
|
||||
/* ____
|
||||
|
@ -581,128 +558,23 @@ 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);
|
||||
static jmethodID const methodId =
|
||||
jni::GetMethodID(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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Dismiss information box
|
||||
void CallOnDismissListener(shared_ptr<jobject> obj)
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
static jmethodID const methodId = jni::GetJavaMethodID(env, *obj.get(), "onDismiss", "()V");
|
||||
static jmethodID const methodId = jni::GetMethodID(env, *obj.get(), "onDismiss", "()V");
|
||||
ASSERT(methodId, ());
|
||||
env->CallVoidMethod(*obj.get(), methodId);
|
||||
}
|
||||
|
@ -711,68 +583,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:
|
||||
{
|
||||
// TODO(AlexZ): Refactor out passing custom name for shared links.
|
||||
auto const & cn = static_cast<PoiMarkPoint const *>(mark)->GetCustomName();
|
||||
if (!cn.empty())
|
||||
info.m_name = cn;
|
||||
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)
|
||||
|
@ -780,7 +599,7 @@ extern "C"
|
|||
JNIEnv * env = jni::GetEnv();
|
||||
// cache methodID - it cannot change after class is loaded.
|
||||
// http://developer.android.com/training/articles/perf-jni.html#jclass_jmethodID_and_jfieldID more details here
|
||||
static jmethodID const methodId = jni::GetJavaMethodID(env, *obj.get(), "onRoutingEvent",
|
||||
static jmethodID const methodId = jni::GetMethodID(env, *obj.get(), "onRoutingEvent",
|
||||
"(I[Lcom/mapswithme/maps/MapStorage$Index;[Lcom/mapswithme/maps/MapStorage$Index;)V");
|
||||
ASSERT(methodId, ());
|
||||
|
||||
|
@ -809,7 +628,7 @@ extern "C"
|
|||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
jobject listener = *sharedListener.get();
|
||||
static jmethodID const methodId = jni::GetJavaMethodID(env, listener, "onRouteBuildingProgress", "(F)V");
|
||||
static jmethodID const methodId = jni::GetMethodID(env, listener, "onRouteBuildingProgress", "(F)V");
|
||||
env->CallVoidMethod(listener, methodId, progress);
|
||||
}
|
||||
|
||||
|
@ -830,13 +649,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());
|
||||
}
|
||||
|
@ -1158,33 +977,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));
|
||||
|
||||
|
@ -1200,7 +998,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);
|
||||
|
||||
|
@ -1354,4 +1152,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"
|
||||
|
|
|
@ -56,6 +56,8 @@ namespace android
|
|||
location::EMyPositionMode m_currentMode;
|
||||
bool m_isCurrentModeInitialized;
|
||||
|
||||
UserMark const * m_activeUserMark;
|
||||
|
||||
public:
|
||||
Framework();
|
||||
~Framework();
|
||||
|
@ -160,13 +162,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);
|
||||
|
|
|
@ -23,7 +23,7 @@ extern "C"
|
|||
g_framework->SetMyPositionMode(mode);
|
||||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
env->CallVoidMethod(*obj.get(), jni::GetJavaMethodID(env, *obj.get(), "onMyPositionModeChangedCallback", "(I)V"), static_cast<jint>(mode));
|
||||
env->CallVoidMethod(*obj.get(), jni::GetMethodID(env, *obj.get(), "onMyPositionModeChangedCallback", "(I)V"), static_cast<jint>(mode));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
|
|
@ -40,7 +40,7 @@ extern "C"
|
|||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MapFragment_nativeConnectDownloadButton(JNIEnv * env, jobject thiz)
|
||||
{
|
||||
jmethodID methodID = jni::GetJavaMethodID(env, thiz, "onDownloadCountryClicked", "(IIII)V");
|
||||
jmethodID methodID = jni::GetMethodID(env, thiz, "onDownloadCountryClicked", "(IIII)V");
|
||||
g_framework->NativeFramework()->SetDownloadCountryListener(bind(&CallOnDownloadCountryClicked,
|
||||
jni::make_global_ref(thiz), _1, _2, methodID));
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ extern "C"
|
|||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
|
||||
jmethodID methodID = jni::GetJavaMethodID(env, *obj.get(), "onCountryStatusChanged", "(Lcom/mapswithme/maps/MapStorage$Index;)V");
|
||||
jmethodID methodID = jni::GetMethodID(env, *obj.get(), "onCountryStatusChanged", "(Lcom/mapswithme/maps/MapStorage$Index;)V");
|
||||
env->CallVoidMethod(*obj.get(), methodID, ToJava(idx));
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ extern "C"
|
|||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
|
||||
jmethodID methodID = jni::GetJavaMethodID(env, *obj.get(), "onCountryProgress", "(Lcom/mapswithme/maps/MapStorage$Index;JJ)V");
|
||||
jmethodID methodID = jni::GetMethodID(env, *obj.get(), "onCountryProgress", "(Lcom/mapswithme/maps/MapStorage$Index;JJ)V");
|
||||
env->CallVoidMethod(*obj.get(), methodID, ToJava(idx), current, total);
|
||||
}
|
||||
|
||||
|
|
|
@ -144,20 +144,13 @@ extern "C"
|
|||
if ( g_javaListener )
|
||||
env->DeleteGlobalRef(g_javaListener);
|
||||
g_javaListener = env->NewGlobalRef(thiz);
|
||||
g_updateResultsId = jni::GetJavaMethodID(env, g_javaListener, "onResultsUpdate", "([Lcom/mapswithme/maps/search/SearchResult;J)V");
|
||||
ASSERT(g_updateResultsId, ());
|
||||
g_endResultsId = jni::GetJavaMethodID(env, g_javaListener, "onResultsEnd", "(J)V");
|
||||
ASSERT(g_endResultsId, ());
|
||||
g_updateResultsId = jni::GetMethodID(env, g_javaListener, "onResultsUpdate", "([Lcom/mapswithme/maps/search/SearchResult;J)V");
|
||||
g_endResultsId = jni::GetMethodID(env, g_javaListener, "onResultsEnd", "(J)V");
|
||||
g_resultClass = static_cast<jclass>(env->NewGlobalRef(env->FindClass("com/mapswithme/maps/search/SearchResult")));
|
||||
ASSERT(g_resultClass, ());
|
||||
g_resultConstructor = env->GetMethodID(g_resultClass, "<init>", "(Ljava/lang/String;Lcom/mapswithme/maps/search/SearchResult$Description;DD[I)V");
|
||||
ASSERT(g_resultConstructor, ());
|
||||
g_suggestConstructor = env->GetMethodID(g_resultClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;[I)V");
|
||||
ASSERT(g_suggestConstructor, ());
|
||||
g_resultConstructor = jni::GetConstructorID(env, g_resultClass, "(Ljava/lang/String;Lcom/mapswithme/maps/search/SearchResult$Description;DD[I)V");
|
||||
g_suggestConstructor = jni::GetConstructorID(env, g_resultClass, "(Ljava/lang/String;Ljava/lang/String;[I)V");
|
||||
g_descriptionClass = static_cast<jclass>(env->NewGlobalRef(env->FindClass("com/mapswithme/maps/search/SearchResult$Description")));
|
||||
ASSERT(g_descriptionClass, ());
|
||||
g_descriptionConstructor = env->GetMethodID(g_descriptionClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZ)V");
|
||||
ASSERT(g_descriptionConstructor, ());
|
||||
g_descriptionConstructor = jni::GetConstructorID(env, g_descriptionClass, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZ)V");
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
|
|
153
android/jni/com/mapswithme/maps/UserMarkHelper.cpp
Normal file
153
android/jni/com/mapswithme/maps/UserMarkHelper.cpp
Normal file
|
@ -0,0 +1,153 @@
|
|||
#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
|
34
android/jni/com/mapswithme/maps/UserMarkHelper.hpp
Normal file
34
android/jni/com/mapswithme/maps/UserMarkHelper.hpp
Normal file
|
@ -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
|
|
@ -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));
|
||||
|
|
|
@ -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 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)
|
||||
{
|
||||
return getBmCategory(id)->GetUserMarkCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTracksCount(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
return getBmCategory(id)->GetTracksCount();
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
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?
|
||||
|
||||
ASSERT(nBookmark, ("Bookmark must not be null with index:)", index));
|
||||
|
||||
jobject jBookmark = env->NewObject(bookmarkClazz, cId, id, index,
|
||||
jni::ToJavaString(env, nBookmark->GetName()));
|
||||
g_framework->InjectMetadata(env, bookmarkClazz, jBookmark, metadata);
|
||||
|
||||
return jBookmark;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
BookmarkCategory * category = getBmCategory(id);
|
||||
Track const * nTrack = category->GetTrack(index);
|
||||
|
||||
ASSERT(nTrack, ("Track must not be null with index:)", index));
|
||||
|
||||
string formattedLenght;
|
||||
MeasurementUtils::FormatDistance(nTrack->GetLengthMeters(), formattedLenght);
|
||||
|
||||
dp::Color nColor = nTrack->GetColor(0);
|
||||
|
||||
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);
|
||||
}
|
||||
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)
|
||||
{
|
||||
return getBmCategory(id)->GetUserMarkCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTracksCount(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
return getBmCategory(id)->GetTracksCount();
|
||||
}
|
||||
|
||||
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; }
|
||||
|
||||
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);
|
||||
|
||||
ASSERT(nTrack, ("Track must not be null with index:)", index));
|
||||
|
||||
string formattedLenght;
|
||||
MeasurementUtils::FormatDistance(nTrack->GetLengthMeters(), formattedLenght);
|
||||
|
||||
dp::Color nColor = nTrack->GetColor(0);
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
75
android/jni/com/mapswithme/maps/editor/Editor.cpp
Normal file
75
android/jni/com/mapswithme/maps/editor/Editor.cpp
Normal file
|
@ -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"
|
|
@ -70,7 +70,7 @@ public:
|
|||
JNIEnv * env = jni::GetEnv();
|
||||
ASSERT ( env, () );
|
||||
|
||||
jmethodID methodId = jni::GetJavaMethodID(env, m_self, "cancel", "(Z)Z");
|
||||
jmethodID methodId = jni::GetMethodID(env, m_self, "cancel", "(Z)Z");
|
||||
ASSERT ( methodId, () );
|
||||
|
||||
env->CallBooleanMethod(m_self, methodId, false);
|
||||
|
|
116
android/res/layout/fragment_auth_editor.xml
Normal file
116
android/res/layout/fragment_auth_editor.xml
Normal file
|
@ -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>
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
@ -989,87 +992,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)
|
||||
if (MapObject.isOfType(MapObject.API_POINT, object))
|
||||
{
|
||||
final ParsedMwmRequest request = ParsedMwmRequest.getCurrentRequest();
|
||||
if (request == null)
|
||||
return;
|
||||
|
||||
request.setPointData(object.getLat(), object.getLon(), object.getName(), object.getSearchId());
|
||||
object.setTypeName(request.getCallerName(MwmApplication.get()).toString());
|
||||
|
||||
}
|
||||
else if (MapObject.isOfType(MapObject.MY_POSITION, object))
|
||||
{
|
||||
if (Framework.nativeIsRoutingActive())
|
||||
return;
|
||||
}
|
||||
|
||||
setFullscreen(false);
|
||||
if (mPlacePage.hasMapObject(object))
|
||||
return;
|
||||
|
||||
request.setPointData(lat, lon, name, id);
|
||||
mPlacePage.setMapObject(object);
|
||||
mPlacePage.setState(State.PREVIEW);
|
||||
|
||||
runOnUiThread(new Runnable()
|
||||
{
|
||||
@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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMyPositionActivated(final double lat, final double lon)
|
||||
{
|
||||
final MapObject mypos = new MapObject.MyPosition(lat, lon);
|
||||
|
||||
runOnUiThread(new Runnable()
|
||||
{
|
||||
@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);
|
||||
}
|
||||
|
||||
private void activateMapObject(MapObject object)
|
||||
{
|
||||
setFullscreen(false);
|
||||
if (!mPlacePage.hasMapObject(object))
|
||||
{
|
||||
mPlacePage.setMapObject(object);
|
||||
mPlacePage.setState(State.PREVIEW);
|
||||
|
||||
if (UiUtils.isVisible(mFadeView))
|
||||
mFadeView.fadeOut(false);
|
||||
}
|
||||
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()))
|
||||
|
@ -1077,6 +1035,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
setFullscreen(!mIsFullscreen);
|
||||
}
|
||||
else
|
||||
{
|
||||
mPlacePage.hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void setFullscreen(boolean isFullscreen)
|
||||
|
@ -1332,7 +1294,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();
|
||||
}
|
||||
|
@ -1347,7 +1309,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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
public final Creator<Bookmark> CREATOR = new Creator<Bookmark>() {
|
||||
@Override
|
||||
public Bookmark createFromParcel(Parcel source)
|
||||
{
|
||||
return new Bookmark(source);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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 getTypeName()
|
||||
{
|
||||
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 setParams(String name, Icon icon, String descr)
|
||||
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 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1,49 +1,84 @@
|
|||
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 +124,69 @@ public abstract class MapObject implements Parcelable
|
|||
|
||||
public double getLon() { return mLon; }
|
||||
|
||||
public String getTypeName() { return mTypeName; }
|
||||
|
||||
public boolean getIsDroppedPin()
|
||||
{
|
||||
return mIsDroppedPin;
|
||||
}
|
||||
|
||||
public String getMetadata(Metadata.MetadataType type)
|
||||
{
|
||||
return mMetadata.getMetadata(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return properly formatted and translated cuisine string.
|
||||
*/
|
||||
@NonNull
|
||||
public 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 static boolean isOfType(@MapObjectType int type, MapObject object)
|
||||
{
|
||||
return object != null && object.getMapObjectType() == type;
|
||||
}
|
||||
|
||||
public String getSearchId()
|
||||
{
|
||||
return mSearchId;
|
||||
}
|
||||
|
||||
public void setLat(double lat)
|
||||
{
|
||||
mLat = lat;
|
||||
|
@ -99,11 +197,9 @@ public abstract class MapObject implements Parcelable
|
|||
mLon = lon;
|
||||
}
|
||||
|
||||
public String getPoiTypeName() { return mTypeName; }
|
||||
|
||||
public boolean isDroppedPin()
|
||||
public void setTypeName(String typeName)
|
||||
{
|
||||
return mDroppedPin;
|
||||
mTypeName = typeName;
|
||||
}
|
||||
|
||||
public void addMetadata(int type, String value)
|
||||
|
@ -117,13 +213,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 +227,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 +253,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
28
android/src/com/mapswithme/maps/editor/AuthFragment.java
Normal file
28
android/src/com/mapswithme/maps/editor/AuthFragment.java
Normal file
|
@ -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");
|
||||
}
|
||||
}
|
35
android/src/com/mapswithme/maps/editor/Editor.java
Normal file
35
android/src/com/mapswithme/maps/editor/Editor.java
Normal file
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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,128 @@ 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);
|
||||
boolean anyEditableMeta = false;
|
||||
for (int type : editableMeta)
|
||||
{
|
||||
switch (Metadata.MetadataType.fromInt(type))
|
||||
{
|
||||
case FMD_OPEN_HOURS:
|
||||
anyEditableMeta = true;
|
||||
UiUtils.show(mOpeningHours, mEditOpeningHours);
|
||||
break;
|
||||
case FMD_PHONE_NUMBER:
|
||||
anyEditableMeta = true;
|
||||
UiUtils.show(mPhoneBlock);
|
||||
break;
|
||||
case FMD_WEBSITE:
|
||||
anyEditableMeta = true;
|
||||
UiUtils.show(mWebBlock);
|
||||
break;
|
||||
case FMD_EMAIL:
|
||||
anyEditableMeta = true;
|
||||
UiUtils.show(mEmailBlock);
|
||||
break;
|
||||
case FMD_CUISINE:
|
||||
anyEditableMeta = true;
|
||||
UiUtils.show(mCuisineBlock);
|
||||
break;
|
||||
case FMD_INTERNET:
|
||||
anyEditableMeta = true;
|
||||
UiUtils.show(mWifiBlock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!anyEditableMeta)
|
||||
UiUtils.hide(mMetadataBlock);
|
||||
}
|
||||
|
||||
private void refreshOpeningTime()
|
||||
|
@ -85,22 +204,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 +241,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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
final Fragment editorFragment = Fragment.instantiate(getActivity(), EditorFragment.class.getName(), getArguments());
|
||||
getChildFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragment_container, editorFragment)
|
||||
.commit();
|
||||
|
||||
mToolbarController.setTitle("Edit POI");
|
||||
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;
|
||||
}
|
||||
|
||||
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, EditorFragment.class.getName())
|
||||
.commit();
|
||||
}
|
||||
|
||||
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 void onClick(View v)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -219,8 +219,7 @@ public class RoutingController
|
|||
Log.d(TAG, "[B] State: " + mState + ", BuildState: " + mBuildState + " -> " + newState);
|
||||
mBuildState = newState;
|
||||
|
||||
if (mBuildState == BuildState.BUILT &&
|
||||
!(mStartPoint instanceof MapObject.MyPosition))
|
||||
if (mBuildState == BuildState.BUILT && !MapObject.isOfType(MapObject.MY_POSITION, mStartPoint))
|
||||
Framework.nativeDisableFollowing();
|
||||
}
|
||||
|
||||
|
@ -354,7 +353,7 @@ public class RoutingController
|
|||
{
|
||||
Log.d(TAG, "start");
|
||||
|
||||
if (!(mStartPoint instanceof MapObject.MyPosition))
|
||||
if (!MapObject.isOfType(MapObject.MY_POSITION, mStartPoint))
|
||||
{
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_START_SUGGEST_REBUILD);
|
||||
AlohaHelper.logClick(AlohaHelper.ROUTING_START_SUGGEST_REBUILD);
|
||||
|
@ -362,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);
|
||||
|
@ -393,7 +392,7 @@ public class RoutingController
|
|||
titleView.setText(R.string.p2p_only_from_current);
|
||||
builder.setCustomTitle(titleView);
|
||||
|
||||
if (mEndPoint instanceof MapObject.MyPosition)
|
||||
if (MapObject.isOfType(MapObject.MY_POSITION, mEndPoint))
|
||||
{
|
||||
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener()
|
||||
{
|
||||
|
@ -551,7 +550,7 @@ public class RoutingController
|
|||
Framework.nativeSetRouteStartPoint(0.0, 0.0, false);
|
||||
else
|
||||
Framework.nativeSetRouteStartPoint(mStartPoint.getLat(), mStartPoint.getLon(),
|
||||
!(mStartPoint instanceof MapObject.MyPosition));
|
||||
!MapObject.isOfType(MapObject.MY_POSITION, mStartPoint));
|
||||
|
||||
if (mEndPoint == null)
|
||||
Framework.nativeSetRouteEndPoint(0.0, 0.0, false);
|
||||
|
|
|
@ -39,9 +39,11 @@ public class RoutingPlanInplaceController extends RoutingPlanController
|
|||
|
||||
if (show)
|
||||
{
|
||||
boolean open = (mSlotsRestoredState == null ? !(RoutingController.get().getStartPoint() instanceof MapObject.MyPosition) ||
|
||||
(RoutingController.get().getEndPoint() == null)
|
||||
: mSlotsRestoredState);
|
||||
final MapObject start = RoutingController.get().getStartPoint();
|
||||
final MapObject end = RoutingController.get().getEndPoint();
|
||||
boolean open = (mSlotsRestoredState == null
|
||||
? (!MapObject.isOfType(MapObject.MY_POSITION, start) || end == null)
|
||||
: mSlotsRestoredState);
|
||||
showSlots(open, false);
|
||||
mSlotsRestoredState = null;
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class SlotFrame extends LinearLayout
|
|||
return;
|
||||
}
|
||||
|
||||
if (mMapObject instanceof MapObject.MyPosition)
|
||||
if (MapObject.isOfType(MapObject.MY_POSITION, mMapObject))
|
||||
mText.setText(R.string.p2p_your_location);
|
||||
else
|
||||
mText.setText(mMapObject.getName());
|
||||
|
|
|
@ -351,7 +351,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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -85,7 +85,7 @@ public class DirectionFragment extends BaseMwmDialogFragment implements Location
|
|||
if (mMapObject != null && isResumed())
|
||||
{
|
||||
mTvTitle.setText(mMapObject.getName());
|
||||
mTvSubtitle.setText(mMapObject.getPoiTypeName());
|
||||
mTvSubtitle.setText(mMapObject.getTypeName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.getTypeName()
|
||||
: mMapObject.getTypeName() + ", " + 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 (MapObject.isOfType(MapObject.MY_POSITION, mMapObject))
|
||||
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 ||
|
||||
MapObject.isOfType(MapObject.MY_POSITION, mMapObject))
|
||||
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 (MapObject.isOfType(MapObject.API_POINT, mMapObject) && !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 (MapObject.isOfType(MapObject.BOOKMARK, mMapObject))
|
||||
{
|
||||
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 (MapObject.isOfType(MapObject.BOOKMARK, mMapObject))
|
||||
{
|
||||
final Bookmark currentBookmark = (Bookmark) mMapObject;
|
||||
MapObject p;
|
||||
|
@ -876,8 +861,8 @@ 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);
|
||||
final BookmarkColorDialogFragment dialogFragment =
|
||||
(BookmarkColorDialogFragment) Fragment.instantiate(getContext(), BookmarkColorDialogFragment.class.getName(), args);
|
||||
|
||||
dialogFragment.setOnColorSetListener(new BookmarkColorDialogFragment.OnBookmarkColorChangeListener()
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -17,6 +17,7 @@ public class SimpleTimetableFragment extends BaseMwmRecyclerFragment
|
|||
HoursMinutesPickerFragment.OnPickListener
|
||||
{
|
||||
private SimpleTimetableAdapter mAdapter;
|
||||
private Timetable[] mInitTts;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState)
|
||||
|
@ -28,6 +29,8 @@ public class SimpleTimetableFragment extends BaseMwmRecyclerFragment
|
|||
protected RecyclerView.Adapter createAdapter()
|
||||
{
|
||||
mAdapter = new SimpleTimetableAdapter(this);
|
||||
if (mInitTts != null)
|
||||
mAdapter.setTimetables(mInitTts);
|
||||
return mAdapter;
|
||||
}
|
||||
|
||||
|
@ -60,8 +63,6 @@ public class SimpleTimetableFragment extends BaseMwmRecyclerFragment
|
|||
{
|
||||
if (tts == null)
|
||||
return;
|
||||
|
||||
createAdapter();
|
||||
mAdapter.setTimetables(tts);
|
||||
mInitTts = tts;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ 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 ?
|
||||
R.string.my_position_share_email : R.string.bookmark_share_email;
|
||||
final int subjectId = mMapObject.getType() == MapObject.MapObjectType.MY_POSITION ?
|
||||
R.string.my_position_share_email_subject : R.string.bookmark_share_email_subject;
|
||||
final int textId = MapObject.isOfType(MapObject.MY_POSITION, mMapObject) ? R.string.my_position_share_email
|
||||
: R.string.bookmark_share_email;
|
||||
final int subjectId = MapObject.isOfType(MapObject.MY_POSITION, mMapObject) ? R.string.my_position_share_email_subject
|
||||
: R.string.bookmark_share_email_subject;
|
||||
|
||||
setText(activity.getString(textId, address, ge0Url, httpUrl));
|
||||
setSubject(activity.getString(subjectId));
|
||||
|
|
|
@ -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.isOfType(MapObject.MY_POSITION, mapObject) ? R.string.my_position_share_sms : R.string.bookmark_share_sms;
|
||||
final String body = activity.getString(bodyId, ge0Url, httpUrl);
|
||||
|
||||
shareWithText(activity, body);
|
||||
|
|
|
@ -334,6 +334,7 @@ public enum Statistics
|
|||
|
||||
public static String getPointType(MapObject point)
|
||||
{
|
||||
return point instanceof MapObject.MyPosition ? Statistics.EventParam.MY_POSITION : Statistics.EventParam.POINT;
|
||||
return MapObject.isOfType(MapObject.MY_POSITION, point) ? Statistics.EventParam.MY_POSITION
|
||||
: Statistics.EventParam.POINT;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue