forked from organicmaps/organicmaps
codereview
This commit is contained in:
parent
e996fe0ed4
commit
8be498f8d4
6 changed files with 89 additions and 148 deletions
|
@ -916,15 +916,15 @@ extern "C"
|
|||
Bookmark * b = g_framework->NativeFramework()->
|
||||
GetBookmarkManager().AdditionalPoiLayerGetBookmark(nIndex);
|
||||
|
||||
static jclass javaClazz = env->GetObjectClass(jsearchResult);
|
||||
const jclass javaClazz = env->GetObjectClass(jsearchResult);
|
||||
|
||||
static jfieldID nameId = env->GetFieldID(javaClazz, "mName", "Ljava/lang/String;");
|
||||
const jfieldID nameId = env->GetFieldID(javaClazz, "mName", "Ljava/lang/String;");
|
||||
env->SetObjectField(jsearchResult, nameId, jni::ToJavaString(env, b->GetName()));
|
||||
|
||||
static jfieldID latId = env->GetFieldID(javaClazz, "mLat", "D");
|
||||
const jfieldID latId = env->GetFieldID(javaClazz, "mLat", "D");
|
||||
env->SetDoubleField(jsearchResult, latId, static_cast<jdouble>(MercatorBounds::YToLat(b->GetOrg().y)));
|
||||
|
||||
static jfieldID lonId = env->GetFieldID(javaClazz, "mLon", "D");
|
||||
const jfieldID lonId = env->GetFieldID(javaClazz, "mLon", "D");
|
||||
env->SetDoubleField(jsearchResult, lonId, static_cast<jdouble>(MercatorBounds::XToLon(b->GetOrg().x)));
|
||||
}
|
||||
|
||||
|
|
|
@ -832,12 +832,12 @@ public class MWMActivity extends NvEventQueueActivity
|
|||
|
||||
// Calculate padding as one quarter of height
|
||||
int drawerItemsPadding = 0;
|
||||
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
||||
|
||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
|
||||
{
|
||||
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
||||
drawerItemsPadding = Math.max(dm.heightPixels, dm.widthPixels)/5;
|
||||
}
|
||||
|
||||
Log.d("DrawerPadding", "x=" + drawerItemsPadding);
|
||||
findViewById(R.id.scroll_up).setPadding(0,drawerItemsPadding, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -1266,7 +1266,7 @@ public class MWMActivity extends NvEventQueueActivity
|
|||
@Override
|
||||
public void onPoiActivated(final String name, final String type, final String address, final double lat, final double lon)
|
||||
{
|
||||
final MapObject.Poi poi = new MapObject.Poi(name, lat, lon, type);
|
||||
final MapObject poi = new MapObject.Poi(name, lat, lon, type);
|
||||
|
||||
runOnUiThread(new Runnable()
|
||||
{
|
||||
|
|
|
@ -553,7 +553,7 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
public void onClick(View v)
|
||||
{
|
||||
final Intent vrIntent = InputUtils.createIntentForVoiceRecognition(getResources().getString(R.string.search_map));
|
||||
startActivityForResult(vrIntent, RC_VOICE_RECOGNITIN);
|
||||
startActivityForResult(vrIntent, RC_VOICE_RECOGNITION);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -886,14 +886,14 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
|
||||
|
||||
// Handle voice recognition here
|
||||
private final static int RC_VOICE_RECOGNITIN = 0xCA11;
|
||||
private final static int RC_VOICE_RECOGNITION = 0xCA11;
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if ((requestCode == RC_VOICE_RECOGNITIN) && (resultCode == Activity.RESULT_OK))
|
||||
if ((requestCode == RC_VOICE_RECOGNITION) && (resultCode == Activity.RESULT_OK))
|
||||
{
|
||||
final String result = InputUtils.getMostConfidentResult(data);
|
||||
if (result != null)
|
||||
|
|
|
@ -12,16 +12,10 @@ public class Bookmark extends MapObject
|
|||
private int mBookmark;
|
||||
private double mMerX;
|
||||
private double mMerY;
|
||||
private double mLon;
|
||||
private double mLat;
|
||||
|
||||
//{@ Populate on creation or lazily?
|
||||
private String mName;
|
||||
//{@
|
||||
|
||||
|
||||
/* package */ Bookmark(int categoryId, int bookmarkId, String name)
|
||||
{
|
||||
super(name, 0, 0, "");
|
||||
|
||||
mCategoryId = categoryId;
|
||||
mBookmark = bookmarkId;
|
||||
mName = name;
|
||||
|
|
|
@ -3,41 +3,75 @@ package com.mapswithme.maps.bookmarks.data;
|
|||
import java.io.Serializable;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.SimpleLogger;
|
||||
|
||||
public abstract class MapObject
|
||||
{
|
||||
private static final Logger mLog = SimpleLogger.get("MwmMapObject");
|
||||
protected String mName;
|
||||
protected double mLat;
|
||||
protected double mLon;
|
||||
protected String mTypeName;
|
||||
|
||||
public MapObject(String name, double lat, double lon, String typeName)
|
||||
{
|
||||
mName = name;
|
||||
mLat = lat;
|
||||
mLon = lon;
|
||||
mTypeName = typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(mLat);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(mLon);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
result = prime * result + ((mName == null) ? 0 : mName.hashCode());
|
||||
result = prime * result + ((mTypeName == null) ? 0 : mTypeName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final MapObject other = (MapObject) obj;
|
||||
if (Double.doubleToLongBits(mLat) != Double.doubleToLongBits(other.mLat))
|
||||
return false;
|
||||
if (Double.doubleToLongBits(mLon) != Double.doubleToLongBits(other.mLon))
|
||||
return false;
|
||||
if (mName == null)
|
||||
{
|
||||
if (other.mName != null)
|
||||
return false;
|
||||
}
|
||||
else if (!mName.equals(other.mName))
|
||||
return false;
|
||||
if (mTypeName == null)
|
||||
{
|
||||
if (other.mTypeName != null)
|
||||
return false;
|
||||
}
|
||||
else if (!mTypeName.equals(other.mTypeName))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public double getScale() { return 0; };
|
||||
// Interface
|
||||
public abstract String getName();
|
||||
public abstract double getLat();
|
||||
public abstract double getLon();
|
||||
public abstract String getPoiTypeName();
|
||||
public String getName() { return mName; }
|
||||
public double getLat() { return mLat; }
|
||||
public double getLon() { return mLon; }
|
||||
public String getPoiTypeName() { return mTypeName; }
|
||||
|
||||
public abstract MapObjectType getType();
|
||||
// interface
|
||||
|
||||
public static Integer checkSum(MapObject mo)
|
||||
{
|
||||
if (mo == null) return 0;
|
||||
|
||||
final int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23};
|
||||
|
||||
final int base = primes[mo.getType().ordinal()];
|
||||
final int component1 = Double.valueOf(mo.getLat()).hashCode();
|
||||
final int component2 = Double.valueOf(mo.getLon()).hashCode();
|
||||
final int component3 = mo.getName() == null ? base : mo.getName().hashCode();
|
||||
|
||||
final int sum = (component1 << base)
|
||||
+ (component2 >> base)
|
||||
+ component3;
|
||||
|
||||
mLog.d(String.format("c1=%d c2=%d c3=%d sum=%d", component1, component2, component3, sum));
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static enum MapObjectType implements Serializable
|
||||
{
|
||||
|
@ -50,35 +84,9 @@ public abstract class MapObject
|
|||
|
||||
public static class Poi extends MapObject
|
||||
{
|
||||
private final String mName;
|
||||
private final double mLat;
|
||||
private final double mLon;
|
||||
private final String mTypeName;
|
||||
|
||||
public Poi(String name, double lat, double lon, String typeName)
|
||||
{
|
||||
mName = name;
|
||||
mLat = lat;
|
||||
mLon = lon;
|
||||
mTypeName = typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLat()
|
||||
{
|
||||
return mLat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLon()
|
||||
{
|
||||
return mLon;
|
||||
super(name, lat, lon, typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,97 +94,31 @@ public abstract class MapObject
|
|||
{
|
||||
return MapObjectType.POI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPoiTypeName()
|
||||
{
|
||||
return mTypeName;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SearchResult extends MapObject
|
||||
{
|
||||
private String mName;
|
||||
private double mLat;
|
||||
private double mLon;
|
||||
private String mTypeName;
|
||||
|
||||
public SearchResult(long index)
|
||||
{
|
||||
super("", 0, 0, "");
|
||||
Framework.injectData(this, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLat()
|
||||
{
|
||||
return mLat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLon()
|
||||
{
|
||||
return mLon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapObjectType getType()
|
||||
{
|
||||
return MapObjectType.ADDITIONAL_LAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPoiTypeName()
|
||||
{
|
||||
return mTypeName;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiPoint extends MapObject
|
||||
{
|
||||
private final String mName;
|
||||
private final String mId;
|
||||
private final String mPoiType;
|
||||
private final double mLat;
|
||||
private final double mLon;
|
||||
|
||||
|
||||
public ApiPoint(String name, String id, String poiType, double lat, double lon)
|
||||
{
|
||||
this.mName = name;
|
||||
this.mId = id;
|
||||
this.mPoiType = poiType;
|
||||
this.mLat = lat;
|
||||
this.mLon = lon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLat()
|
||||
{
|
||||
return mLat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLon()
|
||||
{
|
||||
return mLon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPoiTypeName()
|
||||
{
|
||||
return mPoiType;
|
||||
super(name, lat, lon, poiType);
|
||||
mId = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -141,7 +141,7 @@ public class MapInfoView extends LinearLayout
|
|||
|
||||
if (mMapObject.getType() == MapObjectType.BOOKMARK)
|
||||
{
|
||||
final Poi p = new Poi(mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon(), null);
|
||||
final MapObject p = new Poi(mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon(), null);
|
||||
bm.deleteBookmark((Bookmark) mMapObject);
|
||||
setMapObject(p);
|
||||
}
|
||||
|
@ -329,7 +329,12 @@ public class MapInfoView extends LinearLayout
|
|||
|
||||
public boolean hasThatObject(MapObject mo)
|
||||
{
|
||||
return MapObject.checkSum(mo).equals(MapObject.checkSum(mMapObject));
|
||||
if (mo == null && mMapObject == null)
|
||||
return true;
|
||||
else if (mMapObject != null)
|
||||
return mMapObject.equals(mo);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setMapObject(MapObject mo)
|
||||
|
@ -349,7 +354,7 @@ public class MapInfoView extends LinearLayout
|
|||
{
|
||||
case POI:
|
||||
mIsBookmarked.setChecked(false);
|
||||
setBodyForPOI((Poi) mo);
|
||||
setBodyForPOI(mo);
|
||||
break;
|
||||
case BOOKMARK:
|
||||
mIsBookmarked.setChecked(true);
|
||||
|
@ -479,7 +484,7 @@ public class MapInfoView extends LinearLayout
|
|||
}
|
||||
}
|
||||
|
||||
private void setBodyForPOI(Poi poi)
|
||||
private void setBodyForPOI(MapObject poi)
|
||||
{
|
||||
mBodyContainer.removeAllViews();
|
||||
final View poiView = mInflater.inflate(R.layout.info_box_poi, null);
|
||||
|
@ -598,7 +603,7 @@ public class MapInfoView extends LinearLayout
|
|||
if (deleted)
|
||||
{
|
||||
// Make Poi from bookmark
|
||||
final Poi p = new Poi(mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon(), null);
|
||||
final MapObject p = new Poi(mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon(), null);
|
||||
setMapObject(p);
|
||||
// TODO how to handle the case, when bookmark was moved to another group?
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue