Initial commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package com.bumptech.glide.load.resource.drawable;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import com.bumptech.glide.load.Options;
|
||||
import com.bumptech.glide.load.ResourceDecoder;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ResourceDrawableDecoder implements ResourceDecoder<Uri, Drawable> {
|
||||
private final Context a;
|
||||
|
||||
public ResourceDrawableDecoder(Context context) {
|
||||
this.a = context.getApplicationContext();
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.ResourceDecoder
|
||||
public boolean a(Uri uri, Options options) {
|
||||
return uri.getScheme().equals("android.resource");
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.ResourceDecoder
|
||||
public Resource<Drawable> a(Uri uri, int i, int i2, Options options) {
|
||||
int a = a(uri);
|
||||
String authority = uri.getAuthority();
|
||||
return NonOwnedDrawableResource.a(DrawableDecoderCompat.a(this.a, authority.equals(this.a.getPackageName()) ? this.a : a(uri, authority), a));
|
||||
}
|
||||
|
||||
private Context a(Uri uri, String str) {
|
||||
try {
|
||||
return this.a.createPackageContext(str, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
throw new IllegalArgumentException("Failed to obtain context or unrecognized Uri format for: " + uri, e);
|
||||
}
|
||||
}
|
||||
|
||||
private int a(Uri uri) {
|
||||
Integer valueOf;
|
||||
List<String> pathSegments = uri.getPathSegments();
|
||||
if (pathSegments.size() == 2) {
|
||||
String authority = uri.getAuthority();
|
||||
valueOf = Integer.valueOf(this.a.getResources().getIdentifier(pathSegments.get(1), pathSegments.get(0), authority));
|
||||
} else {
|
||||
if (pathSegments.size() == 1) {
|
||||
try {
|
||||
valueOf = Integer.valueOf(pathSegments.get(0));
|
||||
} catch (NumberFormatException unused) {
|
||||
}
|
||||
}
|
||||
valueOf = null;
|
||||
}
|
||||
if (valueOf != null) {
|
||||
if (valueOf.intValue() != 0) {
|
||||
return valueOf.intValue();
|
||||
}
|
||||
throw new IllegalArgumentException("Failed to obtain resource id for: " + uri);
|
||||
}
|
||||
throw new IllegalArgumentException("Unrecognized Uri format: " + uri);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user