@Override public boolean onTouchEvent(PointF point) { if (routeLayer != null && routeLayer.getHelper().isRouterEnabled()) { if (boundsForMiniRoute.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) { showMiniMap = !showMiniMap; view.refreshMap(); return true; } if (boundsForLeftTime.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) { showArrivalTime = !showArrivalTime; view.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME.set(showArrivalTime); view.refreshMap(); return true; } } if (cachedDistString != null && boundsForDist.contains(point.x, point.y)) { AnimateDraggingMapThread thread = view.getAnimatedDraggingThread(); LatLon pointToNavigate = view.getSettings().getPointToNavigate(); if (pointToNavigate != null) { int fZoom = view.getZoom() < 15 ? 15 : view.getZoom(); thread.startMoving( pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true); } } return false; }
@Override public void onDraw(Canvas canvas, RectF latlonBounds, RectF tilesRect, DrawSettings nightMode) { boolean bold = routeLayer.getHelper().isFollowingMode(); int color = !nightMode.isNightMode() ? Color.BLACK : Color.BLACK; if (paintText.getColor() != color) { paintText.setColor(color); paintSubText.setColor(color); paintSmallText.setColor(color); paintSmallSubText.setColor(color); } if (paintText.isFakeBoldText() != bold) { paintText.setFakeBoldText(bold); paintSubText.setFakeBoldText(bold); paintSmallText.setFakeBoldText(bold); paintSmallSubText.setFakeBoldText(bold); } // update data on draw rightStack.updateInfo(); leftStack.updateInfo(); if (view.getRotate() != cachedRotate) { cachedRotate = view.getRotate(); compassView.invalidate(); } lanesControl.updateInfo(); // topText.setTextColor(color); // String text = "Пр.Независимости"; // float ts = topText.getPaint().measureText(text); // int wth = topText.getRight() /*- compassView.getRight()*/; // while(ts > wth && topText.getTextSize() - 1 > 5) { // topText.setTextSize(topText.getTextSize() - 1); // ts = topText.getPaint().measureText(text); // } // topText.setText(text); }
// FIXME alarm control protected NextTurnInfoControl createAlarmInfoControl() { final RoutingHelper routingHelper = routeLayer.getHelper(); final NextTurnInfoControl nextTurnInfo = new NextTurnInfoControl(map, paintSmallText, paintSmallSubText, true) { @Override public boolean updateInfo() { boolean visible = false; if (routeLayer != null && routingHelper.isRouterEnabled() && routingHelper.isFollowingMode()) { // boolean uturnWhenPossible = routingHelper.makeUturnWhenPossible(); } updateVisibility(visible); return true; } }; // initial state // nextTurnInfo.setVisibility(View.GONE); return nextTurnInfo; }
private void drawRouteInfo(Canvas canvas) { if (routeLayer != null && routeLayer.getHelper().isRouterEnabled()) { if (routeLayer.getHelper().isFollowingMode()) { int d = routeLayer.getHelper().getDistanceToNextRouteDirection(); if (showMiniMap || d == 0) { if (!routeLayer.getPath().isEmpty()) { canvas.save(); canvas.clipRect(boundsForMiniRoute); canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintAlphaGray); canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintBlack); canvas.translate( centerMiniRouteX - view.getCenterPointX(), centerMiniRouteY - view.getCenterPointY()); canvas.scale( scaleMiniRoute, scaleMiniRoute, view.getCenterPointX(), view.getCenterPointY()); canvas.rotate(view.getRotate(), view.getCenterPointX(), view.getCenterPointY()); canvas.drawCircle( view.getCenterPointX(), view.getCenterPointY(), 3 / scaleMiniRoute, fillBlack); canvas.drawPath(routeLayer.getPath(), paintMiniRoute); canvas.restore(); } } else { canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintAlphaGray); canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintBlack); RouteDirectionInfo next = routeLayer.getHelper().getNextRouteDirectionInfo(); if (next != null) { if (!Algoritms.objectEquals(cachedTurnType, next.turnType)) { cachedTurnType = next.turnType; calcTurnPath(pathForTurn, cachedTurnType, pathTransform); if (cachedTurnType.getExitOut() > 0) { cachedExitOut = cachedTurnType.getExitOut() + ""; // $NON-NLS-1$ } else { cachedExitOut = null; } } canvas.drawPath(pathForTurn, paintRouteDirection); canvas.drawPath(pathForTurn, paintBlack); if (cachedExitOut != null) { canvas.drawText( cachedExitOut, boundsForMiniRoute.centerX() - 6 * scaleCoefficient, boundsForMiniRoute.centerY() - 9 * scaleCoefficient, paintBlack); } canvas.drawText( OsmAndFormatter.getFormattedDistance(d, map), boundsForMiniRoute.left + 10 * scaleCoefficient, boundsForMiniRoute.bottom - 9 * scaleCoefficient, paintBlack); } } } boolean followingMode = routeLayer.getHelper().isFollowingMode(); int time = routeLayer.getHelper().getLeftTime(); if (time == 0) { cachedLeftTime = 0; cachedLeftTimeString = null; } else { if (followingMode && showArrivalTime) { long toFindTime = time * 1000 + System.currentTimeMillis(); if (Math.abs(toFindTime - cachedLeftTime) > 30000) { cachedLeftTime = toFindTime; if (DateFormat.is24HourFormat(map)) { cachedLeftTimeString = DateFormat.format("kk:mm", toFindTime).toString(); // $NON-NLS-1$ } else { cachedLeftTimeString = DateFormat.format("k:mm aa", toFindTime).toString(); // $NON-NLS-1$ } boundsForLeftTime.left = -paintBlack.measureText(cachedLeftTimeString) - 10 * scaleCoefficient + boundsForLeftTime.right; } } else { if (Math.abs(time - cachedLeftTime) > 30) { cachedLeftTime = time; int hours = time / (60 * 60); int minutes = (time / 60) % 60; cachedLeftTimeString = String.format("%d:%02d", hours, minutes); // $NON-NLS-1$ boundsForLeftTime.left = -paintBlack.measureText(cachedLeftTimeString) - 10 * scaleCoefficient + boundsForLeftTime.right; } } } if (cachedLeftTimeString != null) { int w = (int) (boundsForLeftTime.right - boundsForLeftTime.left); boundsForLeftTime.right = view.getWidth(); boundsForLeftTime.left = view.getWidth() - w; canvas.drawRoundRect(boundsForLeftTime, roundCorner, roundCorner, paintAlphaGray); canvas.drawRoundRect(boundsForLeftTime, roundCorner, roundCorner, paintBlack); canvas.drawText( cachedLeftTimeString, boundsForLeftTime.left + 5 * scaleCoefficient, boundsForLeftTime.bottom - 9 * scaleCoefficient, paintBlack); } } }
private MapInfoControl createLanesControl() { final Path laneStraight = new Path(); Matrix pathTransform = new Matrix(); pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff); TurnPathHelper.calcTurnPath(laneStraight, TurnType.valueOf(TurnType.C, false), pathTransform); final Paint paintBlack = new Paint(); paintBlack.setStyle(Style.STROKE); paintBlack.setColor(Color.BLACK); paintBlack.setAntiAlias(true); paintBlack.setStrokeWidth(2.5f); final Paint paintRouteDirection = new Paint(); paintRouteDirection.setStyle(Style.FILL); paintRouteDirection.setColor(view.getResources().getColor(R.color.nav_arrow)); paintRouteDirection.setAntiAlias(true); final float w = 72 * scaleCoefficient / miniCoeff; final RoutingHelper routingHelper = routeLayer.getHelper(); final MapInfoControl lanesControl = new MapInfoControl(map) { int[] lanes = null; boolean imminent = false; @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int ls = (int) (lanes == null ? 0 : lanes.length * w); setWDimensions(ls, (int) (w + 3 * scaleCoefficient)); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // to change color immediately when needed if (lanes != null && lanes.length > 0) { canvas.save(); // canvas.translate((int) (16 * scaleCoefficient), 0); for (int i = 0; i < lanes.length; i++) { if ((lanes[i] & 1) == 1) { paintRouteDirection.setColor( imminent ? getResources().getColor(R.color.nav_arrow_imminent) : getResources().getColor(R.color.nav_arrow)); } else { paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_distant)); } canvas.drawPath(laneStraight, paintBlack); canvas.drawPath(laneStraight, paintRouteDirection); canvas.translate(w, 0); } canvas.restore(); } } @Override public boolean updateInfo() { boolean visible = false; int locimminent = -1; int[] loclanes = null; if (routeLayer != null && routingHelper.isRouteCalculated()) { if (routingHelper.isRouterEnabled() && routingHelper.isFollowingMode()) { NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false); if (r != null && r.directionInfo != null && r.directionInfo.getTurnType() != null) { loclanes = r.directionInfo.getTurnType().getLanes(); locimminent = r.imminent; // Do not show too far if (locimminent == 2 || locimminent < 0) { loclanes = null; } } } else { int di = map.getMapLayers().getRouteInfoLayer().getDirectionInfo(); if (di >= 0 && map.getMapLayers().getRouteInfoLayer().isVisible()) { RouteDirectionInfo next = routingHelper.getRouteDirections().get(di); if (next != null) { loclanes = next.getTurnType().getLanes(); } } } } visible = loclanes != null && loclanes.length > 0; if (visible) { if (!Arrays.equals(lanes, loclanes)) { lanes = loclanes; requestLayout(); invalidate(); } if ((locimminent == 0) != imminent) { imminent = (locimminent == 0); invalidate(); } } updateVisibility(visible); return true; } }; return lanesControl; }
private NextTurnInfoControl createNextInfoControl() { final RoutingHelper routingHelper = routeLayer.getHelper(); final NextTurnInfoControl nextTurnInfo = new NextTurnInfoControl(map, paintText, paintSubText, false) { NextDirectionInfo calc1 = new NextDirectionInfo(); TurnType straight = TurnType.valueOf(TurnType.C, true); @Override public boolean updateInfo() { boolean visible = false; if (routeLayer != null && routingHelper.isRouterEnabled() && routingHelper.isFollowingMode()) { makeUturnWhenPossible = routingHelper.makeUturnWhenPossible(); if (makeUturnWhenPossible) { visible = true; turnImminent = 1; turnType = TurnType.valueOf(TurnType.TU, view.getSettings().LEFT_SIDE_NAVIGATION.get()); TurnPathHelper.calcTurnPath(pathForTurn, turnType, pathTransform); invalidate(); } else { NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, false); boolean showStraight = false; if (r != null) { RouteDirectionInfo toShowWithoutSpeak = r.directionInfo; if (r.imminent >= 0 && r.imminent < 2) { // next turn is very close (show it) } else { r = routingHelper.getNextRouteDirectionInfo(calc1, true); if (calc1.directionInfo != toShowWithoutSpeak) { // show straight and grey because it is not the closest turn showStraight = r.imminent == -1; } } } if (r != null && r.distanceTo > 0) { visible = true; if (r.directionInfo == null) { if (turnType != null) { turnType = null; invalidate(); } } else if (!Algoritms.objectEquals( turnType, showStraight ? straight : r.directionInfo.getTurnType())) { turnType = showStraight ? straight : r.directionInfo.getTurnType(); TurnPathHelper.calcTurnPath(pathForTurn, turnType, pathTransform); if (turnType.getExitOut() > 0) { exitOut = turnType.getExitOut() + ""; // $NON-NLS-1$ } else { exitOut = null; } invalidate(); } if (distChanged(r.distanceTo, nextTurnDirection)) { invalidate(); nextTurnDirection = r.distanceTo; } if (turnImminent != r.imminent) { turnImminent = r.imminent; invalidate(); } } } } updateVisibility(visible); return true; } }; nextTurnInfo.setOnClickListener( new View.OnClickListener() { // int i = 0; // boolean leftSide = false; @Override public void onClick(View v) { // for test rendering purposes // final int l = TurnType.predefinedTypes.length; // final int exits = 5; // i++; // if (i % (l + exits) >= l ) { // nextTurnInfo.turnType = TurnType.valueOf("EXIT" + (i % (l + exits) - l + 1), // leftSide); // float a = leftSide? -180 + (i % (l + exits) - l + 1) * 50: 180 - (i % (l + // exits) - l + 1) * 50; // nextTurnInfo.turnType.setTurnAngle(a < 0 ? a + 360 : a); // nextTurnInfo.exitOut = (i % (l + exits) - l + 1)+""; // } else { // nextTurnInfo.turnType = TurnType.valueOf(TurnType.predefinedTypes[i % // (TurnType.predefinedTypes.length + exits)], leftSide); // nextTurnInfo.exitOut = ""; // } // nextTurnInfo.turnImminent = (nextTurnInfo.turnImminent + 1) % 3; // nextTurnInfo.nextTurnDirection = 580; // TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn, // nextTurnInfo.turnType,nextTurnInfo.pathTransform); // showMiniMap = true; nextTurnInfo.requestLayout(); view.refreshMap(); } }); // initial state nextTurnInfo.setVisibility(View.GONE); return nextTurnInfo; }
private NextTurnInfoControl createNextNextInfoControl() { final RoutingHelper routingHelper = routeLayer.getHelper(); final NextTurnInfoControl nextTurnInfo = new NextTurnInfoControl(map, paintSmallText, paintSmallSubText, true) { NextDirectionInfo calc1 = new NextDirectionInfo(); @Override public boolean updateInfo() { boolean visible = false; if (routeLayer != null && routingHelper.isRouterEnabled() && routingHelper.isFollowingMode()) { boolean uturnWhenPossible = routingHelper.makeUturnWhenPossible(); NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, false); if (!uturnWhenPossible) { if (r != null) { // next turn is very close (show next next with false to speak) if (r.imminent >= 0 && r.imminent < 2) { r = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, false); } else { r = routingHelper.getNextRouteDirectionInfo(calc1, true); if (r != null) { r = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, true); } } } } if (r != null && r.distanceTo > 0) { visible = true; if (r == null || r.directionInfo == null) { if (turnType != null) { turnType = null; invalidate(); } } else if (!Algoritms.objectEquals(turnType, r.directionInfo.getTurnType())) { turnType = r.directionInfo.getTurnType(); TurnPathHelper.calcTurnPath(pathForTurn, turnType, pathTransform); invalidate(); } if (distChanged(r.distanceTo, nextTurnDirection)) { invalidate(); nextTurnDirection = r.distanceTo; } int imminent = r.imminent; if (turnImminent != imminent) { turnImminent = imminent; invalidate(); } } } updateVisibility(visible); return true; } }; nextTurnInfo.setOnClickListener( new View.OnClickListener() { // int i = 0; @Override public void onClick(View v) { // uncomment to test turn info rendering // final int l = TurnType.predefinedTypes.length; // final int exits = 5; // i++; // if (i % (l + exits) >= l ) { // nextTurnInfo.turnType = TurnType.valueOf("EXIT" + (i % (l + exits) - l + 1), // true); // nextTurnInfo.exitOut = (i % (l + exits) - l + 1)+""; // float a = 180 - (i % (l + exits) - l + 1) * 50; // nextTurnInfo.turnType.setTurnAngle(a < 0 ? a + 360 : a); // } else { // nextTurnInfo.turnType = TurnType.valueOf(TurnType.predefinedTypes[i % // (TurnType.predefinedTypes.length + exits)], true); // nextTurnInfo.exitOut = ""; // } // nextTurnInfo.turnImminent = (nextTurnInfo.turnImminent + 1) % 3; // nextTurnInfo.nextTurnDirection = 580; // TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn, // nexsweepAngletTurnInfo.turnType,nextTurnInfo.pathTransform); // showMiniMap = true; view.refreshMap(); } }); // initial state // nextTurnInfo.setVisibility(View.GONE); return nextTurnInfo; }
public void updateColorShadowsOfText(DrawSettings drawSettings) { boolean transparent = view.getSettings().TRANSPARENT_MAP_THEME.get(); boolean nightMode = drawSettings == null ? false : drawSettings.isNightMode(); boolean following = routeLayer.getHelper().isFollowingMode(); int calcThemeId = (transparent ? 4 : 0) | (nightMode ? 2 : 0) | (following ? 1 : 0); if (themeId != calcThemeId) { themeId = calcThemeId; boolean textBold = following; int textColor = nightMode ? 0xffC8C8C8 : Color.BLACK; int textShadowColor = transparent && !nightMode ? Color.WHITE : Color.TRANSPARENT; int boxTop; int boxTopStack; int boxTopR; int boxTopL; int expand; Drawable boxFree = view.getResources().getDrawable(R.drawable.box_free_simple); if (transparent) { boxTop = R.drawable.box_top_t; boxTopStack = R.drawable.box_top_t_stack; boxTopR = R.drawable.box_top_rt; boxTopL = R.drawable.box_top_lt; expand = R.drawable.box_expand_t; if (nightMode) { boxFree = view.getResources().getDrawable(R.drawable.box_night_free_simple); } } else if (nightMode) { boxTop = R.drawable.box_top_n; boxTopStack = R.drawable.box_top_n_stack; boxTopR = R.drawable.box_top_rn; boxTopL = R.drawable.box_top_ln; expand = R.drawable.box_expand_t; boxFree = view.getResources().getDrawable(R.drawable.box_night_free_simple); } else { boxTop = R.drawable.box_top; boxTopStack = R.drawable.box_top_stack; boxTopR = R.drawable.box_top_r; boxTopL = R.drawable.box_top_l; expand = R.drawable.box_expand; } lanesControl.setBackgroundDrawable(boxFree); rightStack.setTopDrawable(view.getResources().getDrawable(boxTopR)); rightStack.setStackDrawable(boxTopStack); leftStack.setTopDrawable(view.getResources().getDrawable(boxTopL)); leftStack.setStackDrawable(boxTopStack); leftStack.setExpandImageDrawable(view.getResources().getDrawable(expand)); rightStack.setExpandImageDrawable(view.getResources().getDrawable(expand)); statusBar.setBackgroundDrawable(view.getResources().getDrawable(boxTop)); paintText.setColor(textColor); paintSubText.setColor(textColor); paintSmallText.setColor(textColor); paintSmallSubText.setColor(textColor); topText.setShadowColor(textShadowColor); leftStack.setShadowColor(textShadowColor); rightStack.setShadowColor(textShadowColor); paintText.setFakeBoldText(textBold); paintSubText.setFakeBoldText(textBold); paintSmallText.setFakeBoldText(textBold); paintSmallSubText.setFakeBoldText(textBold); rightStack.invalidate(); leftStack.invalidate(); statusBar.invalidate(); } }