From d71cd563662f0763e29bb5eef3d180ec32d40027 Mon Sep 17 00:00:00 2001 From: Krishna Alpeshkumar Patel Date: Wed, 14 Feb 2024 02:44:31 -0500 Subject: [PATCH 1/8] changes of using isEmpty() Resolving conflict for issue #13 --- .../opentracks/chart/ChartView.java | 356 +++++++++--------- 1 file changed, 181 insertions(+), 175 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java index f32bb29ad..7907b071a 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java @@ -64,9 +64,9 @@ */ public class ChartView extends View { - static final int Y_AXIS_INTERVALS = 5; + private static final int Y_AXIS_INTERVALS = 5; - private static final int TARGET_X_AXIS_INTERVALS = 4; + private static final int X_AXIS_INTERVALS = 4; private static final int MIN_ZOOM_LEVEL = 1; private static final int MAX_ZOOM_LEVEL = 10; @@ -122,10 +122,10 @@ public class ChartView extends View { private boolean reportSpeed = true; private boolean showPointer = false; - private final GestureDetectorCompat detectorScrollFlingTab = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() { + private final GestureDetectorCompat scrollFlingTab = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() { @Override - public boolean onDown(MotionEvent e) { + public boolean onDown(final MotionEvent motionEvent) { if (!scroller.isFinished()) { scroller.abortAnimation(); } @@ -133,9 +133,9 @@ public boolean onDown(MotionEvent e) { } @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { + public boolean onScroll(final MotionEvent motionEvent1, final MotionEvent motionEvent2, final float distanceX, final float distanceY) { if (Math.abs(distanceX) > 0) { - int availableToScroll = effectiveWidth * (zoomLevel - 1) - getScrollX(); + final int availableToScroll = effectiveWidth * (zoomLevel - 1) - getScrollX(); if (availableToScroll > 0) { scrollBy(Math.min(availableToScroll, (int) distanceX)); } @@ -144,20 +144,21 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d } @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + public boolean onFling(final MotionEvent motionEvent1,final MotionEvent motionEvent2, final float velocityX,final float velocityY) { fling((int) -velocityX); return true; } @Override - public boolean onSingleTapConfirmed(MotionEvent event) { + public boolean onSingleTapConfirmed(final MotionEvent event) { + boolean isTabComfirmed = false; // Check if the y event is within markerHeight of the marker center if (Math.abs(event.getY() - topBorder - spacer - markerHeight / 2f) < markerHeight) { int minDistance = Integer.MAX_VALUE; Marker nearestMarker = null; synchronized (markers) { - for (Marker marker : markers) { - int distance = Math.abs(getX(getMarkerXValue(marker)) - (int) event.getX() - getScrollX()); + for (final Marker marker : markers) { + final int distance = Math.abs(getX(getMarkerXValue(marker)) - (int) event.getX() - getScrollX()); if (distance < minDistance) { minDistance = distance; nearestMarker = marker; @@ -165,38 +166,38 @@ public boolean onSingleTapConfirmed(MotionEvent event) { } } if (nearestMarker != null && minDistance < markerWidth) { - Intent intent = IntentUtils.newIntent(getContext(), MarkerDetailActivity.class) + final Intent intent = IntentUtils.newIntent(getContext(), MarkerDetailActivity.class) .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, nearestMarker.getId()); getContext().startActivity(intent); - return true; + isTabComfirmed = true; } } - - return false; + return isTabComfirmed; } }); private final ScaleGestureDetector detectorZoom = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() { @Override - public boolean onScale(ScaleGestureDetector detector) { - float scaleFactor = detector.getScaleFactor(); + public boolean onScale(final ScaleGestureDetector detector) { + boolean isOnScale = false; + final float scaleFactor = detector.getScaleFactor(); if (scaleFactor >= 1.1f) { zoomIn(); - return true; + isOnScale = true; } else if (scaleFactor <= 0.9) { zoomOut(); - return true; + isOnScale = true; } - return false; + return isOnScale; } }); - public ChartView(Context context, AttributeSet attributeSet) { + public ChartView(final Context context, final AttributeSet attributeSet) { super(context, attributeSet); - int fontSizeSmall = ThemeUtils.getFontSizeSmallInPx(context); - int fontSizeMedium = ThemeUtils.getFontSizeMediumInPx(context); + final int fontSizeSmall = ThemeUtils.getFontSizeSmallInPx(context); + final int fontSizeMedium = ThemeUtils.getFontSizeMediumInPx(context); seriesList.add(new ChartValueSeries(context, Integer.MIN_VALUE, @@ -210,7 +211,7 @@ public ChartView(Context context, AttributeSet attributeSet) { fontSizeSmall, fontSizeMedium) { @Override - protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) { + protected Double extractDataFromChartPoint(final @NonNull ChartPoint chartPoint) { return chartPoint.altitude(); } @@ -232,7 +233,7 @@ protected boolean drawIfChartPointHasNoData() { fontSizeSmall, fontSizeMedium) { @Override - protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) { + protected Double extractDataFromChartPoint(final @NonNull ChartPoint chartPoint) { return chartPoint.speed(); } @@ -255,7 +256,7 @@ protected boolean drawIfChartPointHasNoData() { fontSizeSmall, fontSizeMedium) { @Override - protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) { + protected Double extractDataFromChartPoint(final @NonNull ChartPoint chartPoint) { return chartPoint.pace(); } @@ -278,7 +279,7 @@ protected boolean drawIfChartPointHasNoData() { fontSizeSmall, fontSizeMedium) { @Override - protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) { + protected Double extractDataFromChartPoint(final @NonNull ChartPoint chartPoint) { return chartPoint.heartRate(); } @@ -300,7 +301,7 @@ protected boolean drawIfChartPointHasNoData() { fontSizeSmall, fontSizeMedium) { @Override - protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) { + protected Double extractDataFromChartPoint(final @NonNull ChartPoint chartPoint) { return chartPoint.cadence(); } @@ -321,7 +322,7 @@ protected boolean drawIfChartPointHasNoData() { fontSizeSmall, fontSizeMedium) { @Override - protected Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) { + protected Double extractDataFromChartPoint(final @NonNull ChartPoint chartPoint) { return chartPoint.power(); } @@ -371,11 +372,11 @@ protected boolean drawIfChartPointHasNoData() { } @Override - public boolean canScrollHorizontally(int direction) { + public boolean canScrollHorizontally(final int direction) { return true; } - public void setChartByDistance(boolean chartByDistance) { + public void setChartByDistance(final boolean chartByDistance) { this.chartByDistance = chartByDistance; } @@ -383,11 +384,11 @@ public UnitSystem getUnitSystem() { return unitSystem; } - public void setUnitSystem(UnitSystem value) { + public void setUnitSystem(final UnitSystem value) { unitSystem = value; } - public boolean getReportSpeed() { + public boolean isReportSpeed() { return reportSpeed; } @@ -396,38 +397,39 @@ public boolean getReportSpeed() { * * @param value report speed (true) or pace (false) */ - public void setReportSpeed(boolean value) { + public void setReportSpeed(final boolean value) { reportSpeed = value; } public boolean applyReportSpeed() { + boolean isApplied = false; if (reportSpeed) { if (!speedSeries.isEnabled()) { speedSeries.setEnabled(true); paceSeries.setEnabled(false); - return true; + isApplied = true; } } else { if (!paceSeries.isEnabled()) { speedSeries.setEnabled(false); paceSeries.setEnabled(true); - return true; + isApplied = true; } } - return false; + return isApplied; } - public void setShowPointer(boolean value) { + public void setShowPointer(final boolean value) { showPointer = value; } - public void addChartPoints(List dataPoints) { + public void addChartPoints(final List dataPoints) { synchronized (chartPoints) { chartPoints.addAll(dataPoints); - for (ChartPoint dataPoint : dataPoints) { + for (final ChartPoint dataPoint : dataPoints) { xExtremityMonitor.update(dataPoint.timeOrDistance()); - for (ChartValueSeries i : seriesList) { + for (final ChartValueSeries i : seriesList) { i.update(dataPoint); } } @@ -456,7 +458,7 @@ public void resetScroll() { scrollTo(0, 0); } - public void addMarker(Marker marker) { + public void addMarker(final Marker marker) { synchronized (markers) { markers.add(marker); } @@ -489,7 +491,7 @@ private void zoomOut() { zoomLevel--; scroller.abortAnimation(); int scrollX = getScrollX(); - int maxWidth = effectiveWidth * (zoomLevel - 1); + final int maxWidth = effectiveWidth * (zoomLevel - 1); if (scrollX > maxWidth) { scrollX = maxWidth; scrollTo(scrollX, 0); @@ -504,8 +506,8 @@ private void zoomOut() { * * @param velocityX velocity of fling in pixels per second */ - private void fling(int velocityX) { - int maxWidth = effectiveWidth * (zoomLevel - 1); + private void fling(final int velocityX) { + final int maxWidth = effectiveWidth * (zoomLevel - 1); scroller.fling(getScrollX(), 0, velocityX, 0, 0, maxWidth, 0, 0); invalidate(); } @@ -515,8 +517,8 @@ private void fling(int velocityX) { * * @param disallow Does disallow parent touch event? */ - private void requestDisallowInterceptTouchEventInParent(boolean disallow) { - ViewParent parent = getParent(); + private void requestDisallowInterceptTouchEventInParent(final boolean disallow) { + final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(disallow); } @@ -527,13 +529,13 @@ private void requestDisallowInterceptTouchEventInParent(boolean disallow) { * * @param deltaX the number of pixels to scroll */ - private void scrollBy(int deltaX) { + private void scrollBy(final int deltaX) { int scrollX = getScrollX() + deltaX; if (scrollX <= 0) { scrollX = 0; } - int maxWidth = effectiveWidth * (zoomLevel - 1); + final int maxWidth = effectiveWidth * (zoomLevel - 1); if (scrollX >= maxWidth) { scrollX = maxWidth; } @@ -548,20 +550,20 @@ private void scrollBy(int deltaX) { @Override public void computeScroll() { if (scroller.computeScrollOffset()) { - int oldX = getScrollX(); - int x = scroller.getCurrX(); - scrollTo(x, 0); - if (oldX != x) { - onScrollChanged(x, 0, oldX, 0); + final int oldX = getScrollX(); + final int newX = scroller.getCurrX(); + scrollTo(newX, 0); + if (oldX != newX) { + onScrollChanged(newX, 0, oldX, 0); postInvalidate(); } } } @Override - public boolean onTouchEvent(MotionEvent event) { - boolean isZoom = detectorZoom.onTouchEvent(event); - boolean isScrollTab = detectorScrollFlingTab.onTouchEvent(event); + public boolean onTouchEvent(final MotionEvent event) { + final boolean isZoom = detectorZoom.onTouchEvent(event); + final boolean isScrollTab = scrollFlingTab.onTouchEvent(event); // ChartView handles zoom gestures (more than one pointer) and all gestures when zoomed itself requestDisallowInterceptTouchEventInParent(event.getPointerCount() != 1 || zoomLevel != MIN_ZOOM_LEVEL); @@ -570,13 +572,13 @@ public boolean onTouchEvent(MotionEvent event) { } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { updateEffectiveDimensionsIfChanged(View.MeasureSpec.getSize(widthMeasureSpec), View.MeasureSpec.getSize(heightMeasureSpec)); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override - protected void onDraw(Canvas canvas) { + protected void onDraw(final Canvas canvas) { synchronized (chartPoints) { canvas.save(); @@ -608,10 +610,10 @@ protected void onDraw(Canvas canvas) { * * @param canvas the canvas */ - private void clipToGraphArea(Canvas canvas) { - int x = getScrollX() + leftBorder; - int y = topBorder; - canvas.clipRect(x, y, x + effectiveWidth, y + effectiveHeight); + private void clipToGraphArea(final Canvas canvas) { + final int xCordinate = getScrollX() + leftBorder; + final int yCordinate = topBorder; + canvas.clipRect(xCordinate, yCordinate, xCordinate + effectiveWidth, yCordinate + effectiveHeight); } /** @@ -619,30 +621,30 @@ private void clipToGraphArea(Canvas canvas) { * * @param canvas the canvas */ - private void drawDataSeries(Canvas canvas) { - for (ChartValueSeries chartValueSeries : seriesList) { + private void drawDataSeries(final Canvas canvas) { + for (final ChartValueSeries chartValueSeries : seriesList) { if (chartValueSeries.isEnabled() && chartValueSeries.hasData()) { chartValueSeries.drawPath(canvas); } } } - private void drawMarker(Canvas canvas) { + private void drawMarker(final Canvas canvas) { synchronized (markers) { - for (Marker marker : markers) { - double xValue = getMarkerXValue(marker); - double markerIconSizeInXaxisUnits = maxX*markerWidth/effectiveWidth / zoomLevel; - if (xValue > maxX + markerIconSizeInXaxisUnits * (1-MARKER_X_ANCHOR)) { + for (final Marker marker : markers) { + final double xValue = getMarkerXValue(marker); + final double markerSizeXaxis = maxX*markerWidth/effectiveWidth / zoomLevel; + if (xValue > maxX + markerSizeXaxis * (1-MARKER_X_ANCHOR)) { continue; // there is no chance that this marker will be visible } canvas.save(); - float x = getX(getMarkerXValue(marker)); - canvas.drawLine(x, topBorder + spacer + markerHeight / 2, x, topBorder + effectiveHeight, markerPaint); + final float xCordinate = getX(getMarkerXValue(marker)); + canvas.drawLine(xCordinate, topBorder + spacer + markerHeight / 2, xCordinate, topBorder + effectiveHeight, markerPaint); // if marker is not near the end of the track then draw it normally - if (xValue < maxX - markerIconSizeInXaxisUnits*(1-MARKER_X_ANCHOR)) { - canvas.translate(x - (markerWidth * MARKER_X_ANCHOR), topBorder + spacer); + if (xValue < maxX - markerSizeXaxis*(1-MARKER_X_ANCHOR)) { + canvas.translate(xCordinate - (markerWidth * MARKER_X_ANCHOR), topBorder + spacer); } else { // marker at the end needs to be drawn mirrored so that it is more visible - canvas.translate(x + (markerWidth * MARKER_X_ANCHOR), topBorder + spacer); + canvas.translate(xCordinate + (markerWidth * MARKER_X_ANCHOR), topBorder + spacer); canvas.scale(-1, 1); } markerPin.draw(canvas); @@ -656,48 +658,48 @@ private void drawMarker(Canvas canvas) { * * @param canvas the canvas */ - private void drawGrid(Canvas canvas) { + private void drawGrid(final Canvas canvas) { // X axis grid - List xAxisMarkerPositions = getXAxisMarkerPositions(getXAxisInterval()); - for (double position : xAxisMarkerPositions) { - int x = getX(position); - canvas.drawLine(x, topBorder, x, topBorder + effectiveHeight, gridPaint); + final List xMarkerPositions = getXAxisMarkerPositions(getXAxisInterval()); + for (final double position : xMarkerPositions) { + final int xCordinate = getX(position); + canvas.drawLine(xCordinate, topBorder, xCordinate, topBorder + effectiveHeight, gridPaint); } // Y axis grid - float rightEdge = getX(maxX); + final float rightEdge = getX(maxX); for (int i = 0; i <= Y_AXIS_INTERVALS; i++) { - double percentage = (double) i / Y_AXIS_INTERVALS; - int range = effectiveHeight - 2 * yAxisOffset; - int y = topBorder + yAxisOffset + (int) (percentage * range); - canvas.drawLine(leftBorder, y, rightEdge, y, gridPaint); + final double percentage = (double) i / Y_AXIS_INTERVALS; + final int range = effectiveHeight - 2 * yAxisOffset; + final int yCordinate = topBorder + yAxisOffset + (int) (percentage * range); + canvas.drawLine(leftBorder, yCordinate, rightEdge, yCordinate, gridPaint); } } private record TitlePosition( int line, // line number (starts at 1, top to bottom numbering) int xPos // x position in points (starts at 0, left to right indexing) - ) {}; + ) {} private record TitleDimensions( int lineCount, // number of lines the titles will take int lineHeight, // height of a line (all lines have the same height) List titlePositions // positions of visible titles (the order corresponds to seriesList) - ) {}; + ) {} /** * Draws series titles. * * @param canvas the canvas */ - private void drawSeriesTitles(Canvas canvas) { - TitleDimensions td = getTitleDimensions(); - Iterator tpI = td.titlePositions.iterator(); - for (ChartValueSeries chartValueSeries : seriesList) { + private void drawSeriesTitles(final Canvas canvas) { + final TitleDimensions titleDimensions = getTitleDimensions(); + final Iterator tpI = titleDimensions.titlePositions.iterator(); + for (final ChartValueSeries chartValueSeries : seriesList) { if (chartValueSeries.isEnabled() && chartValueSeries.hasData() || allowIfEmpty(chartValueSeries)) { - String title = getContext().getString(chartValueSeries.getTitleId(unitSystem)); - Paint paint = chartValueSeries.getTitlePaint(); - TitlePosition tp = tpI.next(); - int y = topBorder - spacer - (td.lineCount - tp.line) * (td.lineHeight + spacer); - canvas.drawText(title, tp.xPos + getScrollX(), y, paint); + final String title = getContext().getString(chartValueSeries.getTitleId(unitSystem)); + final Paint paint = chartValueSeries.getTitlePaint(); + final TitlePosition titlePosition = tpI.next(); + final int yCordinate = topBorder - spacer - (titleDimensions.lineCount - titlePosition.line) * (titleDimensions.lineHeight + spacer); + canvas.drawText(title, titlePosition.xPos + getScrollX(), yCordinate, paint); } } } @@ -709,14 +711,16 @@ private void drawSeriesTitles(Canvas canvas) { private TitleDimensions getTitleDimensions() { int lineCnt = 1; int lineHeight = 0; - List tps = new ArrayList(); + final List tps = new ArrayList(); int xPosInLine = spacer; - for (ChartValueSeries chartValueSeries : seriesList) { + for (final ChartValueSeries chartValueSeries : seriesList) { if (chartValueSeries.isEnabled() && chartValueSeries.hasData() || allowIfEmpty(chartValueSeries)) { - String title = getContext().getString(chartValueSeries.getTitleId(unitSystem)); - Rect rect = getRect(chartValueSeries.getTitlePaint(), title); - if (rect.height() > lineHeight) lineHeight = rect.height(); - int xNextPosInLine = xPosInLine + rect.width() + 2*spacer; + final String title = getContext().getString(chartValueSeries.getTitleId(unitSystem)); + final Rect rect = getRect(chartValueSeries.getTitlePaint(), title); + if (rect.height() > lineHeight) { + lineHeight = rect.height(); + } + final int xNextPosInLine = xPosInLine + rect.width() + 2*spacer; // if second or later title does not fully fit on this line then print it on the next line if (xPosInLine > spacer && xNextPosInLine-spacer > width) { lineCnt++; @@ -734,25 +738,25 @@ private TitleDimensions getTitleDimensions() { * * @param canvas the canvas */ - private void drawXAxis(Canvas canvas) { - int x = getScrollX() + leftBorder; - int y = topBorder + effectiveHeight; - canvas.drawLine(x, y, x + effectiveWidth, y, axisPaint); - String label = getXAxisLabel(); - Rect rect = getRect(axisPaint, label); - int yOffset = rect.height() / 2; - canvas.drawText(label, x + effectiveWidth - rect.width(), y + 3 * yOffset, axisPaint); - - double interval = getXAxisInterval(); - NumberFormat numberFormat = interval < 1 ? X_FRACTION_FORMAT : X_NUMBER_FORMAT; - - for (double markerPosition : getXAxisMarkerPositions(interval)) { + private void drawXAxis(final Canvas canvas) { + final int xCordinate = getScrollX() + leftBorder; + final int yCordinate = topBorder + effectiveHeight; + canvas.drawLine(xCordinate, yCordinate, xCordinate + effectiveWidth, yCordinate, axisPaint); + final String label = getXAxisLabel(); + final Rect rect = getRect(axisPaint, label); + final int yOffset = rect.height() / 2; + canvas.drawText(label, xCordinate + effectiveWidth - rect.width(), yCordinate + 3 * yOffset, axisPaint); + + final double interval = getXAxisInterval(); + final NumberFormat numberFormat = interval < 1 ? X_FRACTION_FORMAT : X_NUMBER_FORMAT; + + for (final double markerPosition : getXAxisMarkerPositions(interval)) { drawXAxisMarker(canvas, markerPosition, numberFormat, spacer + rect.width(), spacer + yOffset); } } private String getXAxisLabel() { - Context context = getContext(); + final Context context = getContext(); if (chartByDistance) { return switch (unitSystem) { case METRIC -> context.getString(R.string.unit_kilometer); @@ -773,17 +777,19 @@ private String getXAxisLabel() { * @param xRightSpace the space taken up by the x axis label * @param yBottomSpace the space between x axis and marker */ - private void drawXAxisMarker(Canvas canvas, double value, NumberFormat numberFormat, int xRightSpace, int yBottomSpace) { - String marker = chartByDistance ? numberFormat.format(value) : StringUtils.formatElapsedTime((Duration.ofMillis((long) value))); - Rect rect = getRect(xAxisMarkerPaint, marker); - int markerXPos = getX(value); - int markerEndXPos = markerXPos + rect.width()/2; - if (markerEndXPos > getScrollX() + leftBorder + effectiveWidth - xRightSpace) return; + private void drawXAxisMarker(final Canvas canvas, final double value,final NumberFormat numberFormat,final int xRightSpace, final int yBottomSpace) { + final String marker = chartByDistance ? numberFormat.format(value) : StringUtils.formatElapsedTime(Duration.ofMillis((long) value)); + final Rect rect = getRect(xAxisMarkerPaint, marker); + final int markerXPos = getX(value); + final int markerEndXPos = markerXPos + rect.width()/2; + if (markerEndXPos > getScrollX() + leftBorder + effectiveWidth - xRightSpace){ + return; + } canvas.drawText(marker, markerXPos, topBorder + effectiveHeight + yBottomSpace + rect.height(), xAxisMarkerPaint); } private double getXAxisInterval() { - double interval = maxX / zoomLevel / TARGET_X_AXIS_INTERVALS; + double interval = maxX / zoomLevel / X_AXIS_INTERVALS; if (interval < 1) { interval = .5; } else if (interval < 5) { @@ -796,8 +802,8 @@ private double getXAxisInterval() { return interval; } - private List getXAxisMarkerPositions(double interval) { - List markers = new ArrayList<>(); + private List getXAxisMarkerPositions(final double interval) { + final List markers = new ArrayList<>(); markers.add(0d); for (int i = 1; i * interval < maxX; i++) { markers.add(i * interval); @@ -814,16 +820,16 @@ private List getXAxisMarkerPositions(double interval) { * * @param canvas the canvas */ - private void drawYAxis(Canvas canvas) { - int x = getScrollX() + leftBorder; - int y = topBorder; - canvas.drawLine(x, y, x, y + effectiveHeight, axisPaint); + private void drawYAxis(final Canvas canvas) { + final int xCordinate = getScrollX() + leftBorder; + final int yCordinate = topBorder; + canvas.drawLine(xCordinate, yCordinate, xCordinate, yCordinate + effectiveHeight, axisPaint); //TODO - int markerXPosition = x - spacer; + int markerXPosition = xCordinate - spacer; for (int i = 0; i < seriesList.size(); i++) { - int index = seriesList.size() - 1 - i; - ChartValueSeries chartValueSeries = seriesList.get(index); + final int index = seriesList.size() - 1 - i; + final ChartValueSeries chartValueSeries = seriesList.get(index); if (chartValueSeries.isEnabled() && chartValueSeries.hasData() || allowIfEmpty(chartValueSeries)) { markerXPosition -= drawYAxisMarkers(chartValueSeries, canvas, markerXPosition) + spacer; } @@ -838,8 +844,8 @@ private void drawYAxis(Canvas canvas) { * @param xPosition the right most x position * @return the maximum marker width. */ - private float drawYAxisMarkers(ChartValueSeries chartValueSeries, Canvas canvas, int xPosition) { - int interval = chartValueSeries.getInterval(); + private float drawYAxisMarkers(final ChartValueSeries chartValueSeries, final Canvas canvas, final int xPosition) { + final int interval = chartValueSeries.getInterval(); float maxMarkerWidth = 0; for (int i = 0; i <= Y_AXIS_INTERVALS; i++) { maxMarkerWidth = Math.max(maxMarkerWidth, drawYAxisMarker(chartValueSeries, canvas, xPosition, @@ -857,29 +863,29 @@ private float drawYAxisMarkers(ChartValueSeries chartValueSeries, Canvas canvas, * @param yValue the y value * @return the marker width. */ - private float drawYAxisMarker(ChartValueSeries chartValueSeries, Canvas canvas, int xPosition, int yValue) { - String marker = chartValueSeries.formatMarker(yValue); - Paint paint = chartValueSeries.getMarkerPaint(); - Rect rect = getRect(paint, marker); - int yPosition = getY(chartValueSeries, yValue) + (rect.height() / 2); + private float drawYAxisMarker(final ChartValueSeries chartValueSeries, final Canvas canvas, final int xPosition,final int yValue) { + final String marker = chartValueSeries.formatMarker(yValue); + final Paint paint = chartValueSeries.getMarkerPaint(); + final Rect rect = getRect(paint, marker); + final int yPosition = getY(chartValueSeries, yValue) + (rect.height() / 2); canvas.drawText(marker, xPosition, yPosition, paint); return paint.measureText(marker); } - private void drawPointer(Canvas canvas) { + private void drawPointer(final Canvas canvas) { if (chartPoints.isEmpty()) { return; } - ChartPoint last = chartPoints.getLast(); + final ChartPoint last = chartPoints.getLast(); - ChartValueSeries firstChartValueSeries = null; - for (ChartValueSeries chartValueSeries : seriesList) { + ChartValueSeries firstChartSeries = null; + for (final ChartValueSeries chartValueSeries : seriesList) { if (chartValueSeries.isEnabled() && chartValueSeries.hasData() && chartValueSeries.isChartPointValid(last)) { - firstChartValueSeries = chartValueSeries; + firstChartSeries = chartValueSeries; break; } } - if (firstChartValueSeries != null && chartPoints.size() > 0) { + if (firstChartValueSeries != null && chartPoints.isEmpty()) { int dx = getX(maxX) - pointer.getIntrinsicWidth() / 2; double value = firstChartValueSeries.extractDataFromChartPoint(last); int dy = getY(firstChartValueSeries, value) - pointer.getIntrinsicHeight(); @@ -897,7 +903,7 @@ private void updateSeries() { } } - private void updateSerie(ChartValueSeries series) { + private void updateSerie(final ChartValueSeries series) { final int yCorner = topBorder + effectiveHeight; final Path path = series.getPath(); @@ -906,25 +912,25 @@ private void updateSerie(ChartValueSeries series) { Integer finalX = null; - for (ChartPoint point : chartPoints) { + for (final ChartPoint point : chartPoints) { if (!series.isChartPointValid(point)) { continue; } - double value = series.extractDataFromChartPoint(point); - int x = getX(point.timeOrDistance()); - int y = getY(series, value); + final double value = series.extractDataFromChartPoint(point); + final int xCordinate = getX(point.timeOrDistance()); + final int yCordinate = getY(series, value); // start from lower left corner if (!drawFirstPoint) { - path.moveTo(x, yCorner); + path.moveTo(xCordinate, yCorner); drawFirstPoint = true; } // draw graph - path.lineTo(x, y); + path.lineTo(xCordinate, yCordinate); - finalX = x; + finalX = xCordinate; } // last point: move to lower right @@ -941,25 +947,25 @@ private void updateSerie(ChartValueSeries series) { */ private void updateDimensions() { maxX = xExtremityMonitor.hasData() ? xExtremityMonitor.getMax() : 1.0; - for (ChartValueSeries chartValueSeries : seriesList) { + for (final ChartValueSeries chartValueSeries : seriesList) { chartValueSeries.updateDimension(); } - float density = getResources().getDisplayMetrics().density; + final float density = getResources().getDisplayMetrics().density; spacer = (int) (density * SPACER); yAxisOffset = (int) (density * Y_AXIS_OFFSET); int markerLength = 0; - for (ChartValueSeries chartValueSeries : seriesList) { + for (final ChartValueSeries chartValueSeries : seriesList) { if (chartValueSeries.isEnabled() && chartValueSeries.hasData() || allowIfEmpty(chartValueSeries)) { - Rect rect = getRect(chartValueSeries.getMarkerPaint(), chartValueSeries.getLargestMarker()); + final Rect rect = getRect(chartValueSeries.getMarkerPaint(), chartValueSeries.getLargestMarker()); markerLength += rect.width() + spacer; } } leftBorder = (int) (density * BORDER + markerLength); - TitleDimensions td = getTitleDimensions(); - topBorder = (int) (density * BORDER + td.lineCount * (td.lineHeight + spacer)); - Rect xAxisLabelRect = getRect(axisPaint, getXAxisLabel()); + final TitleDimensions titleDimensions = getTitleDimensions(); + topBorder = (int) (density * BORDER + titleDimensions.lineCount * (titleDimensions.lineHeight + spacer)); + final Rect xAxisLabelRect = getRect(axisPaint, getXAxisLabel()); // border + x axis marker + spacer + .5 x axis label bottomBorder = (int) (density * BORDER + getRect(xAxisMarkerPaint, "1").height() + spacer + (xAxisLabelRect.height() / 2)); rightBorder = (int) (density * BORDER + spacer); @@ -980,7 +986,7 @@ private void updateEffectiveDimensions() { * @param newWidth the new width * @param newHeight the new height */ - private void updateEffectiveDimensionsIfChanged(int newWidth, int newHeight) { + private void updateEffectiveDimensionsIfChanged(final int newWidth, final int newHeight) { if (width != newWidth || height != newHeight) { width = newWidth; height = newHeight; @@ -998,7 +1004,7 @@ private int getX(double value) { if (value > maxX) { value = maxX; } - double percentage = value / maxX; + final double percentage = value / maxX; return leftBorder + (int) (percentage * effectiveWidth * zoomLevel); } @@ -1008,19 +1014,19 @@ private int getX(double value) { * @param chartValueSeries the chart value series * @param value the value */ - private int getY(ChartValueSeries chartValueSeries, double value) { - int effectiveSpread = chartValueSeries.getInterval() * Y_AXIS_INTERVALS; - double percentage = (value - chartValueSeries.getMinMarkerValue()) / effectiveSpread; - int rangeHeight = effectiveHeight - 2 * yAxisOffset; + private int getY(final ChartValueSeries chartValueSeries,final double value) { + final int effectiveSpread = chartValueSeries.getInterval() * Y_AXIS_INTERVALS; + final double percentage = (value - chartValueSeries.getMinMarkerValue()) / effectiveSpread; + final int rangeHeight = effectiveHeight - 2 * yAxisOffset; return topBorder + yAxisOffset + (int) ((1 - percentage) * rangeHeight); } - private double getMarkerXValue(Marker marker) { + private double getMarkerXValue(final Marker marker) { + int xCordinate = marker.getDuration().toMillis(); if (chartByDistance) { - return marker.getLength().toKM_Miles(unitSystem); - } else { - return marker.getDuration().toMillis(); + xCordinate = marker.getLength().toKM_Miles(unitSystem); } + return xCordinate; } /** @@ -1029,8 +1035,8 @@ private double getMarkerXValue(Marker marker) { * @param paint the paint * @param string the string */ - private Rect getRect(Paint paint, String string) { - Rect rect = new Rect(); + private Rect getRect(final Paint paint,final String string) { + final Rect rect = new Rect(); paint.getTextBounds(string, 0, string.length(), rect); return rect; } @@ -1038,11 +1044,11 @@ private Rect getRect(Paint paint, String string) { /** * Returns true if the index is allowed when the chartData is empty. */ - private boolean allowIfEmpty(ChartValueSeries chartValueSeries) { + private boolean allowIfEmpty(final ChartValueSeries chartValueSeries) { + boolean isAllowed = chartValueSeries.drawIfChartPointHasNoData(); if (!chartPoints.isEmpty()) { - return false; + isAllowed = false; } - - return chartValueSeries.drawIfChartPointHasNoData(); + return isAllowed; } } From 7cd95fe6fa58b8311bea6115e6c456799030ee49 Mon Sep 17 00:00:00 2001 From: BKothari510 Date: Tue, 13 Feb 2024 19:11:06 -0500 Subject: [PATCH 2/8] Refactor - renamed spacer variable --- .../opentracks/chart/ChartView.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java index 7907b071a..3d0b33474 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java @@ -109,7 +109,7 @@ public class ChartView extends View { private int topBorder = BORDER; private int bottomBorder = BORDER; private int rightBorder = BORDER; - private int spacer = SPACER; + private int getSpacer = SPACER; private int yAxisOffset = Y_AXIS_OFFSET; private int width = 0; @@ -153,7 +153,7 @@ public boolean onFling(final MotionEvent motionEvent1,final MotionEvent motionE public boolean onSingleTapConfirmed(final MotionEvent event) { boolean isTabComfirmed = false; // Check if the y event is within markerHeight of the marker center - if (Math.abs(event.getY() - topBorder - spacer - markerHeight / 2f) < markerHeight) { + if (Math.abs(event.getY() - topBorder - getSpacer - markerHeight / 2f) < markerHeight) { int minDistance = Integer.MAX_VALUE; Marker nearestMarker = null; synchronized (markers) { @@ -639,12 +639,12 @@ private void drawMarker(final Canvas canvas) { } canvas.save(); final float xCordinate = getX(getMarkerXValue(marker)); - canvas.drawLine(xCordinate, topBorder + spacer + markerHeight / 2, xCordinate, topBorder + effectiveHeight, markerPaint); + canvas.drawLine(xCordinate, topBorder + getSpacer + markerHeight / 2, xCordinate, topBorder + effectiveHeight, markerPaint); // if marker is not near the end of the track then draw it normally if (xValue < maxX - markerSizeXaxis*(1-MARKER_X_ANCHOR)) { - canvas.translate(xCordinate - (markerWidth * MARKER_X_ANCHOR), topBorder + spacer); + canvas.translate(xCordinate - (markerWidth * MARKER_X_ANCHOR), topBorder + getSpacer); } else { // marker at the end needs to be drawn mirrored so that it is more visible - canvas.translate(xCordinate + (markerWidth * MARKER_X_ANCHOR), topBorder + spacer); + canvas.translate(xCordinate + (markerWidth * MARKER_X_ANCHOR), topBorder + getSpacer); canvas.scale(-1, 1); } markerPin.draw(canvas); @@ -698,7 +698,7 @@ private void drawSeriesTitles(final Canvas canvas) { final String title = getContext().getString(chartValueSeries.getTitleId(unitSystem)); final Paint paint = chartValueSeries.getTitlePaint(); final TitlePosition titlePosition = tpI.next(); - final int yCordinate = topBorder - spacer - (titleDimensions.lineCount - titlePosition.line) * (titleDimensions.lineHeight + spacer); + final int yCordinate = topBorder - getSpacer - (titleDimensions.lineCount - titlePosition.line) * (titleDimensions.lineHeight + getSpacer); canvas.drawText(title, titlePosition.xPos + getScrollX(), yCordinate, paint); } } @@ -712,7 +712,7 @@ private TitleDimensions getTitleDimensions() { int lineCnt = 1; int lineHeight = 0; final List tps = new ArrayList(); - int xPosInLine = spacer; + int xPosInLine = getSpacer; for (final ChartValueSeries chartValueSeries : seriesList) { if (chartValueSeries.isEnabled() && chartValueSeries.hasData() || allowIfEmpty(chartValueSeries)) { final String title = getContext().getString(chartValueSeries.getTitleId(unitSystem)); @@ -720,14 +720,14 @@ private TitleDimensions getTitleDimensions() { if (rect.height() > lineHeight) { lineHeight = rect.height(); } - final int xNextPosInLine = xPosInLine + rect.width() + 2*spacer; + final int xNextPosInLine = xPosInLine + rect.width() + 2*getSpacer; // if second or later title does not fully fit on this line then print it on the next line - if (xPosInLine > spacer && xNextPosInLine-spacer > width) { + if (xPosInLine > getSpacer && xNextPosInLine-getSpacer > width) { lineCnt++; - xPosInLine = spacer; + xPosInLine = getSpacer; } tps.add(new TitlePosition(lineCnt, xPosInLine)); - xPosInLine += rect.width() + 2*spacer; + xPosInLine += rect.width() + 2*getSpacer; } } return new TitleDimensions(lineCnt, lineHeight, tps); @@ -751,7 +751,7 @@ private void drawXAxis(final Canvas canvas) { final NumberFormat numberFormat = interval < 1 ? X_FRACTION_FORMAT : X_NUMBER_FORMAT; for (final double markerPosition : getXAxisMarkerPositions(interval)) { - drawXAxisMarker(canvas, markerPosition, numberFormat, spacer + rect.width(), spacer + yOffset); + drawXAxisMarker(canvas, markerPosition, numberFormat, getSpacer + rect.width(), getSpacer + yOffset); } } @@ -826,12 +826,12 @@ private void drawYAxis(final Canvas canvas) { canvas.drawLine(xCordinate, yCordinate, xCordinate, yCordinate + effectiveHeight, axisPaint); //TODO - int markerXPosition = xCordinate - spacer; + int markerXPosition = xCordinate - getSpacer; for (int i = 0; i < seriesList.size(); i++) { final int index = seriesList.size() - 1 - i; final ChartValueSeries chartValueSeries = seriesList.get(index); if (chartValueSeries.isEnabled() && chartValueSeries.hasData() || allowIfEmpty(chartValueSeries)) { - markerXPosition -= drawYAxisMarkers(chartValueSeries, canvas, markerXPosition) + spacer; + markerXPosition -= drawYAxisMarkers(chartValueSeries, canvas, markerXPosition) + getSpacer; } } } @@ -951,24 +951,24 @@ private void updateDimensions() { chartValueSeries.updateDimension(); } final float density = getResources().getDisplayMetrics().density; - spacer = (int) (density * SPACER); + getSpacer = (int) (density * SPACER); yAxisOffset = (int) (density * Y_AXIS_OFFSET); int markerLength = 0; for (final ChartValueSeries chartValueSeries : seriesList) { if (chartValueSeries.isEnabled() && chartValueSeries.hasData() || allowIfEmpty(chartValueSeries)) { final Rect rect = getRect(chartValueSeries.getMarkerPaint(), chartValueSeries.getLargestMarker()); - markerLength += rect.width() + spacer; + markerLength += rect.width() + getSpacer; } } leftBorder = (int) (density * BORDER + markerLength); final TitleDimensions titleDimensions = getTitleDimensions(); - topBorder = (int) (density * BORDER + titleDimensions.lineCount * (titleDimensions.lineHeight + spacer)); + topBorder = (int) (density * BORDER + titleDimensions.lineCount * (titleDimensions.lineHeight + getSpacer)); final Rect xAxisLabelRect = getRect(axisPaint, getXAxisLabel()); - // border + x axis marker + spacer + .5 x axis label - bottomBorder = (int) (density * BORDER + getRect(xAxisMarkerPaint, "1").height() + spacer + (xAxisLabelRect.height() / 2)); - rightBorder = (int) (density * BORDER + spacer); + // border + x axis marker + getSpacer + .5 x axis label + bottomBorder = (int) (density * BORDER + getRect(xAxisMarkerPaint, "1").height() + getSpacer + (xAxisLabelRect.height() / 2)); + rightBorder = (int) (density * BORDER + getSpacer); updateEffectiveDimensions(); } @@ -977,7 +977,7 @@ private void updateDimensions() { */ private void updateEffectiveDimensions() { effectiveWidth = Math.max(0, width - leftBorder - rightBorder); - effectiveHeight = Math.max(0, height - topBorder - bottomBorder - spacer); + effectiveHeight = Math.max(0, height - topBorder - bottomBorder - getSpacer); } /** From e1b830f6b6845fa1a3889b20301c2ded7c205bcd Mon Sep 17 00:00:00 2001 From: mkjodhani Date: Wed, 14 Feb 2024 22:04:55 -0500 Subject: [PATCH 3/8] Fix PMD Violation in Default Value Initializers Closes #16 This commit resolves the OMD violation and brings the codebase in line with the established coding standards. --- .../opentracks/chart/ChartFragment.java | 4 ++-- .../dennisguse/opentracks/chart/ChartView.java | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java b/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java index e4f9a2771..f6e856368 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java @@ -88,7 +88,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin } if (PreferencesUtils.isKey(R.string.stats_rate_key, key)) { boolean reportSpeed = PreferencesUtils.isReportSpeed(activityTypeLocalized); - if (reportSpeed != viewBinding.chartView.getReportSpeed()) { + if (reportSpeed != viewBinding.chartView.isReportSpeed()) { viewBinding.chartView.setReportSpeed(reportSpeed); viewBinding.chartView.applyReportSpeed(); @@ -166,7 +166,7 @@ public void onTrackUpdated(Track track) { activityTypeLocalized = track.getActivityTypeLocalized(); boolean reportSpeed = PreferencesUtils.isReportSpeed(activityTypeLocalized); - if (reportSpeed != viewBinding.chartView.getReportSpeed()) { + if (reportSpeed != viewBinding.chartView.isReportSpeed()) { viewBinding.chartView.setReportSpeed(reportSpeed); viewBinding.chartView.applyReportSpeed(); } diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java index 3d0b33474..0e0150981 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java @@ -64,7 +64,7 @@ */ public class ChartView extends View { - private static final int Y_AXIS_INTERVALS = 5; + public static final int Y_AXIS_INTERVALS = 5; private static final int X_AXIS_INTERVALS = 4; @@ -112,15 +112,15 @@ public class ChartView extends View { private int getSpacer = SPACER; private int yAxisOffset = Y_AXIS_OFFSET; - private int width = 0; - private int height = 0; - private int effectiveWidth = 0; - private int effectiveHeight = 0; + private int width; + private int height; + private int effectiveWidth; + private int effectiveHeight; - private boolean chartByDistance = false; + private boolean chartByDistance; private UnitSystem unitSystem = UnitSystem.defaultUnitSystem(); private boolean reportSpeed = true; - private boolean showPointer = false; + private boolean showPointer; private final GestureDetectorCompat scrollFlingTab = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() { @@ -1022,7 +1022,7 @@ private int getY(final ChartValueSeries chartValueSeries,final double value) { } private double getMarkerXValue(final Marker marker) { - int xCordinate = marker.getDuration().toMillis(); + double xCordinate = marker.getDuration().toMillis(); if (chartByDistance) { xCordinate = marker.getLength().toKM_Miles(unitSystem); } From 4eb416e709f9aebcd4c2ae4b20ae1f2feb7c34f2 Mon Sep 17 00:00:00 2001 From: Avi Lad Date: Thu, 15 Feb 2024 13:44:03 -0500 Subject: [PATCH 4/8] Solving Issue #18. Renaming local variable, markers, to xAxisMarkers to not be confused with class level variable with same name. --- .../de/dennisguse/opentracks/chart/ChartView.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java index 0e0150981..906a9ca79 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java @@ -803,16 +803,16 @@ private double getXAxisInterval() { } private List getXAxisMarkerPositions(final double interval) { - final List markers = new ArrayList<>(); - markers.add(0d); + final List xAxisMarkers = new ArrayList<>(); + xAxisMarkers.add(0d); for (int i = 1; i * interval < maxX; i++) { - markers.add(i * interval); + xAxisMarkers.add(i * interval); } - if (markers.size() < 2) { - markers.add(maxX); + if (xAxisMarkers.size() < 2) { + xAxisMarkers.add(maxX); } - return markers; + return xAxisMarkers; } /** From 352b3d82ca7d3511dc499281a4983bf65d864291 Mon Sep 17 00:00:00 2001 From: Bharath290403 <77113881+Bharath290403@users.noreply.github.com> Date: Fri, 16 Feb 2024 00:03:30 -0500 Subject: [PATCH 5/8] Update ChartFragment.java Added a Lambda function to improve code Performance. #20 --- .../java/de/dennisguse/opentracks/chart/ChartFragment.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java b/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java index f6e856368..0c9aad531 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java @@ -105,17 +105,14 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin /** * A runnable that will setFrequency the orange pointer as appropriate and redraw. */ - private final Runnable updateChart = new Runnable() { - @Override - public void run() { + private final Runnable updateChart = ()->{ if (!isResumed()) { return; } viewBinding.chartView.setShowPointer(isSelectedTrackRecording()); viewBinding.chartView.invalidate(); - } - }; + }; @Override From eed087117daf70805022c587dfe75be3814ac3da Mon Sep 17 00:00:00 2001 From: SARANKIRTHIC02 Date: Fri, 16 Feb 2024 10:36:13 -0500 Subject: [PATCH 6/8] deprecated added for removal and --- src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java b/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java index 0c9aad531..baa30899e 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartFragment.java @@ -254,7 +254,7 @@ private synchronized void pauseTrackDataHub() { * Returns true if the selected track is recording. * Needs to be synchronized because trackDataHub can be accessed by multiple threads. */ - @Deprecated + @Deprecated(since = "verision x.x",forRemoval = true) //TODO Should not be dynamic but instead set while instantiating, i.e., newFragment(). private synchronized boolean isSelectedTrackRecording() { return trackDataHub != null && trackDataHub.isSelectedTrackRecording(); From 9747479fa297efe456b18e746347b5a65e403350 Mon Sep 17 00:00:00 2001 From: SARANKIRTHIC02 Date: Fri, 16 Feb 2024 10:58:19 -0500 Subject: [PATCH 7/8] issue 2 Determine from actual size of the used drawable --- src/main/java/de/dennisguse/opentracks/chart/ChartView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java index 906a9ca79..4269cb89a 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java @@ -78,7 +78,7 @@ public class ChartView extends View { private static final int Y_AXIS_OFFSET = 16; //TODO Determine from actual size of the used drawable - private static final float MARKER_X_ANCHOR = 13f / 48f; + private static final float MARKER_X_ANCHOR = 0.27083333f; static { X_FRACTION_FORMAT.setMaximumFractionDigits(1); From 8cb55c9267671c555995376d977a2d090ca93b2a Mon Sep 17 00:00:00 2001 From: SARANKIRTHIC02 Date: Fri, 16 Feb 2024 11:01:19 -0500 Subject: [PATCH 8/8] Removed comment --- src/main/java/de/dennisguse/opentracks/chart/ChartView.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java index 4269cb89a..a5bc13632 100644 --- a/src/main/java/de/dennisguse/opentracks/chart/ChartView.java +++ b/src/main/java/de/dennisguse/opentracks/chart/ChartView.java @@ -76,8 +76,7 @@ public class ChartView extends View { private static final int BORDER = 8; private static final int SPACER = 4; private static final int Y_AXIS_OFFSET = 16; - - //TODO Determine from actual size of the used drawable + private static final float MARKER_X_ANCHOR = 0.27083333f; static {