That fuck shit the fascists are using
1package org.tm.archive.components;
2
3import android.content.Context;
4import android.content.res.TypedArray;
5import android.graphics.Canvas;
6import android.graphics.Paint;
7import android.graphics.RectF;
8import android.os.Bundle;
9import android.os.Parcelable;
10import android.util.AttributeSet;
11import android.view.View;
12
13import androidx.annotation.ColorInt;
14import androidx.annotation.NonNull;
15import androidx.annotation.Nullable;
16
17import org.tm.archive.R;
18import org.tm.archive.util.Util;
19
20public class ArcProgressBar extends View {
21
22 private static final int DEFAULT_WIDTH = 10;
23 private static final float DEFAULT_PROGRESS = 0f;
24 private static final int DEFAULT_BACKGROUND_COLOR = 0xFF000000;
25 private static final int DEFAULT_FOREGROUND_COLOR = 0xFFFFFFFF;
26 private static final float DEFAULT_START_ANGLE = 0f;
27 private static final float DEFAULT_SWEEP_ANGLE = 360f;
28 private static final boolean DEFAULT_ROUNDED_ENDS = true;
29
30 private static final String SUPER = "arcprogressbar.super";
31 private static final String PROGRESS = "arcprogressbar.progress";
32
33 private float progress;
34 private final float width;
35 private final RectF arcRect = new RectF();
36
37 private final Paint arcBackgroundPaint;
38 private final Paint arcForegroundPaint;
39 private final float arcStartAngle;
40 private final float arcSweepAngle;
41
42 public ArcProgressBar(@NonNull Context context) {
43 this(context, null);
44 }
45
46 public ArcProgressBar(@NonNull Context context, @Nullable AttributeSet attrs) {
47 this(context, attrs, 0);
48 }
49
50 public ArcProgressBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
51 super(context, attrs, defStyleAttr);
52
53 TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ArcProgressBar, defStyleAttr, 0);
54
55 width = attributes.getDimensionPixelSize(R.styleable.ArcProgressBar_arcWidth, DEFAULT_WIDTH);
56 progress = attributes.getFloat(R.styleable.ArcProgressBar_arcProgress, DEFAULT_PROGRESS);
57 arcBackgroundPaint = createPaint(width, attributes.getColor(R.styleable.ArcProgressBar_arcBackgroundColor, DEFAULT_BACKGROUND_COLOR));
58 arcForegroundPaint = createPaint(width, attributes.getColor(R.styleable.ArcProgressBar_arcForegroundColor, DEFAULT_FOREGROUND_COLOR));
59 arcStartAngle = attributes.getFloat(R.styleable.ArcProgressBar_arcStartAngle, DEFAULT_START_ANGLE);
60 arcSweepAngle = attributes.getFloat(R.styleable.ArcProgressBar_arcSweepAngle, DEFAULT_SWEEP_ANGLE);
61
62 if (attributes.getBoolean(R.styleable.ArcProgressBar_arcRoundedEnds, DEFAULT_ROUNDED_ENDS)) {
63 arcForegroundPaint.setStrokeCap(Paint.Cap.ROUND);
64
65 if (arcSweepAngle <= 360f) {
66 arcBackgroundPaint.setStrokeCap(Paint.Cap.ROUND);
67 }
68 }
69
70 attributes.recycle();
71 }
72
73 private static Paint createPaint(float width, @ColorInt int color) {
74 Paint paint = new Paint();
75
76 paint.setStrokeWidth(width);
77 paint.setStyle(Paint.Style.STROKE);
78 paint.setAntiAlias(true);
79 paint.setColor(color);
80
81 return paint;
82 }
83
84 public void setProgress(float progress) {
85 if (this.progress != progress) {
86 this.progress = progress;
87 invalidate();
88 }
89 }
90
91 @Override
92 protected @Nullable Parcelable onSaveInstanceState() {
93 Parcelable superState = super.onSaveInstanceState();
94
95 Bundle bundle = new Bundle();
96 bundle.putParcelable(SUPER, superState);
97 bundle.putFloat(PROGRESS, progress);
98
99 return bundle;
100 }
101
102 @Override
103 protected void onRestoreInstanceState(Parcelable state) {
104 if (state.getClass() != Bundle.class) throw new IllegalStateException("Expected");
105
106 Bundle restoreState = (Bundle) state;
107
108 Parcelable superState = restoreState.getParcelable(SUPER);
109 super.onRestoreInstanceState(superState);
110
111 progress = restoreState.getLong(PROGRESS);
112 }
113
114 @Override
115 protected void onDraw(Canvas canvas) {
116 float halfWidth = width / 2f;
117 arcRect.set(0 + halfWidth,
118 0 + halfWidth,
119 getWidth() - halfWidth,
120 getHeight() - halfWidth);
121
122 canvas.drawArc(arcRect, arcStartAngle, arcSweepAngle, false, arcBackgroundPaint);
123 canvas.drawArc(arcRect, arcStartAngle, arcSweepAngle * Util.clamp(progress, 0f, 1f), false, arcForegroundPaint);
124 }
125}