package pl.droidsonroids.gif;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;
import android.widget.ImageView;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/* JADX INFO: loaded from: classes3.dex */
public abstract class k {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final List f32046a = Arrays.asList("raw", "drawable", "mipmap");

    public static void a(Drawable drawable, int i10) {
        if (drawable instanceof c) {
            ((c) drawable).f32029g.v(i10);
        }
    }

    public static j b(ImageView imageView, AttributeSet attributeSet, int i10) {
        if (attributeSet == null || imageView.isInEditMode()) {
            return new j();
        }
        j jVar = new j(imageView, attributeSet, i10);
        int i11 = jVar.f901a;
        if (i11 >= 0) {
            a(imageView.getDrawable(), i11);
            a(imageView.getBackground(), i11);
        }
        return jVar;
    }

    public static boolean c(ImageView imageView, Uri uri) {
        if (uri == null) {
            return false;
        }
        try {
            imageView.setImageDrawable(new c(imageView.getContext().getContentResolver(), uri));
            return true;
        } catch (IOException unused) {
            return false;
        }
    }

    public static boolean d(ImageView imageView, boolean z10, int i10) {
        Resources resources = imageView.getResources();
        if (resources != null) {
            try {
                if (!f32046a.contains(resources.getResourceTypeName(i10))) {
                    return false;
                }
                c cVar = new c(resources, i10);
                if (z10) {
                    imageView.setImageDrawable(cVar);
                    return true;
                }
                imageView.setBackground(cVar);
                return true;
            } catch (Resources.NotFoundException | IOException unused) {
            }
        }
        return false;
    }
}
