diff options
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/view')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/view/LineChartView.java | 138 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/view/PieChartView.java | 149 |
2 files changed, 0 insertions, 287 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/view/LineChartView.java b/app/src/main/java/de/danoeh/antennapod/view/LineChartView.java deleted file mode 100644 index 0eb225e8e..000000000 --- a/app/src/main/java/de/danoeh/antennapod/view/LineChartView.java +++ /dev/null @@ -1,138 +0,0 @@ -package de.danoeh.antennapod.view; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.DashPathEffect; -import android.graphics.LinearGradient; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.PixelFormat; -import android.graphics.Shader; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import androidx.annotation.NonNull; -import androidx.appcompat.widget.AppCompatImageView; -import androidx.appcompat.widget.ThemeUtils; -import de.danoeh.antennapod.R; -import io.reactivex.annotations.Nullable; - -public class LineChartView extends AppCompatImageView { - private LineChartDrawable drawable; - - public LineChartView(Context context) { - super(context); - setup(); - } - - public LineChartView(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - setup(); - } - - public LineChartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - setup(); - } - - @SuppressLint("ClickableViewAccessibility") - private void setup() { - drawable = new LineChartDrawable(); - setImageDrawable(drawable); - } - - /** - * Set of data values to display. - */ - public void setData(LineChartData data) { - drawable.data = data; - } - - public static class LineChartData { - private final long valueMax; - private final long[] values; - private final long[] verticalLines; - - public LineChartData(long[] values, long[] verticalLines) { - this.values = values; - long valueMax = 0; - for (long datum : values) { - valueMax = Math.max(datum, valueMax); - } - this.valueMax = valueMax; - this.verticalLines = verticalLines; - } - - public float getHeight(int item) { - return (float) values[item] / valueMax; - } - } - - private class LineChartDrawable extends Drawable { - private LineChartData data; - private final Paint paintLine; - private final Paint paintBackground; - private final Paint paintVerticalLines; - - private LineChartDrawable() { - paintLine = new Paint(); - paintLine.setFlags(Paint.ANTI_ALIAS_FLAG); - paintLine.setStyle(Paint.Style.STROKE); - paintLine.setStrokeJoin(Paint.Join.ROUND); - paintLine.setStrokeCap(Paint.Cap.ROUND); - paintLine.setColor(ThemeUtils.getThemeAttrColor(getContext(), R.attr.colorAccent)); - paintBackground = new Paint(); - paintBackground.setStyle(Paint.Style.FILL); - paintVerticalLines = new Paint(); - paintVerticalLines.setStyle(Paint.Style.STROKE); - paintVerticalLines.setPathEffect(new DashPathEffect(new float[] {10f, 10f}, 0f)); - paintVerticalLines.setColor(0x66777777); - } - - @Override - public void draw(@NonNull Canvas canvas) { - float width = getBounds().width(); - float height = getBounds().height(); - float usableHeight = height * 0.9f; - float stepSize = width / (data.values.length + 1); - - paintVerticalLines.setStrokeWidth(height * 0.005f); - for (long line : data.verticalLines) { - canvas.drawLine((line + 1) * stepSize, 0, (line + 1) * stepSize, height, paintVerticalLines); - } - - paintLine.setStrokeWidth(height * 0.015f); - Path path = new Path(); - for (int i = 0; i < data.values.length; i++) { - if (i == 0) { - path.moveTo((i + 1) * stepSize, (1 - data.getHeight(i)) * usableHeight + height * 0.05f); - } else { - path.lineTo((i + 1) * stepSize, (1 - data.getHeight(i)) * usableHeight + height * 0.05f); - } - } - canvas.drawPath(path, paintLine); - - path.lineTo(data.values.length * stepSize, height); - path.lineTo(stepSize, height); - paintBackground.setShader(new LinearGradient(0, 0, 0, height, - (ThemeUtils.getThemeAttrColor(getContext(), R.attr.colorAccent) & 0xffffff) + 0x66000000, - Color.TRANSPARENT, Shader.TileMode.CLAMP)); - canvas.drawPath(path, paintBackground); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - - @Override - public void setAlpha(int alpha) { - } - - @Override - public void setColorFilter(ColorFilter cf) { - } - } -} diff --git a/app/src/main/java/de/danoeh/antennapod/view/PieChartView.java b/app/src/main/java/de/danoeh/antennapod/view/PieChartView.java deleted file mode 100644 index ab4920119..000000000 --- a/app/src/main/java/de/danoeh/antennapod/view/PieChartView.java +++ /dev/null @@ -1,149 +0,0 @@ -package de.danoeh.antennapod.view; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.Paint; -import android.graphics.PixelFormat; -import android.graphics.RectF; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import androidx.annotation.NonNull; -import androidx.appcompat.widget.AppCompatImageView; -import io.reactivex.annotations.Nullable; - -public class PieChartView extends AppCompatImageView { - private PieChartDrawable drawable; - - public PieChartView(Context context) { - super(context); - setup(); - } - - public PieChartView(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - setup(); - } - - public PieChartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - setup(); - } - - @SuppressLint("ClickableViewAccessibility") - private void setup() { - drawable = new PieChartDrawable(); - setImageDrawable(drawable); - } - - /** - * Set of data values to display. - */ - public void setData(PieChartData data) { - drawable.data = data; - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - int width = getMeasuredWidth(); - setMeasuredDimension(width, width / 2); - } - - public static class PieChartData { - private static final int[] COLOR_VALUES = new int[]{0xFF3775E6, 0xffe51c23, 0xffff9800, 0xff259b24, 0xff9c27b0, - 0xff0099c6, 0xffdd4477, 0xff66aa00, 0xffb82e2e, 0xff316395, - 0xff994499, 0xff22aa99, 0xffaaaa11, 0xff6633cc, 0xff0073e6}; - - private final float valueSum; - private final float[] values; - - public PieChartData(float[] values) { - this.values = values; - float valueSum = 0; - for (float datum : values) { - valueSum += datum; - } - this.valueSum = valueSum; - } - - public float getSum() { - return valueSum; - } - - public float getPercentageOfItem(int index) { - if (valueSum == 0) { - return 0; - } - return values[index] / valueSum; - } - - public boolean isLargeEnoughToDisplay(int index) { - return getPercentageOfItem(index) > 0.04; - } - - public int getColorOfItem(int index) { - if (!isLargeEnoughToDisplay(index)) { - return Color.GRAY; - } - return COLOR_VALUES[index % COLOR_VALUES.length]; - } - } - - private static class PieChartDrawable extends Drawable { - private static final float PADDING_DEGREES = 3f; - private PieChartData data; - private final Paint paint; - - private PieChartDrawable() { - paint = new Paint(); - paint.setFlags(Paint.ANTI_ALIAS_FLAG); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeJoin(Paint.Join.ROUND); - paint.setStrokeCap(Paint.Cap.ROUND); - } - - @Override - public void draw(@NonNull Canvas canvas) { - final float strokeSize = getBounds().height() / 30f; - paint.setStrokeWidth(strokeSize); - - float radius = getBounds().height() - strokeSize; - float center = getBounds().width() / 2.f; - RectF arcBounds = new RectF(center - radius, strokeSize, center + radius, strokeSize + radius * 2); - - float startAngle = 180; - for (int i = 0; i < data.values.length; i++) { - if (!data.isLargeEnoughToDisplay(i)) { - break; - } - paint.setColor(data.getColorOfItem(i)); - float padding = i == 0 ? PADDING_DEGREES / 2 : PADDING_DEGREES; - float sweepAngle = (180f - PADDING_DEGREES) * data.getPercentageOfItem(i); - canvas.drawArc(arcBounds, startAngle + padding, sweepAngle - padding, false, paint); - startAngle = startAngle + sweepAngle; - } - - paint.setColor(Color.GRAY); - float sweepAngle = 360 - startAngle - PADDING_DEGREES / 2; - if (sweepAngle > PADDING_DEGREES) { - canvas.drawArc(arcBounds, startAngle + PADDING_DEGREES, sweepAngle - PADDING_DEGREES, false, paint); - } - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - - @Override - public void setAlpha(int alpha) { - } - - @Override - public void setColorFilter(ColorFilter cf) { - } - } -} |