package n;

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.ListAdapter;
import android.widget.ListView;
import com.martsnew.tv.R;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

/* JADX INFO: loaded from: classes.dex */
public abstract class Y extends ListView {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public P.d f14805A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public M4.k f14806B;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final Rect f14807q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public int f14808r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public int f14809s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public int f14810t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public int f14811u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public int f14812v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public W f14813w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public boolean f14814x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final boolean f14815y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public boolean f14816z;

    public Y(Context context, boolean z8) {
        super(context, null, R.attr.dropDownListViewStyle);
        this.f14807q = new Rect();
        this.f14808r = 0;
        this.f14809s = 0;
        this.f14810t = 0;
        this.f14811u = 0;
        this.f14815y = z8;
        setCacheColorHint(0);
    }

    public final int a(int i, int i5) {
        int listPaddingTop = getListPaddingTop();
        int listPaddingBottom = getListPaddingBottom();
        int dividerHeight = getDividerHeight();
        Drawable divider = getDivider();
        ListAdapter adapter = getAdapter();
        if (adapter == null) {
            return listPaddingTop + listPaddingBottom;
        }
        int measuredHeight = listPaddingTop + listPaddingBottom;
        if (dividerHeight <= 0 || divider == null) {
            dividerHeight = 0;
        }
        int count = adapter.getCount();
        int i8 = 0;
        View view = null;
        for (int i9 = 0; i9 < count; i9++) {
            int itemViewType = adapter.getItemViewType(i9);
            if (itemViewType != i8) {
                view = null;
                i8 = itemViewType;
            }
            view = adapter.getView(i9, 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 (i9 > 0) {
                measuredHeight += dividerHeight;
            }
            measuredHeight += view.getMeasuredHeight();
            if (measuredHeight >= i5) {
                return i5;
            }
        }
        return measuredHeight;
    }

    /* JADX WARN: Removed duplicated region for block: B:81:0x014c  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x0161  */
    /* JADX WARN: Removed duplicated region for block: B:85:0x0166  */
    /* JADX WARN: Removed duplicated region for block: B:89:0x017c  */
    /* JADX WARN: Removed duplicated region for block: B:9:0x0016  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean b(MotionEvent motionEvent, int i) {
        boolean z8;
        boolean zA;
        View childAt;
        View childAt2;
        int actionMasked = motionEvent.getActionMasked();
        boolean z9 = true;
        if (actionMasked == 1) {
            z8 = false;
        } else {
            if (actionMasked != 2) {
                if (actionMasked != 3) {
                    z8 = true;
                    z9 = false;
                } else {
                    z8 = false;
                    z9 = false;
                }
                if (z8 || z9) {
                    this.f14816z = false;
                    setPressed(false);
                    drawableStateChanged();
                    childAt2 = getChildAt(this.f14812v - getFirstVisiblePosition());
                    if (childAt2 != null) {
                        childAt2.setPressed(false);
                    }
                }
                if (z8) {
                    P.d dVar = this.f14805A;
                    if (dVar != null) {
                        if (dVar.f5232F) {
                            dVar.d();
                        }
                        dVar.f5232F = false;
                    }
                } else {
                    if (this.f14805A == null) {
                        this.f14805A = new P.d(this);
                    }
                    P.d dVar2 = this.f14805A;
                    boolean z10 = dVar2.f5232F;
                    dVar2.f5232F = true;
                    dVar2.onTouch(this, motionEvent);
                }
                return z8;
            }
            z8 = true;
        }
        int iFindPointerIndex = motionEvent.findPointerIndex(i);
        if (iFindPointerIndex >= 0) {
            int x8 = (int) motionEvent.getX(iFindPointerIndex);
            int y8 = (int) motionEvent.getY(iFindPointerIndex);
            int iPointToPosition = pointToPosition(x8, y8);
            if (iPointToPosition != -1) {
                View childAt3 = getChildAt(iPointToPosition - getFirstVisiblePosition());
                float f3 = x8;
                float f7 = y8;
                this.f14816z = true;
                T.a(this, f3, f7);
                if (!isPressed()) {
                    setPressed(true);
                }
                layoutChildren();
                int i5 = this.f14812v;
                if (i5 != -1 && (childAt = getChildAt(i5 - getFirstVisiblePosition())) != null && childAt != childAt3 && childAt.isPressed()) {
                    childAt.setPressed(false);
                }
                this.f14812v = iPointToPosition;
                T.a(childAt3, f3 - childAt3.getLeft(), f7 - childAt3.getTop());
                if (!childAt3.isPressed()) {
                    childAt3.setPressed(true);
                }
                Drawable selector = getSelector();
                boolean z11 = (selector == null || iPointToPosition == -1) ? false : true;
                if (z11) {
                    selector.setVisible(false, false);
                }
                int left = childAt3.getLeft();
                int top = childAt3.getTop();
                int right = childAt3.getRight();
                int bottom = childAt3.getBottom();
                Rect rect = this.f14807q;
                rect.set(left, top, right, bottom);
                rect.left -= this.f14808r;
                rect.top -= this.f14809s;
                rect.right += this.f14810t;
                rect.bottom += this.f14811u;
                if (I.a.a()) {
                    zA = V.a(this);
                } else {
                    Field field = X.f14803a;
                    if (field != null) {
                        try {
                            zA = field.getBoolean(this);
                        } catch (IllegalAccessException e8) {
                            e8.printStackTrace();
                            zA = false;
                        }
                    } else {
                        zA = false;
                    }
                }
                if (childAt3.isEnabled() != zA) {
                    boolean z12 = !zA;
                    if (I.a.a()) {
                        V.b(this, z12);
                    } else {
                        Field field2 = X.f14803a;
                        if (field2 != null) {
                            try {
                                field2.set(this, Boolean.valueOf(z12));
                            } catch (IllegalAccessException e9) {
                                e9.printStackTrace();
                            }
                        }
                    }
                    if (iPointToPosition != -1) {
                        refreshDrawableState();
                    }
                }
                if (z11) {
                    float fExactCenterX = rect.exactCenterX();
                    float fExactCenterY = rect.exactCenterY();
                    selector.setVisible(getVisibility() == 0, false);
                    selector.setHotspot(fExactCenterX, fExactCenterY);
                }
                Drawable selector2 = getSelector();
                if (selector2 != null && iPointToPosition != -1) {
                    selector2.setHotspot(f3, f7);
                }
                W w4 = this.f14813w;
                if (w4 != null) {
                    w4.f14802r = false;
                }
                refreshDrawableState();
                if (actionMasked == 1) {
                    performItemClick(childAt3, iPointToPosition, getItemIdAtPosition(iPointToPosition));
                }
                z9 = false;
                z8 = true;
            }
        }
        if (z8) {
            this.f14816z = false;
            setPressed(false);
            drawableStateChanged();
            childAt2 = getChildAt(this.f14812v - getFirstVisiblePosition());
            if (childAt2 != null) {
            }
        }
        if (z8) {
        }
        return z8;
    }

    @Override // android.widget.ListView, android.widget.AbsListView, android.view.ViewGroup, android.view.View
    public final void dispatchDraw(Canvas canvas) {
        Drawable selector;
        Rect rect = this.f14807q;
        if (!rect.isEmpty() && (selector = getSelector()) != null) {
            selector.setBounds(rect);
            selector.draw(canvas);
        }
        super.dispatchDraw(canvas);
    }

    @Override // android.widget.AbsListView, android.view.ViewGroup, android.view.View
    public final void drawableStateChanged() {
        if (this.f14806B != null) {
            return;
        }
        super.drawableStateChanged();
        W w4 = this.f14813w;
        if (w4 != null) {
            w4.f14802r = true;
        }
        Drawable selector = getSelector();
        if (selector != null && this.f14816z && isPressed()) {
            selector.setState(getDrawableState());
        }
    }

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

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

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

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

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

    @Override // android.view.View
    public boolean onHoverEvent(MotionEvent motionEvent) {
        int i = Build.VERSION.SDK_INT;
        int i5 = 26;
        if (i < 26) {
            return super.onHoverEvent(motionEvent);
        }
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 10 && this.f14806B == null) {
            M4.k kVar = new M4.k(i5, this);
            this.f14806B = kVar;
            post(kVar);
        }
        boolean zOnHoverEvent = super.onHoverEvent(motionEvent);
        if (actionMasked != 9 && actionMasked != 7) {
            setSelection(-1);
            return zOnHoverEvent;
        }
        int iPointToPosition = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
        if (iPointToPosition != -1 && iPointToPosition != getSelectedItemPosition()) {
            View childAt = getChildAt(iPointToPosition - getFirstVisiblePosition());
            if (childAt.isEnabled()) {
                requestFocus();
                if (i < 30 || !U.f14792d) {
                    setSelectionFromTop(iPointToPosition, childAt.getTop() - getTop());
                } else {
                    try {
                        U.f14789a.invoke(this, Integer.valueOf(iPointToPosition), childAt, Boolean.FALSE, -1, -1);
                        U.f14790b.invoke(this, Integer.valueOf(iPointToPosition));
                        U.f14791c.invoke(this, Integer.valueOf(iPointToPosition));
                    } catch (IllegalAccessException e8) {
                        e8.printStackTrace();
                    } catch (InvocationTargetException e9) {
                        e9.printStackTrace();
                    }
                }
            }
            Drawable selector = getSelector();
            if (selector != null && this.f14816z && isPressed()) {
                selector.setState(getDrawableState());
            }
        }
        return zOnHoverEvent;
    }

    @Override // android.widget.AbsListView, android.view.View
    public final boolean onTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0) {
            this.f14812v = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
        }
        M4.k kVar = this.f14806B;
        if (kVar != null) {
            Y y8 = (Y) kVar.f4260r;
            y8.f14806B = null;
            y8.removeCallbacks(kVar);
        }
        return super.onTouchEvent(motionEvent);
    }

    public void setListSelectionHidden(boolean z8) {
        this.f14814x = z8;
    }

    @Override // android.widget.AbsListView
    public void setSelector(Drawable drawable) {
        W w4 = null;
        if (drawable != null) {
            W w6 = new W();
            Drawable drawable2 = w6.f14801q;
            if (drawable2 != null) {
                drawable2.setCallback(null);
            }
            w6.f14801q = drawable;
            drawable.setCallback(w6);
            w6.f14802r = true;
            w4 = w6;
        }
        this.f14813w = w4;
        super.setSelector(w4);
        Rect rect = new Rect();
        if (drawable != null) {
            drawable.getPadding(rect);
        }
        this.f14808r = rect.left;
        this.f14809s = rect.top;
        this.f14810t = rect.right;
        this.f14811u = rect.bottom;
    }
}
