package com.ifpdos.videopresenter.view;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import b.b.a.f.f;
import com.ifpdos.autotest.R;
import com.ifpdos.videopresenter.b.l;
import com.ifpdos.videopresenter.b.m;
import org.greenrobot.eventbus.ThreadMode;
import org.greenrobot.eventbus.j;

/* JADX INFO: compiled from: LoadingCameraView.java */
/* JADX INFO: loaded from: classes.dex */
public class h extends View {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final ViewGroup f2428c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private ValueAnimator f2429d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private ImageView f2430e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private Context f2431f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private ImageView f2432g;
    private ImageView h;
    private View i;

    public h(Context context, ViewGroup viewGroup) {
        super(context);
        this.f2431f = context;
        this.f2428c = viewGroup;
        a(context);
    }

    private void a(Context context) {
        int[] iArr = {R.drawable.loading_camera_bottom, R.drawable.loading_camera_refresh, R.drawable.loading_camera_top};
        Bitmap bitmapDecodeResource = BitmapFactory.decodeResource(this.f2431f.getResources(), iArr[2]);
        Bitmap bitmapDecodeResource2 = BitmapFactory.decodeResource(this.f2431f.getResources(), iArr[1]);
        Bitmap bitmapDecodeResource3 = BitmapFactory.decodeResource(this.f2431f.getResources(), iArr[0]);
        View viewInflate = LayoutInflater.from(context).inflate(R.layout.view_load_camera, this.f2428c);
        viewInflate.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
        viewInflate.setBackgroundResource(R.color.expo_bg);
        this.f2432g = (ImageView) viewInflate.findViewById(R.id.loading_camera_background);
        this.f2430e = (ImageView) viewInflate.findViewById(R.id.loading_camera_progress);
        this.h = (ImageView) viewInflate.findViewById(R.id.loading_camera_top);
        this.f2432g.setImageBitmap(bitmapDecodeResource3);
        this.f2430e.setImageBitmap(bitmapDecodeResource2);
        this.h.setImageBitmap(bitmapDecodeResource);
        this.i = viewInflate.findViewById(R.id.loading_text);
        e();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
    public /* synthetic */ void c(ValueAnimator valueAnimator) {
        this.f2430e.setRotation(((Float) valueAnimator.getAnimatedValue()).floatValue());
    }

    private void d() {
        ValueAnimator valueAnimator = this.f2429d;
        if (valueAnimator == null) {
            return;
        }
        valueAnimator.cancel();
        this.f2429d = null;
    }

    private void e() {
        if (this.f2429d != null) {
            return;
        }
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 359.0f);
        this.f2429d = valueAnimatorOfFloat;
        valueAnimatorOfFloat.setDuration(1000L);
        this.f2429d.setInterpolator(new LinearInterpolator());
        this.f2429d.setRepeatCount(-1);
        this.f2429d.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.ifpdos.videopresenter.view.b
            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                this.f2400a.c(valueAnimator);
            }
        });
        this.f2429d.start();
    }

    private void h() {
        f.EnumC0033f enumC0033fG = b.b.a.c.g().f().g();
        if (enumC0033fG == f.EnumC0033f.PREVIEWING) {
            g();
        } else {
            if (enumC0033fG == f.EnumC0033f.TAKING_PICTURE || enumC0033fG == f.EnumC0033f.STOP_PREVIEWING) {
                return;
            }
            f();
        }
    }

    public void f() {
        if (getVisibility() == 0) {
            return;
        }
        setVisibility(0);
        e();
    }

    public void g() {
        if (getVisibility() == 4) {
            return;
        }
        d();
        setVisibility(4);
    }

    @j(threadMode = ThreadMode.MAIN)
    public void onActivityPause(com.ifpdos.videopresenter.b.b bVar) {
        if (getVisibility() == 0) {
            d();
        }
    }

    @j(threadMode = ThreadMode.MAIN)
    public void onActivityResume(com.ifpdos.videopresenter.b.c cVar) {
        if (getVisibility() == 0) {
            e();
        }
    }

    @Override // android.view.View
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        org.greenrobot.eventbus.c.c().o(this);
    }

    @Override // android.view.View
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        org.greenrobot.eventbus.c.c().q(this);
    }

    @j(threadMode = ThreadMode.MAIN)
    public void onModelEventOccur(com.ifpdos.videopresenter.b.j jVar) {
        h();
    }

    @j(threadMode = ThreadMode.MAIN)
    public void onSlotEventOccur(l lVar) {
        h();
    }

    @j(threadMode = ThreadMode.MAIN)
    public void onStatusChanged(m mVar) {
        h();
    }

    @Override // android.view.View
    public void setVisibility(int i) {
        this.f2432g.setVisibility(i);
        this.f2430e.setVisibility(i);
        this.h.setVisibility(i);
        this.i.setVisibility(i);
        super.setVisibility(i);
    }
}
