Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
fd9f2739b5
5 changed files with 61 additions and 112 deletions
|
@ -188,8 +188,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
private boolean mIsDestroyed = false;
|
||||
private InAppHelper inAppHelper;
|
||||
|
||||
private DrawerLayout.DrawerListener drawerListener;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
long tm = System.currentTimeMillis();
|
||||
|
@ -291,30 +289,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
|
||||
mapActions.updateDrawerMenu();
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
drawerListener = new DrawerLayout.DrawerListener() {
|
||||
@Override
|
||||
public void onDrawerSlide(View drawerView, float slideOffset) {
|
||||
mapView.setMultiTouch(false);
|
||||
mapView.setMultiTouchEndTime(0);
|
||||
mapView.getLayerByClass(RulerControlLayer.class).refreshMapDelayed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerClosed(View drawerView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerStateChanged(int newState) {
|
||||
|
||||
}
|
||||
};
|
||||
drawerLayout.addDrawerListener(drawerListener);
|
||||
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
|
||||
screenOffReceiver = new ScreenOffReceiver();
|
||||
|
@ -1009,9 +983,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
if (inAppHelper != null) {
|
||||
inAppHelper.stop();
|
||||
}
|
||||
if (drawerLayout != null) {
|
||||
drawerLayout.removeDrawerListener(drawerListener);
|
||||
}
|
||||
mIsDestroyed = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@ public class MultiTouchSupport {
|
|||
|
||||
public void onGestureInit(float x1, float y1, float x2, float y2);
|
||||
|
||||
public void onActionPointerDownOrMove(float x1, float y1, float x2, float y2);
|
||||
|
||||
public void onActionPointerUp();
|
||||
|
||||
public void onActionCancel();
|
||||
}
|
||||
|
||||
private boolean multiTouchAPISupported = false;
|
||||
|
@ -86,6 +86,9 @@ public class MultiTouchSupport {
|
|||
}
|
||||
int actionCode = event.getAction() & ACTION_MASK;
|
||||
try {
|
||||
if (actionCode == MotionEvent.ACTION_CANCEL) {
|
||||
listener.onActionCancel();
|
||||
}
|
||||
Integer pointCount = (Integer) getPointerCount.invoke(event);
|
||||
if(pointCount < 2){
|
||||
if(inZoomMode){
|
||||
|
@ -106,9 +109,7 @@ public class MultiTouchSupport {
|
|||
angleDefined = true;
|
||||
angle = (float) (Math.atan2(y2 - y1, x2 -x1) * 180 / Math.PI);
|
||||
}
|
||||
if (actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_MOVE) {
|
||||
listener.onActionPointerDownOrMove(x1, y1, x2, y2);
|
||||
} else if (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_POINTER_UP) {
|
||||
if (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_POINTER_UP) {
|
||||
listener.onActionPointerUp();
|
||||
}
|
||||
if (actionCode == ACTION_POINTER_DOWN) {
|
||||
|
|
|
@ -161,12 +161,11 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
private boolean afterDoubleTap = false;
|
||||
private boolean wasMapLinkedBeforeGesture = false;
|
||||
|
||||
private float firstTouchPointX;
|
||||
private float firstTouchPointY;
|
||||
private float secondTouchPointX;
|
||||
private float secondTouchPointY;
|
||||
private LatLon firstTouchPointLatLon;
|
||||
private LatLon secondTouchPointLatLon;
|
||||
private boolean multiTouch;
|
||||
private long multiTouchEndTime;
|
||||
private boolean wasZoomInMultiTouch;
|
||||
|
||||
public OsmandMapTileView(MapActivity activity, int w, int h) {
|
||||
this.activity = activity;
|
||||
|
@ -312,36 +311,28 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
}
|
||||
|
||||
// ///////////////////////// NON UI PART (could be extracted in common) /////////////////////////////
|
||||
public float getFirstTouchPointX() {
|
||||
return firstTouchPointX;
|
||||
public LatLon getFirstTouchPointLatLon() {
|
||||
return firstTouchPointLatLon;
|
||||
}
|
||||
|
||||
public float getFirstTouchPointY() {
|
||||
return firstTouchPointY;
|
||||
}
|
||||
|
||||
public float getSecondTouchPointX() {
|
||||
return secondTouchPointX;
|
||||
}
|
||||
|
||||
public float getSecondTouchPointY() {
|
||||
return secondTouchPointY;
|
||||
public LatLon getSecondTouchPointLatLon() {
|
||||
return secondTouchPointLatLon;
|
||||
}
|
||||
|
||||
public boolean isMultiTouch() {
|
||||
return multiTouch;
|
||||
}
|
||||
|
||||
public void setMultiTouch(boolean multiTouch) {
|
||||
this.multiTouch = multiTouch;
|
||||
}
|
||||
|
||||
public long getMultiTouchEndTime() {
|
||||
return multiTouchEndTime;
|
||||
}
|
||||
|
||||
public void setMultiTouchEndTime(long multiTouchEndTime) {
|
||||
this.multiTouchEndTime = multiTouchEndTime;
|
||||
public boolean isWasZoomInMultiTouch() {
|
||||
return wasZoomInMultiTouch;
|
||||
}
|
||||
|
||||
public void setWasZoomInMultiTouch(boolean wasZoomInMultiTouch) {
|
||||
this.wasZoomInMultiTouch = wasZoomInMultiTouch;
|
||||
}
|
||||
|
||||
public void setIntZoom(int zoom) {
|
||||
|
@ -999,8 +990,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
private LatLon initialCenterLatLon;
|
||||
private boolean startRotating = false;
|
||||
private static final float ANGLE_THRESHOLD = 30;
|
||||
private int cacheIntZoom = getZoom();
|
||||
private double cacheFractionalZoom = getZoomFractionalPart();
|
||||
|
||||
@Override
|
||||
public void onZoomOrRotationEnded(double relativeToStart, float angleRelative) {
|
||||
|
@ -1049,35 +1038,29 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
if (x1 != x2 || y1 != y2) {
|
||||
firstTouchPointX = x1;
|
||||
firstTouchPointY = y1;
|
||||
secondTouchPointX = x2;
|
||||
secondTouchPointY = y2;
|
||||
firstTouchPointLatLon = currentViewport.getLatLonFromPixel(x1, y1);
|
||||
secondTouchPointLatLon = currentViewport.getLatLonFromPixel(x2, y2);
|
||||
multiTouch = true;
|
||||
wasZoomInMultiTouch = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionPointerDownOrMove(float x1, float y1, float x2, float y2) {
|
||||
firstTouchPointX = x1;
|
||||
firstTouchPointY = y1;
|
||||
secondTouchPointX = x2;
|
||||
secondTouchPointY = y2;
|
||||
multiTouch = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionPointerUp() {
|
||||
multiTouch = false;
|
||||
if (cacheIntZoom != getZoom() || cacheFractionalZoom != getZoomFractionalPart()) {
|
||||
cacheIntZoom = getZoom();
|
||||
cacheFractionalZoom = getZoomFractionalPart();
|
||||
multiTouchEndTime = 0;
|
||||
if (isZooming()) {
|
||||
wasZoomInMultiTouch = true;
|
||||
} else {
|
||||
multiTouchEndTime = System.currentTimeMillis();
|
||||
wasZoomInMultiTouch = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionCancel() {
|
||||
multiTouch = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onZoomStarted(PointF centerPoint) {
|
||||
initialMultiTouchCenterPoint = centerPoint;
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.os.Message;
|
|||
import android.view.View;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.QuadPoint;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
|
@ -27,7 +28,7 @@ import gnu.trove.list.array.TIntArrayList;
|
|||
|
||||
public class RulerControlLayer extends OsmandMapLayer {
|
||||
|
||||
public static final long DELAY = 1500;
|
||||
public static final long DELAY = 2000;
|
||||
private static final int TEXT_SIZE = 14;
|
||||
|
||||
private final MapActivity mapActivity;
|
||||
|
@ -40,10 +41,10 @@ public class RulerControlLayer extends OsmandMapLayer {
|
|||
private float maxRadius;
|
||||
private int radius;
|
||||
private double roundedDist;
|
||||
private boolean showTwoFingersDistance;
|
||||
|
||||
private QuadPoint cacheCenter;
|
||||
private int cacheIntZoom;
|
||||
private double cacheFractionalZoom;
|
||||
private double cacheTileX;
|
||||
private double cacheTileY;
|
||||
private long cacheMultiTouchEndTime;
|
||||
|
@ -64,6 +65,10 @@ public class RulerControlLayer extends OsmandMapLayer {
|
|||
this.mapActivity = mapActivity;
|
||||
}
|
||||
|
||||
public boolean isShowTwoFingersDistance() {
|
||||
return showTwoFingersDistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLayer(final OsmandMapTileView view) {
|
||||
app = mapActivity.getMyApplication();
|
||||
|
@ -113,21 +118,21 @@ public class RulerControlLayer extends OsmandMapLayer {
|
|||
final QuadPoint center = tb.getCenterPixelPoint();
|
||||
final RulerMode mode = app.getSettings().RULER_MODE.get();
|
||||
|
||||
if (cacheIntZoom != view.getZoom() || cacheFractionalZoom != view.getZoomFractionalPart()) {
|
||||
cacheIntZoom = view.getZoom();
|
||||
cacheFractionalZoom = view.getZoomFractionalPart();
|
||||
view.setMultiTouchEndTime(0);
|
||||
cacheMultiTouchEndTime = 0;
|
||||
if (view.isMultiTouch() && view.isZooming()) {
|
||||
view.setWasZoomInMultiTouch(true);
|
||||
} else if (cacheMultiTouchEndTime != view.getMultiTouchEndTime()) {
|
||||
cacheMultiTouchEndTime = view.getMultiTouchEndTime();
|
||||
refreshMapDelayed();
|
||||
}
|
||||
if (!view.isZooming() && view.isMultiTouch() || System.currentTimeMillis() - cacheMultiTouchEndTime < DELAY) {
|
||||
float x1 = view.getFirstTouchPointX();
|
||||
float y1 = view.getFirstTouchPointY();
|
||||
float x2 = view.getSecondTouchPointX();
|
||||
float y2 = view.getSecondTouchPointY();
|
||||
drawFingerDistance(canvas, tb, center, x1, y1, x2, y2, settings.isNightMode());
|
||||
showTwoFingersDistance = !view.isWasZoomInMultiTouch() && !view.isZooming() && (view.isMultiTouch() || System.currentTimeMillis() - cacheMultiTouchEndTime < DELAY);
|
||||
if (showTwoFingersDistance) {
|
||||
LatLon firstTouchPoint = view.getFirstTouchPointLatLon();
|
||||
LatLon secondTouchPoint = view.getSecondTouchPointLatLon();
|
||||
float x1 = tb.getPixXFromLonNoRot(firstTouchPoint.getLongitude());
|
||||
float y1 = tb.getPixYFromLatNoRot(firstTouchPoint.getLatitude());
|
||||
float x2 = tb.getPixXFromLonNoRot(secondTouchPoint.getLongitude());
|
||||
float y2 = tb.getPixYFromLatNoRot(secondTouchPoint.getLatitude());
|
||||
drawFingerDistance(canvas, x1, y1, x2, y2, settings.isNightMode());
|
||||
} else if (mode == RulerMode.FIRST) {
|
||||
drawCenterIcon(canvas, tb, center, settings.isNightMode());
|
||||
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
|
||||
|
@ -149,12 +154,10 @@ public class RulerControlLayer extends OsmandMapLayer {
|
|||
handler.sendEmptyMessageDelayed(0, DELAY + 50);
|
||||
}
|
||||
|
||||
private void drawFingerDistance(Canvas canvas, RotatedTileBox tb, QuadPoint center, float x1, float y1, float x2, float y2, boolean nightMode) {
|
||||
canvas.rotate(-tb.getRotate(), center.x, center.y);
|
||||
private void drawFingerDistance(Canvas canvas, float x1, float y1, float x2, float y2, boolean nightMode) {
|
||||
canvas.drawLine(x1, y1, x2, y2, lineAttrs.paint);
|
||||
drawFingerTouchIcon(canvas, x1, y1, nightMode);
|
||||
drawFingerTouchIcon(canvas, x2, y2, nightMode);
|
||||
canvas.rotate(tb.getRotate(), center.x, center.y);
|
||||
}
|
||||
|
||||
private void drawFingerTouchIcon(Canvas canvas, float x, float y, boolean nightMode) {
|
||||
|
|
|
@ -150,7 +150,7 @@ public class MapInfoWidgetsFactory {
|
|||
RulerMode mode = rulerMode.get();
|
||||
if (mode == RulerMode.FIRST) {
|
||||
return RULER_CONTROL_WIDGET_STATE_FIRST_MODE;
|
||||
} else if (mode == RulerMode.SECOND){
|
||||
} else if (mode == RulerMode.SECOND) {
|
||||
return RULER_CONTROL_WIDGET_STATE_SECOND_MODE;
|
||||
} else {
|
||||
return RULER_CONTROL_WIDGET_STATE_EMPTY_MODE;
|
||||
|
@ -184,30 +184,23 @@ public class MapInfoWidgetsFactory {
|
|||
|
||||
public TextInfoWidget createRulerControl(final MapActivity map) {
|
||||
final String title = map.getResources().getString(R.string.map_widget_show_ruler);
|
||||
final TextInfoWidget rulerControl = new TextInfoWidget(map) {
|
||||
boolean needNewLatLon;
|
||||
long cacheMultiTouchEndTime;
|
||||
final TextInfoWidget rulerControl = new TextInfoWidget(map) {
|
||||
RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer();
|
||||
LatLon cacheFirstTouchPoint = new LatLon(0, 0);
|
||||
LatLon cacheSecondTouchPoint = new LatLon(0, 0);
|
||||
|
||||
@Override
|
||||
public boolean updateInfo(DrawSettings drawSettings) {
|
||||
RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get();
|
||||
OsmandMapTileView view = map.getMapView();
|
||||
|
||||
if (cacheMultiTouchEndTime != view.getMultiTouchEndTime()) {
|
||||
cacheMultiTouchEndTime = view.getMultiTouchEndTime();
|
||||
needNewLatLon = true;
|
||||
}
|
||||
if (!view.isZooming() && view.isMultiTouch() || System.currentTimeMillis() - cacheMultiTouchEndTime < RulerControlLayer.DELAY) {
|
||||
if (needNewLatLon) {
|
||||
float x1 = view.getFirstTouchPointX();
|
||||
float y1 = view.getFirstTouchPointY();
|
||||
float x2 = view.getSecondTouchPointX();
|
||||
float y2 = view.getSecondTouchPointY();
|
||||
LatLon firstFinger = view.getCurrentRotatedTileBox().getLatLonFromPixel(x1, y1);
|
||||
LatLon secondFinger = view.getCurrentRotatedTileBox().getLatLonFromPixel(x2, y2);
|
||||
setDistanceText(firstFinger.getLatitude(), firstFinger.getLongitude(),
|
||||
secondFinger.getLatitude(), secondFinger.getLongitude());
|
||||
needNewLatLon = false;
|
||||
if (rulerLayer.isShowTwoFingersDistance()) {
|
||||
if (!cacheFirstTouchPoint.equals(view.getFirstTouchPointLatLon()) ||
|
||||
!cacheSecondTouchPoint.equals(view.getSecondTouchPointLatLon())) {
|
||||
cacheFirstTouchPoint = view.getFirstTouchPointLatLon();
|
||||
cacheSecondTouchPoint = view.getSecondTouchPointLatLon();
|
||||
setDistanceText(cacheFirstTouchPoint.getLatitude(), cacheFirstTouchPoint.getLongitude(),
|
||||
cacheSecondTouchPoint.getLatitude(), cacheSecondTouchPoint.getLongitude());
|
||||
}
|
||||
} else if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) {
|
||||
Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||
|
@ -217,10 +210,8 @@ public class MapInfoWidgetsFactory {
|
|||
setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(),
|
||||
centerLoc.getLatitude(), centerLoc.getLongitude());
|
||||
}
|
||||
needNewLatLon = true;
|
||||
} else {
|
||||
setText(title, null);
|
||||
needNewLatLon = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue