package androidx.appcompat.widget;

import android.R;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.InputFilter;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.TransformationMethod;
import android.util.AttributeSet;
import android.view.ActionMode;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.CompoundButton;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.s1;
import androidx.emoji2.text.t;
import d.h;
import d.j;
import l.a1;
import l.f0;
import l.f4;
import l.j3;
import l.k3;
import l.l3;
import l.p1;
import l.p3;
import u0.p;

/* JADX INFO: loaded from: classes.dex */
public class SwitchCompat extends CompoundButton {

    /* JADX INFO: renamed from: v0, reason: collision with root package name */
    public static final j3 f762v0 = new j3(0, Float.class, "thumbPos");

    /* JADX INFO: renamed from: w0, reason: collision with root package name */
    public static final int[] f763w0 = {R.attr.state_checked};
    public boolean Q;
    public CharSequence R;
    public CharSequence S;
    public CharSequence T;
    public CharSequence U;
    public boolean V;
    public int W;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Drawable f764a;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public final int f765a0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public ColorStateList f766b;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public float f767b0;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public PorterDuff.Mode f768c;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public float f769c0;

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

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public final VelocityTracker f771d0;

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

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public final int f773e0;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Drawable f774f;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public float f775f0;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public ColorStateList f776g;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public PorterDuff.Mode f778h;

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

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

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

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

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

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

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

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

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

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

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

    @Nullable
    private k3 mEmojiCompatInitCallback;

    @Nullable
    private TransformationMethod mSwitchTransformationMethod;

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

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    public final TextPaint f791o0;

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    public ColorStateList f792p0;

    /* JADX INFO: renamed from: q0, reason: collision with root package name */
    public StaticLayout f793q0;

    /* JADX INFO: renamed from: r0, reason: collision with root package name */
    public StaticLayout f794r0;

    /* JADX INFO: renamed from: s0, reason: collision with root package name */
    public ObjectAnimator f795s0;

    /* JADX INFO: renamed from: t0, reason: collision with root package name */
    public f0 f796t0;

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

    public SwitchCompat(@NonNull Context context) {
        this(context, null);
    }

    @Nullable
    private CharSequence doTransformForOnOffText(@Nullable CharSequence charSequence) {
        TransformationMethod transformationMethodWrapTransformationMethod = getEmojiTextViewHelper().wrapTransformationMethod(this.mSwitchTransformationMethod);
        return transformationMethodWrapTransformationMethod != null ? transformationMethodWrapTransformationMethod.getTransformation(charSequence, this) : charSequence;
    }

    @NonNull
    private f0 getEmojiTextViewHelper() {
        if (this.f796t0 == null) {
            this.f796t0 = new f0(this);
        }
        return this.f796t0;
    }

    private boolean getTargetCheckedState() {
        return this.f775f0 > 0.5f;
    }

    private int getThumbOffset() {
        boolean z10 = f4.f29682a;
        return (int) (((getLayoutDirection() == 1 ? 1.0f - this.f775f0 : this.f775f0) * getThumbScrollRange()) + 0.5f);
    }

    private int getThumbScrollRange() {
        Drawable drawable = this.f774f;
        if (drawable == null) {
            return 0;
        }
        Rect rect = this.f797u0;
        drawable.getPadding(rect);
        Drawable drawable2 = this.f764a;
        Rect rectB = drawable2 != null ? p1.b(drawable2) : p1.f29807c;
        return ((((this.f777g0 - this.f781i0) - rect.left) - rect.right) - rectB.left) - rectB.right;
    }

    private void setTextOffInternal(CharSequence charSequence) {
        this.T = charSequence;
        this.U = doTransformForOnOffText(charSequence);
        this.f794r0 = null;
        if (this.V) {
            d();
        }
    }

    private void setTextOnInternal(CharSequence charSequence) {
        this.R = charSequence;
        this.S = doTransformForOnOffText(charSequence);
        this.f793q0 = null;
        if (this.V) {
            d();
        }
    }

    public final void a() {
        Drawable drawable = this.f764a;
        if (drawable != null) {
            if (this.f770d || this.f772e) {
                Drawable drawableMutate = drawable.mutate();
                this.f764a = drawableMutate;
                if (this.f770d) {
                    k0.a.setTintList(drawableMutate, this.f766b);
                }
                if (this.f772e) {
                    k0.a.setTintMode(this.f764a, this.f768c);
                }
                if (this.f764a.isStateful()) {
                    this.f764a.setState(getDrawableState());
                }
            }
        }
    }

