200 lines
5.8 KiB
Java
200 lines
5.8 KiB
Java
package com.lyft.android.scissors;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Matrix;
|
|
import android.graphics.Paint;
|
|
import android.graphics.Rect;
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.net.Uri;
|
|
import android.util.AttributeSet;
|
|
import android.view.MotionEvent;
|
|
import android.widget.ImageView;
|
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
|
import o.C0413GaN;
|
|
import o.EvK;
|
|
import o.ZGg;
|
|
import o.rcp;
|
|
import o.tOX;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class CropView extends ImageView {
|
|
public tOX a;
|
|
public Bitmap b;
|
|
private Matrix c;
|
|
private Paint d;
|
|
public RVV e;
|
|
private Paint i;
|
|
|
|
public CropView(Context context) {
|
|
super(context);
|
|
this.i = new Paint();
|
|
this.d = new Paint();
|
|
this.c = new Matrix();
|
|
OB_(context, null);
|
|
}
|
|
|
|
public CropView(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.i = new Paint();
|
|
this.d = new Paint();
|
|
this.c = new Matrix();
|
|
OB_(context, attributeSet);
|
|
}
|
|
|
|
private void OB_(Context context, AttributeSet attributeSet) {
|
|
ZGg OC_ = ZGg.OC_(context, attributeSet);
|
|
this.a = new tOX(OC_);
|
|
this.d.setFilterBitmap(true);
|
|
this.i.setColor(OC_.d);
|
|
}
|
|
|
|
@Override // android.widget.ImageView, android.view.View
|
|
protected void onDraw(Canvas canvas) {
|
|
super.onDraw(canvas);
|
|
if (this.b == null) {
|
|
return;
|
|
}
|
|
OA_(canvas);
|
|
int i = this.a.h;
|
|
int i2 = this.a.j;
|
|
int width = (getWidth() - i) / 2;
|
|
float height = (getHeight() - i2) / 2;
|
|
canvas.drawRect(BitmapDescriptorFactory.HUE_RED, height, width, getHeight() - r1, this.i);
|
|
canvas.drawRect(BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, getWidth(), height, this.i);
|
|
canvas.drawRect(getWidth() - width, height, getWidth(), getHeight() - r1, this.i);
|
|
canvas.drawRect(BitmapDescriptorFactory.HUE_RED, getHeight() - r1, getWidth(), getHeight(), this.i);
|
|
}
|
|
|
|
public final void OA_(Canvas canvas) {
|
|
this.c.reset();
|
|
tOX tox = this.a;
|
|
Matrix matrix = this.c;
|
|
matrix.postTranslate((-tox.e) / 2.0f, (-tox.a) / 2.0f);
|
|
float f = tox.f;
|
|
matrix.postScale(f, f);
|
|
matrix.postTranslate(tox.i.d, tox.i.c);
|
|
canvas.drawBitmap(this.b, this.c, this.d);
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onSizeChanged(int i, int i2, int i3, int i4) {
|
|
super.onSizeChanged(i, i2, i3, i4);
|
|
c();
|
|
}
|
|
|
|
public void setViewportRatio(float f) {
|
|
float f2 = BitmapDescriptorFactory.HUE_RED;
|
|
if (Float.compare(f, BitmapDescriptorFactory.HUE_RED) == 0) {
|
|
f = this.b != null ? r4.getWidth() / r4.getHeight() : 0.0f;
|
|
}
|
|
tOX tox = this.a;
|
|
tox.d = f;
|
|
ZGg zGg = tox.c;
|
|
if (f > BitmapDescriptorFactory.HUE_RED) {
|
|
f2 = f;
|
|
}
|
|
zGg.b = f2;
|
|
c();
|
|
invalidate();
|
|
}
|
|
|
|
@Override // android.widget.ImageView
|
|
public void setImageResource(int i) {
|
|
setImageBitmap(i > 0 ? BitmapFactory.decodeResource(getResources(), i) : null);
|
|
}
|
|
|
|
@Override // android.widget.ImageView
|
|
public void setImageDrawable(Drawable drawable) {
|
|
Bitmap OJ_;
|
|
if (drawable instanceof BitmapDrawable) {
|
|
OJ_ = ((BitmapDrawable) drawable).getBitmap();
|
|
} else {
|
|
OJ_ = drawable != null ? C0413GaN.OJ_(drawable, getWidth(), getHeight()) : null;
|
|
}
|
|
setImageBitmap(OJ_);
|
|
}
|
|
|
|
@Override // android.widget.ImageView
|
|
public void setImageURI(Uri uri) {
|
|
if (this.e == null) {
|
|
this.e = new RVV(this);
|
|
}
|
|
rcp.RVV rvv = new rcp.RVV(this.e.d);
|
|
if (rvv.a.getWidth() == 0 && rvv.a.getHeight() == 0) {
|
|
rvv.a(uri);
|
|
} else {
|
|
rvv.d(uri);
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.ImageView
|
|
public void setImageBitmap(Bitmap bitmap) {
|
|
this.b = bitmap;
|
|
c();
|
|
invalidate();
|
|
}
|
|
|
|
private void c() {
|
|
Bitmap bitmap = this.b;
|
|
boolean z = bitmap == null;
|
|
int width = z ? 0 : bitmap.getWidth();
|
|
int height = z ? 0 : this.b.getHeight();
|
|
tOX tox = this.a;
|
|
int width2 = getWidth();
|
|
int height2 = getHeight();
|
|
tox.d = tox.c.b;
|
|
tox.b = new Rect(0, 0, width2 / 2, height2 / 2);
|
|
float f = width / height;
|
|
float f2 = width2 / height2;
|
|
float f3 = tox.c.b;
|
|
if (Float.compare(BitmapDescriptorFactory.HUE_RED, f3) != 0) {
|
|
f = f3;
|
|
}
|
|
if (f > f2) {
|
|
int i = width2 - (tox.c.e << 1);
|
|
tox.h = i;
|
|
tox.j = (int) (i * (1.0f / f));
|
|
} else {
|
|
int i2 = height2 - (tox.c.e << 1);
|
|
tox.j = i2;
|
|
tox.h = (int) (i2 * f);
|
|
}
|
|
tox.e = width;
|
|
tox.a = height;
|
|
if (width <= 0 || height <= 0) {
|
|
return;
|
|
}
|
|
float max = Math.max(tox.h / tox.e, tox.j / tox.a);
|
|
tox.g = max;
|
|
tox.f = Math.max(tox.f, max);
|
|
tox.e();
|
|
EvK evK = tox.i;
|
|
float f4 = tox.b.right;
|
|
float f5 = tox.b.bottom;
|
|
evK.d = f4;
|
|
evK.c = f5;
|
|
tox.c();
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean dispatchTouchEvent(MotionEvent motionEvent) {
|
|
super.dispatchTouchEvent(motionEvent);
|
|
this.a.onEvent(motionEvent);
|
|
invalidate();
|
|
return true;
|
|
}
|
|
|
|
/* loaded from: classes3.dex */
|
|
public static class RVV {
|
|
public final CropView d;
|
|
|
|
public RVV(CropView cropView) {
|
|
this.d = cropView;
|
|
}
|
|
}
|
|
}
|