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

232 lines
8.1 KiB
Java

package com.jaredrummler.android.colorpicker;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.ColorInt;
import androidx.core.view.ViewCompat;
import c.i.a.f.e.o.c;
import c.k.a.a.a;
import java.util.Locale;
public class ColorPanelView extends View {
public Drawable i;
public Paint j;
public Paint k;
public Paint l;
public Paint m;
public Rect n;
public Rect o;
public RectF p = new RectF();
public boolean q;
public int r;
/* renamed from: s reason: collision with root package name */
public int f2375s = -9539986;
public int t = -16777216;
public int u;
public ColorPanelView(Context context, AttributeSet attributeSet) {
super(context, attributeSet, 0);
TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.f.ColorPanelView);
this.u = obtainStyledAttributes.getInt(R.f.ColorPanelView_cpv_colorShape, 1);
boolean z2 = obtainStyledAttributes.getBoolean(R.f.ColorPanelView_cpv_showOldColor, false);
this.q = z2;
if (!z2 || this.u == 1) {
this.f2375s = obtainStyledAttributes.getColor(R.f.ColorPanelView_cpv_borderColor, -9539986);
obtainStyledAttributes.recycle();
if (this.f2375s == -9539986) {
TypedArray obtainStyledAttributes2 = context.obtainStyledAttributes(new TypedValue().data, new int[]{16842808});
this.f2375s = obtainStyledAttributes2.getColor(0, this.f2375s);
obtainStyledAttributes2.recycle();
}
this.r = c.z(context, 1.0f);
Paint paint = new Paint();
this.j = paint;
paint.setAntiAlias(true);
Paint paint2 = new Paint();
this.k = paint2;
paint2.setAntiAlias(true);
if (this.q) {
this.m = new Paint();
}
if (this.u == 1) {
Bitmap bitmap = ((BitmapDrawable) context.getResources().getDrawable(R.b.cpv_alpha)).getBitmap();
Paint paint3 = new Paint();
this.l = paint3;
paint3.setAntiAlias(true);
Shader.TileMode tileMode = Shader.TileMode.REPEAT;
this.l.setShader(new BitmapShader(bitmap, tileMode, tileMode));
return;
}
return;
}
throw new IllegalStateException("Color preview is only available in circle mode");
}
public void a() {
int[] iArr = new int[2];
Rect rect = new Rect();
getLocationOnScreen(iArr);
getWindowVisibleDisplayFrame(rect);
Context context = getContext();
int width = getWidth();
int height = getHeight();
int i = (height / 2) + iArr[1];
int i2 = (width / 2) + iArr[0];
if (ViewCompat.getLayoutDirection(this) == 0) {
i2 = context.getResources().getDisplayMetrics().widthPixels - i2;
}
StringBuilder sb = new StringBuilder("#");
if (Color.alpha(this.t) != 255) {
sb.append(Integer.toHexString(this.t).toUpperCase(Locale.ENGLISH));
} else {
sb.append(String.format("%06X", Integer.valueOf(16777215 & this.t)).toUpperCase(Locale.ENGLISH));
}
Toast makeText = Toast.makeText(context, sb.toString(), 0);
if (i < rect.height()) {
makeText.setGravity(8388661, i2, (iArr[1] + height) - rect.top);
} else {
makeText.setGravity(81, 0, height);
}
makeText.show();
}
public int getBorderColor() {
return this.f2375s;
}
public int getColor() {
return this.t;
}
public int getShape() {
return this.u;
}
@Override // android.view.View
public void onDraw(Canvas canvas) {
this.j.setColor(this.f2375s);
this.k.setColor(this.t);
int i = this.u;
if (i == 0) {
if (this.r > 0) {
canvas.drawRect(this.n, this.j);
}
Drawable drawable = this.i;
if (drawable != null) {
drawable.draw(canvas);
}
canvas.drawRect(this.o, this.k);
} else if (i == 1) {
int measuredWidth = getMeasuredWidth() / 2;
if (this.r > 0) {
canvas.drawCircle((float) (getMeasuredWidth() / 2), (float) (getMeasuredHeight() / 2), (float) measuredWidth, this.j);
}
if (Color.alpha(this.t) < 255) {
canvas.drawCircle((float) (getMeasuredWidth() / 2), (float) (getMeasuredHeight() / 2), (float) (measuredWidth - this.r), this.l);
}
if (this.q) {
canvas.drawArc(this.p, 90.0f, 180.0f, true, this.m);
canvas.drawArc(this.p, 270.0f, 180.0f, true, this.k);
return;
}
canvas.drawCircle((float) (getMeasuredWidth() / 2), (float) (getMeasuredHeight() / 2), (float) (measuredWidth - this.r), this.k);
}
}
@Override // android.view.View
public void onMeasure(int i, int i2) {
int i3 = this.u;
if (i3 == 0) {
setMeasuredDimension(View.MeasureSpec.getSize(i), View.MeasureSpec.getSize(i2));
} else if (i3 == 1) {
super.onMeasure(i, i);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
} else {
super.onMeasure(i, i2);
}
}
@Override // android.view.View
public void onRestoreInstanceState(Parcelable parcelable) {
if (parcelable instanceof Bundle) {
Bundle bundle = (Bundle) parcelable;
this.t = bundle.getInt("color");
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("color", this.t);
return bundle;
}
@Override // android.view.View
public void onSizeChanged(int i, int i2, int i3, int i4) {
super.onSizeChanged(i, i2, i3, i4);
if (this.u == 0 || this.q) {
Rect rect = new Rect();
this.n = rect;
rect.left = getPaddingLeft();
this.n.right = i - getPaddingRight();
this.n.top = getPaddingTop();
this.n.bottom = i2 - getPaddingBottom();
if (this.q) {
Rect rect2 = this.n;
int i5 = rect2.left;
int i6 = this.r;
this.p = new RectF((float) (i5 + i6), (float) (rect2.top + i6), (float) (rect2.right - i6), (float) (rect2.bottom - i6));
return;
}
Rect rect3 = this.n;
int i7 = rect3.left;
int i8 = this.r;
this.o = new Rect(i7 + i8, rect3.top + i8, rect3.right - i8, rect3.bottom - i8);
a aVar = new a(c.z(getContext(), 4.0f));
this.i = aVar;
aVar.setBounds(Math.round((float) this.o.left), Math.round((float) this.o.top), Math.round((float) this.o.right), Math.round((float) this.o.bottom));
}
}
public void setBorderColor(int i) {
this.f2375s = i;
invalidate();
}
public void setColor(int i) {
this.t = i;
invalidate();
}
public void setOriginalColor(@ColorInt int i) {
Paint paint = this.m;
if (paint != null) {
paint.setColor(i);
}
}
public void setShape(int i) {
this.u = i;
invalidate();
}
}