package com.google.android.material.behavior;

import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.accessibility.d;
import androidx.core.view.accessibility.g;
import androidx.core.view.y;
import x.c;

/* JADX INFO: loaded from: classes.dex */
public class SwipeDismissBehavior<V extends View> extends CoordinatorLayout.c<V> {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    x.c f3580a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    c f3581b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private boolean f3582c;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private float f3583d = 0.0f;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    int f3585f = 2;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    float f3586g = 0.5f;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    float f3587h = 0.0f;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    float f3588i = 0.5f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private final c.AbstractC0087c f3589j = new a();

    class a extends c.AbstractC0087c {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private int f3590a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private int f3591b = -1;

        a() {
        }

        private boolean n(View view, float f3) {
            if (f3 == 0.0f) {
                return Math.abs(view.getLeft() - this.f3590a) >= Math.round(((float) view.getWidth()) * SwipeDismissBehavior.this.f3586g);
            }
            boolean z2 = y.E(view) == 1;
            int i3 = SwipeDismissBehavior.this.f3585f;
            if (i3 == 2) {
                return true;
            }
            if (i3 == 0) {
                if (z2) {
                    if (f3 >= 0.0f) {
                        return false;
                    }
                } else if (f3 <= 0.0f) {
                    return false;
                }
                return true;
            }
            if (i3 != 1) {
                return false;
            }
            if (z2) {
                if (f3 <= 0.0f) {
                    return false;
                }
            } else if (f3 >= 0.0f) {
                return false;
            }
            return true;
        }

        @Override // x.c.AbstractC0087c
        public int a(View view, int i3, int i4) {
            int width;
            int width2;
            int width3;
            boolean z2 = y.E(view) == 1;
            int i5 = SwipeDismissBehavior.this.f3585f;
            if (i5 == 0) {
                if (z2) {
                    width = this.f3590a - view.getWidth();
                    width2 = this.f3590a;
                } else {
                    width = this.f3590a;
                    width3 = view.getWidth();
                    width2 = width3 + width;
                }
            } else if (i5 != 1) {
                width = this.f3590a - view.getWidth();
                width2 = this.f3590a + view.getWidth();
            } else if (z2) {
                width = this.f3590a;
                width3 = view.getWidth();
                width2 = width3 + width;
            } else {
                width = this.f3590a - view.getWidth();
                width2 = this.f3590a;
            }
            return SwipeDismissBehavior.G(width, i3, width2);
        }

        @Override // x.c.AbstractC0087c
        public int b(View view, int i3, int i4) {
            return view.getTop();
        }

        @Override // x.c.AbstractC0087c
        public int d(View view) {
            return view.getWidth();
        }

        @Override // x.c.AbstractC0087c
        public void i(View view, int i3) {
            this.f3591b = i3;
            this.f3590a = view.getLeft();
            ViewParent parent = view.getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
        }

        @Override // x.c.AbstractC0087c
        public void j(int i3) {
            c cVar = SwipeDismissBehavior.this.f3581b;
            if (cVar != null) {
                cVar.b(i3);
            }
        }

        @Override // x.c.AbstractC0087c
        public void k(View view, int i3, int i4, int i5, int i6) {
            float width = this.f3590a + (view.getWidth() * SwipeDismissBehavior.this.f3587h);
            float width2 = this.f3590a + (view.getWidth() * SwipeDismissBehavior.this.f3588i);
            float f3 = i3;
            if (f3 <= width) {
                view.setAlpha(1.0f);
            } else if (f3 >= width2) {
                view.setAlpha(0.0f);
            } else {
                view.setAlpha(SwipeDismissBehavior.F(0.0f, 1.0f - SwipeDismissBehavior.I(width, width2, f3), 1.0f));
            }
        }

        @Override // x.c.AbstractC0087c
        public void l(View view, float f3, float f4) {
            int i3;
            boolean z2;
            c cVar;
            this.f3591b = -1;
            int width = view.getWidth();
            if (n(view, f3)) {
                int left = view.getLeft();
                int i4 = this.f3590a;
                i3 = left < i4 ? i4 - width : i4 + width;
                z2 = true;
            } else {
                i3 = this.f3590a;
                z2 = false;
            }
            if (SwipeDismissBehavior.this.f3580a.F(i3, view.getTop())) {
                y.j0(view, new d(view, z2));
            } else {
                if (!z2 || (cVar = SwipeDismissBehavior.this.f3581b) == null) {
                    return;
                }
                cVar.a(view);
            }
        }

