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.BitmapFactory;
7import android.graphics.Canvas;
8import android.graphics.Paint;
9import android.graphics.PorterDuff;
10import android.graphics.PorterDuffColorFilter;
11import android.graphics.PorterDuffXfermode;
12import android.util.AttributeSet;
13import android.view.View;
14
15import org.tm.archive.R;
16
17public class HourglassView extends View {
18
19 private final Paint foregroundPaint;
20 private final Paint backgroundPaint;
21 private final Paint progressPaint;
22
23 private Bitmap empty;
24 private Bitmap full;
25
26 private float percentage;
27 private int offset;
28
29 public HourglassView(Context context) {
30 this(context, null);
31 }
32
33 public HourglassView(Context context, AttributeSet attrs) {
34 this(context, attrs, 0);
35 }
36
37 public HourglassView(Context context, AttributeSet attrs, int defStyleAttr) {
38 super(context, attrs, defStyleAttr);
39
40 int tint = 0;
41
42 if (attrs != null) {
43 TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HourglassView, 0, 0);
44 this.empty = BitmapFactory.decodeResource(getResources(), typedArray.getResourceId(R.styleable.HourglassView_empty, 0));
45 this.full = BitmapFactory.decodeResource(getResources(), typedArray.getResourceId(R.styleable.HourglassView_full, 0));
46 this.percentage = typedArray.getInt(R.styleable.HourglassView_percentage, 50);
47 this.offset = typedArray.getInt(R.styleable.HourglassView_offset, 0);
48 tint = typedArray.getColor(R.styleable.HourglassView_tint, 0);
49 typedArray.recycle();
50 }
51
52 this.backgroundPaint = new Paint();
53 this.foregroundPaint = new Paint();
54 this.progressPaint = new Paint();
55
56 this.backgroundPaint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));
57 this.foregroundPaint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));
58
59 this.progressPaint.setColor(getResources().getColor(R.color.black));
60 this.progressPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
61
62 setLayerType(View.LAYER_TYPE_SOFTWARE, null);
63 }
64
65 @Override
66 public void onDraw(Canvas canvas) {
67 float progressHeight = (full.getHeight() - (offset*2)) * (percentage / 100);
68
69 canvas.drawBitmap(full, 0, 0, backgroundPaint);
70 canvas.drawRect(0, 0, full.getWidth(), offset + progressHeight, progressPaint);
71 canvas.drawBitmap(empty, 0, 0, foregroundPaint);
72 }
73
74 public void setPercentage(float percentage) {
75 this.percentage = percentage;
76 invalidate();
77 }
78
79 public void setTint(int tint) {
80 this.backgroundPaint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));
81 this.foregroundPaint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));
82 }
83}