package p028j;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import p001a0.C0012f;
import p007c.C0485a;
import p011d0.C0598a;
import p016f.C0683f;
import p023h0.C0875k4;
import p032k0.C1332t;

/* renamed from: j.k2 */
/* loaded from: classes.dex */
public class C1127k2 extends ListView {

    /* renamed from: d */
    public final Rect f2736d;

    /* renamed from: e */
    public int f2737e;

    /* renamed from: f */
    public int f2738f;

    /* renamed from: g */
    public int f2739g;

    /* renamed from: h */
    public int f2740h;

    /* renamed from: i */
    public int f2741i;

    /* renamed from: j */
    public C1131d f2742j;

    /* renamed from: k */
    public boolean f2743k;

    /* renamed from: l */
    public boolean f2744l;

    /* renamed from: m */
    public boolean f2745m;

    /* renamed from: n */
    public C0875k4 f2746n;

    /* renamed from: o */
    public C1332t f2747o;

    /* renamed from: p */
    public RunnableC1133f f2748p;

    /* renamed from: j.k2$a */
    /* loaded from: classes.dex */
    public static class C1128a {
        /* renamed from: a */
        public static void m2074a(View view, float f, float f2) {
            view.drawableHotspotChanged(f, f2);
        }
    }

    /* renamed from: j.k2$b */
    /* loaded from: classes.dex */
    public static class C1129b {

        /* renamed from: a */
        public static Method f2749a;

        /* renamed from: b */
        public static Method f2750b;

        /* renamed from: c */
        public static Method f2751c;

        /* renamed from: d */
        public static boolean f2752d;

