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

252 lines
11 KiB
Java

package c.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 c.q.a.g;
import c.q.a.i.c;
import com.yalantis.ucrop.UCropActivity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.nio.channels.FileChannel;
/* compiled from: BitmapCropTask */
public class a extends AsyncTask<Void, Void, Throwable> {
public final WeakReference<Context> a;
public Bitmap b;
/* renamed from: c reason: collision with root package name */
public final RectF f1525c;
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 c.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 c.q.a.i.a aVar, @Nullable c.q.a.h.a aVar2) {
this.a = new WeakReference<>(context);
this.b = bitmap;
this.f1525c = cVar.a;
this.d = cVar.b;
this.e = cVar.f1524c;
this.f = cVar.d;
this.g = aVar.a;
this.h = aVar.b;
this.i = aVar.f1522c;
this.j = aVar.d;
this.k = aVar.e;
this.l = aVar.f;
this.m = aVar2;
}
/* JADX WARNING: Removed duplicated region for block: B:36:0x0162 */
/* JADX WARNING: Removed duplicated region for block: B:65:0x0230 */
/* JADX WARNING: Removed duplicated region for block: B:80:0x0276 */
/* JADX WARNING: Removed duplicated region for block: B:82:0x027b */
public final boolean a() throws IOException {
boolean z2;
FileChannel fileChannel;
Throwable th;
if (this.g > 0 && this.h > 0) {
float width = this.f1525c.width() / this.e;
float height = this.f1525c.height() / this.e;
int i = this.g;
if (width > ((float) i) || height > ((float) this.h)) {
float min = Math.min(((float) i) / width, ((float) this.h) / height);
Bitmap bitmap = this.b;
Bitmap createScaledBitmap = Bitmap.createScaledBitmap(bitmap, Math.round(((float) bitmap.getWidth()) * min), Math.round(((float) this.b.getHeight()) * min), false);
Bitmap bitmap2 = this.b;
if (bitmap2 != createScaledBitmap) {
bitmap2.recycle();
}
this.b = createScaledBitmap;
this.e /= min;
}
}
if (this.f != 0.0f) {
Matrix matrix = new Matrix();
matrix.setRotate(this.f, (float) (this.b.getWidth() / 2), (float) (this.b.getHeight() / 2));
Bitmap bitmap3 = this.b;
Bitmap createBitmap = Bitmap.createBitmap(bitmap3, 0, 0, bitmap3.getWidth(), this.b.getHeight(), matrix, true);
Bitmap bitmap4 = this.b;
if (bitmap4 != createBitmap) {
bitmap4.recycle();
}
this.b = createBitmap;
}
this.p = Math.round((this.f1525c.left - this.d.left) / this.e);
this.q = Math.round((this.f1525c.top - this.d.top) / this.e);
this.n = Math.round(this.f1525c.width() / this.e);
int round = Math.round(this.f1525c.height() / this.e);
this.o = round;
int round2 = Math.round(((float) Math.max(this.n, round)) / 1000.0f) + 1;
if (this.g <= 0 || this.h <= 0) {
float f = (float) round2;
if (Math.abs(this.f1525c.left - this.d.left) <= f && Math.abs(this.f1525c.top - this.d.top) <= f && Math.abs(this.f1525c.bottom - this.d.bottom) <= f && Math.abs(this.f1525c.right - this.d.right) <= f && this.f == 0.0f) {
z2 = false;
Log.i("BitmapCropTask", "Should crop: " + z2);
FileChannel fileChannel2 = null;
OutputStream outputStream = null;
FileChannel fileChannel3 = null;
if (!z2) {
ExifInterface exifInterface = new ExifInterface(this.k);
Bitmap createBitmap2 = Bitmap.createBitmap(this.b, this.p, this.q, this.n, this.o);
Context context = this.a.get();
if (context != null) {
try {
outputStream = context.getContentResolver().openOutputStream(Uri.fromFile(new File(this.l)));
createBitmap2.compress(this.i, this.j, outputStream);
createBitmap2.recycle();
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException unused) {
}
}
}
}
if (this.i.equals(Bitmap.CompressFormat.JPEG)) {
int i2 = this.n;
int i3 = this.o;
String str = this.l;
byte[] bArr = c.q.a.k.c.a;
String[] strArr = {"FNumber", "DateTime", "DateTimeDigitized", "ExposureTime", "Flash", "FocalLength", "GPSAltitude", "GPSAltitudeRef", "GPSDateStamp", "GPSLatitude", "GPSLatitudeRef", "GPSLongitude", "GPSLongitudeRef", "GPSProcessingMethod", "GPSTimeStamp", "PhotographicSensitivity", "Make", "Model", "SubSecTime", "SubSecTimeDigitized", "SubSecTimeOriginal", "WhiteBalance"};
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("ImageWidth", String.valueOf(i2));
exifInterface2.setAttribute("ImageLength", String.valueOf(i3));
exifInterface2.setAttribute("Orientation", "0");
exifInterface2.saveAttributes();
} catch (IOException e) {
Log.d("ImageHeaderParser", e.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 {
fileChannel3 = new FileOutputStream(new File(str4)).getChannel();
channel.transferTo(0, channel.size(), fileChannel3);
channel.close();
channel.close();
if (fileChannel3 != null) {
fileChannel3.close();
}
} catch (Throwable th2) {
th = th2;
fileChannel = fileChannel3;
fileChannel2 = channel;
if (fileChannel2 != null) {
}
if (fileChannel != null) {
}
throw th;
}
} catch (Throwable th3) {
th = th3;
fileChannel = null;
if (fileChannel2 != null) {
fileChannel2.close();
}
if (fileChannel != null) {
fileChannel.close();
}
throw th;
}
}
return false;
}
}
z2 = true;
Log.i("BitmapCropTask", "Should crop: " + z2);
FileChannel fileChannel2 = null;
OutputStream outputStream = null;
FileChannel fileChannel3 = null;
if (!z2) {
}
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object[]] */
@Override // android.os.AsyncTask
@Nullable
public Throwable doInBackground(Void[] voidArr) {
Bitmap bitmap = this.b;
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.b = null;
return null;
} catch (Throwable th) {
return th;
}
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // android.os.AsyncTask
public void onPostExecute(@Nullable Throwable th) {
Throwable th2 = th;
c.q.a.h.a aVar = this.m;
if (aVar == null) {
return;
}
if (th2 == null) {
Uri fromFile = Uri.fromFile(new File(this.l));
c.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.v.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();
}
}