Fix the number of circles and maximum radius
This commit is contained in:
parent
ab936ec746
commit
a8aa190b7e
2 changed files with 25 additions and 11 deletions
|
@ -66,6 +66,7 @@
|
||||||
<dimen name="map_small_button_size">44dp</dimen>
|
<dimen name="map_small_button_size">44dp</dimen>
|
||||||
<dimen name="map_small_button_margin">5dp</dimen>
|
<dimen name="map_small_button_margin">5dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="map_ruler_radius">100dp</dimen>
|
||||||
<dimen name="map_ruler_width">120dp</dimen>
|
<dimen name="map_ruler_width">120dp</dimen>
|
||||||
<dimen name="map_ruler_bottom_margin">9dp</dimen>
|
<dimen name="map_ruler_bottom_margin">9dp</dimen>
|
||||||
<dimen name="map_alarm_size">78dp</dimen>
|
<dimen name="map_alarm_size">78dp</dimen>
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.graphics.Paint;
|
||||||
import android.graphics.Paint.Style;
|
import android.graphics.Paint.Style;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.text.TextPaint;
|
import android.text.TextPaint;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.data.QuadPoint;
|
import net.osmand.data.QuadPoint;
|
||||||
|
@ -20,6 +21,8 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class RulerControlLayer extends OsmandMapLayer {
|
public class RulerControlLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
private static final int TEXT_SIZE = 14;
|
private static final int TEXT_SIZE = 14;
|
||||||
|
@ -29,9 +32,10 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
private int maxRadius;
|
private int maxRadius;
|
||||||
private int radius;
|
private int radius;
|
||||||
private int cacheZoom;
|
private int cacheZoom;
|
||||||
|
private int halfMaxSide;
|
||||||
private double cacheTileX;
|
private double cacheTileX;
|
||||||
private double cacheTileY;
|
private double cacheTileY;
|
||||||
private String[] cacheDistances;
|
private ArrayList<String> cacheDistances;
|
||||||
private Bitmap centerIcon;
|
private Bitmap centerIcon;
|
||||||
private Paint bitmapPaint;
|
private Paint bitmapPaint;
|
||||||
private Paint distancePaint;
|
private Paint distancePaint;
|
||||||
|
@ -47,11 +51,17 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
public void initLayer(OsmandMapTileView view) {
|
public void initLayer(OsmandMapTileView view) {
|
||||||
app = mapActivity.getMyApplication();
|
app = mapActivity.getMyApplication();
|
||||||
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
|
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
|
||||||
cacheDistances = new String[3];
|
cacheDistances = new ArrayList<>();
|
||||||
maxRadius = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_width);
|
maxRadius = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_radius);
|
||||||
|
|
||||||
centerIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center);
|
centerIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center);
|
||||||
|
|
||||||
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||||
|
mapActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||||
|
int height = displayMetrics.heightPixels;
|
||||||
|
int width = displayMetrics.widthPixels;
|
||||||
|
halfMaxSide = (int) ((width > height ? width : height) / 2.2);
|
||||||
|
|
||||||
bitmapPaint = new Paint();
|
bitmapPaint = new Paint();
|
||||||
bitmapPaint.setAntiAlias(true);
|
bitmapPaint.setAntiAlias(true);
|
||||||
bitmapPaint.setDither(true);
|
bitmapPaint.setDither(true);
|
||||||
|
@ -93,7 +103,8 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
drawDistance(canvas, tb, center, currentLoc);
|
drawDistance(canvas, tb, center, currentLoc);
|
||||||
}
|
}
|
||||||
} else if (mode == RulerMode.SECOND) {
|
} else if (mode == RulerMode.SECOND) {
|
||||||
for (int i = 1; i < 4; i++) {
|
updateData(tb);
|
||||||
|
for (int i = 1; i <= cacheDistances.size(); i++) {
|
||||||
drawCircle(canvas, tb, i, center);
|
drawCircle(canvas, tb, i, center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,10 +125,8 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawCircle(Canvas canvas, RotatedTileBox tb, int circleNumber, QuadPoint center) {
|
private void drawCircle(Canvas canvas, RotatedTileBox tb, int circleNumber, QuadPoint center) {
|
||||||
updateData(tb);
|
|
||||||
|
|
||||||
Rect bounds = new Rect();
|
Rect bounds = new Rect();
|
||||||
String text = cacheDistances[circleNumber - 1];
|
String text = cacheDistances.get(circleNumber - 1);
|
||||||
textPaint.getTextBounds(text, 0, text.length(), bounds);
|
textPaint.getTextBounds(text, 0, text.length(), bounds);
|
||||||
|
|
||||||
float left;
|
float left;
|
||||||
|
@ -149,6 +158,7 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
cacheZoom = tb.getZoom();
|
cacheZoom = tb.getZoom();
|
||||||
cacheTileX = tb.getCenterTileX();
|
cacheTileX = tb.getCenterTileX();
|
||||||
cacheTileY = tb.getCenterTileY();
|
cacheTileY = tb.getCenterTileY();
|
||||||
|
cacheDistances.clear();
|
||||||
|
|
||||||
final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2);
|
final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2);
|
||||||
double pixDensity = tb.getPixWidth() / dist;
|
double pixDensity = tb.getPixWidth() / dist;
|
||||||
|
@ -156,9 +166,12 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
OsmAndFormatter.calculateRoundedDist(maxRadius / pixDensity, app);
|
OsmAndFormatter.calculateRoundedDist(maxRadius / pixDensity, app);
|
||||||
radius = (int) (pixDensity * roundedDist);
|
radius = (int) (pixDensity * roundedDist);
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
int halfSide = halfMaxSide;
|
||||||
cacheDistances[i] = OsmAndFormatter.getFormattedDistance((float) roundedDist * (i + 1),
|
int i = 1;
|
||||||
app, false).replaceAll(" ", "");
|
|
||||||
|
while ((halfSide -= radius) > 0) {
|
||||||
|
cacheDistances.add(OsmAndFormatter.getFormattedDistance((float) roundedDist * i++,
|
||||||
|
app, false).replaceAll(" ", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue