374 lines
13 KiB
Java
374 lines
13 KiB
Java
package c.q.a.l;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Matrix;
|
|
import android.graphics.RectF;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.util.AttributeSet;
|
|
import androidx.annotation.IntRange;
|
|
import androidx.annotation.Nullable;
|
|
import c.q.a.h.c;
|
|
import c.q.a.l.c;
|
|
import com.yalantis.ucrop.UCropActivity;
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.Arrays;
|
|
/* compiled from: CropImageView */
|
|
public class a extends c {
|
|
public float A;
|
|
public c B;
|
|
public Runnable C;
|
|
public Runnable D;
|
|
public float E;
|
|
public float F;
|
|
public int G;
|
|
public int H;
|
|
public long I;
|
|
|
|
/* renamed from: x reason: collision with root package name */
|
|
public final RectF f1529x;
|
|
|
|
/* renamed from: y reason: collision with root package name */
|
|
public final Matrix f1530y;
|
|
|
|
/* renamed from: z reason: collision with root package name */
|
|
public float f1531z;
|
|
|
|
/* compiled from: CropImageView */
|
|
/* renamed from: c.q.a.l.a$a reason: collision with other inner class name */
|
|
public static class RunnableC0172a implements Runnable {
|
|
public final WeakReference<a> i;
|
|
public final long j;
|
|
public final long k = System.currentTimeMillis();
|
|
public final float l;
|
|
public final float m;
|
|
public final float n;
|
|
public final float o;
|
|
public final float p;
|
|
public final float q;
|
|
public final boolean r;
|
|
|
|
public RunnableC0172a(a aVar, long j, float f, float f2, float f3, float f4, float f5, float f6, boolean z2) {
|
|
this.i = new WeakReference<>(aVar);
|
|
this.j = j;
|
|
this.l = f;
|
|
this.m = f2;
|
|
this.n = f3;
|
|
this.o = f4;
|
|
this.p = f5;
|
|
this.q = f6;
|
|
this.r = z2;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
a aVar = this.i.get();
|
|
if (aVar != null) {
|
|
float min = (float) Math.min(this.j, System.currentTimeMillis() - this.k);
|
|
float f = this.n;
|
|
float f2 = (float) this.j;
|
|
float f3 = (min / f2) - 1.0f;
|
|
float f4 = (f3 * f3 * f3) + 1.0f;
|
|
float f5 = (f * f4) + 0.0f;
|
|
float f6 = (f4 * this.o) + 0.0f;
|
|
float A = c.i.a.f.e.o.c.A(min, 0.0f, this.q, f2);
|
|
if (min < ((float) this.j)) {
|
|
float[] fArr = aVar.j;
|
|
aVar.g(f5 - (fArr[0] - this.l), f6 - (fArr[1] - this.m));
|
|
if (!this.r) {
|
|
aVar.l(this.p + A, aVar.f1529x.centerX(), aVar.f1529x.centerY());
|
|
}
|
|
if (!aVar.j(aVar.i)) {
|
|
aVar.post(this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* compiled from: CropImageView */
|
|
public static class b implements Runnable {
|
|
public final WeakReference<a> i;
|
|
public final long j;
|
|
public final long k = System.currentTimeMillis();
|
|
public final float l;
|
|
public final float m;
|
|
public final float n;
|
|
public final float o;
|
|
|
|
public b(a aVar, long j, float f, float f2, float f3, float f4) {
|
|
this.i = new WeakReference<>(aVar);
|
|
this.j = j;
|
|
this.l = f;
|
|
this.m = f2;
|
|
this.n = f3;
|
|
this.o = f4;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
a aVar = this.i.get();
|
|
if (aVar != null) {
|
|
float min = (float) Math.min(this.j, System.currentTimeMillis() - this.k);
|
|
float A = c.i.a.f.e.o.c.A(min, 0.0f, this.m, (float) this.j);
|
|
if (min < ((float) this.j)) {
|
|
aVar.l(this.l + A, this.n, this.o);
|
|
aVar.post(this);
|
|
return;
|
|
}
|
|
aVar.setImageToWrapCropBounds(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public a(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
}
|
|
|
|
public a(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.f1529x = new RectF();
|
|
this.f1530y = new Matrix();
|
|
this.A = 10.0f;
|
|
this.D = null;
|
|
this.G = 0;
|
|
this.H = 0;
|
|
this.I = 500;
|
|
}
|
|
|
|
@Override // c.q.a.l.c
|
|
public void d() {
|
|
super.d();
|
|
Drawable drawable = getDrawable();
|
|
if (drawable != null) {
|
|
float intrinsicWidth = (float) drawable.getIntrinsicWidth();
|
|
float intrinsicHeight = (float) drawable.getIntrinsicHeight();
|
|
if (this.f1531z == 0.0f) {
|
|
this.f1531z = intrinsicWidth / intrinsicHeight;
|
|
}
|
|
int i = this.m;
|
|
float f = (float) i;
|
|
float f2 = this.f1531z;
|
|
int i2 = (int) (f / f2);
|
|
int i3 = this.n;
|
|
if (i2 > i3) {
|
|
float f3 = (float) i3;
|
|
int i4 = (int) (f2 * f3);
|
|
int i5 = (i - i4) / 2;
|
|
this.f1529x.set((float) i5, 0.0f, (float) (i4 + i5), f3);
|
|
} else {
|
|
int i6 = (i3 - i2) / 2;
|
|
this.f1529x.set(0.0f, (float) i6, f, (float) (i2 + i6));
|
|
}
|
|
h(intrinsicWidth, intrinsicHeight);
|
|
float width = this.f1529x.width();
|
|
float height = this.f1529x.height();
|
|
float max = Math.max(this.f1529x.width() / intrinsicWidth, this.f1529x.height() / intrinsicHeight);
|
|
RectF rectF = this.f1529x;
|
|
float f4 = ((height - (intrinsicHeight * max)) / 2.0f) + rectF.top;
|
|
this.l.reset();
|
|
this.l.postScale(max, max);
|
|
this.l.postTranslate(((width - (intrinsicWidth * max)) / 2.0f) + rectF.left, f4);
|
|
setImageMatrix(this.l);
|
|
c cVar = this.B;
|
|
if (cVar != null) {
|
|
((d) cVar).a.j.setTargetAspectRatio(this.f1531z);
|
|
}
|
|
c.a aVar = this.o;
|
|
if (aVar != null) {
|
|
((UCropActivity.a) aVar).b(getCurrentScale());
|
|
((UCropActivity.a) this.o).a(getCurrentAngle());
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // c.q.a.l.c
|
|
public void f(float f, float f2, float f3) {
|
|
if (f > 1.0f && getCurrentScale() * f <= getMaxScale()) {
|
|
super.f(f, f2, f3);
|
|
} else if (f < 1.0f && getCurrentScale() * f >= getMinScale()) {
|
|
super.f(f, f2, f3);
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
public c.q.a.h.c getCropBoundsChangeListener() {
|
|
return this.B;
|
|
}
|
|
|
|
public float getMaxScale() {
|
|
return this.E;
|
|
}
|
|
|
|
public float getMinScale() {
|
|
return this.F;
|
|
}
|
|
|
|
public float getTargetAspectRatio() {
|
|
return this.f1531z;
|
|
}
|
|
|
|
public final void h(float f, float f2) {
|
|
float min = Math.min(Math.min(this.f1529x.width() / f, this.f1529x.width() / f2), Math.min(this.f1529x.height() / f2, this.f1529x.height() / f));
|
|
this.F = min;
|
|
this.E = min * this.A;
|
|
}
|
|
|
|
public void i() {
|
|
removeCallbacks(this.C);
|
|
removeCallbacks(this.D);
|
|
}
|
|
|
|
public boolean j(float[] fArr) {
|
|
this.f1530y.reset();
|
|
this.f1530y.setRotate(-getCurrentAngle());
|
|
float[] copyOf = Arrays.copyOf(fArr, fArr.length);
|
|
this.f1530y.mapPoints(copyOf);
|
|
float[] s2 = c.q.a.k.a.s(this.f1529x);
|
|
this.f1530y.mapPoints(s2);
|
|
return c.q.a.k.a.g0(copyOf).contains(c.q.a.k.a.g0(s2));
|
|
}
|
|
|
|
public void k(float f) {
|
|
e(f, this.f1529x.centerX(), this.f1529x.centerY());
|
|
}
|
|
|
|
public void l(float f, float f2, float f3) {
|
|
if (f <= getMaxScale()) {
|
|
f(f / getCurrentScale(), f2, f3);
|
|
}
|
|
}
|
|
|
|
public void setCropBoundsChangeListener(@Nullable c.q.a.h.c cVar) {
|
|
this.B = cVar;
|
|
}
|
|
|
|
public void setCropRect(RectF rectF) {
|
|
this.f1531z = rectF.width() / rectF.height();
|
|
this.f1529x.set(rectF.left - ((float) getPaddingLeft()), rectF.top - ((float) getPaddingTop()), rectF.right - ((float) getPaddingRight()), rectF.bottom - ((float) getPaddingBottom()));
|
|
Drawable drawable = getDrawable();
|
|
if (drawable != null) {
|
|
h((float) drawable.getIntrinsicWidth(), (float) drawable.getIntrinsicHeight());
|
|
}
|
|
setImageToWrapCropBounds(true);
|
|
}
|
|
|
|
/* JADX DEBUG: Can't convert new array creation: APUT found in different block: 0x0091: APUT (r3v10 float[]), (0 ??[int, short, byte, char]), (r13v6 float) */
|
|
public void setImageToWrapCropBounds(boolean z2) {
|
|
float f;
|
|
float f2;
|
|
float f3;
|
|
float f4;
|
|
if (this.f1532s && !j(this.i)) {
|
|
float[] fArr = this.j;
|
|
float f5 = fArr[0];
|
|
float f6 = fArr[1];
|
|
float currentScale = getCurrentScale();
|
|
float centerX = this.f1529x.centerX() - f5;
|
|
float centerY = this.f1529x.centerY() - f6;
|
|
this.f1530y.reset();
|
|
this.f1530y.setTranslate(centerX, centerY);
|
|
float[] fArr2 = this.i;
|
|
float[] copyOf = Arrays.copyOf(fArr2, fArr2.length);
|
|
this.f1530y.mapPoints(copyOf);
|
|
boolean j = j(copyOf);
|
|
if (j) {
|
|
this.f1530y.reset();
|
|
this.f1530y.setRotate(-getCurrentAngle());
|
|
float[] fArr3 = this.i;
|
|
float[] copyOf2 = Arrays.copyOf(fArr3, fArr3.length);
|
|
float[] s2 = c.q.a.k.a.s(this.f1529x);
|
|
this.f1530y.mapPoints(copyOf2);
|
|
this.f1530y.mapPoints(s2);
|
|
RectF g02 = c.q.a.k.a.g0(copyOf2);
|
|
RectF g03 = c.q.a.k.a.g0(s2);
|
|
float f7 = g02.left - g03.left;
|
|
float f8 = g02.top - g03.top;
|
|
float f9 = g02.right - g03.right;
|
|
float f10 = g02.bottom - g03.bottom;
|
|
float[] fArr4 = new float[4];
|
|
if (f7 <= 0.0f) {
|
|
f7 = 0.0f;
|
|
}
|
|
fArr4[0] = f7;
|
|
if (f8 <= 0.0f) {
|
|
f8 = 0.0f;
|
|
}
|
|
fArr4[1] = f8;
|
|
if (f9 >= 0.0f) {
|
|
f9 = 0.0f;
|
|
}
|
|
fArr4[2] = f9;
|
|
if (f10 >= 0.0f) {
|
|
f10 = 0.0f;
|
|
}
|
|
fArr4[3] = f10;
|
|
this.f1530y.reset();
|
|
this.f1530y.setRotate(getCurrentAngle());
|
|
this.f1530y.mapPoints(fArr4);
|
|
f4 = -(fArr4[0] + fArr4[2]);
|
|
f3 = -(fArr4[1] + fArr4[3]);
|
|
f = currentScale;
|
|
f2 = 0.0f;
|
|
} else {
|
|
RectF rectF = new RectF(this.f1529x);
|
|
this.f1530y.reset();
|
|
this.f1530y.setRotate(getCurrentAngle());
|
|
this.f1530y.mapRect(rectF);
|
|
float[] fArr5 = this.i;
|
|
f = currentScale;
|
|
float[] fArr6 = {(float) Math.sqrt(Math.pow((double) (fArr5[1] - fArr5[3]), 2.0d) + Math.pow((double) (fArr5[0] - fArr5[2]), 2.0d)), (float) Math.sqrt(Math.pow((double) (fArr5[3] - fArr5[5]), 2.0d) + Math.pow((double) (fArr5[2] - fArr5[4]), 2.0d))};
|
|
f4 = centerX;
|
|
f2 = (Math.max(rectF.width() / fArr6[0], rectF.height() / fArr6[1]) * f) - f;
|
|
f3 = centerY;
|
|
}
|
|
if (z2) {
|
|
RunnableC0172a aVar = new RunnableC0172a(this, this.I, f5, f6, f4, f3, f, f2, j);
|
|
this.C = aVar;
|
|
post(aVar);
|
|
return;
|
|
}
|
|
g(f4, f3);
|
|
if (!j) {
|
|
l(f + f2, this.f1529x.centerX(), this.f1529x.centerY());
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setImageToWrapCropBoundsAnimDuration(@IntRange(from = 100) long j) {
|
|
if (j > 0) {
|
|
this.I = j;
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Animation duration cannot be negative value.");
|
|
}
|
|
|
|
public void setMaxResultImageSizeX(@IntRange(from = 10) int i) {
|
|
this.G = i;
|
|
}
|
|
|
|
public void setMaxResultImageSizeY(@IntRange(from = 10) int i) {
|
|
this.H = i;
|
|
}
|
|
|
|
public void setMaxScaleMultiplier(float f) {
|
|
this.A = f;
|
|
}
|
|
|
|
public void setTargetAspectRatio(float f) {
|
|
Drawable drawable = getDrawable();
|
|
if (drawable == null) {
|
|
this.f1531z = f;
|
|
return;
|
|
}
|
|
if (f == 0.0f) {
|
|
this.f1531z = ((float) drawable.getIntrinsicWidth()) / ((float) drawable.getIntrinsicHeight());
|
|
} else {
|
|
this.f1531z = f;
|
|
}
|
|
c.q.a.h.c cVar = this.B;
|
|
if (cVar != null) {
|
|
((d) cVar).a.j.setTargetAspectRatio(this.f1531z);
|
|
}
|
|
}
|
|
}
|