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:
authorAlexei Vitenko <AlexeiVitenko@gmail.com>2013-02-02 15:16:25 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:50:45 +0300
commitfb7491a7d79411236484c42ef89c0b41a5fad826 (patch)
treec4a0ec6eba62d217218f20d0d8254e0418fffe29 /android
parentccc793872ecd4c8a839c86a3cd019337f6f5a1bd (diff)
[android] [bookmarks] draw popup in opengl-layer
Diffstat (limited to 'android')
-rw-r--r--android/jni/com/mapswithme/maps/Framework.cpp158
-rw-r--r--android/jni/com/mapswithme/maps/Framework.hpp33
-rw-r--r--android/jni/com/mapswithme/maps/MWMActivity.cpp33
-rw-r--r--android/src/com/mapswithme/maps/MWMActivity.java157
-rw-r--r--android/src/com/mapswithme/maps/SearchActivity.java12
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/BookmarkActivity.java9
6 files changed, 196 insertions, 206 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp
index ecb2feeff2..51a0403d88 100644
--- a/android/jni/com/mapswithme/maps/Framework.cpp
+++ b/android/jni/com/mapswithme/maps/Framework.cpp
@@ -20,6 +20,7 @@
#include "../../../../../platform/location.hpp"
#include "../../../../../base/math.hpp"
+#include "../../../../../base/logging.hpp"
#include "../../../../../std/shared_ptr.hpp"
#include "../../../../../std/bind.hpp"
@@ -56,6 +57,8 @@ namespace android
size_t const measurementsCount = 5;
m_sensors[0].SetCount(measurementsCount);
m_sensors[1].SetCount(measurementsCount);
+
+ m_work.GetBookmarkBalloon()->setOnClickListener(bind(&Framework::OnBalloonClick, this, _1));
}
Framework::~Framework()
@@ -271,8 +274,8 @@ namespace android
m_scheduledTask.reset(new ScheduledTask(bind(
& android::Framework::CallLongClickListener,
this,
- static_cast<int>(x1),
- static_cast<int>(y1)),
+ static_cast<double>(x1),
+ static_cast<double>(y1)),
static_cast<int>(LONG_CLICK_LENGTH_SEC * 1000)
));
m_longClickTimer.Reset();
@@ -430,7 +433,9 @@ namespace android
void Framework::ShowSearchResult(search::Result const & r)
{
m_doLoadState = false;
-
+ ::Framework::AddressInfo info;
+ info.MakeFrom(r);
+ ActivatePopupWithAddressInfo(r.GetFeatureCenter(), info);
m_work.ShowSearchResult(r);
}
@@ -552,38 +557,157 @@ namespace android
return &m_work;
}
- void Framework::CallClickListener(int x, int y)
+ void Framework::CallClickListener(double x, double y)
+ {
+ if (!HandleOnSmthClick(x, y))
+ DeactivatePopup();
+ }
+
+ void Framework::CallLongClickListener(double x, double y)
{
- if (!m_onClickListener.empty())
+ if (!HandleOnSmthClick(x, y))
{
- m_onClickListener(x, y);
+ AdditionalHandlingForLongClick(x, y);
}
}
- void Framework::CallLongClickListener(int x, int y)
+
+ bool Framework::HandleOnSmthClick(double x, double y)
{
- if (!m_onLongClickListener.empty())
+ BookmarkAndCategory bac = m_work.GetBookmark(m2::PointD(x, y));
+ if (ValidateBookmarkAndCategory(bac))
{
- m_onLongClickListener(x, y);
+ Bookmark b = *(m_work.GetBmCategory(bac.first)->GetBookmark(bac.second));
+ ActivatePopup(b.GetOrg(), b.GetName());
+ return true;
+ }
+ else
+ {
+ ::Framework::AddressInfo adInfo;
+ m2::PointD pxPivot;
+ if (m_work.GetVisiblePOI(m2::PointD(x, y), pxPivot, adInfo))
+ {
+ ActivatePopupWithAddressInfo(m_work.PtoG(pxPivot), adInfo);
+ return true;
+ }
+ else
+ return false;
}
}
- void Framework::AddClickListener(Framework::TOnClickListener const & l)
+ bool Framework::AdditionalHandlingForLongClick(double x, double y)
{
- m_onClickListener = l;
+ m2::PointD point(x, y);
+ ::Framework::AddressInfo adInfo;
+ m_work.GetAddressInfo(point, adInfo);
+ ActivatePopupWithAddressInfo(m_work.PtoG(point), adInfo);
}
- void Framework::RemoveClickListener()
+ void Framework::ToCamelCase(string & s)
{
- m_onClickListener.clear();
+ if (s.length() > 0)
+ {
+ s[0] = toupper(s[0]);
+ for(std::string::iterator it = s.begin() + 1; it != s.end(); ++it)
+ {
+ if(!isalpha(*(it - 1)) &&
+ islower(*it))
+ {
+ *it = toupper(*it);
+ }
+ }
+ }
+ }
+
+ void Framework::ActivatePopupWithAddressInfo(m2::PointD const & bmkPosition, ::Framework::AddressInfo const & adInfo)
+ {
+ string name = adInfo.m_name;
+ string type = "";
+ if (adInfo.GetBestType() != 0)
+ type = adInfo.GetBestType();
+ string bmkname;
+ if (name.empty() && type.empty())
+ {
+ bmkname = m_work.GetStringsBundle().GetString("dropped_pin");
+ }
+ else
+ if (!name.empty())
+ {
+ bmkname = name;
+ }
+ else
+ if (!type.empty())
+ {
+ bmkname = type;
+ }
+ else
+ {
+ std::stringstream cstream;
+ cstream << name << " (" << type << ")";
+ bmkname = cstream.str();
+ }
+
+ ActivatePopup(bmkPosition, bmkname);
+ m_work.DrawPlacemark(bmkPosition);
+ m_work.Invalidate();
+ }
+
+ void Framework::ActivatePopup(m2::PointD const & bmkPosition, string const & name)
+ {
+ gui::BookmarkBalloon * b = m_work.GetBookmarkBalloon();
+ m_work.DisablePlacemark();
+ b->setBookmarkPivot(bmkPosition);
+ b->setBookmarkName(name);
+ b->setIsVisible(true);
+ m_work.Invalidate();
+ }
+
+ void Framework::DeactivatePopup()
+ {
+ gui::BookmarkBalloon * b = m_work.GetBookmarkBalloon();
+ b->setIsVisible(false);
+ m_work.DisablePlacemark();
+ m_work.Invalidate();
+ }
+
+ void Framework::OnBalloonClick(gui::Element * e)
+ {
+ gui::BookmarkBalloon * balloon = static_cast<gui::BookmarkBalloon *>(e);
+ BookmarkAndCategory bac = m_work.GetBookmark(m_work.GtoP(balloon->getBookmarkPivot()));
+ if (ValidateBookmarkAndCategory(bac))
+ {
+ m_balloonClickListener(bac);
+ }
+ else
+ {
+ BookmarkCategory * cat;
+ if (m_work.GetBmCategoriesCount() == 0)
+ {
+ m_work.AddBookmark(m_work.GetStringsBundle().GetString("my_places"), Bookmark(balloon->getBookmarkPivot(), balloon->getBookmarkName(), "placemark-red"));
+ cat = m_work.GetBmCategory(m_work.GetBmCategoriesCount()-1);
+ }
+ else
+ {
+ cat = m_work.GetBmCategory(m_work.GetBmCategoriesCount()-1);
+ LOG(LDEBUG,("Paladin", (balloon->getBookmarkPivot(), balloon->getBookmarkName(), "placemark-red")));
+ m_work.AddBookmark(cat->GetName(), Bookmark(balloon->getBookmarkPivot(), balloon->getBookmarkName(), "placemark-red"));
+ }
+ cat->SaveToKMLFile();
+ int catSize = cat->GetBookmarksCount() - 1;
+ if (catSize > 0)
+ {
+ bac = BookmarkAndCategory(m_work.GetBmCategoriesCount()-1, catSize);
+ m_balloonClickListener(bac);
+ }
+ }
}
- void Framework::AddLongClickListener(TOnLongClickListener const & l)
+ void Framework::AddBalloonClickListener(TOnBalloonClickListener const & l)
{
- m_onLongClickListener = l;
+ m_balloonClickListener = l;
}
- void Framework::RemoveLongClickListener()
+ void Framework::RemoveBalloonClickListener()
{
- m_onLongClickListener.clear();
+ m_balloonClickListener.clear();
}
}
diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp
index 0cab228b32..e2389338c3 100644
--- a/android/jni/com/mapswithme/maps/Framework.hpp
+++ b/android/jni/com/mapswithme/maps/Framework.hpp
@@ -13,6 +13,8 @@
#include "../../../../../base/scheduled_task.hpp"
#include "../../../../../base/strings_bundle.hpp"
+#include "../../../../../search/result.hpp"
+
#include "../../../nv_event/nv_event.hpp"
class CountryStatusDisplay;
@@ -22,16 +24,13 @@ namespace android
class Framework
{
private:
- typedef function<void(int, int)> TOnClickListener;
- typedef function<void(int, int)> TOnLongClickListener;
::Framework m_work;
-
+ typedef function<void (BookmarkAndCategory)> TOnBalloonClickListener;
VideoTimer * m_videoTimer;
void CallRepaint();
- TOnClickListener m_onClickListener;
- TOnLongClickListener m_onLongClickListener;
+ TOnBalloonClickListener m_balloonClickListener;
boost::shared_ptr<ScheduledTask> m_scheduledTask;
int m_onClickFnsHandler;
@@ -59,9 +58,22 @@ namespace android
math::AvgVector<float, 3> m_sensors[2];
- void CallClickListener(int x, int y);
- void CallLongClickListener(int x, int y);
+ void CallClickListener(double x, double y);
+ void CallLongClickListener(double x, double y);
void KillLongTouchTask();
+
+ bool HandleOnSmthClick(double x, double y);
+ bool AdditionalHandlingForLongClick(double x, double y);
+ void ActivatePopup(m2::PointD const & bmkPosition, string const & name);
+ void ActivatePopupWithAddressInfo(m2::PointD const & bmkPosition, ::Framework::AddressInfo const & adInfo);
+ void OnBalloonClick(gui::Element * e);
+ void ToCamelCase(string & c);
+
+ inline bool ValidateBookmarkAndCategory(BookmarkAndCategory const & bac)
+ {
+ return bac.first > -1 && bac.second > -1;
+ }
+
public:
Framework();
~Framework();
@@ -118,12 +130,11 @@ namespace android
void Scale(double k);
- void AddClickListener(TOnClickListener const & l);
- void RemoveClickListener();
- void AddLongClickListener(TOnLongClickListener const & l);
- void RemoveLongClickListener();
+ void AddBalloonClickListener(TOnBalloonClickListener const & l);
+ void RemoveBalloonClickListener();
+ void DeactivatePopup();
::Framework * NativeFramework();
};
}
diff --git a/android/jni/com/mapswithme/maps/MWMActivity.cpp b/android/jni/com/mapswithme/maps/MWMActivity.cpp
index 96b5ba3033..1d27c7d90e 100644
--- a/android/jni/com/mapswithme/maps/MWMActivity.cpp
+++ b/android/jni/com/mapswithme/maps/MWMActivity.cpp
@@ -12,46 +12,31 @@
extern "C"
{
- void CallClickListener(shared_ptr<jobject> obj, jmethodID methodID, int x, int y)
+ void CallBalloonClickListener(shared_ptr<jobject> obj, BookmarkAndCategory & bac)
{
+ jmethodID methodID = jni::GetJavaMethodID(jni::GetEnv(), *obj.get(), "onClick", "(II)V");
if (methodID != 0)
{
- jni::GetEnv()->CallVoidMethod(*obj.get(), methodID, x, y);
+ jni::GetEnv()->CallVoidMethod(*obj.get(), methodID, bac.first, bac.second);
}
}
- void CallLongClickListener(shared_ptr<jobject> obj, int x, int y)
- {
- CallClickListener(obj, jni::GetJavaMethodID(jni::GetEnv(), *obj.get(), "onLongClick", "(II)V"), x, y);
- }
-
- void CallShortClickListener(shared_ptr<jobject> obj, int x, int y)
- {
- CallClickListener(obj, jni::GetJavaMethodID(jni::GetEnv(), *obj.get(), "onClick", "(II)V"), x, y);
- }
-
- JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_MWMActivity_addOnLongClickListener(JNIEnv * env, jobject thiz, jobject l)
- {
- return g_framework->AddLongClickListener(bind(&CallLongClickListener,jni::make_global_ref(l), _1, _2));
- }
-
JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_MWMActivity_addOnClickListener(JNIEnv * env, jobject thiz, jobject l)
+ Java_com_mapswithme_maps_MWMActivity_setOnPopupClickListener(JNIEnv * env, jobject thiz, jobject l)
{
- return g_framework->AddClickListener(bind(&CallShortClickListener,jni::make_global_ref(l), _1, _2));
+ return g_framework->AddBalloonClickListener(bind(&CallBalloonClickListener,jni::make_global_ref(l), _1));
}
JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_MWMActivity_removeOnLongClickListener()
+ Java_com_mapswithme_maps_MWMActivity_deactivatePopup(JNIEnv * env, jobject thiz)
{
- g_framework->RemoveLongClickListener();
+ return g_framework->DeactivatePopup();
}
JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_MWMActivity_removeOnClickListener()
+ Java_com_mapswithme_maps_MWMActivity_removeOnPopupClickListener()
{
- g_framework->RemoveClickListener();
+ g_framework->RemoveBalloonClickListener();
}
JNIEXPORT void JNICALL
diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java
index f925a72b06..67477e173e 100644
--- a/android/src/com/mapswithme/maps/MWMActivity.java
+++ b/android/src/com/mapswithme/maps/MWMActivity.java
@@ -11,38 +11,22 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.telephony.TelephonyManager;
-import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceHolder.Callback;
-import android.view.SurfaceView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.mapswithme.maps.bookmarks.BookmarkActivity;
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
-import com.mapswithme.maps.bookmarks.PopupLayout;
-import com.mapswithme.maps.bookmarks.data.AddressInfo;
-import com.mapswithme.maps.bookmarks.data.Bookmark;
-import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
-import com.mapswithme.maps.bookmarks.data.ParcelablePointD;
import com.mapswithme.maps.location.LocationService;
import com.mapswithme.maps.settings.UnitLocale;
import com.mapswithme.util.ConnectionState;
@@ -60,26 +44,18 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
private MWMApplication mApplication = null;
private BroadcastReceiver m_externalStorageReceiver = null;
private AlertDialog m_storageDisconnectedDialog = null;
- private BookmarkManager m_BookmarkManager;
//showDialog(int, Bundle) available only form API 8
private String mProDialogMessage;
- private interface OnLongClickListener
+ private interface OnNativePopupClickListenter
{
- void onLongClick(int x, int y);
+ void onClick(int cat, int bmk);
}
- private interface OnClickListenter
- {
- void onClick(int x, int y);
- }
-
- private native void addOnLongClickListener(Object l);
- private native void removeOnLongClickListener();
-
- private native void addOnClickListener(Object l);
- private native void removeOnClickListener();
+ private native void setOnPopupClickListener(Object l);
+ private native void removeOnPopupClickListener();
+ private native void deactivatePopup();
private LocationService getLocationService()
{
@@ -308,7 +284,6 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
private boolean m_needCheckUpdate = true;
- private PopupLayout m_popupLayout;
private void checkUpdateMaps()
{
@@ -453,6 +428,7 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
runOnUiThread(new Runnable()
{
+ @SuppressWarnings("deprecation")
@Override
public void run()
{
@@ -560,120 +536,28 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
alignZoomButtons();
- BookmarkTouchHandler handler = new BookmarkTouchHandler(m_popupLayout = (PopupLayout)findViewById(R.id.map_popup));
- m_BookmarkManager = BookmarkManager.getBookmarkManager(getApplicationContext());
- addOnLongClickListener(handler);
- addOnClickListener(handler);
- }
-
- @Override
- protected void onStart()
- {
- super.onStart();
- if (getIntent().hasExtra(SearchActivity.SEARCH_RESULT))
+ setOnPopupClickListener(new OnNativePopupClickListenter()
{
- m_popupLayout.activate(m_BookmarkManager.previewBookmark((AddressInfo)getIntent().getParcelableExtra(SearchActivity.SEARCH_RESULT)),
- getWindowManager());
- getIntent().removeExtra(SearchActivity.SEARCH_RESULT);
- }
- }
- @Override
- protected void onStop()
- {
- if (m_popupLayout != null)
- {
- m_popupLayout.deactivate();
- }
- super.onStop();
- }
-
- private class BookmarkTouchHandler implements OnClickListenter, OnLongClickListener
- {
- private PopupLayout m_PopupLayout;
-
- BookmarkTouchHandler(PopupLayout pop)
- {
- m_PopupLayout = pop;
- }
- @Override
- public void onLongClick(int x, int y)
- {
- handleOnSmthClick(x, y, true);
- }
-
- @Override
- public void onClick(final int x, final int y)
- {
- if (m_popupLayout.isActive())
- {
- if(!m_PopupLayout.handleClick(x, y, mApplication.isProVersion()))
- {
- if (mApplication.isProVersion())
- {
- handleOnSmthClick(x, y, false);
- }
- }
- else
- {
- if (!mApplication.isProVersion())
- {
- showProVersionBanner(getString(R.string.bookmarks_in_pro_version));
- }
- }
- }
- else
- {
- handleOnSmthClick(x, y, false);
- }
-
- }
-
- private boolean handleOnSmthClick(int x, int y, boolean longClick)
- {
- ParcelablePoint b = m_BookmarkManager.findBookmark(new ParcelablePointD(x, y));
- if (b != null)
- {
- m_PopupLayout.activate(m_BookmarkManager.getBookmark(b.getPoint().x, b.getPoint().y), getWindowManager());
- return true;
- }
- else
+ @Override
+ public void onClick(int cat, int bmk)
{
- AddressInfo info = null;
- if ((info = m_BookmarkManager.getPOI(new ParcelablePointD(x, y))) != null)
- {
- m_PopupLayout.activate(m_BookmarkManager.previewBookmark(info), getWindowManager());
- return true;
- }
- else
- if (longClick)
- {
- info = m_BookmarkManager.getAddressInfo(new ParcelablePointD(x, y));
- m_PopupLayout.activate(m_BookmarkManager.previewBookmark(info), getWindowManager());
- return true;
- }
- else
- {
- return false;
- }
+ startActivity(
+ new Intent(MWMActivity.this, BookmarkActivity.class)
+ .putExtra(
+ BookmarkActivity.PIN,
+ new ParcelablePoint(cat, bmk
+ )
+ ));
}
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event)
- {
- m_popupLayout.requestInvalidation();
- return super.onTouchEvent(event);
+ });
}
@Override
- public void onDestroy()
+ protected void onStop()
{
- if (mApplication.isProVersion())
- removeOnLongClickListener();
- removeOnClickListener();
- super.onDestroy();
+ deactivatePopup();
+ super.onStop();
}
private void alignZoomButtons()
@@ -839,7 +723,6 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
startWatchingCompassStatusUpdate();
startWatchingExternalStorage();
- m_popupLayout.requestInvalidation();
super.onResume();
}
diff --git a/android/src/com/mapswithme/maps/SearchActivity.java b/android/src/com/mapswithme/maps/SearchActivity.java
index 202c595534..b5081f229e 100644
--- a/android/src/com/mapswithme/maps/SearchActivity.java
+++ b/android/src/com/mapswithme/maps/SearchActivity.java
@@ -362,7 +362,7 @@ public class SearchActivity extends ListActivity implements LocationService.List
}
/// Show tapped country or get suggestion or get category to search.
- public String onItemClick(int position, Intent mapIntent)
+ public String onItemClick(int position)
{
if (isShowCategories())
{
@@ -372,8 +372,6 @@ public class SearchActivity extends ListActivity implements LocationService.List
}
else
{
- mapIntent.removeExtra(SEARCH_RESULT);
-
final SearchResult r = m_context.getResult(position, m_resultID);
if (r != null)
{
@@ -381,7 +379,6 @@ public class SearchActivity extends ListActivity implements LocationService.List
{
// show country and close activity
SearchActivity.nativeShowItem(position);
- mapIntent.putExtra(SEARCH_RESULT, r.getAddressInfo());
return null;
}
else
@@ -524,13 +521,10 @@ public class SearchActivity extends ListActivity implements LocationService.List
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
-
- Intent mapIntent = new Intent(this, MWMActivity.class);
- mapIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- final String suggestion = getSA().onItemClick(position, mapIntent);
+ final String suggestion = getSA().onItemClick(position);
if (suggestion == null)
{
- startActivity(mapIntent);
+ finish();
}
else
{
diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkActivity.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkActivity.java
index 2adc952913..e9caf4ed93 100644
--- a/android/src/com/mapswithme/maps/bookmarks/BookmarkActivity.java
+++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkActivity.java
@@ -54,14 +54,7 @@ public class BookmarkActivity extends AbstractBookmarkActivity
{
super.onCreate(savedInstanceState);
setContentView(R.layout.pin);
- if (getIntent().getExtras().containsKey(BOOKMARK_POSITION))
- {
- // create new bookmark
- mPin = mManager.getBookmark(((ParcelablePointD)getIntent().getExtras().getParcelable(BOOKMARK_POSITION)));
- mPin.setName(getIntent().getExtras().getString(BOOKMARK_NAME));
- findViewById(R.id.pin_name).requestFocus();
- }
- else if (getIntent().getExtras().containsKey(PIN))
+ if (getIntent().getExtras().containsKey(PIN))
{
Point mPinPair = ((ParcelablePoint)getIntent().getParcelableExtra(PIN)).getPoint();
mCurrentCategoryId = mPinPair.x;