    public final void b() {
        Drawable drawable = this.f774f;
        if (drawable != null) {
            if (this.f780i || this.f782j) {
                Drawable drawableMutate = drawable.mutate();
                this.f774f = drawableMutate;
                if (this.f780i) {
                    k0.a.setTintList(drawableMutate, this.f776g);
                }
                if (this.f782j) {
                    k0.a.setTintMode(this.f774f, this.f778h);
                }
                if (this.f774f.isStateful()) {
                    this.f774f.setState(getDrawableState());
                }
            }
        }
    }

    public final void c() {
        setTextOnInternal(this.R);
        setTextOffInternal(this.T);
        requestLayout();
    }

    public final void d() {
        if (this.mEmojiCompatInitCallback == null && this.f796t0.f29679b.f26148a.b() && t.d()) {
            t tVarA = t.a();
            int iB = tVarA.b();
            if (iB == 3 || iB == 0) {
                k3 k3Var = new k3(this);
                this.mEmojiCompatInitCallback = k3Var;
                tVarA.g(k3Var);
            }
        }
    }

    @Override // android.view.View
    public final void draw(Canvas canvas) {
        int i10;
        int i11;
        int i12 = this.f783j0;
        int i13 = this.f785k0;
        int i14 = this.f787l0;
        int i15 = this.f789m0;
        int thumbOffset = getThumbOffset() + i12;
        Drawable drawable = this.f764a;
        Rect rectB = drawable != null ? p1.b(drawable) : p1.f29807c;
        Drawable drawable2 = this.f774f;
        Rect rect = this.f797u0;
        if (drawable2 != null) {
            drawable2.getPadding(rect);
            int i16 = rect.left;
            thumbOffset += i16;
            if (rectB != null) {
                int i17 = rectB.left;
                if (i17 > i16) {
                    i12 += i17 - i16;
                }
                int i18 = rectB.top;
                int i19 = rect.top;
                i10 = i18 > i19 ? (i18 - i19) + i13 : i13;
                int i20 = rectB.right;
                int i21 = rect.right;
                if (i20 > i21) {
                    i14 -= i20 - i21;
                }
                int i22 = rectB.bottom;
                int i23 = rect.bottom;
                if (i22 > i23) {
                    i11 = i15 - (i22 - i23);
                }
                this.f774f.setBounds(i12, i10, i14, i11);
            } else {
                i10 = i13;
            }
            i11 = i15;
            this.f774f.setBounds(i12, i10, i14, i11);
        }
        Drawable drawable3 = this.f764a;
        if (drawable3 != null) {
            drawable3.getPadding(rect);
            int i24 = thumbOffset - rect.left;
            int i25 = thumbOffset + this.f781i0 + rect.right;
            this.f764a.setBounds(i24, i13, i25, i15);
            Drawable background = getBackground();
            if (background != null) {
                background.setHotspotBounds(i24, i13, i25, i15);
            }
        }
        super.draw(canvas);
    }

    @Override // android.widget.CompoundButton, android.widget.TextView, android.view.View
    public final void drawableHotspotChanged(float f10, float f11) {
        super.drawableHotspotChanged(f10, f11);
        Drawable drawable = this.f764a;
        if (drawable != null) {
            drawable.setHotspot(f10, f11);
        }
        Drawable drawable2 = this.f774f;
        if (drawable2 != null) {
            drawable2.setHotspot(f10, f11);
        }
    }

    @Override // android.widget.CompoundButton, android.widget.TextView, android.view.View
    public final void drawableStateChanged() {
        super.drawableStateChanged();
        int[] drawableState = getDrawableState();
        Drawable drawable = this.f764a;
        boolean state = (drawable == null || !drawable.isStateful()) ? false : drawable.setState(drawableState);
        Drawable drawable2 = this.f774f;
        if (drawable2 != null && drawable2.isStateful()) {
            state |= drawable2.setState(drawableState);
        }
        if (state) {
            invalidate();
        }
    }

    @Override // android.widget.CompoundButton, android.widget.TextView
    public int getCompoundPaddingLeft() {
        boolean z10 = f4.f29682a;
        if (getLayoutDirection() != 1) {
            return super.getCompoundPaddingLeft();
        }
        int compoundPaddingLeft = super.getCompoundPaddingLeft() + this.f777g0;
        return !TextUtils.isEmpty(getText()) ? compoundPaddingLeft + this.f788m : compoundPaddingLeft;
    }

