Initial commit
This commit is contained in:
181
sources/com/google/android/gms/common/images/ImageManager.java
Normal file
181
sources/com/google/android/gms/common/images/ImageManager.java
Normal file
@@ -0,0 +1,181 @@
|
||||
package com.google.android.gms.common.images;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import androidx.collection.LruCache;
|
||||
import com.google.android.gms.common.annotation.KeepName;
|
||||
import com.google.android.gms.common.internal.Asserts;
|
||||
import com.google.android.gms.internal.base.zak;
|
||||
import com.google.android.gms.internal.base.zal;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class ImageManager {
|
||||
private static final Object i = new Object();
|
||||
private static HashSet<Uri> j = new HashSet<>();
|
||||
private final Context a;
|
||||
private final Handler b;
|
||||
private final ExecutorService c;
|
||||
private final zaa d;
|
||||
private final zak e;
|
||||
private final Map<com.google.android.gms.common.images.zaa, ImageReceiver> f;
|
||||
private final Map<Uri, ImageReceiver> g;
|
||||
private final Map<Uri, Long> h;
|
||||
|
||||
@KeepName
|
||||
private final class ImageReceiver extends ResultReceiver {
|
||||
private final Uri mUri;
|
||||
private final ArrayList<com.google.android.gms.common.images.zaa> zamp;
|
||||
|
||||
ImageReceiver(Uri uri) {
|
||||
super(new zal(Looper.getMainLooper()));
|
||||
this.mUri = uri;
|
||||
this.zamp = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override // android.os.ResultReceiver
|
||||
public final void onReceiveResult(int i, Bundle bundle) {
|
||||
ImageManager.this.c.execute(ImageManager.this.new zab(this.mUri, (ParcelFileDescriptor) bundle.getParcelable("com.google.android.gms.extra.fileDescriptor")));
|
||||
}
|
||||
|
||||
public final void zab(com.google.android.gms.common.images.zaa zaaVar) {
|
||||
Asserts.a("ImageReceiver.addImageRequest() must be called in the main thread");
|
||||
this.zamp.add(zaaVar);
|
||||
}
|
||||
|
||||
public final void zac(com.google.android.gms.common.images.zaa zaaVar) {
|
||||
Asserts.a("ImageReceiver.removeImageRequest() must be called in the main thread");
|
||||
this.zamp.remove(zaaVar);
|
||||
}
|
||||
|
||||
public final void zace() {
|
||||
Intent intent = new Intent("com.google.android.gms.common.images.LOAD_IMAGE");
|
||||
intent.putExtra("com.google.android.gms.extras.uri", this.mUri);
|
||||
intent.putExtra("com.google.android.gms.extras.resultReceiver", this);
|
||||
intent.putExtra("com.google.android.gms.extras.priority", 3);
|
||||
ImageManager.this.a.sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class zaa extends LruCache<com.google.android.gms.common.images.zab, Bitmap> {
|
||||
}
|
||||
|
||||
private final class zab implements Runnable {
|
||||
private final Uri a;
|
||||
private final ParcelFileDescriptor b;
|
||||
|
||||
public zab(Uri uri, ParcelFileDescriptor parcelFileDescriptor) {
|
||||
this.a = uri;
|
||||
this.b = parcelFileDescriptor;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
boolean z;
|
||||
Bitmap bitmap;
|
||||
Asserts.b("LoadBitmapFromDiskRunnable can't be executed in the main thread");
|
||||
ParcelFileDescriptor parcelFileDescriptor = this.b;
|
||||
boolean z2 = false;
|
||||
Bitmap bitmap2 = null;
|
||||
if (parcelFileDescriptor != null) {
|
||||
try {
|
||||
bitmap2 = BitmapFactory.decodeFileDescriptor(parcelFileDescriptor.getFileDescriptor());
|
||||
} catch (OutOfMemoryError e) {
|
||||
String valueOf = String.valueOf(this.a);
|
||||
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 34);
|
||||
sb.append("OOM while loading bitmap for uri: ");
|
||||
sb.append(valueOf);
|
||||
Log.e("ImageManager", sb.toString(), e);
|
||||
z2 = true;
|
||||
}
|
||||
try {
|
||||
this.b.close();
|
||||
} catch (IOException e2) {
|
||||
Log.e("ImageManager", "closed failed", e2);
|
||||
}
|
||||
z = z2;
|
||||
bitmap = bitmap2;
|
||||
} else {
|
||||
bitmap = null;
|
||||
z = false;
|
||||
}
|
||||
CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
ImageManager.this.b.post(ImageManager.this.new zad(this.a, bitmap, z, countDownLatch));
|
||||
try {
|
||||
countDownLatch.await();
|
||||
} catch (InterruptedException unused) {
|
||||
String valueOf2 = String.valueOf(this.a);
|
||||
StringBuilder sb2 = new StringBuilder(String.valueOf(valueOf2).length() + 32);
|
||||
sb2.append("Latch interrupted while posting ");
|
||||
sb2.append(valueOf2);
|
||||
Log.w("ImageManager", sb2.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class zad implements Runnable {
|
||||
private final Uri a;
|
||||
private final Bitmap b;
|
||||
private final CountDownLatch c;
|
||||
private boolean d;
|
||||
|
||||
public zad(Uri uri, Bitmap bitmap, boolean z, CountDownLatch countDownLatch) {
|
||||
this.a = uri;
|
||||
this.b = bitmap;
|
||||
this.d = z;
|
||||
this.c = countDownLatch;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
Asserts.a("OnBitmapLoadedRunnable must be executed in the main thread");
|
||||
boolean z = this.b != null;
|
||||
if (ImageManager.this.d != null) {
|
||||
if (this.d) {
|
||||
ImageManager.this.d.a();
|
||||
System.gc();
|
||||
this.d = false;
|
||||
ImageManager.this.b.post(this);
|
||||
return;
|
||||
}
|
||||
if (z) {
|
||||
ImageManager.this.d.a(new com.google.android.gms.common.images.zab(this.a), this.b);
|
||||
}
|
||||
}
|
||||
ImageReceiver imageReceiver = (ImageReceiver) ImageManager.this.g.remove(this.a);
|
||||
if (imageReceiver != null) {
|
||||
ArrayList arrayList = imageReceiver.zamp;
|
||||
int size = arrayList.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
com.google.android.gms.common.images.zaa zaaVar = (com.google.android.gms.common.images.zaa) arrayList.get(i);
|
||||
if (z) {
|
||||
zaaVar.a(ImageManager.this.a, this.b, false);
|
||||
} else {
|
||||
ImageManager.this.h.put(this.a, Long.valueOf(SystemClock.elapsedRealtime()));
|
||||
zaaVar.a(ImageManager.this.a, ImageManager.this.e, false);
|
||||
}
|
||||
ImageManager.this.f.remove(zaaVar);
|
||||
}
|
||||
}
|
||||
this.c.countDown();
|
||||
synchronized (ImageManager.i) {
|
||||
ImageManager.j.remove(this.a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
110
sources/com/google/android/gms/common/images/WebImage.java
Normal file
110
sources/com/google/android/gms/common/images/WebImage.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.google.android.gms.common.images;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.baidu.cloud.media.player.misc.IMediaFormat;
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable;
|
||||
import com.google.android.gms.common.internal.safeparcel.SafeParcelWriter;
|
||||
import java.util.Locale;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class WebImage extends AbstractSafeParcelable {
|
||||
public static final Parcelable.Creator<WebImage> CREATOR = new zae();
|
||||
private final int zale;
|
||||
private final int zand;
|
||||
private final int zane;
|
||||
private final Uri zanf;
|
||||
|
||||
WebImage(int i, Uri uri, int i2, int i3) {
|
||||
this.zale = i;
|
||||
this.zanf = uri;
|
||||
this.zand = i2;
|
||||
this.zane = i3;
|
||||
}
|
||||
|
||||
private static Uri zaa(JSONObject jSONObject) {
|
||||
if (jSONObject.has("url")) {
|
||||
try {
|
||||
return Uri.parse(jSONObject.getString("url"));
|
||||
} catch (JSONException unused) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj != null && (obj instanceof WebImage)) {
|
||||
WebImage webImage = (WebImage) obj;
|
||||
if (Objects.a(this.zanf, webImage.zanf) && this.zand == webImage.zand && this.zane == webImage.zane) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final int getHeight() {
|
||||
return this.zane;
|
||||
}
|
||||
|
||||
public final Uri getUrl() {
|
||||
return this.zanf;
|
||||
}
|
||||
|
||||
public final int getWidth() {
|
||||
return this.zand;
|
||||
}
|
||||
|
||||
public final int hashCode() {
|
||||
return Objects.a(this.zanf, Integer.valueOf(this.zand), Integer.valueOf(this.zane));
|
||||
}
|
||||
|
||||
public final JSONObject toJson() {
|
||||
JSONObject jSONObject = new JSONObject();
|
||||
try {
|
||||
jSONObject.put("url", this.zanf.toString());
|
||||
jSONObject.put(IMediaFormat.KEY_WIDTH, this.zand);
|
||||
jSONObject.put(IMediaFormat.KEY_HEIGHT, this.zane);
|
||||
} catch (JSONException unused) {
|
||||
}
|
||||
return jSONObject;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return String.format(Locale.US, "Image %dx%d %s", Integer.valueOf(this.zand), Integer.valueOf(this.zane), this.zanf.toString());
|
||||
}
|
||||
|
||||
@Override // android.os.Parcelable
|
||||
public final void writeToParcel(Parcel parcel, int i) {
|
||||
int a = SafeParcelWriter.a(parcel);
|
||||
SafeParcelWriter.a(parcel, 1, this.zale);
|
||||
SafeParcelWriter.a(parcel, 2, (Parcelable) getUrl(), i, false);
|
||||
SafeParcelWriter.a(parcel, 3, getWidth());
|
||||
SafeParcelWriter.a(parcel, 4, getHeight());
|
||||
SafeParcelWriter.a(parcel, a);
|
||||
}
|
||||
|
||||
public WebImage(Uri uri, int i, int i2) throws IllegalArgumentException {
|
||||
this(1, uri, i, i2);
|
||||
if (uri == null) {
|
||||
throw new IllegalArgumentException("url cannot be null");
|
||||
}
|
||||
if (i < 0 || i2 < 0) {
|
||||
throw new IllegalArgumentException("width and height must not be negative");
|
||||
}
|
||||
}
|
||||
|
||||
public WebImage(Uri uri) throws IllegalArgumentException {
|
||||
this(uri, 0, 0);
|
||||
}
|
||||
|
||||
public WebImage(JSONObject jSONObject) throws IllegalArgumentException {
|
||||
this(zaa(jSONObject), jSONObject.optInt(IMediaFormat.KEY_WIDTH, 0), jSONObject.optInt(IMediaFormat.KEY_HEIGHT, 0));
|
||||
}
|
||||
}
|
25
sources/com/google/android/gms/common/images/zaa.java
Normal file
25
sources/com/google/android/gms/common/images/zaa.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.google.android.gms.common.images;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.google.android.gms.common.internal.Asserts;
|
||||
import com.google.android.gms.internal.base.zak;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class zaa {
|
||||
protected int a;
|
||||
|
||||
final void a(Context context, Bitmap bitmap, boolean z) {
|
||||
Asserts.a(bitmap);
|
||||
a(new BitmapDrawable(context.getResources(), bitmap), z, false, true);
|
||||
}
|
||||
|
||||
protected abstract void a(Drawable drawable, boolean z, boolean z2, boolean z3);
|
||||
|
||||
final void a(Context context, zak zakVar, boolean z) {
|
||||
int i = this.a;
|
||||
a(i != 0 ? context.getResources().getDrawable(i) : null, z, false, false);
|
||||
}
|
||||
}
|
27
sources/com/google/android/gms/common/images/zab.java
Normal file
27
sources/com/google/android/gms/common/images/zab.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.google.android.gms.common.images;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class zab {
|
||||
public final Uri a;
|
||||
|
||||
public zab(Uri uri) {
|
||||
this.a = uri;
|
||||
}
|
||||
|
||||
public final boolean equals(Object obj) {
|
||||
if (!(obj instanceof zab)) {
|
||||
return false;
|
||||
}
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
return Objects.a(((zab) obj).a, this.a);
|
||||
}
|
||||
|
||||
public final int hashCode() {
|
||||
return Objects.a(this.a);
|
||||
}
|
||||
}
|
40
sources/com/google/android/gms/common/images/zae.java
Normal file
40
sources/com/google/android/gms/common/images/zae.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.google.android.gms.common.images;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.google.android.gms.common.internal.safeparcel.SafeParcelReader;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class zae implements Parcelable.Creator<WebImage> {
|
||||
@Override // android.os.Parcelable.Creator
|
||||
public final /* synthetic */ WebImage createFromParcel(Parcel parcel) {
|
||||
int b = SafeParcelReader.b(parcel);
|
||||
int i = 0;
|
||||
Uri uri = null;
|
||||
int i2 = 0;
|
||||
int i3 = 0;
|
||||
while (parcel.dataPosition() < b) {
|
||||
int a = SafeParcelReader.a(parcel);
|
||||
int a2 = SafeParcelReader.a(a);
|
||||
if (a2 == 1) {
|
||||
i = SafeParcelReader.x(parcel, a);
|
||||
} else if (a2 == 2) {
|
||||
uri = (Uri) SafeParcelReader.a(parcel, a, Uri.CREATOR);
|
||||
} else if (a2 == 3) {
|
||||
i2 = SafeParcelReader.x(parcel, a);
|
||||
} else if (a2 != 4) {
|
||||
SafeParcelReader.C(parcel, a);
|
||||
} else {
|
||||
i3 = SafeParcelReader.x(parcel, a);
|
||||
}
|
||||
}
|
||||
SafeParcelReader.q(parcel, b);
|
||||
return new WebImage(i, uri, i2, i3);
|
||||
}
|
||||
|
||||
@Override // android.os.Parcelable.Creator
|
||||
public final /* synthetic */ WebImage[] newArray(int i) {
|
||||
return new WebImage[i];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user