use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class MapVectorLayer method drawRenderedMap.
private boolean drawRenderedMap(Canvas canvas, Bitmap bmp, RotatedTileBox bmpLoc, RotatedTileBox currentViewport) {
boolean shown = false;
if (bmp != null && bmpLoc != null) {
float rot = -bmpLoc.getRotate();
canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
final RotatedTileBox calc = currentViewport.copy();
calc.setRotate(bmpLoc.getRotate());
QuadPointDouble lt = bmpLoc.getLeftTopTile(bmpLoc.getZoom());
QuadPointDouble rb = bmpLoc.getRightBottomTile(bmpLoc.getZoom());
final float x1 = calc.getPixXFromTile(lt.x, lt.y, bmpLoc.getZoom());
final float x2 = calc.getPixXFromTile(rb.x, rb.y, bmpLoc.getZoom());
final float y1 = calc.getPixYFromTile(lt.x, lt.y, bmpLoc.getZoom());
final float y2 = calc.getPixYFromTile(rb.x, rb.y, bmpLoc.getZoom());
// LatLon lt = bmpLoc.getLeftTopLatLon();
// LatLon rb = bmpLoc.getRightBottomLatLon();
// final float x1 = calc.getPixXFromLatLon(lt.getLatitude(), lt.getLongitude());
// final float x2 = calc.getPixXFromLatLon(rb.getLatitude(), rb.getLongitude());
// final float y1 = calc.getPixYFromLatLon(lt.getLatitude(), lt.getLongitude());
// final float y2 = calc.getPixYFromLatLon(rb.getLatitude(), rb.getLongitude());
destImage.set(x1, y1, x2, y2);
if (!bmp.isRecycled()) {
canvas.drawBitmap(bmp, null, destImage, paintImg);
shown = true;
}
canvas.rotate(-rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
}
return shown;
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class MapContextMenuFragment method onCreateView.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
screenHeight = AndroidUtils.getScreenHeight(getActivity());
skipHalfScreenStateLimit = screenHeight * SKIP_HALF_SCREEN_STATE_KOEF;
viewHeight = screenHeight - AndroidUtils.getStatusBarHeight(getMainActivity());
fabPaddingTopPx = dpToPx(FAB_PADDING_TOP_DP);
markerPaddingPx = dpToPx(MARKER_PADDING_DP);
markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP);
menu = getMainActivity().getContextMenu();
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
if (!menu.isActive()) {
return view;
}
nightMode = menu.isNightMode();
mainView = view.findViewById(R.id.context_menu_main);
leftTitleButtonController = menu.getLeftTitleButtonController();
rightTitleButtonController = menu.getRightTitleButtonController();
topRightTitleButtonController = menu.getTopRightTitleButtonController();
RotatedTileBox box = getBox();
customMapCenter = menu.getMapCenter() != null;
if (!customMapCenter) {
mapCenter = box.getCenterLatLon();
menu.setMapCenter(mapCenter);
double markerLat = menu.getLatLon().getLatitude();
double markerLon = menu.getLatLon().getLongitude();
origMarkerX = (int) box.getPixXFromLatLon(markerLat, markerLon);
origMarkerY = (int) box.getPixYFromLatLon(markerLat, markerLon);
} else {
mapCenter = menu.getMapCenter();
origMarkerX = box.getCenterPixelX();
origMarkerY = box.getCenterPixelY();
}
// Left title button
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
if (leftTitleButtonController != null) {
leftTitleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
leftTitleButtonController.buttonPressed();
}
});
}
// Right title button
final Button rightTitleButton = (Button) view.findViewById(R.id.title_button_right);
if (rightTitleButtonController != null) {
rightTitleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rightTitleButtonController.buttonPressed();
}
});
}
// Top Right title button
final Button topRightTitleButton = (Button) view.findViewById(R.id.title_button_top_right);
if (topRightTitleButtonController != null) {
topRightTitleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
topRightTitleButtonController.buttonPressed();
}
});
}
updateButtonsAndProgress();
if (menu.isLandscapeLayout()) {
final TypedValue typedValueAttr = new TypedValue();
getMainActivity().getTheme().resolveAttribute(R.attr.left_menu_view_bg, typedValueAttr, true);
mainView.setBackgroundResource(typedValueAttr.resourceId);
mainView.setLayoutParams(new FrameLayout.LayoutParams(menu.getLandscapeWidthPx(), ViewGroup.LayoutParams.MATCH_PARENT));
View fabContainer = view.findViewById(R.id.context_menu_fab_container);
fabContainer.setLayoutParams(new FrameLayout.LayoutParams(menu.getLandscapeWidthPx(), ViewGroup.LayoutParams.MATCH_PARENT));
}
runLayoutListener();
final GestureDetector singleTapDetector = new GestureDetector(view.getContext(), new SingleTapConfirm());
final View.OnTouchListener slideTouchListener = new View.OnTouchListener() {
private float dy;
private float dyMain;
private VelocityTracker velocity;
private boolean slidingUp;
private boolean slidingDown;
private float velocityY;
private float maxVelocityY;
private boolean hasMoved;
@Override
public boolean onTouch(View v, MotionEvent event) {
if (singleTapDetector.onTouchEvent(event)) {
moving = false;
int posY = getViewY();
if (!centered) {
if (!zoomIn && menu.supportZoomIn()) {
LatLon centerLatLon = getMainActivity().getScreenCenter();
if (centerLatLon.equals(menu.getLatLon())) {
zoomIn = true;
}
}
centerMarkerLocation();
} else if (!zoomIn && menu.supportZoomIn()) {
int fZoom = getZoom();
zoomIn = true;
if (fZoom < ZOOM_IN_STANDARD) {
/* todo animation
AnimateDraggingMapThread thread = map.getAnimatedDraggingThread();
thread.startZooming(ZOOM_IN_STANDARD,
map.getZoomFractionalPart(), true);
*/
getMainActivity().setZoom(ZOOM_IN_STANDARD);
}
}
if (hasMoved) {
applyPosY(posY, false, false, 0, 0);
}
openMenuHalfScreen();
return true;
}
if (menu.isLandscapeLayout()) {
return true;
}
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
hasMoved = false;
dy = event.getY();
dyMain = getViewY();
velocity = VelocityTracker.obtain();
velocityY = 0;
maxVelocityY = 0;
velocity.addMovement(event);
moving = true;
break;
case MotionEvent.ACTION_MOVE:
if (moving) {
hasMoved = true;
float y = event.getY();
float newY = getViewY() + (y - dy);
setViewY((int) newY, false, false);
menuFullHeight = view.getHeight() - (int) newY + 10;
if (!oldAndroid()) {
ViewGroup.LayoutParams lp = mainView.getLayoutParams();
lp.height = Math.max(menuFullHeight, menuTitleHeight);
mainView.setLayoutParams(lp);
mainView.requestLayout();
}
velocity.addMovement(event);
velocity.computeCurrentVelocity(1000);
velocityY = Math.abs(velocity.getYVelocity());
if (velocityY > maxVelocityY)
maxVelocityY = velocityY;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (moving) {
moving = false;
int currentY = getViewY();
slidingUp = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) < -50;
slidingDown = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) > 50;
velocity.recycle();
boolean skipHalfScreenState = Math.abs(currentY - dyMain) > skipHalfScreenStateLimit;
changeMenuState(currentY, skipHalfScreenState, slidingUp, slidingDown);
}
break;
}
return true;
}
};
View topView = view.findViewById(R.id.context_menu_top_view);
topView.setOnTouchListener(slideTouchListener);
View topShadowView = view.findViewById(R.id.context_menu_top_shadow);
topShadowView.setOnTouchListener(slideTouchListener);
View topShadowAllView = view.findViewById(R.id.context_menu_top_shadow_all);
// AndroidUtils.setBackground(getMainActivity(), topShadowAllView, nightMode, R.drawable.bg_map_context_menu_light,
// R.drawable.bg_map_context_menu_dark);
topShadowAllView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getY() <= dpToPx(SHADOW_HEIGHT_TOP_DP) || event.getAction() != MotionEvent.ACTION_DOWN)
return slideTouchListener.onTouch(v, event);
else
return false;
}
});
buildHeader();
AndroidUtils.setTextPrimaryColor(getMainActivity(), (TextView) view.findViewById(R.id.context_menu_line1), nightMode);
View menuLine2 = view.findViewById(R.id.context_menu_line2);
if (menuLine2 != null) {
AndroidUtils.setTextSecondaryColor(getMainActivity(), (TextView) menuLine2, nightMode);
}
((Button) view.findViewById(R.id.title_button_top_right)).setTextColor(!nightMode ? getResources().getColor(R.color.map_widget_blue) : getResources().getColor(R.color.osmand_orange));
AndroidUtils.setTextSecondaryColor(getMainActivity(), (TextView) view.findViewById(R.id.distance), nightMode);
((Button) view.findViewById(R.id.title_button)).setTextColor(!nightMode ? getResources().getColor(R.color.map_widget_blue) : getResources().getColor(R.color.osmand_orange));
AndroidUtils.setTextSecondaryColor(getMainActivity(), (TextView) view.findViewById(R.id.title_button_right_text), nightMode);
((Button) view.findViewById(R.id.title_button_right)).setTextColor(!nightMode ? getResources().getColor(R.color.map_widget_blue) : getResources().getColor(R.color.osmand_orange));
// FAB
/*
fabView = (ImageView) view.findViewById(R.id.context_menu_fab_view);
if (menu.fabVisible()) {
fabView.setImageDrawable(iconsCache.getIcon(menu.getFabIconId(), 0));
if (menu.isLandscapeLayout()) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) fabView.getLayoutParams();
params.setMargins(0, 0, dpToPx(28f), 0);
fabView.setLayoutParams(params);
}
fabView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
menu.fabPressed();
}
});
} else {
fabView.setVisibility(View.GONE);
}
*/
buildBottomView();
view.findViewById(R.id.context_menu_bottom_scroll).setBackgroundColor(nightMode ? getResources().getColor(R.color.ctx_menu_info_view_bg_dark) : getResources().getColor(R.color.ctx_menu_info_view_bg_light));
view.findViewById(R.id.context_menu_bottom_view).setBackgroundColor(nightMode ? getResources().getColor(R.color.ctx_menu_info_view_bg_dark) : getResources().getColor(R.color.ctx_menu_info_view_bg_light));
return view;
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class MapContextMenuFragment method getAdjustedMarkerLocation.
private LatLon getAdjustedMarkerLocation(int y, LatLon reqMarkerLocation, boolean center, int zoom) {
double markerLat = reqMarkerLocation.getLatitude();
double markerLon = reqMarkerLocation.getLongitude();
RotatedTileBox box = getBox();
// box.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
box.setZoom(zoom);
int markerMapCenterX = (int) box.getPixXFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
int markerMapCenterY = (int) box.getPixYFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
float cpyOrig = box.getCenterPixelPoint().y;
box.setCenterLocation(0.5f, 0.5f);
int markerX = (int) box.getPixXFromLatLon(markerLat, markerLon);
int markerY = (int) box.getPixYFromLatLon(markerLat, markerLon);
QuadPoint cp = box.getCenterPixelPoint();
float cpx = cp.x;
float cpy = cp.y;
float cpyDelta = menu.isLandscapeLayout() ? 0 : cpyOrig - cpy;
markerY += cpyDelta;
y += cpyDelta;
float origMarkerY = this.origMarkerY + cpyDelta;
LatLon latlon;
if (center) {
latlon = reqMarkerLocation;
} else {
latlon = box.getLatLonFromPixel(markerMapCenterX, markerMapCenterY);
}
if (menu.isLandscapeLayout()) {
int x = menu.getLandscapeWidthPx();
if (markerX - markerPaddingXPx < x || markerX > origMarkerX) {
int dx = (x + markerPaddingXPx) - markerX;
int dy = 0;
if (center) {
dy = (int) cpy - markerY;
} else {
cpy = cpyOrig;
}
if (dx >= 0 || center) {
latlon = box.getLatLonFromPixel(cpx - dx, cpy - dy);
}
}
} else {
if (markerY + markerPaddingPx > y || markerY < origMarkerY) {
int dx = 0;
int dy = markerY - (y - markerPaddingPx);
if (markerY - dy <= origMarkerY) {
if (center) {
dx = markerX - (int) cpx;
}
latlon = box.getLatLonFromPixel(cpx + dx, cpy + dy);
}
}
}
return latlon;
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class ContextMenuLayer method enterMovingMode.
private void enterMovingMode(RotatedTileBox tileBox) {
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_SHORT);
menu.updateMapCenter(null);
menu.hide();
LatLon ll = menu.getLatLon();
RotatedTileBox rb = new RotatedTileBox(tileBox);
rb.setCenterLocation(0.5f, 0.5f);
rb.setLatLonCenter(ll.getLatitude(), ll.getLongitude());
double lat = rb.getLatFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
double lon = rb.getLonFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
view.setLatLon(lat, lon);
mInChangeMarkerPositionMode = true;
mMoveMarkerBottomSheetHelper.show(menu.getRightIcon());
mark(View.INVISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info);
View collapseButton = activity.findViewById(R.id.map_collapse_button);
if (collapseButton != null && collapseButton.getVisibility() == View.VISIBLE) {
wasCollapseButtonVisible = true;
collapseButton.setVisibility(View.INVISIBLE);
} else {
wasCollapseButtonVisible = false;
}
view.refreshMap();
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class MapQuickActionLayer method quitMovingMarker.
private void quitMovingMarker() {
RotatedTileBox tileBox = mapActivity.getMapView().getCurrentRotatedTileBox();
if (!isFolowPoint(tileBox, mapActivity.getContextMenu()) && previousMapPosition != OsmandSettings.BOTTOM_CONSTANT) {
RotatedTileBox rb = tileBox.copy();
rb.setCenterLocation(0.5f, 0.5f);
LatLon ll = tileBox.getCenterLatLon();
rb.setLatLonCenter(ll.getLatitude(), ll.getLongitude());
double lat = tileBox.getLatFromPixel(rb.getCenterPixelX(), rb.getCenterPixelY());
double lon = tileBox.getLonFromPixel(rb.getCenterPixelX(), rb.getCenterPixelY());
view.setLatLon(lat, lon);
}
view.setMapPosition(previousMapPosition);
inMovingMarkerMode = false;
mark(View.VISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info);
View collapseButton = mapActivity.findViewById(R.id.map_collapse_button);
if (collapseButton != null && wasCollapseButtonVisible) {
collapseButton.setVisibility(View.VISIBLE);
}
view.refreshMap();
}
Aggregations