    @Override // android.widget.CompoundButton, android.widget.TextView
    public int getCompoundPaddingRight() {
        boolean z10 = f4.f29682a;
        if (getLayoutDirection() == 1) {
            return super.getCompoundPaddingRight();
        }
        int compoundPaddingRight = super.getCompoundPaddingRight() + this.f777g0;
        return !TextUtils.isEmpty(getText()) ? compoundPaddingRight + this.f788m : compoundPaddingRight;
    }

    @Override // android.widget.TextView
    @Nullable
    public ActionMode.Callback getCustomSelectionActionModeCallback() {
        return p.unwrapCustomSelectionActionModeCallback(super.getCustomSelectionActionModeCallback());
    }

    public boolean getShowText() {
        return this.V;
    }

    public boolean getSplitTrack() {
        return this.Q;
    }

    public int getSwitchMinWidth() {
        return this.f786l;
    }

    public int getSwitchPadding() {
        return this.f788m;
    }

    public CharSequence getTextOff() {
        return this.T;
    }

    public CharSequence getTextOn() {
        return this.R;
    }

    public Drawable getThumbDrawable() {
        return this.f764a;
    }

    @FloatRange(from = 0.0d, to = 1.0d)
    public final float getThumbPosition() {
        return this.f775f0;
    }

    public int getThumbTextPadding() {
        return this.f784k;
    }

    @Nullable
    public ColorStateList getThumbTintList() {
        return this.f766b;
    }

    @Nullable
    public PorterDuff.Mode getThumbTintMode() {
        return this.f768c;
    }

    public Drawable getTrackDrawable() {
        return this.f774f;
    }

    @Nullable
    public ColorStateList getTrackTintList() {
        return this.f776g;
    }

    @Nullable
    public PorterDuff.Mode getTrackTintMode() {
        return this.f778h;
    }

    @Override // android.widget.CompoundButton, android.widget.TextView, android.view.View
    public final void jumpDrawablesToCurrentState() {
        super.jumpDrawablesToCurrentState();
        Drawable drawable = this.f764a;
        if (drawable != null) {
            drawable.jumpToCurrentState();
        }
        Drawable drawable2 = this.f774f;
        if (drawable2 != null) {
            drawable2.jumpToCurrentState();
        }
        ObjectAnimator objectAnimator = this.f795s0;
        if (objectAnimator == null || !objectAnimator.isStarted()) {
            return;
        }
        this.f795s0.end();
        this.f795s0 = null;
    }

    @Override // android.widget.CompoundButton, android.widget.TextView, android.view.View
    public int[] onCreateDrawableState(int i10) {
        int[] iArrOnCreateDrawableState = super.onCreateDrawableState(i10 + 1);
        if (isChecked()) {
            View.mergeDrawableStates(iArrOnCreateDrawableState, f763w0);
        }
        return iArrOnCreateDrawableState;
    }

    @Override // android.widget.CompoundButton, android.widget.TextView, android.view.View
    public final void onDraw(Canvas canvas) {
        int width;
        super.onDraw(canvas);
        Drawable drawable = this.f774f;
        Rect rect = this.f797u0;
        if (drawable != null) {
            drawable.getPadding(rect);
        } else {
            rect.setEmpty();
        }
        int i10 = this.f785k0;
        int i11 = this.f789m0;
        int i12 = i10 + rect.top;
        int i13 = i11 - rect.bottom;
        Drawable drawable2 = this.f764a;
        if (drawable != null) {
            if (!this.Q || drawable2 == null) {
                drawable.draw(canvas);
            } else {
                Rect rectB = p1.b(drawable2);
                drawable2.copyBounds(rect);
                rect.left += rectB.left;
                rect.right -= rectB.right;
                int iSave = canvas.save();
                canvas.clipRect(rect, Region.Op.DIFFERENCE);
                drawable.draw(canvas);
                canvas.restoreToCount(iSave);
            }
        }
        int iSave2 = canvas.save();
        if (drawable2 != null) {
            drawable2.draw(canvas);
        }
        StaticLayout staticLayout = getTargetCheckedState() ? this.f793q0 : this.f794r0;
        if (staticLayout != null) {
            int[] drawableState = getDrawableState();
            ColorStateList colorStateList = this.f792p0;
            TextPaint textPaint = this.f791o0;
            if (colorStateList != null) {
                textPaint.setColor(colorStateList.getColorForState(drawableState, 0));
            }
            textPaint.drawableState = drawableState;
            if (drawable2 != null) {
                Rect bounds = drawable2.getBounds();
                width = bounds.left + bounds.right;
            } else {
                width = getWidth();
            }
            canvas.translate((width / 2) - (staticLayout.getWidth() / 2), ((i12 + i13) / 2) - (staticLayout.getHeight() / 2));
            staticLayout.draw(canvas);
        }
        canvas.restoreToCount(iSave2);
    }

