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.Bitmap;
6import android.graphics.Canvas;
7import android.graphics.Color;
8import android.graphics.Paint;
9import android.graphics.PorterDuff;
10import android.graphics.PorterDuffXfermode;
11import android.graphics.RectF;
12import android.util.AttributeSet;
13import android.view.View;
14
15import org.tm.archive.R;
16
17public class ShapeScrim extends View {
18
19 private enum ShapeType {
20 CIRCLE, SQUARE
21 }
22
23 private final Paint eraser;
24 private final ShapeType shape;
25 private final float radius;
26 private final int canvasColor;
27
28 private Bitmap scrim;
29 private Canvas scrimCanvas;
30 private int scrimWidth;
31 private int scrimHeight;
32
33 public ShapeScrim(Context context) {
34 this(context, null);
35 }
36
37 public ShapeScrim(Context context, AttributeSet attrs) {
38 this(context, attrs, 0);
39 }
40
41 public ShapeScrim(Context context, AttributeSet attrs, int defStyleAttr) {
42 super(context, attrs, defStyleAttr);
43
44 if (attrs != null) {
45 TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ShapeScrim, 0, 0);
46 String shapeName = typedArray.getString(R.styleable.ShapeScrim_shape);
47
48 if ("square".equalsIgnoreCase(shapeName)) this.shape = ShapeType.SQUARE;
49 else if ("circle".equalsIgnoreCase(shapeName)) this.shape = ShapeType.CIRCLE;
50 else this.shape = ShapeType.SQUARE;
51
52 this.radius = typedArray.getFloat(R.styleable.ShapeScrim_radius, 0.4f);
53
54 typedArray.recycle();
55 } else {
56 this.shape = ShapeType.SQUARE;
57 this.radius = 0.4f;
58 }
59
60 this.eraser = new Paint();
61 this.eraser.setColor(0xFFFFFFFF);
62 this.eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
63
64 this.canvasColor = Color.parseColor("#55BDBDBD");
65 }
66
67 @Override
68 protected void onLayout(boolean changed, int l, int t, int r, int b) {
69 super.onLayout(changed, l, t, r, b);
70 int shortDimension = Math.min(getWidth(), getHeight());
71 float drawRadius = shortDimension * radius;
72
73 float left = (getMeasuredWidth() / 2 ) - drawRadius;
74 float top = (getMeasuredHeight() / 2) - drawRadius;
75 float right = left + (drawRadius * 2);
76 float bottom = top + (drawRadius * 2);
77
78 scrimWidth = (int) (right - left);
79 scrimHeight = (int) (bottom - top);
80 }
81
82 @Override
83 public void onDraw(Canvas canvas) {
84 super.onDraw(canvas);
85
86 int shortDimension = Math.min(getWidth(), getHeight());
87 float drawRadius = shortDimension * radius;
88
89 if (scrimCanvas == null) {
90 scrim = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
91 scrimCanvas = new Canvas(scrim);
92 }
93
94 scrim.eraseColor(Color.TRANSPARENT);
95 scrimCanvas.drawColor(canvasColor);
96
97 if (shape == ShapeType.CIRCLE) drawCircle(scrimCanvas, drawRadius, eraser);
98 else drawSquare(scrimCanvas, drawRadius, eraser);
99
100 canvas.drawBitmap(scrim, 0, 0, null);
101 }
102
103 @Override
104 public void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
105 super.onSizeChanged(width, height, oldHeight, oldHeight);
106
107 if (width != oldWidth || height != oldHeight) {
108 scrim = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
109 scrimCanvas = new Canvas(scrim);
110 }
111 }
112
113 private void drawCircle(Canvas canvas, float radius, Paint eraser) {
114 canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, eraser);
115 }
116
117 private void drawSquare(Canvas canvas, float radius, Paint eraser) {
118 float left = (getWidth() / 2 ) - radius;
119 float top = (getHeight() / 2) - radius;
120 float right = left + (radius * 2);
121 float bottom = top + (radius * 2);
122
123 RectF square = new RectF(left, top, right, bottom);
124
125 canvas.drawRoundRect(square, 25, 25, eraser);
126 }
127
128 public int getScrimWidth() {
129 return scrimWidth;
130 }
131
132 public int getScrimHeight() {
133 return scrimHeight;
134 }
135}