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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandr Zatsepin <alexzatsepin@users.noreply.github.com>2016-11-24 16:53:27 +0300
committerGitHub <noreply@github.com>2016-11-24 16:53:27 +0300
commitdd7599998201423b95a260ee6ff972bb310812c6 (patch)
treebe246305389f0332718baad629076e90900991f8
parentd0de17010e54e7c3dfdfc04e93f029df2588d00c (diff)
parente197c059713ee2edbeccadc2a5a9f3cc042a12bb (diff)
Merge pull request #4744 from goblinr/MAPSME-87-ext-fix-editor-restore-state
[android] Fixed editor restore state.
-rw-r--r--android/jni/com/mapswithme/maps/Framework.cpp44
-rw-r--r--android/jni/com/mapswithme/maps/editor/Editor.cpp7
-rw-r--r--android/src/com/mapswithme/maps/Framework.java2
-rw-r--r--android/src/com/mapswithme/maps/MwmActivity.java16
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java35
-rw-r--r--android/src/com/mapswithme/maps/editor/Editor.java2
-rw-r--r--android/src/com/mapswithme/maps/editor/EditorActivity.java32
-rw-r--r--android/src/com/mapswithme/maps/editor/EditorHostFragment.java5
-rw-r--r--map/framework.cpp18
-rw-r--r--map/framework.hpp7
10 files changed, 141 insertions, 27 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp
index 4e09eacc95..6fd1ed8af1 100644
--- a/android/jni/com/mapswithme/maps/Framework.cpp
+++ b/android/jni/com/mapswithme/maps/Framework.cpp
@@ -626,6 +626,50 @@ Java_com_mapswithme_maps_Framework_nativeSetMapObjectListener(JNIEnv * env, jcla
}
JNIEXPORT void JNICALL
+Java_com_mapswithme_maps_Framework_nativeRestoreMapObject(JNIEnv * env, jclass clazz,
+ jobject jMapObject)
+{
+ static jmethodID const getMapObjectTypeId =
+ jni::GetMethodID(env, jMapObject, "getMapObjectType", "()I");
+
+ place_page::Info info;
+ jint type = env->CallIntMethod(jMapObject, getMapObjectTypeId);
+ switch (type)
+ {
+ case usermark_helper::kBookmark:
+ {
+ static jmethodID const getCategoryId =
+ jni::GetMethodID(env, jMapObject, "getCategoryId", "()I");
+ static jmethodID const getBookmarkId =
+ jni::GetMethodID(env, jMapObject, "getBookmarkId", "()I");
+ jint categoryId = env->CallIntMethod(jMapObject, getCategoryId);
+ jint bookmarkId = env->CallIntMethod(jMapObject, getBookmarkId);
+ BookmarkAndCategory bnc = BookmarkAndCategory(bookmarkId, categoryId);
+ BookmarkCategory * pCat = frm()->GetBmCategory(categoryId);
+ Bookmark const * pBmk = static_cast<Bookmark const *>(pCat->GetUserMark(bookmarkId));
+ frm()->FillBookmarkInfo(*pBmk, bnc, info);
+ break;
+ }
+ case usermark_helper::kMyPosition:
+ {
+ frm()->FillMyPositionInfo(info);
+ break;
+ }
+ default:
+ {
+ static jmethodID const getLatId = jni::GetMethodID(env, jMapObject, "getLat", "()D");
+ static jmethodID const getLonId = jni::GetMethodID(env, jMapObject, "getLon", "()D");
+ jdouble lat = env->CallDoubleMethod(jMapObject, getLatId);
+ jdouble lon = env->CallDoubleMethod(jMapObject, getLonId);
+ frm()->FillPoiInfo(m2::PointD(MercatorBounds::FromLatLon(lat, lon)), info);
+ break;
+ }
+ }
+
+ g_framework->SetPlacePageInfo(info);
+}
+
+JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeRemoveMapObjectListener(JNIEnv * env, jclass)
{
frm()->SetMapSelectionListeners({}, {});
diff --git a/android/jni/com/mapswithme/maps/editor/Editor.cpp b/android/jni/com/mapswithme/maps/editor/Editor.cpp
index 7a6b075c1e..2040fee1e2 100644
--- a/android/jni/com/mapswithme/maps/editor/Editor.cpp
+++ b/android/jni/com/mapswithme/maps/editor/Editor.cpp
@@ -417,12 +417,13 @@ Java_com_mapswithme_maps_editor_Editor_nativeClearLocalEdits(JNIEnv * env, jclas
Editor::Instance().ClearAllLocalEdits();
}
-JNIEXPORT void JNICALL
-Java_com_mapswithme_maps_editor_Editor_nativeStartEdit(JNIEnv *, jclass)
+JNIEXPORT void JNICALL Java_com_mapswithme_maps_editor_Editor_nativeStartEdit(JNIEnv *, jclass,
+ jint drawScale = -1)
{
::Framework * frm = g_framework->NativeFramework();
place_page::Info const & info = g_framework->GetPlacePageInfo();
- CHECK(frm->GetEditableMapObject(info.GetID(), g_editableMapObject), ("Invalid feature in the place page."));
+ CHECK(frm->GetEditableMapObject(info.GetID(), g_editableMapObject, drawScale),
+ ("Invalid feature in the place page."));
}
JNIEXPORT void JNICALL
diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java
index bddef7a50a..d178b621e5 100644
--- a/android/src/com/mapswithme/maps/Framework.java
+++ b/android/src/com/mapswithme/maps/Framework.java
@@ -128,6 +128,8 @@ public class Framework
public static native void nativeRemoveMapObjectListener();
+ public static native void nativeRestoreMapObject(@NonNull MapObject mapObject);
+
@UiThread
public static native String nativeGetOutdatedCountriesString();
diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java
index a646361824..f178a25f2f 100644
--- a/android/src/com/mapswithme/maps/MwmActivity.java
+++ b/android/src/com/mapswithme/maps/MwmActivity.java
@@ -45,7 +45,6 @@ import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.downloader.MigrationFragment;
import com.mapswithme.maps.downloader.OnmapDownloader;
import com.mapswithme.maps.editor.AuthDialogFragment;
-import com.mapswithme.maps.editor.Editor;
import com.mapswithme.maps.editor.EditorActivity;
import com.mapswithme.maps.editor.EditorHostFragment;
import com.mapswithme.maps.editor.FeatureCategoryActivity;
@@ -116,7 +115,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
ReportFragment.class.getName() };
// Instance state
private static final String STATE_PP = "PpState";
- private static final String STATE_MAP_OBJECT = "MapObject";
+ public static final String STATE_MAP_OBJECT = "MapObject";
// Map tasks that we run AFTER rendering initialized
private final Stack<MapTask> mTasks = new Stack<>();
@@ -341,13 +340,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
public void showEditor()
{
- // TODO(yunikkk) think about refactoring. It probably should be called in editor.
- Editor.nativeStartEdit();
Statistics.INSTANCE.trackEditorLaunch(false);
if (mIsFragmentContainer)
replaceFragment(EditorHostFragment.class, null, null);
else
- EditorActivity.start(this);
+ EditorActivity.start(this, mPlacePage.getMapObject(), Framework.nativeGetDrawScale());
}
private void shareMyLocation()
@@ -784,8 +781,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (state != State.HIDDEN)
{
mPlacePageRestored = true;
- mPlacePage.setMapObject((MapObject) savedInstanceState.getParcelable(STATE_MAP_OBJECT), true);
- mPlacePage.setState(state);
+ MapObject mapObject = savedInstanceState.getParcelable(STATE_MAP_OBJECT);
+ if (mapObject != null)
+ {
+ Framework.nativeRestoreMapObject(mapObject);
+ mPlacePage.setMapObject(mapObject, true);
+ mPlacePage.setState(state);
+ }
}
if (!mIsFragmentContainer && RoutingController.get().isPlanning())
diff --git a/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java b/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java
index 44979ab664..1ca09cb516 100644
--- a/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java
+++ b/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java
@@ -13,11 +13,14 @@ import com.mapswithme.util.Constants;
@SuppressLint("ParcelCreator")
public class Bookmark extends MapObject
{
- private final Icon mIcon;
+ @Nullable
+ private Icon mIcon;
private int mCategoryId;
private int mBookmarkId;
- private double mMerX;
- private double mMerY;
+ @Nullable
+ private Double mMerX;
+ @Nullable
+ private Double mMerY;
Bookmark(@IntRange(from = 0) int categoryId, @IntRange(from = 0) int bookmarkId, String title,
@Nullable Banner banner)
@@ -26,8 +29,6 @@ public class Bookmark extends MapObject
mCategoryId = categoryId;
mBookmarkId = bookmarkId;
- mIcon = getIconInternal();
- initXY();
}
private void initXY()
@@ -53,8 +54,6 @@ public class Bookmark extends MapObject
super(source);
mCategoryId = source.readInt();
mBookmarkId = source.readInt();
- mIcon = getIconInternal();
- initXY();
}
@Override
@@ -71,16 +70,38 @@ public class Bookmark extends MapObject
public DistanceAndAzimut getDistanceAndAzimuth(double cLat, double cLon, double north)
{
+ if (mMerX == null || mMerY == null)
+ initXY();
return Framework.nativeGetDistanceAndAzimuth(mMerX, mMerY, cLat, cLon, north);
}
+ @Override
+ public double getLat()
+ {
+ if (mMerX == null || mMerY == null)
+ initXY();
+ return super.getLat();
+ }
+
+ @Override
+ public double getLon()
+ {
+ if (mMerX == null || mMerY == null)
+ initXY();
+ return super.getLon();
+ }
+
+ @NonNull
private Icon getIconInternal()
{
return BookmarkManager.getIconByType((mCategoryId >= 0) ? nativeGetIcon(mCategoryId, mBookmarkId) : "");
}
+ @NonNull
public Icon getIcon()
{
+ if (mIcon == null)
+ mIcon = getIconInternal();
return mIcon;
}
diff --git a/android/src/com/mapswithme/maps/editor/Editor.java b/android/src/com/mapswithme/maps/editor/Editor.java
index 274895485c..337acdfac2 100644
--- a/android/src/com/mapswithme/maps/editor/Editor.java
+++ b/android/src/com/mapswithme/maps/editor/Editor.java
@@ -140,7 +140,7 @@ public final class Editor
* That method should be called, when user opens editor from place page, so that information in editor
* could refresh.
*/
- public static native void nativeStartEdit();
+ public static native void nativeStartEdit(int drawScale);
/**
* @return true if feature was saved. False if some error occurred (eg. no space)
*/
diff --git a/android/src/com/mapswithme/maps/editor/EditorActivity.java b/android/src/com/mapswithme/maps/editor/EditorActivity.java
index 2661b5b1b4..f886c612da 100644
--- a/android/src/com/mapswithme/maps/editor/EditorActivity.java
+++ b/android/src/com/mapswithme/maps/editor/EditorActivity.java
@@ -2,14 +2,22 @@ package com.mapswithme.maps.editor;
import android.app.Activity;
import android.content.Intent;
+import android.os.Bundle;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
+import com.mapswithme.maps.Framework;
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
+import com.mapswithme.maps.bookmarks.data.MapObject;
public class EditorActivity extends BaseMwmFragmentActivity
{
public static final String EXTRA_NEW_OBJECT = "ExtraNewMapObject";
+ private static final String EXTRA_MAP_OBJECT = "ExtraMapObject";
+ public static final String EXTRA_DRAW_SCALE = "ExtraDrawScale";
+
+ private int mDrawScale = -1;
@Override
protected Class<? extends Fragment> getFragmentClass()
@@ -17,9 +25,31 @@ public class EditorActivity extends BaseMwmFragmentActivity
return EditorHostFragment.class;
}
- public static void start(@NonNull Activity activity)
+ public static void start(@NonNull Activity activity, @NonNull MapObject mapObject, int drawScale)
{
final Intent intent = new Intent(activity, EditorActivity.class);
+ intent.putExtra(EXTRA_MAP_OBJECT, mapObject);
+ intent.putExtra(EXTRA_DRAW_SCALE, drawScale);
activity.startActivity(intent);
}
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+
+ Bundle extras = getIntent().getExtras();
+ if (extras != null)
+ {
+ mDrawScale = extras.getInt(EXTRA_DRAW_SCALE);
+ MapObject mapObject = extras.getParcelable(EXTRA_MAP_OBJECT);
+ if (mapObject != null)
+ Framework.nativeRestoreMapObject(mapObject);
+ }
+ }
+
+ public int getDrawScale()
+ {
+ return mDrawScale;
+ }
}
diff --git a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java
index 1355a78d6f..929bfa1efd 100644
--- a/android/src/com/mapswithme/maps/editor/EditorHostFragment.java
+++ b/android/src/com/mapswithme/maps/editor/EditorHostFragment.java
@@ -114,6 +114,11 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
+
+ if (!(getActivity() instanceof EditorActivity))
+ Editor.nativeStartEdit(-1);
+ else
+ Editor.nativeStartEdit(((EditorActivity) getActivity()).getDrawScale());
mToolbarController.findViewById(R.id.save).setOnClickListener(this);
mToolbarController.getToolbar().setNavigationOnClickListener(new View.OnClickListener()
{
diff --git a/map/framework.cpp b/map/framework.cpp
index 5b1f751771..9231dd0bbf 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -728,6 +728,11 @@ void Framework::FillBookmarkInfo(Bookmark const & bmk, BookmarkAndCategory const
info.m_bookmarkDescription = data.GetDescription();
}
+void Framework::FillPoiInfo(m2::PointD const & pt, place_page::Info & info) const
+{
+ FillPointInfo(pt, string(), info);
+}
+
void Framework::FillFeatureInfo(FeatureID const & fid, place_page::Info & info) const
{
if (!fid.IsValid())
@@ -2106,10 +2111,12 @@ void Framework::UpdateMinBuildingsTapZoom()
feature::GetDrawableScaleRange(classif().GetTypeByPath({"building"})).first);
}
-FeatureID Framework::FindBuildingAtPoint(m2::PointD const & mercator) const
+FeatureID Framework::FindBuildingAtPoint(m2::PointD const & mercator, int drawScale /*= -1*/) const
{
FeatureID featureId;
- if (GetDrawScale() >= m_minBuildingsTapZoom)
+ bool matchZoom =
+ drawScale < 0 ? GetDrawScale() >= m_minBuildingsTapZoom : drawScale >= m_minBuildingsTapZoom;
+ if (matchZoom)
{
constexpr int kScale = scales::GetUpperScale();
constexpr double kSelectRectWidthInMeters = 1.1;
@@ -2941,7 +2948,8 @@ bool Framework::CreateMapObject(m2::PointD const & mercator, uint32_t const feat
return osm::Editor::Instance().CreatePoint(featureType, mercator, mwmId, emo);
}
-bool Framework::GetEditableMapObject(FeatureID const & fid, osm::EditableMapObject & emo) const
+bool Framework::GetEditableMapObject(FeatureID const & fid, osm::EditableMapObject & emo,
+ int drawScale /*= -1*/) const
{
if (!fid.IsValid())
return false;
@@ -2965,8 +2973,8 @@ bool Framework::GetEditableMapObject(FeatureID const & fid, osm::EditableMapObje
if (!ftypes::IsBuildingChecker::Instance()(ft) &&
(emo.GetHouseNumber().empty() || emo.GetStreet().m_defaultName.empty()))
{
- SetHostingBuildingAddress(FindBuildingAtPoint(feature::GetCenter(ft)),
- index, coder, emo);
+ SetHostingBuildingAddress(FindBuildingAtPoint(feature::GetCenter(ft), drawScale), index, coder,
+ emo);
}
return true;
diff --git a/map/framework.hpp b/map/framework.hpp
index 4f5f689e41..8b5e53db9d 100644
--- a/map/framework.hpp
+++ b/map/framework.hpp
@@ -386,7 +386,7 @@ private:
place_page::Info & outInfo) const;
unique_ptr<TapEvent> MakeTapEvent(m2::PointD const & center, FeatureID const & fid,
TapEvent::Source source) const;
- FeatureID FindBuildingAtPoint(m2::PointD const & mercator) const;
+ FeatureID FindBuildingAtPoint(m2::PointD const & mercator, int drawScale = -1) const;
void UpdateMinBuildingsTapZoom();
int m_minBuildingsTapZoom;
@@ -623,10 +623,11 @@ private:
void FillInfoFromFeatureType(FeatureType const & ft, place_page::Info & info) const;
void FillApiMarkInfo(ApiMarkPoint const & api, place_page::Info & info) const;
void FillSearchResultInfo(SearchMarkPoint const & smp, place_page::Info & info) const;
- void FillMyPositionInfo(place_page::Info & info) const;
public:
void FillBookmarkInfo(Bookmark const & bmk, BookmarkAndCategory const & bac, place_page::Info & info) const;
+ void FillPoiInfo(m2::PointD const & pt, place_page::Info & info) const;
+ void FillMyPositionInfo(place_page::Info & info) const;
/// @returns address of nearby building with house number in approx 1km distance.
search::AddressInfo GetAddressInfoAtPoint(m2::PointD const & pt) const;
@@ -805,7 +806,7 @@ public:
bool CreateMapObject(m2::PointD const & mercator, uint32_t const featureType, osm::EditableMapObject & emo) const;
/// @returns false if feature is invalid or can't be edited.
- bool GetEditableMapObject(FeatureID const & fid, osm:: EditableMapObject & emo) const;
+ bool GetEditableMapObject(FeatureID const & fid, osm:: EditableMapObject & emo, int drawScale = -1) const;
osm::Editor::SaveResult SaveEditedMapObject(osm::EditableMapObject emo);
void DeleteFeature(FeatureID const & fid) const;
osm::NewFeatureCategories GetEditorCategories() const;