    @Override // android.view.View
    public final void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        super.onInitializeAccessibilityEvent(accessibilityEvent);
        accessibilityEvent.setClassName("android.widget.Switch");
    }

    @Override // android.view.View
    public final void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
        super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
        accessibilityNodeInfo.setClassName("android.widget.Switch");
        if (Build.VERSION.SDK_INT < 30) {
            CharSequence charSequence = isChecked() ? this.R : this.T;
            if (TextUtils.isEmpty(charSequence)) {
                return;
            }
            CharSequence text = accessibilityNodeInfo.getText();
            if (TextUtils.isEmpty(text)) {
                accessibilityNodeInfo.setText(charSequence);
                return;
            }
            StringBuilder sb = new StringBuilder();
            sb.append(text);
            sb.append(' ');
            sb.append(charSequence);
            accessibilityNodeInfo.setText(sb);
        }
    }

    @Override // android.widget.TextView, android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        int iMax;
        int width;
        int paddingLeft;
        int height;
        int paddingTop;
        super.onLayout(z10, i10, i11, i12, i13);
        int iMax2 = 0;
        if (this.f764a != null) {
            Drawable drawable = this.f774f;
            Rect rect = this.f797u0;
            if (drawable != null) {
                drawable.getPadding(rect);
            } else {
                rect.setEmpty();
            }
            Rect rectB = p1.b(this.f764a);
            iMax = Math.max(0, rectB.left - rect.left);
            iMax2 = Math.max(0, rectB.right - rect.right);
        } else {
            iMax = 0;
        }
        boolean z11 = f4.f29682a;
        if (getLayoutDirection() == 1) {
            paddingLeft = getPaddingLeft() + iMax;
            width = ((this.f777g0 + paddingLeft) - iMax) - iMax2;
        } else {
            width = (getWidth() - getPaddingRight()) - iMax2;
            paddingLeft = (width - this.f777g0) + iMax + iMax2;
        }
        int gravity = getGravity() & 112;
        if (gravity == 16) {
            int height2 = ((getHeight() + getPaddingTop()) - getPaddingBottom()) / 2;
            int i14 = this.f779h0;
            int i15 = height2 - (i14 / 2);
            height = i14 + i15;
            paddingTop = i15;
        } else if (gravity != 80) {
            paddingTop = getPaddingTop();
            height = this.f779h0 + paddingTop;
        } else {
            height = getHeight() - getPaddingBottom();
            paddingTop = height - this.f779h0;
        }
        this.f783j0 = paddingLeft;
        this.f785k0 = paddingTop;
        this.f789m0 = height;
        this.f787l0 = width;
    }

    @Override // android.widget.TextView, android.view.View
    public final void onMeasure(int i10, int i11) {
        int intrinsicWidth;
        int intrinsicHeight;
        int intrinsicHeight2 = 0;
        if (this.V) {
            StaticLayout staticLayout = this.f793q0;
            TextPaint textPaint = this.f791o0;
            if (staticLayout == null) {
                CharSequence charSequence = this.S;
                this.f793q0 = new StaticLayout(charSequence, textPaint, charSequence != null ? (int) Math.ceil(Layout.getDesiredWidth(charSequence, textPaint)) : 0, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
            }
            if (this.f794r0 == null) {
                CharSequence charSequence2 = this.U;
                this.f794r0 = new StaticLayout(charSequence2, textPaint, charSequence2 != null ? (int) Math.ceil(Layout.getDesiredWidth(charSequence2, textPaint)) : 0, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
            }
        }
        Drawable drawable = this.f764a;
        Rect rect = this.f797u0;
        if (drawable != null) {
            drawable.getPadding(rect);
            intrinsicWidth = (this.f764a.getIntrinsicWidth() - rect.left) - rect.right;
            intrinsicHeight = this.f764a.getIntrinsicHeight();
        } else {
            intrinsicWidth = 0;
            intrinsicHeight = 0;
        }
        this.f781i0 = Math.max(this.V ? (this.f784k * 2) + Math.max(this.f793q0.getWidth(), this.f794r0.getWidth()) : 0, intrinsicWidth);
        Drawable drawable2 = this.f774f;
        if (drawable2 != null) {
            drawable2.getPadding(rect);
            intrinsicHeight2 = this.f774f.getIntrinsicHeight();
        } else {
            rect.setEmpty();
        }
        int iMax = rect.left;
        int iMax2 = rect.right;
        Drawable drawable3 = this.f764a;
        if (drawable3 != null) {
            Rect rectB = p1.b(drawable3);
            iMax = Math.max(iMax, rectB.left);
            iMax2 = Math.max(iMax2, rectB.right);
        }
        int iMax3 = this.f790n0 ? Math.max(this.f786l, (this.f781i0 * 2) + iMax + iMax2) : this.f786l;
        int iMax4 = Math.max(intrinsicHeight2, intrinsicHeight);
        this.f777g0 = iMax3;
        this.f779h0 = iMax4;
        super.onMeasure(i10, i11);
        if (getMeasuredHeight() < iMax4) {
            setMeasuredDimension(getMeasuredWidthAndState(), iMax4);
        }
    }

    @Override // android.view.View
    public final void onPopulateAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        super.onPopulateAccessibilityEvent(accessibilityEvent);
        CharSequence charSequence = isChecked() ? this.R : this.T;
        if (charSequence != null) {
            accessibilityEvent.getText().add(charSequence);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:40:0x008f  */
    @Override // android.widget.TextView, android.view.View
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean onTouchEvent(MotionEvent motionEvent) {
        boolean targetCheckedState;
        VelocityTracker velocityTracker = this.f771d0;
        velocityTracker.addMovement(motionEvent);
        int actionMasked = motionEvent.getActionMasked();
        int i10 = this.f765a0;
        if (actionMasked != 0) {
            if (actionMasked == 1) {
                if (this.W == 2) {
                    this.W = 0;
                    boolean z10 = motionEvent.getAction() == 1 && isEnabled();
                    boolean zIsChecked = isChecked();
                    if (z10) {
                        velocityTracker.computeCurrentVelocity(1000);
                        float xVelocity = velocityTracker.getXVelocity();
                        if (Math.abs(xVelocity) > this.f773e0) {
                            boolean z11 = f4.f29682a;
                            targetCheckedState = getLayoutDirection() != 1 ? xVelocity > 0.0f : xVelocity < 0.0f;
                        } else {
                            targetCheckedState = getTargetCheckedState();
                        }
                    } else {
                        targetCheckedState = zIsChecked;
                    }
                    if (targetCheckedState != zIsChecked) {
                        playSoundEffect(0);
                    }
                    setChecked(targetCheckedState);
                    MotionEvent motionEventObtain = MotionEvent.obtain(motionEvent);
                    motionEventObtain.setAction(3);
                    super.onTouchEvent(motionEventObtain);
                    motionEventObtain.recycle();
                    super.onTouchEvent(motionEvent);
                    return true;
                }
                this.W = 0;
                velocityTracker.clear();
            } else if (actionMasked == 2) {
                int i11 = this.W;
                if (i11 == 1) {
                    float x10 = motionEvent.getX();
                    float y10 = motionEvent.getY();
                    if (Math.abs(x10 - this.f767b0) > i10 || Math.abs(y10 - this.f769c0) > i10) {
                        this.W = 2;
                        getParent().requestDisallowInterceptTouchEvent(true);
                        this.f767b0 = x10;
                        this.f769c0 = y10;
                        return true;
                    }
                } else if (i11 == 2) {
                    float x11 = motionEvent.getX();
                    int thumbScrollRange = getThumbScrollRange();
                    float f10 = x11 - this.f767b0;
                    float f11 = thumbScrollRange != 0 ? f10 / thumbScrollRange : f10 > 0.0f ? 1.0f : -1.0f;
                    boolean z12 = f4.f29682a;
                    if (getLayoutDirection() == 1) {
                        f11 = -f11;
                    }
                    float f12 = this.f775f0;
                    float f13 = f11 + f12;
                    float f14 = f13 >= 0.0f ? f13 > 1.0f ? 1.0f : f13 : 0.0f;
                    if (f14 != f12) {
                        this.f767b0 = x11;
                        setThumbPosition(f14);
                    }
                    return true;
                }
            } else if (actionMasked == 3) {
            }
        } else {
            float x12 = motionEvent.getX();
            float y11 = motionEvent.getY();
            if (isEnabled() && this.f764a != null) {
                int thumbOffset = getThumbOffset();
                Drawable drawable = this.f764a;
                Rect rect = this.f797u0;
                drawable.getPadding(rect);
                int i12 = this.f785k0 - i10;
                int i13 = (this.f783j0 + thumbOffset) - i10;
                int i14 = this.f781i0 + i13 + rect.left + rect.right + i10;
                int i15 = this.f789m0 + i10;
                if (x12 > i13 && x12 < i14 && y11 > i12 && y11 < i15) {
                    this.W = 1;
                    this.f767b0 = x12;
                    this.f769c0 = y11;
                }
            }
        }
        return super.onTouchEvent(motionEvent);
    }

    @Override // android.widget.TextView
    public void setAllCaps(boolean z10) {
        super.setAllCaps(z10);
        getEmojiTextViewHelper().b(z10);
    }

    @Override // android.widget.CompoundButton, android.widget.Checkable
    public void setChecked(boolean z10) {
        super.setChecked(z10);
        boolean zIsChecked = isChecked();
        if (zIsChecked) {
            if (Build.VERSION.SDK_INT >= 30) {
                CharSequence string = this.R;
                if (string == null) {
                    string = getResources().getString(h.abc_capital_on);
                }
                s1.setStateDescription(this, string);
            }
        } else if (Build.VERSION.SDK_INT >= 30) {
            CharSequence string2 = this.T;
            if (string2 == null) {
                string2 = getResources().getString(h.abc_capital_off);
            }
            s1.setStateDescription(this, string2);
        }
        if (getWindowToken() == null || !isLaidOut()) {
            ObjectAnimator objectAnimator = this.f795s0;
            if (objectAnimator != null) {
                objectAnimator.cancel();
            }
            setThumbPosition(zIsChecked ? 1.0f : 0.0f);
            return;
        }
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat(this, f762v0, zIsChecked ? 1.0f : 0.0f);
        this.f795s0 = objectAnimatorOfFloat;
        objectAnimatorOfFloat.setDuration(250L);
        this.f795s0.setAutoCancel(true);
        this.f795s0.start();
    }

    @Override // android.widget.TextView
    public void setCustomSelectionActionModeCallback(@Nullable ActionMode.Callback callback) {
        super.setCustomSelectionActionModeCallback(p.wrapCustomSelectionActionModeCallback(this, callback));
    }

    public void setEmojiCompatEnabled(boolean z10) {
        getEmojiTextViewHelper().c(z10);
        setTextOnInternal(this.R);
        setTextOffInternal(this.T);
        requestLayout();
    }

    public final void setEnforceSwitchWidth(boolean z10) {
        this.f790n0 = z10;
        invalidate();
    }

    @Override // android.widget.TextView
    public void setFilters(@NonNull InputFilter[] inputFilterArr) {
        super.setFilters(getEmojiTextViewHelper().a(inputFilterArr));
    }

    public void setShowText(boolean z10) {
        if (this.V != z10) {
            this.V = z10;
            requestLayout();
            if (z10) {
                d();
            }
        }
    }

    public void setSplitTrack(boolean z10) {
        this.Q = z10;
        invalidate();
    }

    public void setSwitchMinWidth(int i10) {
        this.f786l = i10;
        requestLayout();
    }

    public void setSwitchPadding(int i10) {
        this.f788m = i10;
        requestLayout();
    }

    public void setSwitchTextAppearance(Context context, int i10) {
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(i10, j.TextAppearance);
        p3 p3Var = new p3(context, typedArrayObtainStyledAttributes);
        ColorStateList colorStateListA = p3Var.a(j.TextAppearance_android_textColor);
        if (colorStateListA != null) {
            this.f792p0 = colorStateListA;
        } else {
            this.f792p0 = getTextColors();
        }
        int dimensionPixelSize = typedArrayObtainStyledAttributes.getDimensionPixelSize(j.TextAppearance_android_textSize, 0);
        if (dimensionPixelSize != 0) {
            float f10 = dimensionPixelSize;
            TextPaint textPaint = this.f791o0;
            if (f10 != textPaint.getTextSize()) {
                textPaint.setTextSize(f10);
                requestLayout();
            }
        }
        int i11 = typedArrayObtainStyledAttributes.getInt(j.TextAppearance_android_typeface, -1);
        setSwitchTypeface(i11 != 1 ? i11 != 2 ? i11 != 3 ? null : Typeface.MONOSPACE : Typeface.SERIF : Typeface.SANS_SERIF, typedArrayObtainStyledAttributes.getInt(j.TextAppearance_android_textStyle, -1));
        if (typedArrayObtainStyledAttributes.getBoolean(j.TextAppearance_textAllCaps, false)) {
            Context context2 = getContext();
            i.a aVar = new i.a();
            aVar.f26475a = context2.getResources().getConfiguration().locale;
            this.mSwitchTransformationMethod = aVar;
        } else {
            this.mSwitchTransformationMethod = null;
        }
        setTextOnInternal(this.R);
        setTextOffInternal(this.T);
        p3Var.e();
    }

    public void setSwitchTypeface(Typeface typeface, int i10) {
        TextPaint textPaint = this.f791o0;
        if (i10 <= 0) {
            textPaint.setFakeBoldText(false);
            textPaint.setTextSkewX(0.0f);
            setSwitchTypeface(typeface);
        } else {
            Typeface typefaceDefaultFromStyle = typeface == null ? Typeface.defaultFromStyle(i10) : Typeface.create(typeface, i10);
            setSwitchTypeface(typefaceDefaultFromStyle);
            int i11 = (~(typefaceDefaultFromStyle != null ? typefaceDefaultFromStyle.getStyle() : 0)) & i10;
            textPaint.setFakeBoldText((i11 & 1) != 0);
            textPaint.setTextSkewX((i11 & 2) != 0 ? -0.25f : 0.0f);
        }
    }

    public void setTextOff(CharSequence charSequence) {
        setTextOffInternal(charSequence);
        requestLayout();
        if (isChecked() || Build.VERSION.SDK_INT < 30) {
            return;
        }
        CharSequence string = this.T;
        if (string == null) {
            string = getResources().getString(h.abc_capital_off);
        }
        s1.setStateDescription(this, string);
    }

    public void setTextOn(CharSequence charSequence) {
        setTextOnInternal(charSequence);
        requestLayout();
        if (!isChecked() || Build.VERSION.SDK_INT < 30) {
            return;
        }
        CharSequence string = this.R;
        if (string == null) {
            string = getResources().getString(h.abc_capital_on);
        }
        s1.setStateDescription(this, string);
    }

    public void setThumbDrawable(Drawable drawable) {
        Drawable drawable2 = this.f764a;
        if (drawable2 != null) {
            drawable2.setCallback(null);
        }
        this.f764a = drawable;
        if (drawable != null) {
            drawable.setCallback(this);
        }
        requestLayout();
    }

    public void setThumbPosition(float f10) {
        this.f775f0 = f10;
        invalidate();
    }

    public void setThumbResource(int i10) {
        setThumbDrawable(f.a.getDrawable(getContext(), i10));
    }

    public void setThumbTextPadding(int i10) {
        this.f784k = i10;
        requestLayout();
    }

    public void setThumbTintList(@Nullable ColorStateList colorStateList) {
        this.f766b = colorStateList;
        this.f770d = true;
        a();
    }

    public void setThumbTintMode(@Nullable PorterDuff.Mode mode) {
        this.f768c = mode;
        this.f772e = true;
        a();
    }

    public void setTrackDrawable(Drawable drawable) {
        Drawable drawable2 = this.f774f;
        if (drawable2 != null) {
            drawable2.setCallback(null);
        }
        this.f774f = drawable;
        if (drawable != null) {
            drawable.setCallback(this);
        }
        requestLayout();
    }

    public void setTrackResource(int i10) {
        setTrackDrawable(f.a.getDrawable(getContext(), i10));
    }

    public void setTrackTintList(@Nullable ColorStateList colorStateList) {
        this.f776g = colorStateList;
        this.f780i = true;
        b();
    }

    public void setTrackTintMode(@Nullable PorterDuff.Mode mode) {
        this.f778h = mode;
        this.f782j = true;
        b();
    }

    @Override // android.widget.CompoundButton, android.widget.Checkable
    public final void toggle() {
        setChecked(!isChecked());
    }

    @Override // android.widget.CompoundButton, android.widget.TextView, android.view.View
    public final boolean verifyDrawable(Drawable drawable) {
        return super.verifyDrawable(drawable) || drawable == this.f764a || drawable == this.f774f;
    }

    public SwitchCompat(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, d.a.switchStyle);
    }

    public SwitchCompat(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        this.f766b = null;
        this.f768c = null;
        this.f770d = false;
        this.f772e = false;
        this.f776g = null;
        this.f778h = null;
        this.f780i = false;
        this.f782j = false;
        this.f771d0 = VelocityTracker.obtain();
        this.f790n0 = true;
        this.f797u0 = new Rect();
        l3.a(getContext(), this);
        TextPaint textPaint = new TextPaint(1);
        this.f791o0 = textPaint;
        textPaint.density = getResources().getDisplayMetrics().density;
        int[] iArr = j.SwitchCompat;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, iArr, i10, 0);
        p3 p3Var = new p3(context, typedArrayObtainStyledAttributes);
        s1.saveAttributeDataForStyleable(this, context, iArr, attributeSet, typedArrayObtainStyledAttributes, i10, 0);
        Drawable drawableB = p3Var.b(j.SwitchCompat_android_thumb);
        this.f764a = drawableB;
        if (drawableB != null) {
            drawableB.setCallback(this);
        }
        Drawable drawableB2 = p3Var.b(j.SwitchCompat_track);
        this.f774f = drawableB2;
        if (drawableB2 != null) {
            drawableB2.setCallback(this);
        }
        setTextOnInternal(typedArrayObtainStyledAttributes.getText(j.SwitchCompat_android_textOn));
        setTextOffInternal(typedArrayObtainStyledAttributes.getText(j.SwitchCompat_android_textOff));
        this.V = typedArrayObtainStyledAttributes.getBoolean(j.SwitchCompat_showText, true);
        this.f784k = typedArrayObtainStyledAttributes.getDimensionPixelSize(j.SwitchCompat_thumbTextPadding, 0);
        this.f786l = typedArrayObtainStyledAttributes.getDimensionPixelSize(j.SwitchCompat_switchMinWidth, 0);
        this.f788m = typedArrayObtainStyledAttributes.getDimensionPixelSize(j.SwitchCompat_switchPadding, 0);
        this.Q = typedArrayObtainStyledAttributes.getBoolean(j.SwitchCompat_splitTrack, false);
        ColorStateList colorStateListA = p3Var.a(j.SwitchCompat_thumbTint);
        if (colorStateListA != null) {
            this.f766b = colorStateListA;
            this.f770d = true;
        }
        PorterDuff.Mode modeC = p1.c(typedArrayObtainStyledAttributes.getInt(j.SwitchCompat_thumbTintMode, -1), null);
        if (this.f768c != modeC) {
            this.f768c = modeC;
            this.f772e = true;
        }
        if (this.f770d || this.f772e) {
            a();
        }
        ColorStateList colorStateListA2 = p3Var.a(j.SwitchCompat_trackTint);
        if (colorStateListA2 != null) {
            this.f776g = colorStateListA2;
            this.f780i = true;
        }
        PorterDuff.Mode modeC2 = p1.c(typedArrayObtainStyledAttributes.getInt(j.SwitchCompat_trackTintMode, -1), null);
        if (this.f778h != modeC2) {
            this.f778h = modeC2;
            this.f782j = true;
        }
        if (this.f780i || this.f782j) {
            b();
        }
        int resourceId = typedArrayObtainStyledAttributes.getResourceId(j.SwitchCompat_switchTextAppearance, 0);
        if (resourceId != 0) {
            setSwitchTextAppearance(context, resourceId);
        }
        new a1(this).loadFromAttributes(attributeSet, i10);
        p3Var.e();
        ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
        this.f765a0 = viewConfiguration.getScaledTouchSlop();
        this.f773e0 = viewConfiguration.getScaledMinimumFlingVelocity();
        getEmojiTextViewHelper().loadFromAttributes(attributeSet, i10);
        refreshDrawableState();
        setChecked(isChecked());
    }

    public void setSwitchTypeface(Typeface typeface) {
        TextPaint textPaint = this.f791o0;
        if ((textPaint.getTypeface() == null || textPaint.getTypeface().equals(typeface)) && (textPaint.getTypeface() != null || typeface == null)) {
            return;
        }
        textPaint.setTypeface(typeface);
        requestLayout();
        invalidate();
    }
}
