forked from organicmaps/organicmaps
[android] Refactored and fixed azimuth display.
This commit is contained in:
parent
ab91a74d83
commit
4c3c4896bb
7 changed files with 20 additions and 126 deletions
|
@ -68,9 +68,9 @@ public class Framework
|
|||
|
||||
public native static double[] getScreenRectCenter();
|
||||
|
||||
public native static DistanceAndAzimut nativeGetDistanceAndAzimut(double merX, double merY, double cLat, double cLon, double north);
|
||||
public native static DistanceAndAzimut nativeGetDistanceAndAzimut(double dstMerX, double dstMerY, double srcLat, double srcLon, double north);
|
||||
|
||||
public native static DistanceAndAzimut nativeGetDistanceAndAzimutFromLatLon(double lat, double lon, double cLat, double cLon, double north);
|
||||
public native static DistanceAndAzimut nativeGetDistanceAndAzimutFromLatLon(double dstLat, double dstLon, double srcLat, double srcLon, double north);
|
||||
|
||||
public native static String nativeFormatLatLon(double lat, double lon, boolean useDMSFormat);
|
||||
|
||||
|
|
|
@ -2,23 +2,22 @@ package com.mapswithme.maps.bookmarks.data;
|
|||
|
||||
public class DistanceAndAzimut
|
||||
{
|
||||
private String m_distance;
|
||||
private double m_athimuth;
|
||||
private String mDistance;
|
||||
private double mAzimuth;
|
||||
|
||||
public String getDistance()
|
||||
{
|
||||
return m_distance;
|
||||
return mDistance;
|
||||
}
|
||||
|
||||
public double getAthimuth()
|
||||
public double getAzimuth()
|
||||
{
|
||||
return m_athimuth;
|
||||
return mAzimuth;
|
||||
}
|
||||
|
||||
public DistanceAndAzimut(String m_distance, double m_athimuth)
|
||||
public DistanceAndAzimut(String distance, double azimuth)
|
||||
{
|
||||
super();
|
||||
this.m_distance = m_distance;
|
||||
this.m_athimuth = m_athimuth;
|
||||
mDistance = distance;
|
||||
mAzimuth = azimuth;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.mapswithme.maps.routing;
|
|||
|
||||
import android.location.Location;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
|
@ -91,7 +90,7 @@ public class RoutingInfo
|
|||
public void setTurnDrawable(ImageView view, DistanceAndAzimut distanceAndAzimut)
|
||||
{
|
||||
view.setImageResource(R.drawable.ic_direction_pedestrian);
|
||||
ViewHelper.setRotation(view, -(float) Math.toDegrees(distanceAndAzimut.getAthimuth()));
|
||||
ViewHelper.setRotation(view, (float) Math.toDegrees(distanceAndAzimut.getAzimuth()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,10 +133,4 @@ public class RoutingInfo
|
|||
this.pedestrianNextDirection.setLatitude(pedestrianDirectionLat);
|
||||
this.pedestrianNextDirection.setLongitude(pedestrianDirectionLon);
|
||||
}
|
||||
|
||||
private void dumpLanes(SingleLaneInfo[] lanes)
|
||||
{
|
||||
for (int j = 0; j < lanes.length; j++)
|
||||
Log.d("JNIARRAY", " " + "Lane number " + j + ". " + lanes[j]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,117 +8,22 @@ import android.widget.ImageView;
|
|||
|
||||
public class ArrowView extends ImageView
|
||||
{
|
||||
static private String TAG = ArrowView.class.getName();
|
||||
|
||||
private final static long UPDATE_RATE = 30;
|
||||
private final static long UPDATE_DELAY = 1000 / UPDATE_RATE;
|
||||
private final static double ROTATION_SPEED = 120;
|
||||
private final static double ROTATION_STEP = ROTATION_SPEED / UPDATE_RATE;
|
||||
private final static double ERR = ROTATION_STEP;
|
||||
|
||||
private float mWidth;
|
||||
private float mHeight;
|
||||
|
||||
private final static int ALLOW_ANIMATION = 0x1;
|
||||
private final static int DO_ANIMATION = 0x2;
|
||||
private final static int DRAW_ARROW = 0x4;
|
||||
private final static int DRAW_CIRCLE = 0x8;
|
||||
private int mFlags = 0;
|
||||
|
||||
// Animation params
|
||||
private float mCurrentAngle;
|
||||
private float mAngle;
|
||||
|
||||
private boolean testFlag(int flag)
|
||||
{
|
||||
return (mFlags & flag) != 0;
|
||||
}
|
||||
|
||||
private void setFlag(int flag, boolean value)
|
||||
{
|
||||
if (value)
|
||||
mFlags |= flag;
|
||||
else
|
||||
mFlags &= (~flag);
|
||||
}
|
||||
|
||||
private Runnable mAnimateTask = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (step())
|
||||
postDelayed(this, UPDATE_DELAY);
|
||||
}
|
||||
};
|
||||
|
||||
public ArrowView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public void setDrawCircle(boolean draw)
|
||||
public void setAzimuth(double azimuth)
|
||||
{
|
||||
setFlag(DRAW_CIRCLE, draw);
|
||||
}
|
||||
|
||||
public void setAnimation(boolean allow)
|
||||
{
|
||||
setFlag(ALLOW_ANIMATION, allow);
|
||||
}
|
||||
|
||||
public void setAzimut(double azimut)
|
||||
{
|
||||
mAngle = (float) Math.toDegrees(azimut - Math.PI / 2); // subtract PI / 2 case initial image is vertically oriented
|
||||
|
||||
if (testFlag(ALLOW_ANIMATION) && testFlag(DO_ANIMATION))
|
||||
animateRotation();
|
||||
else
|
||||
{
|
||||
mCurrentAngle = mAngle; // to skip rotation from 0
|
||||
setFlag(DO_ANIMATION, true);
|
||||
}
|
||||
|
||||
mAngle = (float) Math.toDegrees(azimuth);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void animateRotation()
|
||||
{
|
||||
removeCallbacks(mAnimateTask);
|
||||
post(mAnimateTask);
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
setFlag(DRAW_ARROW, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow()
|
||||
{
|
||||
super.onDetachedFromWindow();
|
||||
removeCallbacks(mAnimateTask);
|
||||
}
|
||||
|
||||
private boolean step()
|
||||
{
|
||||
final double diff = mAngle - mCurrentAngle;
|
||||
if (Math.abs(diff) > ERR)
|
||||
{
|
||||
// Choosing the shortest way at [0, 360] looped segment
|
||||
final double signum = -1 * Math.signum(diff) * Math.signum(Math.abs(diff) - 180);
|
||||
mCurrentAngle += signum * ROTATION_STEP;
|
||||
if (mCurrentAngle < 0)
|
||||
mCurrentAngle += 360;
|
||||
else if (mCurrentAngle > 360)
|
||||
mCurrentAngle -= 360;
|
||||
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh)
|
||||
{
|
||||
|
@ -132,7 +37,7 @@ public class ArrowView extends ImageView
|
|||
protected void onDraw(@NonNull Canvas canvas)
|
||||
{
|
||||
canvas.save();
|
||||
canvas.rotate(-mCurrentAngle, mWidth / 2, mHeight / 2);
|
||||
canvas.rotate(mAngle, mWidth / 2, mHeight / 2);
|
||||
super.onDraw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
|
|
|
@ -294,7 +294,7 @@ public class RoutingLayout extends FrameLayout implements CompoundButton.OnCheck
|
|||
{
|
||||
Location location = LocationHelper.INSTANCE.getLastLocation();
|
||||
DistanceAndAzimut distanceAndAzimut = Framework.nativeGetDistanceAndAzimutFromLatLon(
|
||||
mEndPoint.getLat(), mEndPoint.getLon(), location.getLatitude(), location.getLongitude(), mNorth);
|
||||
info.pedestrianNextDirection.getLatitude(), info.pedestrianNextDirection.getLongitude(), location.getLatitude(), location.getLongitude(), mNorth);
|
||||
|
||||
String[] splitDistance = distanceAndAzimut.getDistance().split(" ");
|
||||
mTvTurnDistance.setText(getSpannedDistance(getResources().getDimensionPixelSize(R.dimen.text_size_display_1),
|
||||
|
|
|
@ -131,13 +131,10 @@ public class DirectionFragment extends DialogFragment implements LocationHelper.
|
|||
mMapObject.getLat(), mMapObject.getLon(),
|
||||
last.getLatitude(), last.getLongitude(), north);
|
||||
|
||||
if (da.getAthimuth() >= 0)
|
||||
mAvDirection.setAzimut(da.getAthimuth());
|
||||
if (da.getAzimuth() >= 0)
|
||||
mAvDirection.setAzimuth(da.getAzimuth());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationError(int errorCode)
|
||||
{
|
||||
|
||||
}
|
||||
public void onLocationError(int errorCode) {}
|
||||
}
|
||||
|
|
|
@ -535,10 +535,10 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
mMapObject.getLat(), mMapObject.getLon(),
|
||||
l.getLatitude(), l.getLongitude(), northAzimuth);
|
||||
|
||||
if (da.getAthimuth() >= 0)
|
||||
if (da.getAzimuth() >= 0)
|
||||
{
|
||||
mAvDirection.setVisibility(View.VISIBLE);
|
||||
mAvDirection.setAzimut(da.getAthimuth());
|
||||
mAvDirection.setAzimuth(da.getAzimuth());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue