Remove zero axis from gpx chart. Cleanup code.
This commit is contained in:
parent
524901f1b5
commit
f4bcee4315
3 changed files with 96 additions and 228 deletions
|
@ -52,6 +52,7 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -67,12 +68,5 @@
|
|||
android:layout_height="150dp"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
|
||||
<!--
|
||||
<net.osmand.plus.myplaces.ElevationView
|
||||
android:id="@+id/elevation"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="150dp"
|
||||
android:layout_gravity="center_vertical" />
|
||||
-->
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
package net.osmand.plus.myplaces;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by maw on 02.09.15., original credit goes to gibbsnich
|
||||
* Developed further by Hardy 2016-11
|
||||
*/
|
||||
public class ElevationView extends ImageView {
|
||||
|
||||
double maxElevation, minElevation;
|
||||
float xDistance;
|
||||
List<GPXUtilities.Elevation> elevationList;
|
||||
|
||||
private OsmandApplication app;
|
||||
private MetricsConstants mc;
|
||||
|
||||
public ElevationView(Context ctx, AttributeSet as) {
|
||||
super(ctx, as);
|
||||
app = (OsmandApplication) ctx.getApplicationContext();
|
||||
mc = app.getSettings().METRIC_SYSTEM.get();
|
||||
}
|
||||
|
||||
public void onDraw(Canvas canvas) {
|
||||
final float screenScale = getResources().getDisplayMetrics().density;
|
||||
|
||||
final boolean useFeet = (mc == MetricsConstants.MILES_AND_FEET) || (mc == MetricsConstants.MILES_AND_YARDS);
|
||||
final String unit = useFeet ? app.getString(R.string.foot) : app.getString(R.string.m);
|
||||
int stepBase = useFeet ? 200 : 100;
|
||||
final float convEle = useFeet ? 3.28084f : 1.0f;
|
||||
|
||||
final int maxBase = ((int)Math.floor((maxElevation * convEle / stepBase) + 1)) * stepBase;
|
||||
final int minBase = (int)Math.floor((minElevation * convEle / stepBase)) * stepBase;
|
||||
final float yDistance = maxBase - minBase;
|
||||
if ((!useFeet && (yDistance <= 100)) || (useFeet && (yDistance <= 200))) { //Draw 50m/100ft markers for smallest scale
|
||||
stepBase = stepBase/2;
|
||||
}
|
||||
final float xPer = (float)canvas.getWidth() / xDistance;
|
||||
final float yPer = (float)canvas.getHeight() / yDistance;
|
||||
final float canvasRight = (float)canvas.getWidth() - 1f;
|
||||
final float canvasBottom = (float)canvas.getHeight() - 1f;
|
||||
|
||||
// This y transform apparently needed to assure top and bottom lines show up on all devices
|
||||
final float yOffset = 2f;
|
||||
final float ySlope = ((float)canvas.getHeight() - 2f * yOffset) / (float)canvas.getHeight();
|
||||
|
||||
Paint barPaint = new Paint();
|
||||
barPaint.setColor(getResources().getColor(R.color.dialog_inactive_text_color_dark));
|
||||
barPaint.setTextSize((int)(16f * screenScale + 0.5f));
|
||||
barPaint.setTypeface(Typeface.create(Typeface.DEFAULT_BOLD, Typeface.BOLD));
|
||||
float yTextLast = 9999f;
|
||||
for (int i = minBase; i <= maxBase ; i += stepBase) {
|
||||
float y = yOffset + ySlope * (canvasBottom - yPer * (float)(i - minBase));
|
||||
canvas.drawLine(0, y, canvasRight, y, barPaint);
|
||||
if ((yTextLast - y) >= (int)(32f * screenScale + 0.5f)) { // Overlap prevention
|
||||
canvas.drawText(String.valueOf(i) + " " + unit, (int)(8f * screenScale + 0.5f), y - (int)(2f * screenScale + 0.5f), barPaint);
|
||||
yTextLast = y;
|
||||
}
|
||||
}
|
||||
|
||||
float lastX = 0, lastY = 0;
|
||||
float xDistSum = 0;
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(getResources().getColor(R.color.gpx_altitude_asc));
|
||||
paint.setStrokeWidth((int)(2f * screenScale + 0.5f));
|
||||
boolean first = true;
|
||||
if (elevationList != null) {
|
||||
for (GPXUtilities.Elevation elevation : elevationList) {
|
||||
xDistSum += elevation.distance;
|
||||
float nextX = xPer * xDistSum;
|
||||
float nextY = yOffset + ySlope * (canvasBottom - yPer * (float)(elevation.elevation * convEle - minBase));
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
canvas.drawLine(lastX, lastY, nextX, nextY, paint);
|
||||
}
|
||||
lastX = nextX;
|
||||
lastY = nextY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setElevationData(List<GPXUtilities.Elevation> elevationData) {
|
||||
elevationList = elevationData;
|
||||
}
|
||||
|
||||
public void setMaxElevation(double max) {
|
||||
maxElevation = max;
|
||||
}
|
||||
|
||||
public void setMinElevation(double min) {
|
||||
minElevation = min;
|
||||
}
|
||||
|
||||
public void setTotalDistance(float dist) {
|
||||
xDistance = dist;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -471,9 +471,46 @@ public class SelectedGPXFragment extends OsmAndListFragment {
|
|||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View row = convertView;
|
||||
LineChart mChart = null;
|
||||
final boolean useFeet = (mc == MetricsConstants.MILES_AND_FEET) || (mc == MetricsConstants.MILES_AND_YARDS);
|
||||
if (row == null) {
|
||||
LayoutInflater inflater = getMyActivity().getLayoutInflater();
|
||||
row = inflater.inflate(R.layout.gpx_item_list_item, parent, false);
|
||||
|
||||
mChart = (LineChart) row.findViewById(R.id.chart);
|
||||
//mChart.setHardwareAccelerationEnabled(true);
|
||||
mChart.setTouchEnabled(true);
|
||||
mChart.setDragEnabled(true);
|
||||
mChart.setScaleEnabled(true);
|
||||
mChart.setPinchZoom(true);
|
||||
mChart.setScaleYEnabled(false);
|
||||
mChart.setAutoScaleMinMaxEnabled(true);
|
||||
mChart.setDrawBorders(false);
|
||||
mChart.getDescription().setEnabled(false);
|
||||
mChart.setMaxVisibleValueCount(10);
|
||||
|
||||
// create a custom MarkerView (extend MarkerView) and specify the layout
|
||||
// to use for it
|
||||
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.chart_marker_view, useFeet);
|
||||
mv.setChartView(mChart); // For bounds control
|
||||
mChart.setMarker(mv); // Set the marker to the chart
|
||||
mChart.setDrawMarkers(true);
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setDrawAxisLine(false);
|
||||
xAxis.setDrawGridLines(false);
|
||||
xAxis.setDrawAxisLine(false);
|
||||
xAxis.setPosition(BOTTOM);
|
||||
|
||||
YAxis yAxis = mChart.getAxisLeft();
|
||||
yAxis.enableGridDashedLine(10f, 5f, 0f);
|
||||
yAxis.setGridColor(ActivityCompat.getColor(getActivity(), R.color.divider_color));
|
||||
yAxis.setDrawAxisLine(false);
|
||||
|
||||
Legend legend = mChart.getLegend();
|
||||
legend.setEnabled(false);
|
||||
|
||||
mChart.getAxisRight().setEnabled(false);
|
||||
}
|
||||
GpxDisplayItem child = getItem(position);
|
||||
TextView label = (TextView) row.findViewById(R.id.name);
|
||||
|
@ -514,46 +551,11 @@ public class SelectedGPXFragment extends OsmAndListFragment {
|
|||
description.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
final LineChart mChart = (LineChart) row.findViewById(R.id.chart);
|
||||
//mChart.setHardwareAccelerationEnabled(true);
|
||||
mChart.setTouchEnabled(true);
|
||||
mChart.setDragEnabled(true);
|
||||
mChart.setScaleEnabled(true);
|
||||
mChart.setPinchZoom(true);
|
||||
mChart.setScaleYEnabled(false);
|
||||
mChart.setAutoScaleMinMaxEnabled(true);
|
||||
mChart.setDrawBorders(false);
|
||||
mChart.getDescription().setEnabled(false);
|
||||
mChart.setMaxVisibleValueCount(10);
|
||||
|
||||
final boolean useFeet = (mc == MetricsConstants.MILES_AND_FEET) || (mc == MetricsConstants.MILES_AND_YARDS);
|
||||
// create a custom MarkerView (extend MarkerView) and specify the layout
|
||||
// to use for it
|
||||
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.chart_marker_view, useFeet);
|
||||
mv.setChartView(mChart); // For bounds control
|
||||
mChart.setMarker(mv); // Set the marker to the chart
|
||||
mChart.setDrawMarkers(true);
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
xAxis.setDrawAxisLine(false);
|
||||
xAxis.setDrawGridLines(false);
|
||||
xAxis.setDrawAxisLine(false);
|
||||
xAxis.setPosition(BOTTOM);
|
||||
|
||||
YAxis yAxis = mChart.getAxisLeft();
|
||||
yAxis.enableGridDashedLine(10f, 5f, 0f);
|
||||
yAxis.setGridColor(ActivityCompat.getColor(getActivity(), R.color.divider_color));
|
||||
yAxis.setDrawAxisLine(false);
|
||||
|
||||
Legend legend = mChart.getLegend();
|
||||
legend.setEnabled(false);
|
||||
|
||||
mChart.getAxisRight().setEnabled(false);
|
||||
|
||||
if (mChart != null) {
|
||||
if (child.analysis != null && child.analysis.elevationData != null && child.analysis.isElevationSpecified() && (child.analysis.totalDistance > 0)) {
|
||||
|
||||
if (child.analysis.minElevation >= 0) {
|
||||
yAxis.setAxisMinimum(0f);
|
||||
//mChart.getAxisLeft().setAxisMinimum(0f);
|
||||
}
|
||||
|
||||
final float convEle = useFeet ? 3.28084f : 1.0f;
|
||||
|
@ -575,7 +577,6 @@ public class SelectedGPXFragment extends OsmAndListFragment {
|
|||
|
||||
dataSet.setColor(Color.BLACK);
|
||||
dataSet.setDrawValues(false);
|
||||
//set1.setCircleColor(Color.BLACK);
|
||||
dataSet.setLineWidth(0f);
|
||||
dataSet.setValueTextSize(9f);
|
||||
dataSet.setDrawFilled(true);
|
||||
|
@ -585,18 +586,16 @@ public class SelectedGPXFragment extends OsmAndListFragment {
|
|||
dataSet.setDrawCircles(false);
|
||||
dataSet.setDrawCircleHole(false);
|
||||
|
||||
dataSet.setHighlightEnabled(true); // allow highlighting for DataSet
|
||||
// set this to false to disable the drawing of highlight indicator (lines)
|
||||
dataSet.setHighlightEnabled(true);
|
||||
dataSet.setDrawVerticalHighlightIndicator(true);
|
||||
dataSet.setDrawHorizontalHighlightIndicator(false);
|
||||
dataSet.setHighLightColor(Color.BLACK); // color for highlight indicator
|
||||
dataSet.setHighLightColor(Color.BLACK);
|
||||
|
||||
if (Utils.getSDKInt() >= 18) {
|
||||
// fill drawable only supported on api level 18 and above
|
||||
Drawable drawable = ContextCompat.getDrawable(getActivity(), R.drawable.line_chart_fade_orange);
|
||||
dataSet.setFillDrawable(drawable);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dataSet.setFillColor(ContextCompat.getColor(getActivity(), R.color.osmand_orange));
|
||||
}
|
||||
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
|
@ -612,18 +611,8 @@ public class SelectedGPXFragment extends OsmAndListFragment {
|
|||
} else {
|
||||
mChart.setVisibility(View.GONE);
|
||||
}
|
||||
/*
|
||||
ElevationView elevationImg = (ElevationView) row.findViewById(R.id.elevation);
|
||||
if (child.analysis != null && child.analysis.elevationData != null && child.analysis.isElevationSpecified() && (child.analysis.totalDistance > 0)) {
|
||||
elevationImg.setElevationData(child.analysis.elevationData);
|
||||
elevationImg.setMaxElevation(child.analysis.maxElevation);
|
||||
elevationImg.setMinElevation(child.analysis.minElevation);
|
||||
elevationImg.setTotalDistance(child.analysis.totalDistance); //Use raw data for graph, not channel detection noise filter (facilitates visual double check)
|
||||
elevationImg.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
elevationImg.setVisibility(View.GONE);
|
||||
}
|
||||
*/
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue