package ῲ.ῲ.㴹;

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.ListAdapter;
import android.widget.ListView;
import androidx.appcompat.R$attr;
import java.lang.reflect.Field;
import ῲ.ᨨ.ᨨ.C1768;
import ῲ.ᨨ.㳳.C1833;
import ῲ.ῲ.ʬ.K.C1872;

/* renamed from: ῲ.ῲ.㴹.㗽  reason: contains not printable characters */
/* compiled from: DropDownListView */
public class C2035 extends ListView {

    /* renamed from: ʬ  reason: contains not printable characters */
    public int f6889 = 0;

    /* renamed from: Ԕ  reason: contains not printable characters */
    public C1833 f6890;

    /* renamed from: ඓ  reason: contains not printable characters */
    public int f6891 = 0;

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

    /* renamed from: ᨨ  reason: contains not printable characters */
    public C2037 f6893;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final Rect f6894 = new Rect();

    /* renamed from: ⁱ  reason: contains not printable characters */
    public int f6895;

    /* renamed from: 㑃  reason: contains not printable characters */
    public boolean f6896;

    /* renamed from: 㗗  reason: contains not printable characters */
    public RunnableC2036 f6897;

    /* renamed from: 㳳  reason: contains not printable characters */
    public boolean f6898;

    /* renamed from: 㴹  reason: contains not printable characters */
    public int f6899 = 0;

    /* renamed from: 㸾  reason: contains not printable characters */
    public int f6900 = 0;

    /* renamed from: 㿎  reason: contains not printable characters */
    public Field f6901;

    /* renamed from: 䁗  reason: contains not printable characters */
    public C1768 f6902;

    /* renamed from: ῲ.ῲ.㴹.㗽$ῲ  reason: contains not printable characters */
    /* compiled from: DropDownListView */
    public class RunnableC2036 implements Runnable {
        public RunnableC2036() {
        }

        public void run() {
            C2035 r0 = C2035.this;
            r0.f6897 = null;
            r0.drawableStateChanged();
        }
    }

    /* renamed from: ῲ.ῲ.㴹.㗽$K  reason: contains not printable characters */
    /* compiled from: DropDownListView */
    public static class C2037 extends C1872 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public boolean f6904 = true;

        public C2037(Drawable drawable) {
            super(drawable);
        }

        @Override // ῲ.ῲ.ʬ.K.C1872
        public void draw(Canvas canvas) {
            if (this.f6904) {
                super.draw(canvas);
            }
        }

        @Override // ῲ.ῲ.ʬ.K.C1872
        public void setHotspot(float f, float f2) {
            if (this.f6904) {
                super.setHotspot(f, f2);
            }
        }

        @Override // ῲ.ῲ.ʬ.K.C1872
        public void setHotspotBounds(int i, int i2, int i3, int i4) {
            if (this.f6904) {
                super.setHotspotBounds(i, i2, i3, i4);
            }
        }

        @Override // ῲ.ῲ.ʬ.K.C1872
        public boolean setState(int[] iArr) {
            if (this.f6904) {
                return super.setState(iArr);
            }
            return false;
        }

