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

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import ඓ.ῲ.K.C1218;
import ඓ.ῲ.K.ComponentCallbacks2C1161;
import ඓ.ῲ.K.ComponentCallbacks2C1163;
import ඓ.ῲ.K.ؿ.C0821;
import ඓ.ῲ.K.ᓣ.C0825;
import ඓ.ῲ.K.ᓣ.C0845;
import ඓ.ῲ.K.ᕣ.AbstractC1030;
import ඓ.ῲ.K.ᕣ.ᨨ.AbstractC0951;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0967;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0976;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.C0964;
import ඓ.ῲ.K.㗗.AbstractC1198;
import ඓ.ῲ.K.㗗.C1190;
import ඓ.ῲ.K.㗗.ᨨ.AbstractC1192;
import ඓ.ῲ.K.㗗.㿎.AbstractC1201;
import ඓ.ῲ.K.㳳.AbstractC1215;
import ඓ.ῲ.K.㳳.C1212;
import ඓ.ῲ.K.㳳.C1213;
import ῲ.ᨨ.㳳.C1841;
import ῲ.㴪.K.K.AbstractC2258;

/* renamed from: ඓ.ῲ.K.ᕣ.ᕣ.ⁱ.ⁱ  reason: contains not printable characters */
/* compiled from: GifFrameLoader */
public class C0906 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final List<AbstractC0908> f4171 = new ArrayList();

    /* renamed from: Ԕ  reason: contains not printable characters */
    public C0909 f4172;

    /* renamed from: ؿ  reason: contains not printable characters */
    public int f4173;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final AbstractC0976 f4174;

    /* renamed from: ᓣ  reason: contains not printable characters */
    public int f4175;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public boolean f4176;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public C1218<Bitmap> f4177;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final Handler f4178;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public boolean f4179;

    /* renamed from: K  reason: contains not printable characters */
    public final AbstractC1215 f4180;

    /* renamed from: 㑃  reason: contains not printable characters */
    public C0909 f4181;

    /* renamed from: 㗗  reason: contains not printable characters */
    public int f4182;

    /* renamed from: 㳳  reason: contains not printable characters */
    public C0909 f4183;

    /* renamed from: 㴹  reason: contains not printable characters */
    public boolean f4184;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final ComponentCallbacks2C1163 f4185;

    /* renamed from: 㿎  reason: contains not printable characters */
    public boolean f4186;

    /* renamed from: 䁗  reason: contains not printable characters */
    public Bitmap f4187;

    /* renamed from: ඓ.ῲ.K.ᕣ.ᕣ.ⁱ.ⁱ$ʬ  reason: contains not printable characters */
    /* compiled from: GifFrameLoader */
    public class C0907 implements Handler.Callback {
        public C0907() {
        }

        public boolean handleMessage(Message message) {
            int i = message.what;
            if (i == 1) {
                C0906.this.m2602((C0909) message.obj);
                return true;
            } else if (i != 2) {
                return false;
            } else {
                C0906.this.f4185.m3123((C0909) message.obj);
                return false;
            }
        }
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᕣ.ⁱ.ⁱ$ῲ  reason: contains not printable characters */
    /* compiled from: GifFrameLoader */
    public interface AbstractC0908 {
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᕣ.ⁱ.ⁱ$K  reason: contains not printable characters */
    /* compiled from: GifFrameLoader */
    public static class C0909 extends AbstractC1201<Bitmap> {

        /* renamed from: ඓ  reason: contains not printable characters */
        public final Handler f4189;

        /* renamed from: ⁱ  reason: contains not printable characters */
        public final long f4190;

        /* renamed from: 㴹  reason: contains not printable characters */
        public final int f4191;

        /* renamed from: 㿎  reason: contains not printable characters */
        public Bitmap f4192;

        public C0909(Handler handler, int i, long j) {
            this.f4189 = handler;
            this.f4191 = i;
            this.f4190 = j;
        }

        @Override // ඓ.ῲ.K.㗗.㿎.AbstractC1211
        /* renamed from: ʬ  reason: contains not printable characters */
        public void m2608(Drawable drawable) {
            this.f4192 = null;
        }

        @Override // ඓ.ῲ.K.㗗.㿎.AbstractC1211
        /* renamed from: K  reason: contains not printable characters */
        public void m2609(Object obj, AbstractC1192 r4) {
            this.f4192 = (Bitmap) obj;
            this.f4189.sendMessageAtTime(this.f4189.obtainMessage(1, this), this.f4190);
        }
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᕣ.ⁱ.ⁱ$㸾  reason: contains not printable characters */
    /* compiled from: GifFrameLoader */
    public interface AbstractC0910 {
    }

    public C0906(ComponentCallbacks2C1161 r5, AbstractC1215 k, int i, int i2, AbstractC1030<Bitmap> r9, Bitmap bitmap) {
        AbstractC0976 r0 = r5.f4670;
        ComponentCallbacks2C1163 r1 = ComponentCallbacks2C1161.m3104(r5.f4673.getBaseContext());
        C1218<Bitmap> r52 = ComponentCallbacks2C1161.m3104(r5.f4673.getBaseContext()).m3127().m3292(((C1190) ((C1190) C1190.m3183(AbstractC0951.f4300).m3212(true)).m3228(true)).m3217(i, i2));
        this.f4185 = r1;
        Handler handler = new Handler(Looper.getMainLooper(), new C0907());
        this.f4174 = r0;
        this.f4178 = handler;
        this.f4177 = r52;
        this.f4180 = k;
        m2603(r9, bitmap);
    }

    public void setOnEveryFrameReadyListener(AbstractC0910 r1) {
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public Bitmap m2594() {
        C0909 k = this.f4183;
        if (k != null) {
            return k.f4192;
        }
        return this.f4187;
    }

    /* renamed from: ඓ  reason: contains not printable characters */
    public Bitmap m2595() {
        return this.f4187;
    }

    /* renamed from: ᨨ  reason: contains not printable characters */
    public int m2596() {
        return this.f4173;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m2598(AbstractC0908 r2) {
        this.f4171.remove(r2);
        if (this.f4171.isEmpty()) {
            this.f4184 = false;
        }
    }

    /* renamed from: ⁱ  reason: contains not printable characters */
    public int m2599() {
        return this.f4175;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2603(AbstractC1030<Bitmap> r4, Bitmap bitmap) {
        C1841.m4783(r4, "Argument must not be null");
        C1841.m4783(bitmap, "Argument must not be null");
        this.f4187 = bitmap;
        this.f4177 = this.f4177.m3292(new C1190().m3226(r4, true));
        this.f4182 = C0845.m2454(bitmap);
        this.f4173 = bitmap.getWidth();
        this.f4175 = bitmap.getHeight();
    }

    /* renamed from: 㳳  reason: contains not printable characters */
    public final void m2604() {
        int i;
        if (this.f4184 && !this.f4179) {
            int i2 = 0;
            if (this.f4186) {
                C1841.m4796(this.f4172 == null, "Pending target must be null when starting from the first frame");
                ((C1213) this.f4180).f4801 = -1;
                this.f4186 = false;
            }
            C0909 k = this.f4172;
            if (k != null) {
                this.f4172 = null;
                m2602(k);
                return;
            }
            this.f4179 = true;
            C1213 r0 = (C1213) this.f4180;
            C1212 r5 = r0.f4806;
            int i3 = r5.f4782;
            if (i3 > 0 && (i = r0.f4801) >= 0) {
                i2 = (i < 0 || i >= i3) ? -1 : r5.f4783.get(i).f4818;
            }
            long uptimeMillis = SystemClock.uptimeMillis() + ((long) i2);
            AbstractC1215 k2 = this.f4180;
            C1213 r1 = (C1213) k2;
            r1.f4801 = (r1.f4801 + 1) % r1.f4806.f4782;
            this.f4181 = new C0909(this.f4178, ((C1213) k2).f4801, uptimeMillis);
            C1218<Bitmap> r02 = this.f4177.m3292((AbstractC1198<?>) ((C1190) new C1190().m3225(new C0821(Double.valueOf(Math.random())))));
            r02.f4833 = this.f4180;
            r02.f4841 = true;
            r02.m3291(this.f4181, null, r02, C0825.f4050);
        }
    }

    /* renamed from: 㴹  reason: contains not printable characters */
    public int m2605() {
        return ((C1213) this.f4180).f4806.f4782;
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public int m2606() {
        C0909 k = this.f4183;
        if (k != null) {
            return k.f4191;
        }
        return -1;
    }

    /* renamed from: 㿎  reason: contains not printable characters */
    public int m2607() {
        C1213 r0 = (C1213) this.f4180;
        return (r0.f4809.length * 4) + r0.f4811.limit() + r0.f4802.length + this.f4182;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public ByteBuffer m2597() {
        return ((C1213) this.f4180).f4811.asReadOnlyBuffer();
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2601(AbstractC0908 r3) {
        if (this.f4176) {
            throw new IllegalStateException("Cannot subscribe to a cleared frame loader");
        } else if (!this.f4171.contains(r3)) {
            boolean isEmpty = this.f4171.isEmpty();
            this.f4171.add(r3);
            if (isEmpty && !this.f4184) {
                this.f4184 = true;
                this.f4176 = false;
                m2604();
            }
        } else {
            throw new IllegalStateException("Cannot subscribe twice in a row");
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2600() {
        AbstractC0967 r0;
        AbstractC0967 r3;
        AbstractC0967 r32;
        this.f4171.clear();
        Bitmap bitmap = this.f4187;
        if (bitmap != null) {
            this.f4174.m2772(bitmap);
            this.f4187 = null;
        }
        this.f4184 = false;
        C0909 k = this.f4183;
        if (k != null) {
            this.f4185.m3123(k);
            this.f4183 = null;
        }
        C0909 k2 = this.f4181;
        if (k2 != null) {
            this.f4185.m3123(k2);
            this.f4181 = null;
        }
        C0909 k3 = this.f4172;
        if (k3 != null) {
            this.f4185.m3123(k3);
            this.f4172 = null;
        }
        C1213 r02 = (C1213) this.f4180;
        r02.f4806 = null;
        byte[] bArr = r02.f4802;
        if (!(bArr == null || (r32 = ((C0905) r02.f4795).f4169) == null)) {
            ((C0964) r32).m2743(bArr);
        }
        int[] iArr = r02.f4809;
        if (!(iArr == null || (r3 = ((C0905) r02.f4795).f4169) == null)) {
            ((C0964) r3).m2743(iArr);
        }
        Bitmap bitmap2 = r02.f4814;
        if (bitmap2 != null) {
            ((C0905) r02.f4795).f4170.m2772(bitmap2);
        }
        r02.f4814 = null;
        r02.f4811 = null;
        r02.f4798 = null;
        byte[] bArr2 = r02.f4799;
        if (!(bArr2 == null || (r0 = ((C0905) r02.f4795).f4169) == null)) {
            ((C0964) r0).m2743(bArr2);
        }
        this.f4176 = true;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2602(C0909 k) {
        this.f4179 = false;
        if (this.f4176) {
            this.f4178.obtainMessage(2, k).sendToTarget();
        } else if (!this.f4184) {
            this.f4172 = k;
        } else {
            if (k.f4192 != null) {
                Bitmap bitmap = this.f4187;
                if (bitmap != null) {
                    this.f4174.m2772(bitmap);
                    this.f4187 = null;
                }
                C0909 k2 = this.f4183;
                this.f4183 = k;
                for (int size = this.f4171.size() - 1; size >= 0; size--) {
                    C0901 r4 = (C0901) this.f4171.get(size);
                    Drawable.Callback callback = r4.getCallback();
                    while (callback instanceof Drawable) {
                        callback = ((Drawable) callback).getCallback();
                    }
                    if (callback == null) {
                        r4.stop();
                        r4.invalidateSelf();
                    } else {
                        r4.invalidateSelf();
                        if (r4.f4159.f4166.m2606() == r4.f4159.f4166.m2605() - 1) {
                            r4.f4160++;
                        }
                        int i = r4.f4165;
                        if (i != -1 && r4.f4160 >= i) {
                            List<AbstractC2258.AbstractC2259> list = r4.f4161;
                            if (list != null) {
                                int size2 = list.size();
                                for (int i2 = 0; i2 < size2; i2++) {
                                    r4.f4161.get(i2).onAnimationEnd(r4);
                                }
                            }
                            r4.stop();
                        }
                    }
                }
                if (k2 != null) {
                    this.f4178.obtainMessage(2, k2).sendToTarget();
                }
            }
            m2604();
        }
    }
}
