Skip to content

Commit

Permalink
draw achartengine zoom buttons with scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiusteng committed Jan 12, 2024
1 parent 1e56e1d commit 35b0e4b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Binary file added app/src/main/assets/zoom-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/zoom_in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/zoom_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 18 additions & 9 deletions app/src/main/java/org/achartengine/GraphicalView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.achartengine.tools.Zoom;
import org.achartengine.tools.ZoomListener;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand Down Expand Up @@ -97,12 +98,13 @@ public GraphicalView(Context context, AbstractChart chart) {
mRenderer = ((RoundChart) mChart).getRenderer();
}
if (mRenderer.isZoomButtonsVisible()) {
zoomInImage = BitmapFactory.decodeStream(GraphicalView.class
.getResourceAsStream("image/zoom_in.png"));
zoomOutImage = BitmapFactory.decodeStream(GraphicalView.class
.getResourceAsStream("image/zoom_out.png"));
fitZoomImage = BitmapFactory.decodeStream(GraphicalView.class
.getResourceAsStream("image/zoom-1.png"));
try {
zoomInImage = BitmapFactory.decodeStream(context.getAssets().open("zoom_in.png"));
zoomOutImage = BitmapFactory.decodeStream(context.getAssets().open("zoom_out.png"));
fitZoomImage = BitmapFactory.decodeStream(context.getAssets().open("zoom-1.png"));
} catch (Exception e) {
// no images for buttons
}
}

if (mRenderer instanceof XYMultipleSeriesRenderer
Expand Down Expand Up @@ -164,6 +166,7 @@ public AbstractChart getChart() {
return mChart;
}

@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Expand All @@ -187,13 +190,19 @@ protected void onDraw(Canvas canvas) {
canvas.drawRoundRect(mZoomR, zoomSize / 3, zoomSize / 3, mPaint);
float buttonY = top + height - zoomSize * 0.625f;
if(zoomInImage != null) {
canvas.drawBitmap(zoomInImage, left + width - zoomSize * 2.75f, buttonY, null);
canvas.drawBitmap(zoomInImage, null, new RectF(
left + width - zoomSize * 2.75f, buttonY,
left + width - zoomSize * 2.25f, buttonY + (zoomSize * 0.5f)), null);
}
if(zoomOutImage != null) {
canvas.drawBitmap(zoomOutImage, left + width - zoomSize * 1.75f, buttonY, null);
canvas.drawBitmap(zoomOutImage, null, new RectF(
left + width - zoomSize * 1.75f, buttonY,
left + width - zoomSize * 1.25f, buttonY + (zoomSize * 0.5f)), null);
}
if(fitZoomImage != null) {
canvas.drawBitmap(fitZoomImage, left + width - zoomSize * 0.75f, buttonY, null);
canvas.drawBitmap(fitZoomImage, null, new RectF(
left + width - zoomSize * 0.75f, buttonY,
left + width - zoomSize * 0.25f, buttonY + (zoomSize * 0.5f)), null);
}
}
mDrawn = true;
Expand Down

0 comments on commit 35b0e4b

Please sign in to comment.