package ඓ.ῲ.K.ᕣ.ᕣ.ඓ;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import java.io.IOException;
import java.util.List;
import ඓ.ῲ.K.ᕣ.AbstractC0853;
import ඓ.ῲ.K.ᕣ.C1121;
import ඓ.ῲ.K.ᕣ.ᨨ.AbstractC1027;
import ඓ.K.K.K.C1293;

/* renamed from: ඓ.ῲ.K.ᕣ.ᕣ.ඓ.㸾  reason: contains not printable characters */
/* compiled from: ResourceDrawableDecoder */
public class C0899 implements AbstractC0853<Uri, Drawable> {

    /* renamed from: K  reason: contains not printable characters */
    public final Context f4153;

    public C0899(Context context) {
        this.f4153 = context.getApplicationContext();
    }

    /* Return type fixed from 'ඓ.ῲ.K.ᕣ.ᨨ.䀟' to match base method */
    /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, int, int, ඓ.ῲ.K.ᕣ.㸾] */
    @Override // ඓ.ῲ.K.ᕣ.AbstractC0853
    /* renamed from: K  reason: contains not printable characters */
    public /* bridge */ /* synthetic */ AbstractC1027<Drawable> m2582(Uri uri, int i, int i2, C1121 r4) throws IOException {
        return m2581(uri);
    }

    /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, ඓ.ῲ.K.ᕣ.㸾] */
    @Override // ඓ.ῲ.K.ᕣ.AbstractC0853
    /* renamed from: K  reason: contains not printable characters */
    public boolean m2583(Uri uri, C1121 r2) throws IOException {
        return uri.getScheme().equals("android.resource");
    }

    /* JADX WARN: Incorrect args count in method signature: (Landroid/net/Uri;IILඓ/ῲ/K/ᕣ/㸾;)Lඓ/ῲ/K/ᕣ/ᨨ/䀟<Landroid/graphics/drawable/Drawable;>; */
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC1027 m2581(Uri uri) {
        Context context;
        int i;
        String authority = uri.getAuthority();
        if (authority.equals(this.f4153.getPackageName())) {
            context = this.f4153;
        } else {
            try {
                context = this.f4153.createPackageContext(authority, 0);
            } catch (PackageManager.NameNotFoundException e) {
                if (authority.contains(this.f4153.getPackageName())) {
                    context = this.f4153;
                } else {
                    throw new IllegalArgumentException(C1293.m3410("Failed to obtain context or unrecognized Uri format for: ", uri), e);
                }
            }
        }
        List<String> pathSegments = uri.getPathSegments();
        if (pathSegments.size() == 2) {
            List<String> pathSegments2 = uri.getPathSegments();
            String authority2 = uri.getAuthority();
            String str = pathSegments2.get(0);
            String str2 = pathSegments2.get(1);
            i = context.getResources().getIdentifier(str2, str, authority2);
            if (i == 0) {
                i = Resources.getSystem().getIdentifier(str2, str, "android");
            }
            if (i == 0) {
                throw new IllegalArgumentException(C1293.m3410("Failed to find resource id for: ", uri));
            }
        } else if (pathSegments.size() == 1) {
            try {
                i = Integer.parseInt(uri.getPathSegments().get(0));
            } catch (NumberFormatException e2) {
                throw new IllegalArgumentException(C1293.m3410("Unrecognized Uri format: ", uri), e2);
            }
        } else {
            throw new IllegalArgumentException(C1293.m3410("Unrecognized Uri format: ", uri));
        }
        Drawable r7 = C0898.m2580(this.f4153, context, i, null);
        if (r7 != null) {
            return new C0895(r7);
        }
        return null;
    }
}