        @Override // x.c.AbstractC0087c
        public boolean m(View view, int i3) {
            int i4 = this.f3591b;
            return (i4 == -1 || i4 == i3) && SwipeDismissBehavior.this.E(view);
        }
    }

    class b implements g {
        b() {
        }

        @Override // androidx.core.view.accessibility.g
        public boolean a(View view, g.a aVar) {
            boolean z2 = false;
            if (!SwipeDismissBehavior.this.E(view)) {
                return false;
            }
            boolean z3 = y.E(view) == 1;
            int i3 = SwipeDismissBehavior.this.f3585f;
            if ((i3 == 0 && z3) || (i3 == 1 && !z3)) {
                z2 = true;
            }
            int width = view.getWidth();
            if (z2) {
                width = -width;
            }
            y.b0(view, width);
            view.setAlpha(0.0f);
            c cVar = SwipeDismissBehavior.this.f3581b;
            if (cVar != null) {
                cVar.a(view);
            }
            return true;
        }
    }

    public interface c {
        void a(View view);

        void b(int i3);
    }

    private class d implements Runnable {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private final View f3594e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private final boolean f3595f;

        d(View view, boolean z2) {
            this.f3594e = view;
            this.f3595f = z2;
        }

        @Override // java.lang.Runnable
        public void run() {
            c cVar;
            x.c cVar2 = SwipeDismissBehavior.this.f3580a;
            if (cVar2 != null && cVar2.k(true)) {
                y.j0(this.f3594e, this);
            } else {
                if (!this.f3595f || (cVar = SwipeDismissBehavior.this.f3581b) == null) {
                    return;
                }
                cVar.a(this.f3594e);
            }
        }
    }

    static float F(float f3, float f4, float f5) {
        return Math.min(Math.max(f3, f4), f5);
    }

    static int G(int i3, int i4, int i5) {
        return Math.min(Math.max(i3, i4), i5);
    }

    private void H(ViewGroup viewGroup) {
        if (this.f3580a == null) {
            this.f3580a = this.f3584e ? x.c.l(viewGroup, this.f3583d, this.f3589j) : x.c.m(viewGroup, this.f3589j);
        }
    }

    static float I(float f3, float f4, float f5) {
        return (f5 - f3) / (f4 - f3);
    }

    private void N(View view) {
        y.l0(view, 1048576);
        if (E(view)) {
            y.n0(view, d.a.f1854j, null, new b());
        }
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean D(CoordinatorLayout coordinatorLayout, V v2, MotionEvent motionEvent) {
        x.c cVar = this.f3580a;
        if (cVar == null) {
            return false;
        }
        cVar.z(motionEvent);
        return true;
    }

    public boolean E(View view) {
        return true;
    }

    public void J(float f3) {
        this.f3588i = F(0.0f, f3, 1.0f);
    }

    public void K(c cVar) {
        this.f3581b = cVar;
    }

    public void L(float f3) {
        this.f3587h = F(0.0f, f3, 1.0f);
    }

    public void M(int i3) {
        this.f3585f = i3;
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean k(CoordinatorLayout coordinatorLayout, V v2, MotionEvent motionEvent) {
        boolean zB = this.f3582c;
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 0) {
            zB = coordinatorLayout.B(v2, (int) motionEvent.getX(), (int) motionEvent.getY());
            this.f3582c = zB;
        } else if (actionMasked == 1 || actionMasked == 3) {
            this.f3582c = false;
        }
        if (!zB) {
            return false;
        }
        H(coordinatorLayout);
        return this.f3580a.G(motionEvent);
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean l(CoordinatorLayout coordinatorLayout, V v2, int i3) {
        boolean zL = super.l(coordinatorLayout, v2, i3);
        if (y.C(v2) == 0) {
            y.B0(v2, 1);
            N(v2);
        }
        return zL;
    }
}