        @Override // ῲ.ῲ.ʬ.K.C1872
        public boolean setVisible(boolean z, boolean z2) {
            if (this.f6904) {
                return super.setVisible(z, z2);
            }
            return false;
        }
    }

    public C2035(Context context, boolean z) {
        super(context, null, R$attr.dropDownListViewStyle);
        this.f6892 = z;
        setCacheColorHint(0);
        try {
            this.f6901 = AbsListView.class.getDeclaredField("mIsChildViewEnabled");
            this.f6901.setAccessible(true);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }

    private void setSelectorEnabled(boolean z) {
        C2037 k = this.f6893;
        if (k != null) {
            k.f6904 = z;
        }
    }

    public void dispatchDraw(Canvas canvas) {
        Drawable selector;
        if (!this.f6894.isEmpty() && (selector = getSelector()) != null) {
            selector.setBounds(this.f6894);
            selector.draw(canvas);
        }
        super.dispatchDraw(canvas);
    }

    public void drawableStateChanged() {
        if (this.f6897 == null) {
            super.drawableStateChanged();
            setSelectorEnabled(true);
            m5277();
        }
    }

    public boolean hasFocus() {
        return this.f6892 || super.hasFocus();
    }

    public boolean hasWindowFocus() {
        return this.f6892 || super.hasWindowFocus();
    }

    public boolean isFocused() {
        return this.f6892 || super.isFocused();
    }

    public boolean isInTouchMode() {
        return (this.f6892 && this.f6898) || super.isInTouchMode();
    }

    public void onDetachedFromWindow() {
        this.f6897 = null;
        super.onDetachedFromWindow();
    }

    public boolean onHoverEvent(MotionEvent motionEvent) {
        if (Build.VERSION.SDK_INT < 26) {
            return super.onHoverEvent(motionEvent);
        }
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 10 && this.f6897 == null) {
            this.f6897 = new RunnableC2036();
            RunnableC2036 r1 = this.f6897;
            C2035.this.post(r1);
        }
        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()) {
                    setSelectionFromTop(pointToPosition, childAt.getTop() - getTop());
                }
                m5277();
            }
        } else {
            setSelection(-1);
        }
        return onHoverEvent;
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0) {
            this.f6895 = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
        }
        RunnableC2036 r0 = this.f6897;
        if (r0 != null) {
            C2035 r1 = C2035.this;
            r1.f6897 = null;
            r1.removeCallbacks(r0);
        }
        return super.onTouchEvent(motionEvent);
    }

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

    @Override // android.widget.AbsListView
    public void setSelector(Drawable drawable) {
        this.f6893 = drawable != null ? new C2037(drawable) : null;
        super.setSelector(this.f6893);
        Rect rect = new Rect();
        if (drawable != null) {
            drawable.getPadding(rect);
        }
        this.f6889 = rect.left;
        this.f6900 = rect.top;
        this.f6891 = rect.right;
        this.f6899 = rect.bottom;
    }

    /* renamed from: K  reason: contains not printable characters */
    public int m5276(int i, int i2, int i3) {
        int i4;
        int listPaddingTop = getListPaddingTop();
        int listPaddingBottom = getListPaddingBottom();
        int dividerHeight = getDividerHeight();
        Drawable divider = getDivider();
        ListAdapter adapter = getAdapter();
        if (adapter == null) {
            return listPaddingTop + listPaddingBottom;
        }
        int i5 = listPaddingTop + listPaddingBottom;
        if (dividerHeight <= 0 || divider == null) {
            dividerHeight = 0;
        }
        int count = adapter.getCount();
        int i6 = i5;
        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;
            if (i10 > 0) {
                i4 = View.MeasureSpec.makeMeasureSpec(i10, 1073741824);
            } else {
                i4 = View.MeasureSpec.makeMeasureSpec(0, 0);
            }
            view.measure(i, i4);
            view.forceLayout();
            if (i7 > 0) {
                i6 += dividerHeight;
            }
            i6 += view.getMeasuredHeight();
            if (i6 >= i2) {
                return (i3 < 0 || i7 <= i3 || i9 <= 0 || i6 == i2) ? i2 : i9;
            }
            if (i3 >= 0 && i7 >= i3) {
                i9 = i6;
            }
            i7++;
        }
        return i6;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:5:0x0010, code lost:
        if (r3 != 3) goto L_0x0129;
     */
    /* JADX WARNING: Removed duplicated region for block: B:66:0x0144  */
    /* JADX WARNING: Removed duplicated region for block: B:69:0x014b  */
    /* JADX WARNING: Removed duplicated region for block: B:71:0x0153  */
    /* JADX WARNING: Removed duplicated region for block: B:75:0x016a  */
    /* renamed from: K  reason: contains not printable characters */
    public boolean m5278(MotionEvent motionEvent, int i) {
        boolean z;
        View childAt;
        C1768 r3;
        View childAt2;
        int actionMasked = motionEvent.getActionMasked();
        boolean z2 = true;
        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 childAt3 = getChildAt(pointToPosition - getFirstVisiblePosition());
                float f = (float) x;
                float f2 = (float) y;
                this.f6896 = true;
                int i2 = Build.VERSION.SDK_INT;
                drawableHotspotChanged(f, f2);
                if (!isPressed()) {
                    setPressed(true);
                }
                layoutChildren();
                int i3 = this.f6895;
                if (!(i3 == -1 || (childAt2 = getChildAt(i3 - getFirstVisiblePosition())) == null || childAt2 == childAt3 || !childAt2.isPressed())) {
                    childAt2.setPressed(false);
                }
                this.f6895 = pointToPosition;
                int i4 = Build.VERSION.SDK_INT;
                childAt3.drawableHotspotChanged(f - ((float) childAt3.getLeft()), f2 - ((float) childAt3.getTop()));
                if (!childAt3.isPressed()) {
                    childAt3.setPressed(true);
                }
                Drawable selector = getSelector();
                boolean z3 = (selector == null || pointToPosition == -1) ? false : true;
                if (z3) {
                    selector.setVisible(false, false);
                }
                Rect rect = this.f6894;
                rect.set(childAt3.getLeft(), childAt3.getTop(), childAt3.getRight(), childAt3.getBottom());
                rect.left -= this.f6889;
                rect.top -= this.f6900;
                rect.right += this.f6891;
                rect.bottom += this.f6899;
                try {
                    boolean z4 = this.f6901.getBoolean(this);
                    if (childAt3.isEnabled() != z4) {
                        this.f6901.set(this, Boolean.valueOf(!z4));
                        if (pointToPosition != -1) {
                            refreshDrawableState();
                        }
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                if (z3) {
                    Rect rect2 = this.f6894;
                    float exactCenterX = rect2.exactCenterX();
                    float exactCenterY = rect2.exactCenterY();
                    selector.setVisible(getVisibility() == 0, false);
                    int i5 = Build.VERSION.SDK_INT;
                    selector.setHotspot(exactCenterX, exactCenterY);
                }
                Drawable selector2 = getSelector();
                if (!(selector2 == null || pointToPosition == -1)) {
                    int i6 = Build.VERSION.SDK_INT;
                    selector2.setHotspot(f, f2);
                }
                setSelectorEnabled(false);
                refreshDrawableState();
                if (actionMasked == 1) {
                    performItemClick(childAt3, pointToPosition, getItemIdAtPosition(pointToPosition));
                }
                z = true;
                z2 = false;
            }
            if (!z || z2) {
                this.f6896 = false;
                setPressed(false);
                drawableStateChanged();
                childAt = getChildAt(this.f6895 - getFirstVisiblePosition());
                if (childAt != null) {
                    childAt.setPressed(false);
                }
                r3 = this.f6902;
                if (r3 != null) {
                    r3.m4621();
                    this.f6902 = null;
                }
            }
            if (!z) {
                if (this.f6890 == null) {
                    this.f6890 = new C1833(this);
                }
                this.f6890.m4734(true);
                this.f6890.onTouch(this, motionEvent);
            } else {
                C1833 r2 = this.f6890;
                if (r2 != null) {
                    r2.m4734(false);
                }
            }
            return z;
        }
        z = false;
        z2 = false;
        this.f6896 = false;
        setPressed(false);
        drawableStateChanged();
        childAt = getChildAt(this.f6895 - getFirstVisiblePosition());
        if (childAt != null) {
        }
        r3 = this.f6902;
        if (r3 != null) {
        }
        if (!z) {
        }
        return z;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m5277() {
        Drawable selector = getSelector();
        if (selector != null && this.f6896 && isPressed()) {
            selector.setState(getDrawableState());
        }
    }
}