        static {
            try {
                Class cls = Integer.TYPE;
                Class cls2 = Float.TYPE;
                Method declaredMethod = AbsListView.class.getDeclaredMethod("positionSelector", cls, View.class, Boolean.TYPE, cls2, cls2);
                f2749a = declaredMethod;
                declaredMethod.setAccessible(true);
                Method declaredMethod2 = AdapterView.class.getDeclaredMethod("setSelectedPositionInt", cls);
                f2750b = declaredMethod2;
                declaredMethod2.setAccessible(true);
                Method declaredMethod3 = AdapterView.class.getDeclaredMethod("setNextSelectedPositionInt", cls);
                f2751c = declaredMethod3;
                declaredMethod3.setAccessible(true);
                f2752d = true;
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        }

        /* renamed from: a */
        public static boolean m2073a() {
            return f2752d;
        }

        /* renamed from: b */
        public static void m2072b(C1127k2 c1127k2, int i, View view) {
            try {
                f2749a.invoke(c1127k2, Integer.valueOf(i), view, Boolean.FALSE, -1, -1);
                f2750b.invoke(c1127k2, Integer.valueOf(i));
                f2751c.invoke(c1127k2, Integer.valueOf(i));
            } catch (IllegalAccessException | InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }

    /* renamed from: j.k2$c */
    /* loaded from: classes.dex */
    public static class C1130c {
        /* renamed from: a */
        public static boolean m2071a(AbsListView absListView) {
            return absListView.isSelectedChildViewEnabled();
        }

        /* renamed from: b */
        public static void m2070b(AbsListView absListView, boolean z) {
            absListView.setSelectedChildViewEnabled(z);
        }
    }

    /* renamed from: j.k2$d */
    /* loaded from: classes.dex */
    public static class C1131d extends C0683f {

        /* renamed from: e */
        public boolean f2753e;

        public C1131d(Drawable drawable) {
            super(drawable);
            this.f2753e = true;
        }

        /* renamed from: c */
        public void m2069c(boolean z) {
            this.f2753e = z;
        }

        @Override // p016f.C0683f, android.graphics.drawable.Drawable
        public void draw(Canvas canvas) {
            if (this.f2753e) {
                super.draw(canvas);
            }
        }

        @Override // p016f.C0683f, android.graphics.drawable.Drawable
        public void setHotspot(float f, float f2) {
            if (this.f2753e) {
                super.setHotspot(f, f2);
            }
        }

        @Override // p016f.C0683f, android.graphics.drawable.Drawable
        public void setHotspotBounds(int i, int i2, int i3, int i4) {
            if (this.f2753e) {
                super.setHotspotBounds(i, i2, i3, i4);
            }
        }

        @Override // p016f.C0683f, android.graphics.drawable.Drawable
        public boolean setState(int[] iArr) {
            if (this.f2753e) {
                return super.setState(iArr);
            }
            return false;
        }

        @Override // p016f.C0683f, android.graphics.drawable.Drawable
        public boolean setVisible(boolean z, boolean z2) {
            if (this.f2753e) {
                return super.setVisible(z, z2);
            }
            return false;
        }
    }

    /* renamed from: j.k2$e */
    /* loaded from: classes.dex */
    public static class C1132e {

        /* renamed from: a */
        public static final Field f2754a;

        static {
            Field field = null;
            try {
                field = AbsListView.class.getDeclaredField("mIsChildViewEnabled");
                field.setAccessible(true);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
            f2754a = field;
        }

        /* renamed from: a */
        public static boolean m2068a(AbsListView absListView) {
            Field field = f2754a;
            if (field != null) {
                try {
                    return field.getBoolean(absListView);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                    return false;
                }
            }
            return false;
        }

        /* renamed from: b */
        public static void m2067b(AbsListView absListView, boolean z) {
            Field field = f2754a;
            if (field != null) {
                try {
                    field.set(absListView, Boolean.valueOf(z));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /* renamed from: j.k2$f */
    /* loaded from: classes.dex */
    public class RunnableC1133f implements Runnable {
        public RunnableC1133f() {
        }

        /* renamed from: a */
        public void m2066a() {
            C1127k2 c1127k2 = C1127k2.this;
            c1127k2.f2748p = null;
            c1127k2.removeCallbacks(this);
        }

        /* renamed from: b */
        public void m2065b() {
            C1127k2.this.post(this);
        }

        @Override // java.lang.Runnable
        public void run() {
            C1127k2 c1127k2 = C1127k2.this;
            c1127k2.f2748p = null;
            c1127k2.drawableStateChanged();
        }
    }

    public C1127k2(Context context, boolean z) {
        super(context, null, C0485a.dropDownListViewStyle);
        this.f2736d = new Rect();
        this.f2737e = 0;
        this.f2738f = 0;
        this.f2739g = 0;
        this.f2740h = 0;
        this.f2744l = z;
        setCacheColorHint(0);
    }

    private void setSelectorEnabled(boolean z) {
        C1131d c1131d = this.f2742j;
        if (c1131d != null) {
            c1131d.m2069c(z);
        }
    }

    /* renamed from: a */
    public final void m2085a() {
        this.f2745m = false;
        setPressed(false);
        drawableStateChanged();
        View childAt = getChildAt(this.f2741i - getFirstVisiblePosition());
        if (childAt != null) {
            childAt.setPressed(false);
        }
        C0875k4 c0875k4 = this.f2746n;
        if (c0875k4 != null) {
            c0875k4.m2650c();
            this.f2746n = null;
        }
    }

    /* renamed from: b */
    public final void m2084b(View view, int i) {
        performItemClick(view, i, getItemIdAtPosition(i));
    }

    /* renamed from: c */
    public final void m2083c(Canvas canvas) {
        Drawable selector;
        if (this.f2736d.isEmpty() || (selector = getSelector()) == null) {
            return;
        }
        selector.setBounds(this.f2736d);
        selector.draw(canvas);
    }

    /* renamed from: d */
    public int mo1848d(int i, int i2, int i3, int i4, int i5) {
        int listPaddingTop = getListPaddingTop();
        int listPaddingBottom = getListPaddingBottom();
        int dividerHeight = getDividerHeight();
        Drawable divider = getDivider();
        ListAdapter adapter = getAdapter();
        int i6 = listPaddingTop + listPaddingBottom;
        if (adapter == null) {
            return i6;
        }
        dividerHeight = (dividerHeight <= 0 || divider == null) ? 0 : 0;
        int count = adapter.getCount();
        View view = null;
        int i7 = 0;
        int i8 = 0;
        int i9 = 0;
        while (i7 < count) {
            int itemViewType = adapter.getItemViewType(i7);
            if (itemViewType != i8) {
                view = null;
                i8 = itemViewType;
            }
            view = adapter.getView(i7, view, this);
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            if (layoutParams == null) {
                layoutParams = generateDefaultLayoutParams();
                view.setLayoutParams(layoutParams);
            }
            int i10 = layoutParams.height;
            view.measure(i, i10 > 0 ? View.MeasureSpec.makeMeasureSpec(i10, 1073741824) : View.MeasureSpec.makeMeasureSpec(0, 0));
            view.forceLayout();
            if (i7 > 0) {
                i6 += dividerHeight;
            }
            i6 += view.getMeasuredHeight();
            if (i6 >= i4) {
                return (i5 < 0 || i7 <= i5 || i9 <= 0 || i6 == i4) ? i4 : i9;
            }
            if (i5 >= 0 && i7 >= i5) {
                i9 = i6;
            }
            i7++;
        }
        return i6;
    }

    @Override // android.widget.ListView, android.widget.AbsListView, android.view.ViewGroup, android.view.View
    public void dispatchDraw(Canvas canvas) {
        m2083c(canvas);
        super.dispatchDraw(canvas);
    }

    @Override // android.widget.AbsListView, android.view.ViewGroup, android.view.View
    public void drawableStateChanged() {
        if (this.f2748p != null) {
            return;
        }
        super.drawableStateChanged();
        setSelectorEnabled(true);
        m2075m();
    }

    /* JADX WARN: Code restructure failed: missing block: B:7:0x000c, code lost:
        if (r0 != 3) goto L7;
     */
    /* JADX WARN: Removed duplicated region for block: B:22:0x0048 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:25:0x004f  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x0065  */
    /* renamed from: e */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean mo1847e(MotionEvent motionEvent, int i) {
        boolean z;
        boolean z2;
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 1) {
            z = false;
        } else if (actionMasked == 2) {
            z = true;
        }
        int findPointerIndex = motionEvent.findPointerIndex(i);
        if (findPointerIndex >= 0) {
            int x = (int) motionEvent.getX(findPointerIndex);
            int y = (int) motionEvent.getY(findPointerIndex);
            int pointToPosition = pointToPosition(x, y);
            if (pointToPosition != -1) {
                View childAt = getChildAt(pointToPosition - getFirstVisiblePosition());
                m2079i(childAt, pointToPosition, x, y);
                if (actionMasked == 1) {
                    m2084b(childAt, pointToPosition);
                }
                z2 = false;
                z = true;
                if (z) {
                }
                m2085a();
                if (z) {
                }
                return z;
            }
            z2 = true;
            if (z || z2) {
                m2085a();
            }
            if (z) {
                if (this.f2747o == null) {
                    this.f2747o = new C1332t(this);
                }
                this.f2747o.m1733m(true);
                this.f2747o.onTouch(this, motionEvent);
            } else {
                C1332t c1332t = this.f2747o;
                if (c1332t != null) {
                    c1332t.m1733m(false);
                }
            }
            return z;
        }
        z2 = false;
        z = false;
        if (z) {
        }
        m2085a();
        if (z) {
        }
        return z;
    }

    /* renamed from: f */
    public final void m2082f(int i, View view) {
        Rect rect = this.f2736d;
        rect.set(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
        rect.left -= this.f2737e;
        rect.top -= this.f2738f;
        rect.right += this.f2739g;
        rect.bottom += this.f2740h;
        boolean m2078j = m2078j();
        if (view.isEnabled() != m2078j) {
            m2077k(!m2078j);
            if (i != -1) {
                refreshDrawableState();
            }
        }
    }

    /* renamed from: g */
    public final void m2081g(int i, View view) {
        Drawable selector = getSelector();
        boolean z = (selector == null || i == -1) ? false : true;
        if (z) {
            selector.setVisible(false, false);
        }
        m2082f(i, view);
        if (z) {
            Rect rect = this.f2736d;
            float exactCenterX = rect.exactCenterX();
            float exactCenterY = rect.exactCenterY();
            selector.setVisible(getVisibility() == 0, false);
            C0012f.m5089j(selector, exactCenterX, exactCenterY);
        }
    }

    /* renamed from: h */
    public final void m2080h(int i, View view, float f, float f2) {
        m2081g(i, view);
        Drawable selector = getSelector();
        if (selector == null || i == -1) {
            return;
        }
        C0012f.m5089j(selector, f, f2);
    }

    @Override // android.view.ViewGroup, android.view.View
    public boolean hasFocus() {
        return this.f2744l || super.hasFocus();
    }

    @Override // android.view.View
    public boolean hasWindowFocus() {
        return this.f2744l || super.hasWindowFocus();
    }

    /* renamed from: i */
    public final void m2079i(View view, int i, float f, float f2) {
        View childAt;
        this.f2745m = true;
        int i2 = Build.VERSION.SDK_INT;
        if (i2 >= 21) {
            C1128a.m2074a(this, f, f2);
        }
        if (!isPressed()) {
            setPressed(true);
        }
        layoutChildren();
        int i3 = this.f2741i;
        if (i3 != -1 && (childAt = getChildAt(i3 - getFirstVisiblePosition())) != null && childAt != view && childAt.isPressed()) {
            childAt.setPressed(false);
        }
        this.f2741i = i;
        float left = f - view.getLeft();
        float top = f2 - view.getTop();
        if (i2 >= 21) {
            C1128a.m2074a(view, left, top);
        }
        if (!view.isPressed()) {
            view.setPressed(true);
        }
        m2080h(i, view, f, f2);
        setSelectorEnabled(false);
        refreshDrawableState();
    }

    @Override // android.view.View
    public boolean isFocused() {
        return this.f2744l || super.isFocused();
    }

    @Override // android.view.View
    public boolean isInTouchMode() {
        return (this.f2744l && this.f2743k) || super.isInTouchMode();
    }

    /* renamed from: j */
    public final boolean m2078j() {
        return C0598a.m3289c() ? C1130c.m2071a(this) : C1132e.m2068a(this);
    }

    /* renamed from: k */
    public final void m2077k(boolean z) {
        if (C0598a.m3289c()) {
            C1130c.m2070b(this, z);
        } else {
            C1132e.m2067b(this, z);
        }
    }

    /* renamed from: l */
    public final boolean m2076l() {
        return this.f2745m;
    }

    /* renamed from: m */
    public final void m2075m() {
        Drawable selector = getSelector();
        if (selector != null && m2076l() && isPressed()) {
            selector.setState(getDrawableState());
        }
    }

    @Override // android.widget.ListView, android.widget.AbsListView, android.widget.AdapterView, android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        this.f2748p = null;
        super.onDetachedFromWindow();
    }

    @Override // android.view.View
    public boolean onHoverEvent(MotionEvent motionEvent) {
        int i = Build.VERSION.SDK_INT;
        if (i < 26) {
            return super.onHoverEvent(motionEvent);
        }
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 10 && this.f2748p == null) {
            RunnableC1133f runnableC1133f = new RunnableC1133f();
            this.f2748p = runnableC1133f;
            runnableC1133f.m2065b();
        }
        boolean onHoverEvent = super.onHoverEvent(motionEvent);
        if (actionMasked == 9 || actionMasked == 7) {
            int pointToPosition = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
            if (pointToPosition != -1 && pointToPosition != getSelectedItemPosition()) {
                View childAt = getChildAt(pointToPosition - getFirstVisiblePosition());
                if (childAt.isEnabled()) {
                    requestFocus();
                    if (i < 30 || !C1129b.m2073a()) {
                        setSelectionFromTop(pointToPosition, childAt.getTop() - getTop());
                    } else {
                        C1129b.m2072b(this, pointToPosition, childAt);
                    }
                }
                m2075m();
            }
        } else {
            setSelection(-1);
        }
        return onHoverEvent;
    }

    @Override // android.widget.AbsListView, android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0) {
            this.f2741i = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
        }
        RunnableC1133f runnableC1133f = this.f2748p;
        if (runnableC1133f != null) {
            runnableC1133f.m2066a();
        }
        return super.onTouchEvent(motionEvent);
    }

    public void setListSelectionHidden(boolean z) {
        this.f2743k = z;
    }

    @Override // android.widget.AbsListView
    public void setSelector(Drawable drawable) {
        C1131d c1131d = drawable != null ? new C1131d(drawable) : null;
        this.f2742j = c1131d;
        super.setSelector(c1131d);
        Rect rect = new Rect();
        if (drawable != null) {
            drawable.getPadding(rect);
        }
        this.f2737e = rect.left;
        this.f2738f = rect.top;
        this.f2739g = rect.right;
        this.f2740h = rect.bottom;
    }
}