discord-jadx/app/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerView.java

554 lines
20 KiB
Java

package com.jaredrummler.android.colorpicker;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ComposeShader;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import c.k.a.a.e;
public class ColorPickerView extends View {
public float A = 360.0f;
public float B = 0.0f;
public float C = 0.0f;
public boolean D = false;
public String E = null;
public int F = -4342339;
public int G = -9539986;
public Rect H;
public Rect I;
public Rect J;
public Rect K;
public Point L = null;
public c.k.a.a.a M;
public c N;
public int i;
public int j;
public int k;
public int l;
public int m;
public int n;
public Paint o;
public Paint p;
public Paint q;
public Paint r;
/* renamed from: s reason: collision with root package name */
public Paint f2376s;
public Paint t;
public Shader u;
public Shader v;
public Shader w;
/* renamed from: x reason: collision with root package name */
public b f2377x;
/* renamed from: y reason: collision with root package name */
public b f2378y;
/* renamed from: z reason: collision with root package name */
public int f2379z = 255;
public class b {
public Canvas a;
public Bitmap b;
/* renamed from: c reason: collision with root package name */
public float f2380c;
public b(ColorPickerView colorPickerView, a aVar) {
}
}
public interface c {
}
public ColorPickerView(Context context, AttributeSet attributeSet) {
super(context, attributeSet, 0);
TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.f.ColorPickerView);
this.D = obtainStyledAttributes.getBoolean(R.f.ColorPickerView_cpv_alphaChannelVisible, false);
this.E = obtainStyledAttributes.getString(R.f.ColorPickerView_cpv_alphaChannelText);
this.F = obtainStyledAttributes.getColor(R.f.ColorPickerView_cpv_sliderColor, -4342339);
this.G = obtainStyledAttributes.getColor(R.f.ColorPickerView_cpv_borderColor, -9539986);
obtainStyledAttributes.recycle();
TypedArray obtainStyledAttributes2 = context.obtainStyledAttributes(new TypedValue().data, new int[]{16842808});
if (this.G == -9539986) {
this.G = obtainStyledAttributes2.getColor(0, -9539986);
}
if (this.F == -4342339) {
this.F = obtainStyledAttributes2.getColor(0, -4342339);
}
obtainStyledAttributes2.recycle();
this.i = c.i.a.f.e.o.c.z(getContext(), 30.0f);
this.j = c.i.a.f.e.o.c.z(getContext(), 20.0f);
this.k = c.i.a.f.e.o.c.z(getContext(), 10.0f);
this.l = c.i.a.f.e.o.c.z(getContext(), 5.0f);
this.n = c.i.a.f.e.o.c.z(getContext(), 4.0f);
this.m = c.i.a.f.e.o.c.z(getContext(), 2.0f);
this.o = new Paint();
this.p = new Paint();
this.f2376s = new Paint();
this.q = new Paint();
this.r = new Paint();
this.t = new Paint();
this.p.setStyle(Paint.Style.STROKE);
this.p.setStrokeWidth((float) c.i.a.f.e.o.c.z(getContext(), 2.0f));
this.p.setAntiAlias(true);
this.f2376s.setColor(this.F);
this.f2376s.setStyle(Paint.Style.STROKE);
this.f2376s.setStrokeWidth((float) c.i.a.f.e.o.c.z(getContext(), 2.0f));
this.f2376s.setAntiAlias(true);
this.r.setColor(-14935012);
this.r.setTextSize((float) c.i.a.f.e.o.c.z(getContext(), 14.0f));
this.r.setAntiAlias(true);
this.r.setTextAlign(Paint.Align.CENTER);
this.r.setFakeBoldText(true);
setFocusable(true);
setFocusableInTouchMode(true);
}
private int getPreferredHeight() {
int z2 = c.i.a.f.e.o.c.z(getContext(), 200.0f);
return this.D ? z2 + this.k + this.j : z2;
}
private int getPreferredWidth() {
return c.i.a.f.e.o.c.z(getContext(), 200.0f) + this.i + this.k;
}
/* JADX DEBUG: Can't convert new array creation: APUT found in different block: 0x0087: APUT
(r3v7 float[])
(0 ??[int, short, byte, char])
(wrap: float : 0x0085: ARITH (r2v4 float) = (wrap: float : 0x0083: ARITH (r2v3 float) = (1.0f float) / (r6v1 float)) * (r0v6 float))
*/
public final boolean a(MotionEvent motionEvent) {
Point point = this.L;
int i = 0;
if (point == null) {
return false;
}
int i2 = point.x;
int i3 = point.y;
float f = 0.0f;
if (this.J.contains(i2, i3)) {
float y2 = motionEvent.getY();
Rect rect = this.J;
float height = (float) rect.height();
float f2 = (float) rect.top;
if (y2 >= f2) {
f = y2 > ((float) rect.bottom) ? height : y2 - f2;
}
this.A = 360.0f - ((f * 360.0f) / height);
} else if (this.I.contains(i2, i3)) {
float x2 = motionEvent.getX();
float y3 = motionEvent.getY();
Rect rect2 = this.I;
float[] fArr = new float[2];
float width = (float) rect2.width();
float height2 = (float) rect2.height();
float f3 = (float) rect2.left;
float f4 = x2 < f3 ? 0.0f : x2 > ((float) rect2.right) ? width : x2 - f3;
float f5 = (float) rect2.top;
if (y3 >= f5) {
f = y3 > ((float) rect2.bottom) ? height2 : y3 - f5;
}
fArr[0] = (1.0f / width) * f4;
fArr[1] = 1.0f - ((1.0f / height2) * f);
this.B = fArr[0];
this.C = fArr[1];
} else {
Rect rect3 = this.K;
if (rect3 == null || !rect3.contains(i2, i3)) {
return false;
}
int x3 = (int) motionEvent.getX();
Rect rect4 = this.K;
int width2 = rect4.width();
int i4 = rect4.left;
if (x3 >= i4) {
i = x3 > rect4.right ? width2 : x3 - i4;
}
this.f2379z = 255 - ((i * 255) / width2);
}
return true;
}
public void b(int i, boolean z2) {
c cVar;
int alpha = Color.alpha(i);
float[] fArr = new float[3];
Color.RGBToHSV(Color.red(i), Color.green(i), Color.blue(i), fArr);
this.f2379z = alpha;
float f = fArr[0];
this.A = f;
float f2 = fArr[1];
this.B = f2;
float f3 = fArr[2];
this.C = f3;
if (z2 && (cVar = this.N) != null) {
((e) cVar).k(Color.HSVToColor(alpha, new float[]{f, f2, f3}));
}
invalidate();
}
public String getAlphaSliderText() {
return this.E;
}
public int getBorderColor() {
return this.G;
}
public int getColor() {
return Color.HSVToColor(this.f2379z, new float[]{this.A, this.B, this.C});
}
@Override // android.view.View
public int getPaddingBottom() {
return Math.max(super.getPaddingBottom(), 0);
}
@Override // android.view.View
public int getPaddingLeft() {
return Math.max(super.getPaddingLeft(), 0);
}
@Override // android.view.View
public int getPaddingRight() {
return Math.max(super.getPaddingRight(), 0);
}
@Override // android.view.View
public int getPaddingTop() {
return Math.max(super.getPaddingTop(), 0);
}
public int getSliderTrackerColor() {
return this.F;
}
@Override // android.view.View
public void onDraw(Canvas canvas) {
Rect rect;
if (this.H.width() > 0 && this.H.height() > 0) {
Rect rect2 = this.I;
this.t.setColor(this.G);
Rect rect3 = this.H;
canvas.drawRect((float) rect3.left, (float) rect3.top, (float) (rect2.right + 1), (float) (rect2.bottom + 1), this.t);
if (this.u == null) {
float f = (float) rect2.left;
this.u = new LinearGradient(f, (float) rect2.top, f, (float) rect2.bottom, -1, -16777216, Shader.TileMode.CLAMP);
}
b bVar = this.f2377x;
if (bVar == null || bVar.f2380c != this.A) {
if (bVar == null) {
this.f2377x = new b(this, null);
}
b bVar2 = this.f2377x;
if (bVar2.b == null) {
bVar2.b = Bitmap.createBitmap(rect2.width(), rect2.height(), Bitmap.Config.ARGB_8888);
}
b bVar3 = this.f2377x;
if (bVar3.a == null) {
bVar3.a = new Canvas(this.f2377x.b);
}
int HSVToColor = Color.HSVToColor(new float[]{this.A, 1.0f, 1.0f});
float f2 = (float) rect2.top;
this.v = new LinearGradient((float) rect2.left, f2, (float) rect2.right, f2, -1, HSVToColor, Shader.TileMode.CLAMP);
this.o.setShader(new ComposeShader(this.u, this.v, PorterDuff.Mode.MULTIPLY));
b bVar4 = this.f2377x;
bVar4.a.drawRect(0.0f, 0.0f, (float) bVar4.b.getWidth(), (float) this.f2377x.b.getHeight(), this.o);
this.f2377x.f2380c = this.A;
}
canvas.drawBitmap(this.f2377x.b, (Rect) null, rect2, (Paint) null);
float f3 = this.B;
float f4 = this.C;
Rect rect4 = this.I;
Point point = new Point();
point.x = (int) ((f3 * ((float) rect4.width())) + ((float) rect4.left));
point.y = (int) (((1.0f - f4) * ((float) rect4.height())) + ((float) rect4.top));
this.p.setColor(-16777216);
canvas.drawCircle((float) point.x, (float) point.y, (float) (this.l - c.i.a.f.e.o.c.z(getContext(), 1.0f)), this.p);
this.p.setColor(-2236963);
canvas.drawCircle((float) point.x, (float) point.y, (float) this.l, this.p);
Rect rect5 = this.J;
this.t.setColor(this.G);
canvas.drawRect((float) (rect5.left - 1), (float) (rect5.top - 1), (float) (rect5.right + 1), (float) (rect5.bottom + 1), this.t);
if (this.f2378y == null) {
b bVar5 = new b(this, null);
this.f2378y = bVar5;
bVar5.b = Bitmap.createBitmap(rect5.width(), rect5.height(), Bitmap.Config.ARGB_8888);
this.f2378y.a = new Canvas(this.f2378y.b);
int height = (int) (((float) rect5.height()) + 0.5f);
int[] iArr = new int[height];
float f5 = 360.0f;
for (int i = 0; i < height; i++) {
iArr[i] = Color.HSVToColor(new float[]{f5, 1.0f, 1.0f});
f5 -= 360.0f / ((float) height);
}
Paint paint = new Paint();
paint.setStrokeWidth(0.0f);
for (int i2 = 0; i2 < height; i2++) {
paint.setColor(iArr[i2]);
b bVar6 = this.f2378y;
float f6 = (float) i2;
bVar6.a.drawLine(0.0f, f6, (float) bVar6.b.getWidth(), f6, paint);
}
}
canvas.drawBitmap(this.f2378y.b, (Rect) null, rect5, (Paint) null);
float f7 = this.A;
Rect rect6 = this.J;
float height2 = (float) rect6.height();
Point point2 = new Point();
point2.y = (int) ((height2 - ((f7 * height2) / 360.0f)) + ((float) rect6.top));
point2.x = rect6.left;
RectF rectF = new RectF();
int i3 = rect5.left;
int i4 = this.m;
rectF.left = (float) (i3 - i4);
rectF.right = (float) (rect5.right + i4);
int i5 = point2.y;
int i6 = this.n / 2;
rectF.top = (float) (i5 - i6);
rectF.bottom = (float) (i6 + i5);
canvas.drawRoundRect(rectF, 2.0f, 2.0f, this.f2376s);
if (!(!this.D || (rect = this.K) == null || this.M == null)) {
this.t.setColor(this.G);
canvas.drawRect((float) (rect.left - 1), (float) (rect.top - 1), (float) (rect.right + 1), (float) (rect.bottom + 1), this.t);
this.M.draw(canvas);
float[] fArr = {this.A, this.B, this.C};
int HSVToColor2 = Color.HSVToColor(fArr);
int HSVToColor3 = Color.HSVToColor(0, fArr);
float f8 = (float) rect.top;
LinearGradient linearGradient = new LinearGradient((float) rect.left, f8, (float) rect.right, f8, HSVToColor2, HSVToColor3, Shader.TileMode.CLAMP);
this.w = linearGradient;
this.q.setShader(linearGradient);
canvas.drawRect(rect, this.q);
String str = this.E;
if (str != null && !str.equals("")) {
canvas.drawText(this.E, (float) rect.centerX(), (float) (c.i.a.f.e.o.c.z(getContext(), 4.0f) + rect.centerY()), this.r);
}
int i7 = this.f2379z;
Rect rect7 = this.K;
float width = (float) rect7.width();
Point point3 = new Point();
point3.x = (int) ((width - ((((float) i7) * width) / 255.0f)) + ((float) rect7.left));
point3.y = rect7.top;
RectF rectF2 = new RectF();
int i8 = point3.x;
int i9 = this.n / 2;
rectF2.left = (float) (i8 - i9);
rectF2.right = (float) (i9 + i8);
int i10 = rect.top;
int i11 = this.m;
rectF2.top = (float) (i10 - i11);
rectF2.bottom = (float) (rect.bottom + i11);
canvas.drawRoundRect(rectF2, 2.0f, 2.0f, this.f2376s);
}
}
}
/* JADX WARNING: Code restructure failed: missing block: B:18:0x0058, code lost:
if (r0 != false) goto L_0x005a;
*/
/* JADX WARNING: Code restructure failed: missing block: B:32:0x0087, code lost:
if (r1 > r6) goto L_0x0089;
*/
@Override // android.view.View
public void onMeasure(int i, int i2) {
int i3;
int mode = View.MeasureSpec.getMode(i);
int mode2 = View.MeasureSpec.getMode(i2);
int size = (View.MeasureSpec.getSize(i) - getPaddingLeft()) - getPaddingRight();
int size2 = (View.MeasureSpec.getSize(i2) - getPaddingBottom()) - getPaddingTop();
if (mode != 1073741824 && mode2 != 1073741824) {
int i4 = this.k;
int i5 = this.i;
i3 = size2 + i4 + i5;
int i6 = (size - i4) - i5;
if (this.D) {
int i7 = this.j;
i3 -= i4 + i7;
i6 += i4 + i7;
}
boolean z2 = true;
boolean z3 = i3 <= size;
if (i6 > size2) {
z2 = false;
}
if (!z3 || !z2) {
if (z2 || !z3) {
if (!z3) {
}
setMeasuredDimension(getPaddingRight() + getPaddingLeft() + size, getPaddingBottom() + getPaddingTop() + size2);
}
}
size2 = i6;
setMeasuredDimension(getPaddingRight() + getPaddingLeft() + size, getPaddingBottom() + getPaddingTop() + size2);
} else if (mode != 1073741824 || mode2 == 1073741824) {
if (mode2 == 1073741824 && mode != 1073741824) {
int i8 = this.k;
i3 = size2 + i8 + this.i;
if (this.D) {
i3 -= i8 + this.j;
}
}
setMeasuredDimension(getPaddingRight() + getPaddingLeft() + size, getPaddingBottom() + getPaddingTop() + size2);
} else {
int i9 = this.k;
int i10 = (size - i9) - this.i;
if (this.D) {
i10 += i9 + this.j;
}
if (i10 <= size2) {
size2 = i10;
}
setMeasuredDimension(getPaddingRight() + getPaddingLeft() + size, getPaddingBottom() + getPaddingTop() + size2);
}
size = i3;
setMeasuredDimension(getPaddingRight() + getPaddingLeft() + size, getPaddingBottom() + getPaddingTop() + size2);
}
@Override // android.view.View
public void onRestoreInstanceState(Parcelable parcelable) {
if (parcelable instanceof Bundle) {
Bundle bundle = (Bundle) parcelable;
this.f2379z = bundle.getInt("alpha");
this.A = bundle.getFloat("hue");
this.B = bundle.getFloat("sat");
this.C = bundle.getFloat("val");
this.D = bundle.getBoolean("show_alpha");
this.E = bundle.getString("alpha_text");
parcelable = bundle.getParcelable("instanceState");
}
super.onRestoreInstanceState(parcelable);
}
@Override // android.view.View
public Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.onSaveInstanceState());
bundle.putInt("alpha", this.f2379z);
bundle.putFloat("hue", this.A);
bundle.putFloat("sat", this.B);
bundle.putFloat("val", this.C);
bundle.putBoolean("show_alpha", this.D);
bundle.putString("alpha_text", this.E);
return bundle;
}
@Override // android.view.View
public void onSizeChanged(int i, int i2, int i3, int i4) {
super.onSizeChanged(i, i2, i3, i4);
Rect rect = new Rect();
this.H = rect;
rect.left = getPaddingLeft();
this.H.right = i - getPaddingRight();
this.H.top = getPaddingTop();
this.H.bottom = i2 - getPaddingBottom();
this.u = null;
this.v = null;
this.w = null;
this.f2377x = null;
this.f2378y = null;
Rect rect2 = this.H;
int i5 = rect2.left + 1;
int i6 = rect2.top + 1;
int i7 = rect2.bottom - 1;
int i8 = this.k;
int i9 = ((rect2.right - 1) - i8) - this.i;
if (this.D) {
i7 -= this.j + i8;
}
this.I = new Rect(i5, i6, i9, i7);
Rect rect3 = this.H;
int i10 = rect3.right;
this.J = new Rect((i10 - this.i) + 1, rect3.top + 1, i10 - 1, (rect3.bottom - 1) - (this.D ? this.k + this.j : 0));
if (this.D) {
Rect rect4 = this.H;
int i11 = rect4.bottom;
this.K = new Rect(rect4.left + 1, (i11 - this.j) + 1, rect4.right - 1, i11 - 1);
c.k.a.a.a aVar = new c.k.a.a.a(c.i.a.f.e.o.c.z(getContext(), 4.0f));
this.M = aVar;
aVar.setBounds(Math.round((float) this.K.left), Math.round((float) this.K.top), Math.round((float) this.K.right), Math.round((float) this.K.bottom));
}
}
@Override // android.view.View
public boolean onTouchEvent(MotionEvent motionEvent) {
boolean z2;
int action = motionEvent.getAction();
if (action == 0) {
this.L = new Point((int) motionEvent.getX(), (int) motionEvent.getY());
z2 = a(motionEvent);
} else if (action != 1) {
z2 = action != 2 ? false : a(motionEvent);
} else {
this.L = null;
z2 = a(motionEvent);
}
if (!z2) {
return super.onTouchEvent(motionEvent);
}
c cVar = this.N;
if (cVar != null) {
((e) cVar).k(Color.HSVToColor(this.f2379z, new float[]{this.A, this.B, this.C}));
}
invalidate();
return true;
}
public void setAlphaSliderText(int i) {
setAlphaSliderText(getContext().getString(i));
}
public void setAlphaSliderText(String str) {
this.E = str;
invalidate();
}
public void setAlphaSliderVisible(boolean z2) {
if (this.D != z2) {
this.D = z2;
this.u = null;
this.v = null;
this.w = null;
this.f2378y = null;
this.f2377x = null;
requestLayout();
}
}
public void setBorderColor(int i) {
this.G = i;
invalidate();
}
public void setColor(int i) {
b(i, false);
}
public void setOnColorChangedListener(c cVar) {
this.N = cVar;
}
public void setSliderTrackerColor(int i) {
this.F = i;
this.f2376s.setColor(i);
invalidate();
}
}