2021-07-24 02:37:17 +00:00
|
|
|
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 = -9539986;
|
|
|
|
|
|
|
|
/* renamed from: s reason: collision with root package name */
|
2021-07-27 00:35:07 +00:00
|
|
|
public int f2394s = -16777216;
|
2021-07-24 02:37:17 +00:00
|
|
|
public int t;
|
|
|
|
|
|
|
|
public ColorPanelView(Context context, AttributeSet attributeSet) {
|
|
|
|
super(context, attributeSet, 0);
|
|
|
|
TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.f.ColorPanelView);
|
|
|
|
this.t = obtainStyledAttributes.getInt(R.f.ColorPanelView_cpv_colorShape, 1);
|
|
|
|
boolean z2 = obtainStyledAttributes.getBoolean(R.f.ColorPanelView_cpv_showOldColor, false);
|
|
|
|
this.q = z2;
|
|
|
|
if (!z2 || this.t == 1) {
|
|
|
|
this.r = obtainStyledAttributes.getColor(R.f.ColorPanelView_cpv_borderColor, -9539986);
|
|
|
|
obtainStyledAttributes.recycle();
|
|
|
|
if (this.r == -9539986) {
|
|
|
|
TypedArray obtainStyledAttributes2 = context.obtainStyledAttributes(new TypedValue().data, new int[]{16842808});
|
|
|
|
this.r = obtainStyledAttributes2.getColor(0, this.r);
|
|
|
|
obtainStyledAttributes2.recycle();
|
|
|
|
}
|
|
|
|
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.t == 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("#");
|
2021-07-27 00:35:07 +00:00
|
|
|
if (Color.alpha(this.f2394s) != 255) {
|
|
|
|
sb.append(Integer.toHexString(this.f2394s).toUpperCase(Locale.ENGLISH));
|
2021-07-24 02:37:17 +00:00
|
|
|
} else {
|
2021-07-27 00:35:07 +00:00
|
|
|
sb.append(String.format("%06X", Integer.valueOf(16777215 & this.f2394s)).toUpperCase(Locale.ENGLISH));
|
2021-07-24 02:37:17 +00:00
|
|
|
}
|
|
|
|
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.r;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getColor() {
|
2021-07-27 00:35:07 +00:00
|
|
|
return this.f2394s;
|
2021-07-24 02:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getShape() {
|
|
|
|
return this.t;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // android.view.View
|
|
|
|
public void onDraw(Canvas canvas) {
|
|
|
|
this.j.setColor(this.r);
|
2021-07-27 00:35:07 +00:00
|
|
|
this.k.setColor(this.f2394s);
|
2021-07-24 02:37:17 +00:00
|
|
|
int i = this.t;
|
|
|
|
if (i == 0) {
|
|
|
|
Drawable drawable = this.i;
|
|
|
|
if (drawable != null) {
|
|
|
|
drawable.draw(canvas);
|
|
|
|
}
|
|
|
|
canvas.drawRect(this.o, this.k);
|
|
|
|
} else if (i == 1) {
|
|
|
|
int measuredWidth = getMeasuredWidth() / 2;
|
2021-07-27 00:35:07 +00:00
|
|
|
if (Color.alpha(this.f2394s) < 255) {
|
2021-07-24 02:37:17 +00:00
|
|
|
canvas.drawCircle((float) (getMeasuredWidth() / 2), (float) (getMeasuredHeight() / 2), (float) (measuredWidth + 0), 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 + 0), this.k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // android.view.View
|
|
|
|
public void onMeasure(int i, int i2) {
|
|
|
|
int i3 = this.t;
|
|
|
|
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;
|
2021-07-27 00:35:07 +00:00
|
|
|
this.f2394s = bundle.getInt("color");
|
2021-07-24 02:37:17 +00:00
|
|
|
parcelable = bundle.getParcelable("instanceState");
|
|
|
|
}
|
|
|
|
super.onRestoreInstanceState(parcelable);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // android.view.View
|
|
|
|
public Parcelable onSaveInstanceState() {
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putParcelable("instanceState", super.onSaveInstanceState());
|
2021-07-27 00:35:07 +00:00
|
|
|
bundle.putInt("color", this.f2394s);
|
2021-07-24 02:37:17 +00:00
|
|
|
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.t == 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;
|
|
|
|
this.p = new RectF((float) (rect2.left + 0), (float) (rect2.top + 0), (float) (rect2.right + 0), (float) (rect2.bottom + 0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Rect rect3 = this.n;
|
|
|
|
this.o = new Rect(rect3.left + 0, rect3.top + 0, rect3.right + 0, rect3.bottom + 0);
|
|
|
|
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.r = i;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setColor(int i) {
|
2021-07-27 00:35:07 +00:00
|
|
|
this.f2394s = i;
|
2021-07-24 02:37:17 +00:00
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOriginalColor(@ColorInt int i) {
|
|
|
|
Paint paint = this.m;
|
|
|
|
if (paint != null) {
|
|
|
|
paint.setColor(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setShape(int i) {
|
|
|
|
this.t = i;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|