Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-11-27 14:17:42 +01:00
commit 167326e551
3 changed files with 82 additions and 51 deletions

View file

@ -229,13 +229,17 @@ public class MapContextMenu extends MenuTitleController {
public void show() { public void show() {
if (!isVisible()) { if (!isVisible()) {
MapContextMenuFragment.showInstance(mapActivity); if (!MapContextMenuFragment.showInstance(this, mapActivity)) {
active = false;
}
} }
} }
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)) {
MapContextMenuFragment.showInstance(mapActivity); if (!MapContextMenuFragment.showInstance(this, mapActivity)) {
active = false;
}
} }
} }

View file

@ -142,6 +142,12 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP); markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP);
menu = getMapActivity().getContextMenu(); menu = getMapActivity().getContextMenu();
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
if (!menu.isActive()) {
return view;
}
mainView = view.findViewById(R.id.context_menu_main);
leftTitleButtonController = menu.getLeftTitleButtonController(); leftTitleButtonController = menu.getLeftTitleButtonController();
rightTitleButtonController = menu.getRightTitleButtonController(); rightTitleButtonController = menu.getRightTitleButtonController();
topRightTitleButtonController = menu.getTopRightTitleButtonController(); topRightTitleButtonController = menu.getTopRightTitleButtonController();
@ -166,9 +172,6 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
IconsCache iconsCache = getMyApplication().getIconsCache(); IconsCache iconsCache = getMyApplication().getIconsCache();
boolean light = getMyApplication().getSettings().isLightContent(); boolean light = getMyApplication().getSettings().isLightContent();
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
mainView = view.findViewById(R.id.context_menu_main);
// Left title button // Left title button
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button); final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
if (leftTitleButtonController != null) { if (leftTitleButtonController != null) {
@ -244,14 +247,20 @@ 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) {
if (singleTapDetector.onTouchEvent(event)) { if (singleTapDetector.onTouchEvent(event)) {
showOnMap(menu.getLatLon(), true, false); int posY = getViewY();
if (!centered) {
showOnMap(menu.getLatLon(), true, false,
map.getCurrentRotatedTileBox().getPixHeight() / 2 < posY - markerPaddingPx);
centered = true;
}
if (hasMoved) { if (hasMoved) {
applyPosY(getViewY(), false, false, 0, 0); applyPosY(posY, false, false, 0, 0);
} }
openMenuHalfScreen(); openMenuHalfScreen();
return true; return true;
@ -455,20 +464,17 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
.setDuration(200) .setDuration(200)
.setInterpolator(new DecelerateInterpolator()) .setInterpolator(new DecelerateInterpolator())
.setListener(new AnimatorListenerAdapter() { .setListener(new AnimatorListenerAdapter() {
boolean canceled = false;
@Override @Override
public void onAnimationCancel(Animator animation) { public void onAnimationCancel(Animator animation) {
if (needCloseMenu) { canceled = true;
menu.close();
} else {
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
} }
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
if (!canceled) {
if (needCloseMenu) { if (needCloseMenu) {
menu.close(); menu.close();
} else { } else {
@ -478,6 +484,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
} }
} }
}
}) })
.start(); .start();
@ -628,6 +635,10 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (!menu.isActive()) {
dismissMenu();
return;
}
screenOrientation = DashLocationFragment.getScreenOrientation(getActivity()); screenOrientation = DashLocationFragment.getScreenOrientation(getActivity());
if (menu.displayDistanceDirection()) { if (menu.displayDistanceDirection()) {
getMapActivity().getMapViewTrackingUtilities().setContextMenu(menu); getMapActivity().getMapViewTrackingUtilities().setContextMenu(menu);
@ -643,7 +654,9 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
if (mapCenter != null) {
map.setLatLon(mapCenter.getLatitude(), mapCenter.getLongitude()); map.setLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
}
menu.setMapCenter(null); menu.setMapCenter(null);
getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(true); getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(true);
} }
@ -709,7 +722,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
}); });
} }
private void showOnMap(LatLon latLon, boolean updateCoords, boolean ignoreCoef) { private void showOnMap(LatLon latLon, boolean updateCoords, boolean ignoreCoef, boolean needMove) {
AnimateDraggingMapThread thread = map.getAnimatedDraggingThread(); AnimateDraggingMapThread thread = map.getAnimatedDraggingThread();
int fZoom = map.getZoom(); int fZoom = map.getZoom();
double flat = latLon.getLatitude(); double flat = latLon.getLatitude();
@ -732,8 +745,10 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
origMarkerY = cp.getCenterPixelY(); origMarkerY = cp.getCenterPixelY();
} }
if (needMove) {
thread.startMoving(flat, flon, fZoom, true); thread.startMoving(flat, flon, fZoom, true);
} }
}
private void setAddressLocation() { private void setAddressLocation() {
// Text line 1 // Text line 1
@ -899,7 +914,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
if (animated) { if (animated) {
showOnMap(latlon, false, true); showOnMap(latlon, false, true, true);
} else { } else {
map.setLatLon(latlon.getLatitude(), latlon.getLongitude()); map.setLatLon(latlon.getLatitude(), latlon.getLongitude());
} }
@ -951,12 +966,16 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
public static void showInstance(final MapActivity mapActivity) { public static boolean showInstance(final MapContextMenu menu, final MapActivity mapActivity) {
try {
if (menu.getLatLon() == null) {
return false;
}
int slideInAnim = R.anim.slide_in_bottom; int slideInAnim = R.anim.slide_in_bottom;
int slideOutAnim = R.anim.slide_out_bottom; int slideOutAnim = R.anim.slide_out_bottom;
MapContextMenu menu = mapActivity.getContextMenu();
if (menu.isExtended()) { if (menu.isExtended()) {
slideInAnim = menu.getSlideInAnimation(); slideInAnim = menu.getSlideInAnimation();
slideOutAnim = menu.getSlideOutAnimation(); slideOutAnim = menu.getSlideOutAnimation();
@ -967,6 +986,12 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim) .setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
.add(R.id.fragmentContainer, fragment, TAG) .add(R.id.fragmentContainer, fragment, TAG)
.addToBackStack(TAG).commitAllowingStateLoss(); .addToBackStack(TAG).commitAllowingStateLoss();
return true;
} catch (RuntimeException e) {
return false;
}
} }
//DownloadEvents //DownloadEvents

View file

@ -2,6 +2,7 @@ package net.osmand.plus.views;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Paint.Cap; import android.graphics.Paint.Cap;
import android.graphics.Paint.Join; import android.graphics.Paint.Join;
@ -104,9 +105,9 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
osmandRegions = rm.getOsmandRegions(); osmandRegions = rm.getOsmandRegions();
paintDownloaded = getPaint(view.getResources().getColor(R.color.region_uptodate)); paintDownloaded = getPaint(view.getResources().getColor(R.color.region_uptodate));
paintOutdated = getPaint(view.getResources().getColor(R.color.region_updateable));
paintSelected = getPaint(view.getResources().getColor(R.color.region_selected)); paintSelected = getPaint(view.getResources().getColor(R.color.region_selected));
paintDownloading = getPaint(view.getResources().getColor(R.color.region_downloading)); paintDownloading = getPaint(view.getResources().getColor(R.color.region_downloading));
paintOutdated = getPaint(view.getResources().getColor(R.color.region_updateable));
textPaint = new TextPaint(); textPaint = new TextPaint();
final WindowManager wmgr = (WindowManager) view.getApplication().getSystemService(Context.WINDOW_SERVICE); final WindowManager wmgr = (WindowManager) view.getApplication().getSystemService(Context.WINDOW_SERVICE);
@ -496,7 +497,8 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List<? super DownloadMapObject> dataObjects) { private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List<? super DownloadMapObject> dataObjects) {
int zoom = tb.getZoom(); int zoom = tb.getZoom();
if (zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION && osmandRegions.isInitialized()) { if (zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION
&& data.results != null && osmandRegions.isInitialized()) {
LatLon pointLatLon = tb.getLatLonFromPixel(point.x, point.y); LatLon pointLatLon = tb.getLatLonFromPixel(point.x, point.y);
int point31x = MapUtils.get31TileNumberX(pointLatLon.getLongitude()); int point31x = MapUtils.get31TileNumberX(pointLatLon.getLongitude());
int point31y = MapUtils.get31TileNumberY(pointLatLon.getLatitude()); int point31y = MapUtils.get31TileNumberY(pointLatLon.getLatitude());