discord-jadx/app/src/main/java/b/q/a/j/a.java

307 lines
14 KiB
Java

package b.q.a.j;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.net.Uri;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.exifinterface.media.ExifInterface;
import b.q.a.g;
import b.q.a.i.c;
import b.q.a.k.b;
import com.yalantis.ucrop.UCropActivity;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.nio.channels.FileChannel;
/* compiled from: BitmapCropTask.java */
/* loaded from: classes3.dex */
public class a extends AsyncTask<Void, Void, Throwable> {
public final WeakReference<Context> a;
/* renamed from: b reason: collision with root package name */
public Bitmap f1980b;
public final RectF c;
public final RectF d;
public float e;
public float f;
public final int g;
public final int h;
public final Bitmap.CompressFormat i;
public final int j;
public final String k;
public final String l;
public final b.q.a.h.a m;
public int n;
public int o;
public int p;
public int q;
public a(@NonNull Context context, @Nullable Bitmap bitmap, @NonNull c cVar, @NonNull b.q.a.i.a aVar, @Nullable b.q.a.h.a aVar2) {
this.a = new WeakReference<>(context);
this.f1980b = bitmap;
this.c = cVar.a;
this.d = cVar.f1979b;
this.e = cVar.c;
this.f = cVar.d;
this.g = aVar.a;
this.h = aVar.f1977b;
this.i = aVar.c;
this.j = aVar.d;
this.k = aVar.e;
this.l = aVar.f;
this.m = aVar2;
}
/* JADX WARN: Multi-variable type inference failed */
/* JADX WARN: Removed duplicated region for block: B:115:0x0268 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:119:0x0261 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:38:0x0162 */
/* JADX WARN: Removed duplicated region for block: B:65:0x01e3 */
/* JADX WARN: Removed duplicated region for block: B:84:0x026c */
/*
Code decompiled incorrectly, please refer to instructions dump.
*/
public final boolean a() throws IOException {
int round;
boolean z2;
Throwable th;
IOException e;
FileOutputStream fileOutputStream;
ByteArrayOutputStream byteArrayOutputStream;
Bitmap bitmap;
if (this.g > 0 && this.h > 0) {
float width = this.c.width() / this.e;
float height = this.c.height() / this.e;
int i = this.g;
if (width > i || height > this.h) {
float min = Math.min(i / width, this.h / height);
Bitmap createScaledBitmap = Bitmap.createScaledBitmap(this.f1980b, Math.round(bitmap.getWidth() * min), Math.round(this.f1980b.getHeight() * min), false);
Bitmap bitmap2 = this.f1980b;
if (bitmap2 != createScaledBitmap) {
bitmap2.recycle();
}
this.f1980b = createScaledBitmap;
this.e /= min;
}
}
if (this.f != 0.0f) {
Matrix matrix = new Matrix();
matrix.setRotate(this.f, this.f1980b.getWidth() / 2, this.f1980b.getHeight() / 2);
Bitmap bitmap3 = this.f1980b;
Bitmap createBitmap = Bitmap.createBitmap(bitmap3, 0, 0, bitmap3.getWidth(), this.f1980b.getHeight(), matrix, true);
Bitmap bitmap4 = this.f1980b;
if (bitmap4 != createBitmap) {
bitmap4.recycle();
}
this.f1980b = createBitmap;
}
this.p = Math.round((this.c.left - this.d.left) / this.e);
this.q = Math.round((this.c.top - this.d.top) / this.e);
this.n = Math.round(this.c.width() / this.e);
this.o = Math.round(this.c.height() / this.e);
int round2 = Math.round(Math.max(this.n, round) / 1000.0f) + 1;
if (this.g <= 0 || this.h <= 0) {
float f = round2;
if (Math.abs(this.c.left - this.d.left) <= f && Math.abs(this.c.top - this.d.top) <= f && Math.abs(this.c.bottom - this.d.bottom) <= f && Math.abs(this.c.right - this.d.right) <= f && this.f == 0.0f) {
z2 = false;
Log.i("BitmapCropTask", "Should crop: " + z2);
FileChannel fileChannel = null;
if (!z2) {
ExifInterface exifInterface = new ExifInterface(this.k);
Bitmap createBitmap2 = Bitmap.createBitmap(this.f1980b, this.p, this.q, this.n, this.o);
try {
if (this.a.get() != null) {
try {
fileOutputStream = new FileOutputStream(new File(this.l), false);
try {
byteArrayOutputStream = new ByteArrayOutputStream();
} catch (IOException e2) {
e = e2;
} catch (Throwable th2) {
th = th2;
}
} catch (IOException e3) {
e = e3;
fileChannel = null;
} catch (Throwable th3) {
th = th3;
fileChannel = null;
}
try {
createBitmap2.compress(this.i, this.j, byteArrayOutputStream);
fileOutputStream.write(byteArrayOutputStream.toByteArray());
createBitmap2.recycle();
try {
fileOutputStream.close();
} catch (IOException unused) {
}
byteArrayOutputStream.close();
} catch (IOException e4) {
e = e4;
fileChannel = byteArrayOutputStream;
fileChannel = fileOutputStream;
try {
Log.e("BitmapCropTask", e.getLocalizedMessage());
if (fileChannel != null) {
try {
fileChannel.close();
} catch (IOException unused2) {
}
}
if (fileChannel != null) {
fileChannel.close();
}
if (this.i.equals(Bitmap.CompressFormat.JPEG)) {
}
return true;
} catch (Throwable th4) {
th = th4;
if (fileChannel != null) {
try {
fileChannel.close();
} catch (IOException unused3) {
}
}
if (fileChannel != null) {
try {
fileChannel.close();
} catch (IOException unused4) {
}
}
throw th;
}
} catch (Throwable th5) {
th = th5;
fileChannel = byteArrayOutputStream;
fileChannel = fileOutputStream;
if (fileChannel != null) {
}
if (fileChannel != null) {
}
throw th;
}
}
} catch (IOException unused5) {
}
if (this.i.equals(Bitmap.CompressFormat.JPEG)) {
int i2 = this.n;
int i3 = this.o;
String str = this.l;
byte[] bArr = b.a;
String[] strArr = {ExifInterface.TAG_F_NUMBER, ExifInterface.TAG_DATETIME, ExifInterface.TAG_DATETIME_DIGITIZED, ExifInterface.TAG_EXPOSURE_TIME, ExifInterface.TAG_FLASH, ExifInterface.TAG_FOCAL_LENGTH, ExifInterface.TAG_GPS_ALTITUDE, ExifInterface.TAG_GPS_ALTITUDE_REF, ExifInterface.TAG_GPS_DATESTAMP, ExifInterface.TAG_GPS_LATITUDE, ExifInterface.TAG_GPS_LATITUDE_REF, ExifInterface.TAG_GPS_LONGITUDE, ExifInterface.TAG_GPS_LONGITUDE_REF, ExifInterface.TAG_GPS_PROCESSING_METHOD, ExifInterface.TAG_GPS_TIMESTAMP, ExifInterface.TAG_PHOTOGRAPHIC_SENSITIVITY, ExifInterface.TAG_MAKE, ExifInterface.TAG_MODEL, ExifInterface.TAG_SUBSEC_TIME, ExifInterface.TAG_SUBSEC_TIME_DIGITIZED, ExifInterface.TAG_SUBSEC_TIME_ORIGINAL, ExifInterface.TAG_WHITE_BALANCE};
try {
ExifInterface exifInterface2 = new ExifInterface(str);
for (int i4 = 0; i4 < 22; i4++) {
String str2 = strArr[i4];
String attribute = exifInterface.getAttribute(str2);
if (!TextUtils.isEmpty(attribute)) {
exifInterface2.setAttribute(str2, attribute);
}
}
exifInterface2.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, String.valueOf(i2));
exifInterface2.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, String.valueOf(i3));
exifInterface2.setAttribute(ExifInterface.TAG_ORIENTATION, "0");
exifInterface2.saveAttributes();
} catch (IOException e5) {
Log.d("ImageHeaderParser", e5.getMessage());
}
}
return true;
}
String str3 = this.k;
String str4 = this.l;
if (!str3.equalsIgnoreCase(str4)) {
try {
FileChannel channel = new FileInputStream(new File(str3)).getChannel();
try {
fileChannel = new FileOutputStream(new File(str4)).getChannel();
channel.transferTo(0L, channel.size(), fileChannel);
channel.close();
channel.close();
if (fileChannel != null) {
fileChannel.close();
}
} catch (Throwable th6) {
th = th6;
fileChannel = channel;
if (fileChannel != null) {
fileChannel.close();
}
if (fileChannel != null) {
fileChannel.close();
}
throw th;
}
} catch (Throwable th7) {
th = th7;
fileChannel = null;
}
}
return false;
}
}
z2 = true;
Log.i("BitmapCropTask", "Should crop: " + z2);
FileChannel fileChannel2 = null;
if (!z2) {
}
}
@Override // android.os.AsyncTask
@Nullable
public Throwable doInBackground(Void[] voidArr) {
Bitmap bitmap = this.f1980b;
if (bitmap == null) {
return new NullPointerException("ViewBitmap is null");
}
if (bitmap.isRecycled()) {
return new NullPointerException("ViewBitmap is recycled");
}
if (this.d.isEmpty()) {
return new NullPointerException("CurrentImageRect is empty");
}
try {
a();
this.f1980b = null;
return null;
} catch (Throwable th) {
return th;
}
}
@Override // android.os.AsyncTask
public void onPostExecute(@Nullable Throwable th) {
Throwable th2 = th;
b.q.a.h.a aVar = this.m;
if (aVar == null) {
return;
}
if (th2 == null) {
Uri fromFile = Uri.fromFile(new File(this.l));
b.q.a.h.a aVar2 = this.m;
int i = this.p;
int i2 = this.q;
int i3 = this.n;
int i4 = this.o;
g gVar = (g) aVar2;
UCropActivity uCropActivity = gVar.a;
uCropActivity.setResult(-1, new Intent().putExtra("com.yalantis.ucrop.OutputUri", fromFile).putExtra("com.yalantis.ucrop.CropAspectRatio", uCropActivity.w.getTargetAspectRatio()).putExtra("com.yalantis.ucrop.ImageWidth", i3).putExtra("com.yalantis.ucrop.ImageHeight", i4).putExtra("com.yalantis.ucrop.OffsetX", i).putExtra("com.yalantis.ucrop.OffsetY", i2));
gVar.a.finish();
return;
}
g gVar2 = (g) aVar;
gVar2.a.b(th2);
gVar2.a.finish();
}
}