package net.cachapa.expandablelayout;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes3.dex */
public class ExpandableLayout extends android.widget.FrameLayout {
    private int a;
    private float b;
    private float c;
    private int d;
    private int e;
    private android.view.animation.Interpolator f;
    private android.animation.ValueAnimator g;
    private net.cachapa.expandablelayout.ExpandableLayout.OnExpansionUpdateListener h;

    /* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
    public interface OnExpansionUpdateListener {
        void a(float f, int i);
    }

    /* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
    public interface State {
    }

    public ExpandableLayout(android.content.Context context) {
        this(context, null);
    }

    private void b(int i) {
        android.animation.ValueAnimator valueAnimator = this.g;
        if (valueAnimator != null) {
            valueAnimator.cancel();
            this.g = null;
        }
        android.animation.ValueAnimator valueAnimatorOfFloat = android.animation.ValueAnimator.ofFloat(this.c, i);
        this.g = valueAnimatorOfFloat;
        valueAnimatorOfFloat.setInterpolator(this.f);
        this.g.setDuration(this.a);
        this.g.addUpdateListener(new android.animation.ValueAnimator.AnimatorUpdateListener() { // from class: net.cachapa.expandablelayout.ExpandableLayout.1
            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
            public void onAnimationUpdate(android.animation.ValueAnimator valueAnimator2) {
                net.cachapa.expandablelayout.ExpandableLayout.this.setExpansion(((java.lang.Float) valueAnimator2.getAnimatedValue()).floatValue());
            }
        });
        this.g.addListener(new net.cachapa.expandablelayout.ExpandableLayout.ExpansionListener(i));
        this.g.start();
    }

    public void c() {
        d(true);
    }

    public void d(boolean z) {
        setExpanded(false, z);
    }

    public void e() {
        f(true);
    }

    public void f(boolean z) {
        setExpanded(true, z);
    }

    public boolean g() {
        int i = this.e;
        return i == 2 || i == 3;
    }

    public int getDuration() {
        return this.a;
    }

    public float getExpansion() {
        return this.c;
    }

    public int getOrientation() {
        return this.d;
    }

    public float getParallax() {
        return this.b;
    }

    public int getState() {
        return this.e;
    }

    @Override // android.view.View
    protected void onConfigurationChanged(android.content.res.Configuration configuration) {
        android.animation.ValueAnimator valueAnimator = this.g;
        if (valueAnimator != null) {
            valueAnimator.cancel();
        }
        super.onConfigurationChanged(configuration);
    }

    @Override // android.widget.FrameLayout, android.view.View
    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        int measuredWidth = getMeasuredWidth();
        int measuredHeight = getMeasuredHeight();
        int i5 = this.d == 0 ? measuredWidth : measuredHeight;
        setVisibility((this.c == 0.0f && i5 == 0) ? 8 : 0);
        int iRound = i5 - java.lang.Math.round(i5 * this.c);
        float f = this.b;
        if (f > 0.0f) {
            float f2 = iRound * f;
            for (int i6 = 0; i6 < getChildCount(); i6++) {
                android.view.View childAt = getChildAt(i6);
                if (this.d == 0) {
                    childAt.setTranslationX((getLayoutDirection() != 1 ? -1 : 1) * f2);
                } else {
                    childAt.setTranslationY(-f2);
                }
            }
        }
        if (this.d == 0) {
            setMeasuredDimension(measuredWidth - iRound, measuredHeight);
        } else {
            setMeasuredDimension(measuredWidth, measuredHeight - iRound);
        }
    }

    @Override // android.view.View
    protected void onRestoreInstanceState(android.os.Parcelable parcelable) {
        android.os.Bundle bundle = (android.os.Bundle) parcelable;
        float f = bundle.getFloat("expansion");
        this.c = f;
        this.e = f == 1.0f ? 3 : 0;
        super.onRestoreInstanceState(bundle.getParcelable("super_state"));
    }

    @Override // android.view.View
    protected android.os.Parcelable onSaveInstanceState() {
        android.os.Parcelable parcelableOnSaveInstanceState = super.onSaveInstanceState();
        android.os.Bundle bundle = new android.os.Bundle();
        float f = g() ? 1.0f : 0.0f;
        this.c = f;
        bundle.putFloat("expansion", f);
        bundle.putParcelable("super_state", parcelableOnSaveInstanceState);
        return bundle;
    }

    public void setDuration(int i) {
        this.a = i;
    }

    public void setExpanded(boolean z) {
        setExpanded(z, true);
    }

    public void setExpansion(float f) {
        float f2 = this.c;
        if (f2 == f) {
            return;
        }
        float f5 = f - f2;
        if (f == 0.0f) {
            this.e = 0;
        } else if (f == 1.0f) {
            this.e = 3;
        } else if (f5 < 0.0f) {
            this.e = 1;
        } else if (f5 > 0.0f) {
            this.e = 2;
        }
        setVisibility(this.e == 0 ? 8 : 0);
        this.c = f;
        requestLayout();
        net.cachapa.expandablelayout.ExpandableLayout.OnExpansionUpdateListener onExpansionUpdateListener = this.h;
        if (onExpansionUpdateListener != null) {
            onExpansionUpdateListener.a(f, this.e);
        }
    }

    public void setInterpolator(android.view.animation.Interpolator interpolator) {
        this.f = interpolator;
    }

    public void setOnExpansionUpdateListener(net.cachapa.expandablelayout.ExpandableLayout.OnExpansionUpdateListener onExpansionUpdateListener) {
        this.h = onExpansionUpdateListener;
    }

    public void setOrientation(int i) {
        if (i < 0 || i > 1) {
            throw new java.lang.IllegalArgumentException("Orientation must be either 0 (horizontal) or 1 (vertical)");
        }
        this.d = i;
    }

    public void setParallax(float f) {
        this.b = java.lang.Math.min(1.0f, java.lang.Math.max(0.0f, f));
    }

    public ExpandableLayout(android.content.Context context, android.util.AttributeSet attributeSet) {
        super(context, attributeSet);
        this.a = 300;
        this.f = new net.cachapa.expandablelayout.util.FastOutSlowInInterpolator();
        if (attributeSet != null) {
            android.content.res.TypedArray typedArrayObtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, net.cachapa.expandablelayout.R.styleable.ExpandableLayout);
            this.a = typedArrayObtainStyledAttributes.getInt(net.cachapa.expandablelayout.R.styleable.ExpandableLayout_el_duration, 300);
            this.c = typedArrayObtainStyledAttributes.getBoolean(net.cachapa.expandablelayout.R.styleable.ExpandableLayout_el_expanded, false) ? 1.0f : 0.0f;
            this.d = typedArrayObtainStyledAttributes.getInt(net.cachapa.expandablelayout.R.styleable.ExpandableLayout_android_orientation, 1);
            this.b = typedArrayObtainStyledAttributes.getFloat(net.cachapa.expandablelayout.R.styleable.ExpandableLayout_el_parallax, 1.0f);
            typedArrayObtainStyledAttributes.recycle();
            this.e = this.c != 0.0f ? 3 : 0;
            setParallax(this.b);
        }
    }

    public void setExpanded(boolean z, boolean z4) {
        if (z == g()) {
            return;
        }
        if (z4) {
            b(z ? 1 : 0);
        } else {
            setExpansion(z ? 1.0f : 0.0f);
        }
    }

    /* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
    private class ExpansionListener implements android.animation.Animator.AnimatorListener {
        private int a;
        private boolean b;

        public ExpansionListener(int i) {
            this.a = i;
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationCancel(android.animation.Animator animator) {
            this.b = true;
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationEnd(android.animation.Animator animator) {
            if (this.b) {
                return;
            }
            net.cachapa.expandablelayout.ExpandableLayout.this.e = this.a == 0 ? 0 : 3;
            net.cachapa.expandablelayout.ExpandableLayout.this.setExpansion(this.a);
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationStart(android.animation.Animator animator) {
            net.cachapa.expandablelayout.ExpandableLayout.this.e = this.a == 0 ? 1 : 2;
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationRepeat(android.animation.Animator animator) {
        }
    }
}
