468 lines
18 KiB
Java
468 lines
18 KiB
Java
package b.q.a.j;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.Matrix;
|
|
import android.net.Uri;
|
|
import android.os.AsyncTask;
|
|
import android.util.Log;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import b.q.a.l.c;
|
|
import com.adjust.sdk.Constants;
|
|
import com.yalantis.ucrop.UCropActivity;
|
|
import d0.z.d.m;
|
|
import f0.e0.g.e;
|
|
import f0.x;
|
|
import g0.g;
|
|
import g0.p;
|
|
import g0.y;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.util.Objects;
|
|
import okhttp3.Request;
|
|
import okhttp3.Response;
|
|
import okhttp3.ResponseBody;
|
|
/* compiled from: BitmapLoadTask.java */
|
|
/* loaded from: classes3.dex */
|
|
public class b extends AsyncTask<Void, Void, a> {
|
|
public final Context a;
|
|
|
|
/* renamed from: b reason: collision with root package name */
|
|
public Uri f1981b;
|
|
public Uri c;
|
|
public final int d;
|
|
public final int e;
|
|
public final b.q.a.h.b f;
|
|
|
|
/* compiled from: BitmapLoadTask.java */
|
|
/* loaded from: classes3.dex */
|
|
public static class a {
|
|
public Bitmap a;
|
|
|
|
/* renamed from: b reason: collision with root package name */
|
|
public b.q.a.i.b f1982b;
|
|
public Exception c;
|
|
|
|
public a(@NonNull Bitmap bitmap, @NonNull b.q.a.i.b bVar) {
|
|
this.a = bitmap;
|
|
this.f1982b = bVar;
|
|
}
|
|
|
|
public a(@NonNull Exception exc) {
|
|
this.c = exc;
|
|
}
|
|
}
|
|
|
|
public b(@NonNull Context context, @NonNull Uri uri, @Nullable Uri uri2, int i, int i2, b.q.a.h.b bVar) {
|
|
this.a = context;
|
|
this.f1981b = uri;
|
|
this.c = uri2;
|
|
this.d = i;
|
|
this.e = i2;
|
|
this.f = bVar;
|
|
}
|
|
|
|
public final void a(@NonNull Uri uri, @Nullable Uri uri2) throws NullPointerException, IOException {
|
|
Throwable th;
|
|
InputStream inputStream;
|
|
Log.d("BitmapWorkerTask", "copyFile");
|
|
Objects.requireNonNull(uri2, "Output Uri is null - cannot copy image");
|
|
FileOutputStream fileOutputStream = null;
|
|
try {
|
|
inputStream = this.a.getContentResolver().openInputStream(uri);
|
|
try {
|
|
FileOutputStream fileOutputStream2 = new FileOutputStream(new File(uri2.getPath()));
|
|
try {
|
|
if (inputStream != null) {
|
|
byte[] bArr = new byte[1024];
|
|
while (true) {
|
|
int read = inputStream.read(bArr);
|
|
if (read > 0) {
|
|
fileOutputStream2.write(bArr, 0, read);
|
|
} else {
|
|
try {
|
|
break;
|
|
} catch (IOException unused) {
|
|
}
|
|
}
|
|
}
|
|
fileOutputStream2.close();
|
|
try {
|
|
inputStream.close();
|
|
} catch (IOException unused2) {
|
|
}
|
|
this.f1981b = this.c;
|
|
return;
|
|
}
|
|
throw new NullPointerException("InputStream for given input Uri is null");
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
fileOutputStream = fileOutputStream2;
|
|
if (fileOutputStream != null) {
|
|
try {
|
|
fileOutputStream.close();
|
|
} catch (IOException unused3) {
|
|
}
|
|
}
|
|
if (inputStream != null) {
|
|
try {
|
|
inputStream.close();
|
|
} catch (IOException unused4) {
|
|
}
|
|
}
|
|
this.f1981b = this.c;
|
|
throw th;
|
|
}
|
|
} catch (Throwable th3) {
|
|
th = th3;
|
|
}
|
|
} catch (Throwable th4) {
|
|
th = th4;
|
|
inputStream = null;
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:46:0x0085 A[EXC_TOP_SPLITTER, SYNTHETIC] */
|
|
/* JADX WARN: Removed duplicated region for block: B:52:0x0080 A[EXC_TOP_SPLITTER, SYNTHETIC] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
*/
|
|
public final void b(@NonNull Uri uri, @Nullable Uri uri2) throws NullPointerException, IOException {
|
|
Throwable th;
|
|
Response response;
|
|
p pVar;
|
|
ResponseBody responseBody;
|
|
Log.d("BitmapWorkerTask", "downloadFile");
|
|
Objects.requireNonNull(uri2, "Output Uri is null - cannot download image");
|
|
x xVar = new x();
|
|
g gVar = null;
|
|
try {
|
|
Request.a aVar = new Request.a();
|
|
aVar.f(uri.toString());
|
|
try {
|
|
response = ((e) xVar.b(aVar.a())).execute();
|
|
try {
|
|
g c = response.p.c();
|
|
try {
|
|
OutputStream openOutputStream = this.a.getContentResolver().openOutputStream(uri2);
|
|
if (openOutputStream != null) {
|
|
m.checkParameterIsNotNull(openOutputStream, "$this$sink");
|
|
pVar = new p(openOutputStream, new y());
|
|
try {
|
|
c.k0(pVar);
|
|
try {
|
|
c.close();
|
|
} catch (IOException unused) {
|
|
}
|
|
try {
|
|
pVar.close();
|
|
} catch (IOException unused2) {
|
|
}
|
|
ResponseBody responseBody2 = response.p;
|
|
if (responseBody2 != null) {
|
|
try {
|
|
responseBody2.close();
|
|
} catch (IOException unused3) {
|
|
}
|
|
}
|
|
xVar.m.a();
|
|
this.f1981b = this.c;
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
gVar = c;
|
|
if (gVar != null) {
|
|
try {
|
|
gVar.close();
|
|
} catch (IOException unused4) {
|
|
}
|
|
}
|
|
if (pVar != null) {
|
|
try {
|
|
pVar.close();
|
|
} catch (IOException unused5) {
|
|
}
|
|
}
|
|
if (!(response == null || (responseBody = response.p) == null)) {
|
|
try {
|
|
responseBody.close();
|
|
} catch (IOException unused6) {
|
|
}
|
|
}
|
|
xVar.m.a();
|
|
this.f1981b = this.c;
|
|
throw th;
|
|
}
|
|
} else {
|
|
throw new NullPointerException("OutputStream for given output Uri is null");
|
|
}
|
|
} catch (Throwable th3) {
|
|
th = th3;
|
|
pVar = null;
|
|
}
|
|
} catch (Throwable th4) {
|
|
th = th4;
|
|
pVar = null;
|
|
}
|
|
} catch (Throwable th5) {
|
|
th = th5;
|
|
response = null;
|
|
pVar = null;
|
|
if (gVar != null) {
|
|
}
|
|
if (pVar != null) {
|
|
}
|
|
if (response == null) {
|
|
responseBody.close();
|
|
}
|
|
xVar.m.a();
|
|
this.f1981b = this.c;
|
|
throw th;
|
|
}
|
|
} catch (Throwable th6) {
|
|
th = th6;
|
|
}
|
|
}
|
|
|
|
public final void c() throws NullPointerException, IOException {
|
|
String scheme = this.f1981b.getScheme();
|
|
Log.d("BitmapWorkerTask", "Uri scheme: " + scheme);
|
|
if ("http".equals(scheme) || Constants.SCHEME.equals(scheme)) {
|
|
try {
|
|
b(this.f1981b, this.c);
|
|
} catch (IOException | NullPointerException e) {
|
|
Log.e("BitmapWorkerTask", "Downloading failed", e);
|
|
throw e;
|
|
}
|
|
} else if ("content".equals(scheme)) {
|
|
try {
|
|
a(this.f1981b, this.c);
|
|
} catch (IOException | NullPointerException e2) {
|
|
Log.e("BitmapWorkerTask", "Copying failed", e2);
|
|
throw e2;
|
|
}
|
|
} else if (!"file".equals(scheme)) {
|
|
Log.e("BitmapWorkerTask", "Invalid Uri scheme " + scheme);
|
|
throw new IllegalArgumentException(b.d.b.a.a.v("Invalid Uri scheme", scheme));
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:62:0x013c */
|
|
/* JADX WARN: Removed duplicated region for block: B:63:0x013e */
|
|
/* JADX WARN: Removed duplicated region for block: B:64:0x0141 */
|
|
/* JADX WARN: Removed duplicated region for block: B:65:0x0144 */
|
|
/* JADX WARN: Removed duplicated region for block: B:76:0x015e */
|
|
/* JADX WARN: Removed duplicated region for block: B:78:0x0164 */
|
|
/* JADX WARN: Removed duplicated region for block: B:81:0x0170 */
|
|
/* JADX WARN: Removed duplicated region for block: B:88:0x0194 */
|
|
@Override // android.os.AsyncTask
|
|
@NonNull
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
*/
|
|
public a doInBackground(Void[] voidArr) {
|
|
int i;
|
|
int i2;
|
|
int i3;
|
|
Matrix matrix;
|
|
InputStream openInputStream;
|
|
InputStream openInputStream2;
|
|
boolean z2;
|
|
if (this.f1981b == null) {
|
|
return new a(new NullPointerException("Input Uri cannot be null"));
|
|
}
|
|
try {
|
|
c();
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
options.inJustDecodeBounds = true;
|
|
int i4 = this.d;
|
|
int i5 = this.e;
|
|
int i6 = options.outHeight;
|
|
int i7 = options.outWidth;
|
|
if (i6 > i5 || i7 > i4) {
|
|
int i8 = 1;
|
|
while (true) {
|
|
if (i6 / i8 <= i5 && i7 / i8 <= i4) {
|
|
break;
|
|
}
|
|
i8 *= 2;
|
|
}
|
|
i = i8;
|
|
} else {
|
|
i = 1;
|
|
}
|
|
options.inSampleSize = i;
|
|
options.inJustDecodeBounds = false;
|
|
boolean z3 = false;
|
|
Bitmap bitmap = null;
|
|
while (true) {
|
|
int i9 = -1;
|
|
if (!z3) {
|
|
try {
|
|
try {
|
|
openInputStream2 = this.a.getContentResolver().openInputStream(this.f1981b);
|
|
try {
|
|
bitmap = BitmapFactory.decodeStream(openInputStream2, null, options);
|
|
} catch (Throwable th) {
|
|
if (openInputStream2 != null) {
|
|
try {
|
|
openInputStream2.close();
|
|
} catch (IOException unused) {
|
|
}
|
|
}
|
|
throw th;
|
|
}
|
|
} catch (IOException e) {
|
|
Log.e("BitmapWorkerTask", "doInBackground: ImageDecoder.createSource: ", e);
|
|
StringBuilder R = b.d.b.a.a.R("Bitmap could not be decoded from the Uri: [");
|
|
R.append(this.f1981b);
|
|
R.append("]");
|
|
return new a(new IllegalArgumentException(R.toString(), e));
|
|
}
|
|
} catch (OutOfMemoryError e2) {
|
|
Log.e("BitmapWorkerTask", "doInBackground: BitmapFactory.decodeFileDescriptor: ", e2);
|
|
options.inSampleSize *= 2;
|
|
}
|
|
if (options.outWidth == -1 || options.outHeight == -1) {
|
|
break;
|
|
}
|
|
if (openInputStream2 != null) {
|
|
try {
|
|
openInputStream2.close();
|
|
} catch (IOException unused2) {
|
|
}
|
|
}
|
|
if ((bitmap != null ? bitmap.getByteCount() : 0) > 104857600) {
|
|
options.inSampleSize *= 2;
|
|
z2 = true;
|
|
} else {
|
|
z2 = false;
|
|
}
|
|
if (!z2) {
|
|
z3 = true;
|
|
}
|
|
} else if (bitmap == null) {
|
|
StringBuilder R2 = b.d.b.a.a.R("Bitmap could not be decoded from the Uri: [");
|
|
R2.append(this.f1981b);
|
|
R2.append("]");
|
|
return new a(new IllegalArgumentException(R2.toString()));
|
|
} else {
|
|
Context context = this.a;
|
|
Uri uri = this.f1981b;
|
|
try {
|
|
openInputStream = context.getContentResolver().openInputStream(uri);
|
|
} catch (IOException e3) {
|
|
StringBuilder R3 = b.d.b.a.a.R("getExifOrientation: ");
|
|
R3.append(uri.toString());
|
|
Log.e("BitmapLoadUtils", R3.toString(), e3);
|
|
}
|
|
if (openInputStream == null) {
|
|
i2 = 0;
|
|
switch (i2) {
|
|
case 3:
|
|
case 4:
|
|
i3 = 180;
|
|
break;
|
|
case 5:
|
|
case 6:
|
|
i3 = 90;
|
|
break;
|
|
case 7:
|
|
case 8:
|
|
i3 = 270;
|
|
break;
|
|
default:
|
|
i3 = 0;
|
|
break;
|
|
}
|
|
if (!(i2 == 2 || i2 == 7 || i2 == 4 || i2 == 5)) {
|
|
i9 = 1;
|
|
}
|
|
b.q.a.i.b bVar = new b.q.a.i.b(i2, i3, i9);
|
|
matrix = new Matrix();
|
|
if (i3 != 0) {
|
|
matrix.preRotate(i3);
|
|
}
|
|
if (i9 != 1) {
|
|
matrix.postScale(i9, 1.0f);
|
|
}
|
|
if (!matrix.isIdentity()) {
|
|
return new a(bitmap, bVar);
|
|
}
|
|
try {
|
|
Bitmap createBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
|
if (!bitmap.sameAs(createBitmap)) {
|
|
bitmap = createBitmap;
|
|
}
|
|
} catch (OutOfMemoryError e4) {
|
|
Log.e("BitmapLoadUtils", "transformBitmap: ", e4);
|
|
}
|
|
return new a(bitmap, bVar);
|
|
}
|
|
i2 = new b.q.a.k.b(openInputStream).a();
|
|
try {
|
|
openInputStream.close();
|
|
} catch (IOException unused3) {
|
|
}
|
|
switch (i2) {
|
|
}
|
|
if (i2 == 2) {
|
|
i9 = 1;
|
|
}
|
|
b.q.a.i.b bVar2 = new b.q.a.i.b(i2, i3, i9);
|
|
matrix = new Matrix();
|
|
if (i3 != 0) {
|
|
}
|
|
if (i9 != 1) {
|
|
}
|
|
if (!matrix.isIdentity()) {
|
|
}
|
|
}
|
|
}
|
|
a aVar = new a(new IllegalArgumentException("Bounds for bitmap could not be retrieved from the Uri: [" + this.f1981b + "]"));
|
|
if (openInputStream2 != null) {
|
|
try {
|
|
openInputStream2.close();
|
|
} catch (IOException unused4) {
|
|
}
|
|
}
|
|
return aVar;
|
|
} catch (IOException | NullPointerException e5) {
|
|
return new a(e5);
|
|
}
|
|
}
|
|
|
|
@Override // android.os.AsyncTask
|
|
public void onPostExecute(@NonNull a aVar) {
|
|
a aVar2 = aVar;
|
|
Exception exc = aVar2.c;
|
|
if (exc == null) {
|
|
b.q.a.h.b bVar = this.f;
|
|
Bitmap bitmap = aVar2.a;
|
|
b.q.a.i.b bVar2 = aVar2.f1982b;
|
|
String path = this.f1981b.getPath();
|
|
Uri uri = this.c;
|
|
String path2 = uri == null ? null : uri.getPath();
|
|
c cVar = ((b.q.a.l.b) bVar).a;
|
|
cVar.v = path;
|
|
cVar.w = path2;
|
|
cVar.f1990x = bVar2;
|
|
cVar.f1989s = true;
|
|
cVar.setImageBitmap(bitmap);
|
|
return;
|
|
}
|
|
b.q.a.l.b bVar3 = (b.q.a.l.b) this.f;
|
|
Objects.requireNonNull(bVar3);
|
|
Log.e("TransformImageView", "onFailure: setImageUri", exc);
|
|
c.a aVar3 = bVar3.a.p;
|
|
if (aVar3 != null) {
|
|
UCropActivity.a aVar4 = (UCropActivity.a) aVar3;
|
|
UCropActivity.this.b(exc);
|
|
UCropActivity.this.finish();
|
|
}
|
|
}
|
|
}
|