forked from organicmaps/organicmaps
[android] [bookmarks] show search result as preview bookmark
This commit is contained in:
parent
8f2bbbc4ee
commit
743c554c65
5 changed files with 64 additions and 16 deletions
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "../core/jni_helper.hpp"
|
||||
|
||||
#include "../../../../../indexer/mercator.hpp"
|
||||
|
||||
|
||||
class SearchAdapter
|
||||
{
|
||||
|
@ -219,7 +221,7 @@ Java_com_mapswithme_maps_SearchActivity_nativeGetResult(
|
|||
{
|
||||
jmethodID methodID = env->GetMethodID(
|
||||
klass, "<init>",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;D)V");
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DDD)V");
|
||||
ASSERT ( methodID, () );
|
||||
|
||||
string distance;
|
||||
|
@ -234,12 +236,16 @@ Java_com_mapswithme_maps_SearchActivity_nativeGetResult(
|
|||
}
|
||||
}
|
||||
|
||||
m2::PointD rp = res->GetFeatureCenter();
|
||||
m2::PointD mer(rp.x, rp.y);
|
||||
return env->NewObject(klass, methodID,
|
||||
jni::ToJavaString(env, res->GetString()),
|
||||
jni::ToJavaString(env, res->GetRegionString()),
|
||||
jni::ToJavaString(env, res->GetFeatureType()),
|
||||
jni::ToJavaString(env, res->GetRegionFlag()),
|
||||
jni::ToJavaString(env, distance.c_str()),
|
||||
static_cast<jdouble>(mer.x),
|
||||
static_cast<jdouble>(mer.y),
|
||||
static_cast<jdouble>(azimut));
|
||||
}
|
||||
else
|
||||
|
|
|
@ -566,6 +566,18 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
addOnClickListener(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
if (getIntent().hasExtra(SearchActivity.SEARCH_RESULT))
|
||||
{
|
||||
m_popupLayout.activate(m_BookmarkManager.previewBookmark((AddressInfo)getIntent().getParcelableExtra(SearchActivity.SEARCH_RESULT)),
|
||||
getWindowManager());
|
||||
getIntent().removeExtra(SearchActivity.SEARCH_RESULT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
|
@ -622,7 +634,7 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
ParcelablePoint b = m_BookmarkManager.findBookmark(new ParcelablePointD(x, y));
|
||||
if (b != null)
|
||||
{
|
||||
m_PopupLayout.activate(m_BookmarkManager.getBookmark(b.getPoint().x, b.getPoint().y));
|
||||
m_PopupLayout.activate(m_BookmarkManager.getBookmark(b.getPoint().x, b.getPoint().y), getWindowManager());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -630,14 +642,14 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
AddressInfo info = null;
|
||||
if ((info = m_BookmarkManager.getPOI(new ParcelablePointD(x, y))) != null)
|
||||
{
|
||||
m_PopupLayout.activate(m_BookmarkManager.previewBookmark(info));
|
||||
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));
|
||||
m_PopupLayout.activate(m_BookmarkManager.previewBookmark(info), getWindowManager());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.app.ListActivity;
|
|||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.location.Location;
|
||||
import android.content.Intent;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
|
@ -23,15 +25,19 @@ import android.widget.ProgressBar;
|
|||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.bookmarks.data.AddressInfo;
|
||||
import com.mapswithme.maps.bookmarks.data.Bookmark;
|
||||
import com.mapswithme.maps.bookmarks.data.ParcelablePointD;
|
||||
import com.mapswithme.maps.location.LocationService;
|
||||
|
||||
|
||||
public class SearchActivity extends ListActivity implements LocationService.Listener
|
||||
{
|
||||
private static String TAG = "SearchActivity";
|
||||
public static final String SEARCH_RESULT = "search_result";
|
||||
|
||||
private static class SearchAdapter extends BaseAdapter
|
||||
{
|
||||
{;
|
||||
private final SearchActivity m_context;
|
||||
private final LayoutInflater m_inflater;
|
||||
|
||||
|
@ -180,6 +186,7 @@ public class SearchActivity extends ListActivity implements LocationService.List
|
|||
/// Created from native code.
|
||||
public static class SearchResult
|
||||
{
|
||||
public ParcelablePointD mLocation;
|
||||
public String m_name;
|
||||
public String m_country;
|
||||
public String m_amenity;
|
||||
|
@ -204,7 +211,7 @@ public class SearchActivity extends ListActivity implements LocationService.List
|
|||
// Called from native code
|
||||
@SuppressWarnings("unused")
|
||||
public SearchResult(String name, String country, String amenity,
|
||||
String flag, String distance, double azimut)
|
||||
String flag, String distance, double lat, double lon, double azimut)
|
||||
{
|
||||
m_name = name;
|
||||
m_country = country;
|
||||
|
@ -214,8 +221,16 @@ public class SearchActivity extends ListActivity implements LocationService.List
|
|||
m_distance = distance;
|
||||
m_azimut = azimut;
|
||||
|
||||
mLocation = new ParcelablePointD(lat, lon);
|
||||
|
||||
m_type = 1;
|
||||
}
|
||||
|
||||
//Native code return location in mercator coordinates, we need screen coordinates
|
||||
public AddressInfo getAddressInfo()
|
||||
{
|
||||
return new AddressInfo(m_name, m_amenity, Bookmark.GtoP(mLocation));
|
||||
}
|
||||
}
|
||||
|
||||
private String getCategoryName(String strID)
|
||||
|
@ -347,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)
|
||||
public String onItemClick(int position, Intent mapIntent)
|
||||
{
|
||||
if (isShowCategories())
|
||||
{
|
||||
|
@ -357,6 +372,8 @@ 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)
|
||||
{
|
||||
|
@ -364,6 +381,7 @@ 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
|
||||
|
@ -507,11 +525,12 @@ public class SearchActivity extends ListActivity implements LocationService.List
|
|||
{
|
||||
super.onListItemClick(l, v, position, id);
|
||||
|
||||
final String suggestion = getSA().onItemClick(position);
|
||||
Intent mapIntent = new Intent(this, MWMActivity.class);
|
||||
mapIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
final String suggestion = getSA().onItemClick(position, mapIntent);
|
||||
if (suggestion == null)
|
||||
{
|
||||
// close activity
|
||||
finish();
|
||||
startActivity(mapIntent);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.text.TextUtils.TruncateAt;
|
|||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class PopupLayout extends View
|
||||
{
|
||||
|
@ -82,14 +83,14 @@ public class PopupLayout extends View
|
|||
mTextPaint.setColor(Color.WHITE);
|
||||
}
|
||||
|
||||
public synchronized void activate(final Bookmark bmk)
|
||||
public synchronized void activate(final Bookmark bmk, WindowManager manager)
|
||||
{
|
||||
mBmk = bmk;
|
||||
if (bmk.isPreviewBookmark())
|
||||
{
|
||||
nDrawBookmark(bmk.getPosition().x, bmk.getPosition().y);
|
||||
}
|
||||
mPopup = prepareBitmap(mBmk);
|
||||
mPopup = prepareBitmap(mBmk, manager);
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
|
@ -126,7 +127,7 @@ public class PopupLayout extends View
|
|||
postInvalidate();
|
||||
}
|
||||
|
||||
private Bitmap prepareBitmap(Bookmark bmk)
|
||||
private Bitmap prepareBitmap(Bookmark bmk, WindowManager manager)
|
||||
{
|
||||
anchor = bmk.getPosition().getRoundedPoint();
|
||||
|
||||
|
@ -142,7 +143,7 @@ public class PopupLayout extends View
|
|||
}
|
||||
|
||||
String bmkName = bmk.getName();
|
||||
int pWidth = Math.min(getWidth(), getHeight()) - VERTICAL_MARGIN;
|
||||
int pWidth = Math.min(manager.getDefaultDisplay().getWidth(), manager.getDefaultDisplay().getHeight()) - VERTICAL_MARGIN;
|
||||
int pHeight = mHeight = btn.getHeight() + 10;
|
||||
int maxTextWidth = pWidth - btn.getWidth() - 10;
|
||||
int currentTextWidth = Math.round(mTextPaint.measureText(bmkName));
|
||||
|
|
|
@ -55,9 +55,19 @@ public class Bookmark
|
|||
mMercatorY = ll.y;
|
||||
}
|
||||
|
||||
public static ParcelablePointD GtoP(ParcelablePointD p)
|
||||
{
|
||||
return nGtoP(p.x, p.y);
|
||||
}
|
||||
|
||||
public static ParcelablePointD PtoG(ParcelablePointD p)
|
||||
{
|
||||
return nPtoG(p.x, p.y);
|
||||
}
|
||||
|
||||
private native DistanceAndAthimuth nGetDistanceAndAzimuth(double x, double y, double cLat, double cLon, double north);
|
||||
private native ParcelablePointD nGtoP(double lat, double lon);
|
||||
private native ParcelablePointD nPtoG(double px, double py);
|
||||
private static native ParcelablePointD nGtoP(double x, double y);
|
||||
private static native ParcelablePointD nPtoG(double px, double py);
|
||||
private native ParcelablePointD nGetXY(int c, long b);
|
||||
private native String nGetNamePos(double px, double py);
|
||||
private native String nGetName(int c, long b);
|
||||
|
|
Loading…
Add table
Reference in a new issue