Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-12-19 15:37:23 +01:00
commit 5de094c4ab
2 changed files with 86 additions and 46 deletions

View file

@ -248,15 +248,20 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
if (appModeChanged) { if (appModeChanged) {
wasInit = init(latLon, pointDescription, object); wasInit = init(latLon, pointDescription, object);
} }
if (wasInit && !MapContextMenuFragment.showInstance(this, mapActivity)) { if (wasInit && !MapContextMenuFragment.showInstance(this, mapActivity, true)) {
active = false; active = false;
} }
} else {
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null) {
fragmentRef.get().centerMarkerLocation();
}
} }
} }
public void show(LatLon latLon, PointDescription pointDescription, Object object) { public void show(LatLon latLon, PointDescription pointDescription, Object object) {
if (init(latLon, pointDescription, object)) { if (init(latLon, pointDescription, object)) {
if (!MapContextMenuFragment.showInstance(this, mapActivity)) { if (!MapContextMenuFragment.showInstance(this, mapActivity, false)) {
active = false; active = false;
} }
} }

View file

@ -92,6 +92,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
private boolean customMapCenter; private boolean customMapCenter;
private boolean moving; private boolean moving;
private boolean nightMode; private boolean nightMode;
private boolean centered;
private float skipHalfScreenStateLimit; private float skipHalfScreenStateLimit;
@ -252,7 +253,6 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
private float maxVelocityY; private float maxVelocityY;
private boolean hasMoved; private boolean hasMoved;
private boolean centered;
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
@ -261,9 +261,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
moving = false; moving = false;
int posY = getViewY(); int posY = getViewY();
if (!centered) { if (!centered) {
showOnMap(menu.getLatLon(), true, false, centerMarkerLocation();
map.getCurrentRotatedTileBox().getPixHeight() / 2 < posY - markerPaddingPx);
centered = true;
} }
if (hasMoved) { if (hasMoved) {
applyPosY(posY, false, false, 0, 0); applyPosY(posY, false, false, 0, 0);
@ -541,7 +539,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
.start(); .start();
if (needMapAdjust) { if (needMapAdjust) {
adjustMapPosition(posY, true); adjustMapPosition(posY, true, centered);
} }
} else { } else {
setViewY(posY, false, needMapAdjust); setViewY(posY, false, needMapAdjust);
@ -689,6 +687,9 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
if (menu.displayDistanceDirection()) { if (menu.displayDistanceDirection()) {
getMapActivity().getMapViewTrackingUtilities().setContextMenu(menu); getMapActivity().getMapViewTrackingUtilities().setContextMenu(menu);
} }
if (centered) {
centerMarkerLocation();
}
} }
@Override @Override
@ -770,7 +771,12 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
}); });
} }
private void showOnMap(LatLon latLon, boolean updateCoords, boolean ignoreCoef, boolean needMove) { public void centerMarkerLocation() {
centered = true;
showOnMap(menu.getLatLon(), true, false, true, false);
}
private void showOnMap(LatLon latLon, boolean updateCoords, boolean ignoreCoef, boolean needMove, boolean alreadyAdjusted) {
AnimateDraggingMapThread thread = map.getAnimatedDraggingThread(); AnimateDraggingMapThread thread = map.getAnimatedDraggingThread();
int fZoom = map.getZoom(); int fZoom = map.getZoom();
double flat = latLon.getLatitude(); double flat = latLon.getLatitude();
@ -793,6 +799,12 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
origMarkerY = cp.getCenterPixelY(); origMarkerY = cp.getCenterPixelY();
} }
if (!alreadyAdjusted) {
LatLon adjustedLatLon = getAdjustedMarkerLocation(getPosY(), new LatLon(flat, flon), true);
flat = adjustedLatLon.getLatitude();
flon = adjustedLatLon.getLongitude();
}
if (needMove) { if (needMove) {
thread.startMoving(flat, flon, fZoom, true); thread.startMoving(flat, flon, fZoom, true);
} }
@ -921,53 +933,71 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
if (!customMapCenter) { if (!customMapCenter) {
if (adjustMapPos) { if (adjustMapPos) {
adjustMapPosition(y, animated); adjustMapPosition(y, animated, centered);
} }
} else { } else {
customMapCenter = false; customMapCenter = false;
} }
} }
private void adjustMapPosition(int y, boolean animated) { private void adjustMapPosition(int y, boolean animated, boolean center) {
double markerLat = menu.getLatLon().getLatitude(); LatLon latlon = getAdjustedMarkerLocation(y, menu.getLatLon(), center);
double markerLon = menu.getLatLon().getLongitude();
RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
LatLon latlon = mapCenter;
if (menu.isLandscapeLayout()) {
int markerX = (int)box.getPixXFromLatLon(markerLat, markerLon);
int x = dpToPx(menu.getLandscapeWidthDp());
if (markerX - markerPaddingXPx < x || markerX > origMarkerX) {
int dx = (x + markerPaddingXPx) - markerX;
if (markerX - dx <= origMarkerX) {
QuadPoint cp = box.getCenterPixelPoint();
latlon = box.getLatLonFromPixel(cp.x - dx, cp.y);
} else {
latlon = box.getCenterLatLon();
}
}
} else {
int markerY = (int)box.getPixYFromLatLon(markerLat, markerLon);
if (markerY + markerPaddingPx > y || markerY < origMarkerY) {
int dy = markerY - (y - markerPaddingPx);
if (markerY - dy <= origMarkerY) {
QuadPoint cp = box.getCenterPixelPoint();
latlon = box.getLatLonFromPixel(cp.x + 0, cp.y + dy);
}
}
}
if (map.getLatitude() == latlon.getLatitude() && map.getLongitude() == latlon.getLongitude()) { if (map.getLatitude() == latlon.getLatitude() && map.getLongitude() == latlon.getLongitude()) {
return; return;
} }
if (animated) { if (animated) {
showOnMap(latlon, false, true, true); showOnMap(latlon, false, true, true, true);
} else { } else {
map.setLatLon(latlon.getLatitude(), latlon.getLongitude()); map.setLatLon(latlon.getLatitude(), latlon.getLongitude());
} }
} }
private LatLon getAdjustedMarkerLocation(int y, LatLon reqMarkerLocation, boolean center) {
double markerLat = reqMarkerLocation.getLatitude();
double markerLon = reqMarkerLocation.getLongitude();
RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
LatLon latlon;
if (center) {
latlon = reqMarkerLocation;
} else {
latlon = mapCenter;
}
if (menu.isLandscapeLayout()) {
int markerX = (int)box.getPixXFromLatLon(markerLat, markerLon);
int x = dpToPx(menu.getLandscapeWidthDp());
if (markerX - markerPaddingXPx < x || markerX > origMarkerX) {
int dx = (x + markerPaddingXPx) - markerX;
int dy = 0;
QuadPoint cp = box.getCenterPixelPoint();
if (center) {
int markerY = (int)box.getPixYFromLatLon(markerLat, markerLon);
dy = (int)cp.y - markerY;
}
if (dx > 0 || center) {
latlon = box.getLatLonFromPixel(cp.x - dx, cp.y - dy);
}
}
} else {
int markerY = (int)box.getPixYFromLatLon(markerLat, markerLon);
if (markerY + markerPaddingPx > y || markerY < origMarkerY) {
int dx = 0;
int dy = markerY - (y - markerPaddingPx);
if (markerY - dy <= origMarkerY) {
QuadPoint cp = box.getCenterPixelPoint();
if (center) {
int markerX = (int)box.getPixXFromLatLon(markerLat, markerLon);
dx = markerX - (int)cp.x;
}
latlon = box.getLatLonFromPixel(cp.x + dx, cp.y + dy);
}
}
}
return latlon;
}
private int getFabY(int y) { private int getFabY(int y) {
int fabY = y + fabPaddingTopPx; int fabY = y + fabPaddingTopPx;
if (fabY < fabPaddingTopPx) { if (fabY < fabPaddingTopPx) {
@ -984,6 +1014,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
final int posY = getPosY(); final int posY = getPosY();
setViewY(posY, true, true); setViewY(posY, true, true);
updateMainViewLayout(posY); updateMainViewLayout(posY);
// centering = false;
} }
public void dismissMenu() { public void dismissMenu() {
@ -1004,7 +1035,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
public void setFragmentVisibility(boolean visible) { public void setFragmentVisibility(boolean visible) {
if (visible) { if (visible) {
view.setVisibility(View.VISIBLE); view.setVisibility(View.VISIBLE);
adjustMapPosition(getPosY(), true); adjustMapPosition(getPosY(), true, false);
} else { } else {
view.setVisibility(View.GONE); view.setVisibility(View.GONE);
} }
@ -1017,7 +1048,8 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
public static boolean showInstance(final MapContextMenu menu, final MapActivity mapActivity) { public static boolean showInstance(final MapContextMenu menu, final MapActivity mapActivity,
final boolean centered) {
try { try {
if (menu.getLatLon() == null) { if (menu.getLatLon() == null) {
@ -1033,6 +1065,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
MapContextMenuFragment fragment = new MapContextMenuFragment(); MapContextMenuFragment fragment = new MapContextMenuFragment();
fragment.centered = centered;
mapActivity.getSupportFragmentManager().beginTransaction() mapActivity.getSupportFragmentManager().beginTransaction()
.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim) .setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
.add(R.id.fragmentContainer, fragment, TAG) .add(R.id.fragmentContainer, fragment, TAG)
@ -1062,6 +1095,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
private void updateOnDownload() { private void updateOnDownload() {
if (menu != null) {
boolean wasProgressVisible = menu.getTitleProgressController() != null && menu.getTitleProgressController().visible; boolean wasProgressVisible = menu.getTitleProgressController() != null && menu.getTitleProgressController().visible;
menu.updateData(); menu.updateData();
boolean progressVisible = menu.getTitleProgressController() != null && menu.getTitleProgressController().visible; boolean progressVisible = menu.getTitleProgressController() != null && menu.getTitleProgressController().visible;
@ -1070,6 +1104,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
runLayoutListener(); runLayoutListener();
} }
} }
}
public void updateMenu() { public void updateMenu() {
menu.updateData(); menu.updateData();