content: package androidx.appcompat.widget;
  
  import android.animation.ObjectAnimator;
  import android.content.Context;
  import android.content.res.ColorStateList;
  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.util.Property;
  import android.view.ActionMode;
  import android.view.MotionEvent;
  import android.view.VelocityTracker;
  import android.view.ViewConfiguration;
  import android.view.accessibility.AccessibilityEvent;
  import android.view.accessibility.AccessibilityNodeInfo;
  import android.widget.CompoundButton;
  import androidx.appcompat.R;
  import androidx.appcompat.content.res.AppCompatResources;
  import androidx.appcompat.text.AllCapsTransformationMethod;
  import androidx.core.graphics.drawable.DrawableCompat;
  import androidx.core.view.ViewCompat;
  import androidx.core.widget.TextViewCompat;
  import androidx.emoji2.text.EmojiCompat;
  import java.lang.ref.Reference;
  import java.lang.ref.WeakReference;
  
  public class SwitchCompat extends CompoundButton implements EmojiCompatConfigurationView {
      private static final String ACCESSIBILITY_EVENT_CLASS_NAME = "android.widget.Switch";
      private static final int[] CHECKED_STATE_SET = {16842912};
      private static final int MONOSPACE = 3;
      private static final int SANS = 1;
      private static final int SERIF = 2;
      private static final int THUMB_ANIMATION_DURATION = 250;
      private static final Property<SwitchCompat, Float> THUMB_POS = new Property<SwitchCompat, Float>(Float.class, "thumbPos") {
          public Float get(SwitchCompat object) {
              return Float.valueOf(object.mThumbPosition);
          }
  
          public void set(SwitchCompat object, Float value) {
              object.setThumbPosition(value.floatValue());
          }
      };
      private static final int TOUCH_MODE_DOWN = 1;
      private static final int TOUCH_MODE_DRAGGING = 2;
      private static final int TOUCH_MODE_IDLE = 0;
      private AppCompatEmojiTextHelper mAppCompatEmojiTextHelper;
      private EmojiCompatInitCallback mEmojiCompatInitCallback;
      private boolean mEnforceSwitchWidth;
      private boolean mHasThumbTint;
      private boolean mHasThumbTintMode;
      private boolean mHasTrackTint;
      private boolean mHasTrackTintMode;
      private int mMinFlingVelocity;
      private Layout mOffLayout;
      private Layout mOnLayout;
      ObjectAnimator mPositionAnimator;
      private boolean mShowText;
      private boolean mSplitTrack;
      private int mSwitchBottom;
      private int mSwitchHeight;
      private int mSwitchLeft;
      private int mSwitchMinWidth;
      private int mSwitchPadding;
      private int mSwitchRight;
      private int mSwitchTop;
      private TransformationMethod mSwitchTransformationMethod;
      private int mSwitchWidth;
      private final Rect mTempRect;
      private ColorStateList mTextColors;
      private final AppCompatTextHelper mTextHelper;
      private CharSequence mTextOff;
      private CharSequence mTextOffTransformed;
      private CharSequence mTextOn;
      private CharSequence mTextOnTransformed;
      private final TextPaint mTextPaint;
      private Drawable mThumbDrawable;
      float mThumbPosition;
      private int mThumbTextPadding;
      private ColorStateList mThumbTintList;
      private PorterDuff.Mode mThumbTintMode;
      private int mThumbWidth;
      private int mTouchMode;
      private int mTouchSlop;
      private float mTouchX;
      private float mTouchY;
      private Drawable mTrackDrawable;
      private ColorStateList mTrackTintList;
      private PorterDuff.Mode mTrackTintMode;
      private VelocityTracker mVelocityTracker;
  
      static class Api18Impl {
          private Api18Impl() {
          }
  
          static void setAutoCancel(ObjectAnimator objectAnimator, boolean cancel) {
              objectAnimator.setAutoCancel(cancel);
          }
      }
  
      static class EmojiCompatInitCallback extends EmojiCompat.InitCallback {
          private final Reference<SwitchCompat> mOuterWeakRef;
  
          EmojiCompatInitCallback(SwitchCompat view) {
              this.mOuterWeakRef = new WeakReference(view);
          }
  
          public void onFailed(Throwable throwable) {
              SwitchCompat switchCompat = this.mOuterWeakRef.get();
              if (switchCompat != null) {
                  switchCompat.onEmojiCompatInitializedForSwitchText();
              }
          }
  
          public void onInitialized() {
              SwitchCompat switchCompat = this.mOuterWeakRef.get();
              if (switchCompat != null) {
                  switchCompat.onEmojiCompatInitializedForSwitchText();
              }
          }
      }
  
      public SwitchCompat(Context context) {
          this(context, (AttributeSet) null);
      }
  
      public SwitchCompat(Context context, AttributeSet attrs) {
          this(context, attrs, R.attr.switchStyle);
      }
  
      public SwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
          this.mThumbTintList = null;
          this.mThumbTintMode = null;
          this.mHasThumbTint = false;
          this.mHasThumbTintMode = false;
          this.mTrackTintList = null;
          this.mTrackTintMode = null;
          this.mHasTrackTint = false;
          this.mHasTrackTintMode = false;
          this.mVelocityTracker = VelocityTracker.obtain();
          this.mEnforceSwitchWidth = true;
          this.mTempRect = new Rect();
          ThemeUtils.checkAppCompatTheme(this, getContext());
          TextPaint textPaint = new TextPaint(1);
          this.mTextPaint = textPaint;
          textPaint.density = getResources().getDisplayMetrics().density;
          TintTypedArray obtainStyledAttributes = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SwitchCompat, defStyleAttr, 0);
          ViewCompat.saveAttributeDataForStyleable(this, context, R.styleable.SwitchCompat, attrs, obtainStyledAttributes.getWrappedTypeArray(), defStyleAttr, 0);
          Drawable drawable = obtainStyledAttributes.getDrawable(R.styleable.SwitchCompat_android_thumb);
          this.mThumbDrawable = drawable;
          if (drawable != null) {
              drawable.setCallback(this);
          }
          Drawable drawable2 = obtainStyledAttributes.getDrawable(R.styleable.SwitchCompat_track);
          this.mTrackDrawable = drawable2;
          if (drawable2 != null) {
              drawable2.setCallback(this);
          }
          setTextOnInternal(obtainStyledAttributes.getText(R.styleable.SwitchCompat_android_textOn));
          setTextOffInternal(obtainStyledAttributes.getText(R.styleable.SwitchCompat_android_textOff));
          this.mShowText = obtainStyledAttributes.getBoolean(R.styleable.SwitchCompat_showText, true);
          this.mThumbTextPadding = obtainStyledAttributes.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0);
          this.mSwitchMinWidth = obtainStyledAttributes.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0);
          this.mSwitchPadding = obtainStyledAttributes.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0);
          this.mSplitTrack = obtainStyledAttributes.getBoolean(R.styleable.SwitchCompat_splitTrack, false);
          ColorStateList colorStateList = obtainStyledAttributes.getColorStateList(R.styleable.SwitchCompat_thumbTint);
          if (colorStateList != null) {
              this.mThumbTintList = colorStateList;
              this.mHasThumbTint = true;
          }
          PorterDuff.Mode parseTintMode = DrawableUtils.parseTintMode(obtainStyledAttributes.getInt(R.styleable.SwitchCompat_thumbTintMode, -1), (PorterDuff.Mode) null);
          if (this.mThumbTintMode != parseTintMode) {
              this.mThumbTintMode = parseTintMode;
              this.mHasThumbTintMode = true;
          }
          if (this.mHasThumbTint || this.mHasThumbTintMode) {
              applyThumbTint();
          }
          ColorStateList colorStateList2 = obtainStyledAttributes.getColorStateList(R.styleable.SwitchCompat_trackTint);
          if (colorStateList2 != null) {
              this.mTrackTintList = colorStateList2;
              this.mHasTrackTint = true;
          }
          PorterDuff.Mode parseTintMode2 = DrawableUtils.parseTintMode(obtainStyledAttributes.getInt(R.styleable.SwitchCompat_trackTintMode, -1), (PorterDuff.Mode) null);
          if (this.mTrackTintMode != parseTintMode2) {
              this.mTrackTintMode = parseTintMode2;
              this.mHasTrackTintMode = true;
          }
          if (this.mHasTrackTint || this.mHasTrackTintMode) {
              applyTrackTint();
          }
          int resourceId = obtainStyledAttributes.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0);
          if (resourceId != 0) {
              setSwitchTextAppearance(context, resourceId);
          }
          AppCompatTextHelper appCompatTextHelper = new AppCompatTextHelper(this);
          this.mTextHelper = appCompatTextHelper;
          appCompatTextHelper.loadFromAttributes(attrs, defStyleAttr);
          obtainStyledAttributes.recycle();
          ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
          this.mTouchSlop = viewConfiguration.getScaledTouchSlop();
          this.mMinFlingVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
          getEmojiTextViewHelper().loadFromAttributes(attrs, defStyleAttr);
          refreshDrawableState();
          setChecked(isChecked());
      }
  
      private void animateThumbToCheckedState(boolean newCheckedState) {
          ObjectAnimator ofFloat = ObjectAnimator.ofFloat(this, THUMB_POS, new float[]{newCheckedState ? 1.0f : 0.0f});
          this.mPositionAnimator = ofFloat;
          ofFloat.setDuration(250);
          if (Build.VERSION.SDK_INT >= 18) {
              Api18Impl.setAutoCancel(this.mPositionAnimator, true);
          }
          this.mPositionAnimator.start();
      }
  
      private void applyThumbTint() {
          Drawable drawable = this.mThumbDrawable;
          if (drawable == null) {
              return;
          }
          if (this.mHasThumbTint || this.mHasThumbTintMode) {
              Drawable mutate = DrawableCompat.wrap(drawable).mutate();
              this.mThumbDrawable = mutate;
              if (this.mHasThumbTint) {
                  DrawableCompat.setTintList(mutate, this.mThumbTintList);
              }
              if (this.mHasThumbTintMode) {
                  DrawableCompat.setTintMode(this.mThumbDrawable, this.mThumbTintMode);
              }
              if (this.mThumbDrawable.isStateful()) {
                  this.mThumbDrawable.setState(getDrawableState());
              }
          }
      }
  
      private void applyTrackTint() {
          Drawable drawable = this.mTrackDrawable;
          if (drawable == null) {
              return;
          }
          if (this.mHasTrackTint || this.mHasTrackTintMode) {
              Drawable mutate = DrawableCompat.wrap(drawable).mutate();
              this.mTrackDrawable = mutate;
              if (this.mHasTrackTint) {
                  DrawableCompat.setTintList(mutate, this.mTrackTintList);
              }
              if (this.mHasTrackTintMode) {
                  DrawableCompat.setTintMode(this.mTrackDrawable, this.mTrackTintMode);
              }
              if (this.mTrackDrawable.isStateful()) {
                  this.mTrackDrawable.setState(getDrawableState());
              }
          }
      }
  
      private void cancelPositionAnimator() {
          ObjectAnimator objectAnimator = this.mPositionAnimator;
          if (objectAnimator != null) {
              objectAnimator.cancel();
          }
      }
  
      private void cancelSuperTouch(MotionEvent ev) {
          MotionEvent obtain = MotionEvent.obtain(ev);
          obtain.setAction(3);
          super.onTouchEvent(obtain);
          obtain.recycle();
      }
  
      private static float constrain(float amount, float low, float high) {
          return amount < low ? low : amount > high ? high : amount;
      }
  
      private CharSequence doTransformForOnOffText(CharSequence onOffText) {
          TransformationMethod wrapTransformationMethod = getEmojiTextViewHelper().wrapTransformationMethod(this.mSwitchTransformationMethod);
          return wrapTransformationMethod != null ? wrapTransformationMethod.getTransformation(onOffText, this) : onOffText;
      }
  
      private AppCompatEmojiTextHelper getEmojiTextViewHelper() {
          if (this.mAppCompatEmojiTextHelper == null) {
              this.mAppCompatEmojiTextHelper = new AppCompatEmojiTextHelper(this);
          }
          return this.mAppCompatEmojiTextHelper;
      }
  
      private boolean getTargetCheckedState() {
          return this.mThumbPosition > 0.5f;
      }
  
      private int getThumbOffset() {
          return (int) ((((float) getThumbScrollRange()) * (ViewUtils.isLayoutRtl(this) ? 1.0f - this.mThumbPosition : this.mThumbPosition)) + 0.5f);
      }
  
      private int getThumbScrollRange() {
          Drawable drawable = this.mTrackDrawable;
          if (drawable == null) {
              return 0;
          }
          Rect rect = this.mTempRect;
          drawable.getPadding(rect);
          Drawable drawable2 = this.mThumbDrawable;
          Rect opticalBounds = drawable2 != null ? DrawableUtils.getOpticalBounds(drawable2) : DrawableUtils.INSETS_NONE;
          return ((((this.mSwitchWidth - this.mThumbWidth) - rect.left) - rect.right) - opticalBounds.left) - opticalBounds.right;
      }
  
      private boolean hitThumb(float x, float y) {
          if (this.mThumbDrawable == null) {
              return false;
          }
          int thumbOffset = getThumbOffset();
          this.mThumbDrawable.getPadding(this.mTempRect);
          int i = this.mSwitchTop;
          int i2 = this.mTouchSlop;
          int i3 = i - i2;
          int i4 = (this.mSwitchLeft + thumbOffset) - i2;
          int i5 = this.mThumbWidth + i4 + this.mTempRect.left + this.mTempRect.right;
          int i6 = this.mTouchSlop;
          return x > ((float) i4) && x < ((float) (i5 + i6)) && y > ((float) i3) && y < ((float) (this.mSwitchBottom + i6));
      }
  
      private Layout makeLayout(CharSequence transformedText) {
          TextPaint textPaint = this.mTextPaint;
          return new StaticLayout(transformedText, textPaint, transformedText != null ? (int) Math.ceil((double) Layout.getDesiredWidth(transformedText, textPaint)) : 0, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
      }
  
      private void setOffStateDescriptionOnRAndAbove() {
          if (Build.VERSION.SDK_INT >= 30) {
              CharSequence charSequence = this.mTextOff;
              if (charSequence == null) {
                  charSequence = getResources().getString(R.string.abc_capital_off);
              }
              ViewCompat.setStateDescription(this, charSequence);
          }
      }
  
      private void setOnStateDescriptionOnRAndAbove() {
          if (Build.VERSION.SDK_INT >= 30) {
              CharSequence charSequence = this.mTextOn;
              if (charSequence == null) {
                  charSequence = getResources().getString(R.string.abc_capital_on);
              }
              ViewCompat.setStateDescription(this, charSequence);
          }
      }
  
      private void setSwitchTypefaceByIndex(int typefaceIndex, int styleIndex) {
          Typeface typeface = null;
          switch (typefaceIndex) {
              case 1:
                  typeface = Typeface.SANS_SERIF;
                  break;
              case 2:
                  typeface = Typeface.SERIF;
                  break;
              case 3:
                  typeface = Typeface.MONOSPACE;
                  break;
          }
          setSwitchTypeface(typeface, styleIndex);
      }
  
      private void setTextOffInternal(CharSequence textOff) {
          this.mTextOff = textOff;
          this.mTextOffTransformed = doTransformForOnOffText(textOff);
          this.mOffLayout = null;
          if (this.mShowText) {
              setupEmojiCompatLoadCallback();
          }
      }
  
      private void setTextOnInternal(CharSequence textOn) {
          this.mTextOn = textOn;
          this.mTextOnTransformed = doTransformForOnOffText(textOn);
          this.mOnLayout = null;
          if (this.mShowText) {
              setupEmojiCompatLoadCallback();
          }
      }
  
      private void setupEmojiCompatLoadCallback() {
          if (this.mEmojiCompatInitCallback == null && this.mAppCompatEmojiTextHelper.isEnabled() && EmojiCompat.isConfigured()) {
              EmojiCompat emojiCompat = EmojiCompat.get();
              int loadState = emojiCompat.getLoadState();
              if (loadState == 3 || loadState == 0) {
                  EmojiCompatInitCallback emojiCompatInitCallback = new EmojiCompatInitCallback(this);
                  this.mEmojiCompatInitCallback = emojiCompatInitCallback;
                  emojiCompat.registerInitCallback(emojiCompatInitCallback);
              }
          }
      }
  
      private void stopDrag(MotionEvent ev) {
          this.mTouchMode = 0;
          boolean z = true;
          boolean z2 = ev.getAction() == 1 && isEnabled();
          boolean isChecked = isChecked();
          if (z2) {
              this.mVelocityTracker.computeCurrentVelocity(1000);
              float xVelocity = this.mVelocityTracker.getXVelocity();
              if (Math.abs(xVelocity) <= ((float) this.mMinFlingVelocity)) {
                  z = getTargetCheckedState();
              } else if (!ViewUtils.isLayoutRtl(this) ? xVelocity <= 0.0f : xVelocity >= 0.0f) {
                  z = false;
              }
          } else {
              z = isChecked;
          }
          if (z != isChecked) {
              playSoundEffect(0);
          }
          setChecked(z);
          cancelSuperTouch(ev);
      }
  
      public void draw(Canvas c) {
          Rect rect = this.mTempRect;
          int i = this.mSwitchLeft;
          int i2 = this.mSwitchTop;
          int i3 = this.mSwitchRight;
          int i4 = this.mSwitchBottom;
          int thumbOffset = getThumbOffset() + i;
          Drawable drawable = this.mThumbDrawable;
          Rect opticalBounds = drawable != null ? DrawableUtils.getOpticalBounds(drawable) : DrawableUtils.INSETS_NONE;
          Drawable drawable2 = this.mTrackDrawable;
          if (drawable2 != null) {
              drawable2.getPadding(rect);
              thumbOffset += rect.left;
              int i5 = i;
              int i6 = i2;
              int i7 = i3;
              int i8 = i4;
              if (opticalBounds != null) {
                  if (opticalBounds.left > rect.left) {
                      i5 += opticalBounds.left - rect.left;
                  }
                  if (opticalBounds.top > rect.top) {
                      i6 += opticalBounds.top - rect.top;
                  }
                  if (opticalBounds.right > rect.right) {
                      i7 -= opticalBounds.right - rect.right;
                  }
                  if (opticalBounds.bottom > rect.bottom) {
                      i8 -= opticalBounds.bottom - rect.bottom;
                  }
              }
              this.mTrackDrawable.setBounds(i5, i6, i7, i8);
          }
          Drawable drawable3 = this.mThumbDrawable;
          if (drawable3 != null) {
              drawable3.getPadding(rect);
              int i9 = thumbOffset - rect.left;
              int i10 = this.mThumbWidth + thumbOffset + rect.right;
              this.mThumbDrawable.setBounds(i9, i2, i10, i4);
              Drawable background = getBackground();
              if (background != null) {
                  DrawableCompat.setHotspotBounds(background, i9, i2, i10, i4);
              }
          }
          super.draw(c);
      }
  
      public void drawableHotspotChanged(float x, float y) {
          if (Build.VERSION.SDK_INT >= 21) {
              super.drawableHotspotChanged(x, y);
          }
          Drawable drawable = this.mThumbDrawable;
          if (drawable != null) {
              DrawableCompat.setHotspot(drawable, x, y);
          }
          Drawable drawable2 = this.mTrackDrawable;
          if (drawable2 != null) {
              DrawableCompat.setHotspot(drawable2, x, y);
          }
      }
  
      /* access modifiers changed from: protected */
      public void drawableStateChanged() {
          super.drawableStateChanged();
          int[] drawableState = getDrawableState();
          boolean z = false;
          Drawable drawable = this.mThumbDrawable;
          if (drawable != null && drawable.isStateful()) {
              z = false | drawable.setState(drawableState);
          }
          Drawable drawable2 = this.mTrackDrawable;
          if (drawable2 != null && drawable2.isStateful()) {
              z |= drawable2.setState(drawableState);
          }
          if (z) {
              invalidate();
          }
      }
  
      public int getCompoundPaddingLeft() {
          if (!ViewUtils.isLayoutRtl(this)) {
              return super.getCompoundPaddingLeft();
          }
          int compoundPaddingLeft = super.getCompoundPaddingLeft() + this.mSwitchWidth;
          return !TextUtils.isEmpty(getText()) ? compoundPaddingLeft + this.mSwitchPadding : compoundPaddingLeft;
      }
  
      public int getCompoundPaddingRight() {
          if (ViewUtils.isLayoutRtl(this)) {
              return super.getCompoundPaddingRight();
          }
          int compoundPaddingRight = super.getCompoundPaddingRight() + this.mSwitchWidth;
          return !TextUtils.isEmpty(getText()) ? compoundPaddingRight + this.mSwitchPadding : compoundPaddingRight;
      }
  
      public ActionMode.Callback getCustomSelectionActionModeCallback() {
          return TextViewCompat.unwrapCustomSelectionActionModeCallback(super.getCustomSelectionActionModeCallback());
      }
  
      public boolean getShowText() {
          return this.mShowText;
      }
  
      public boolean getSplitTrack() {
          return this.mSplitTrack;
      }
  
      public int getSwitchMinWidth() {
          return this.mSwitchMinWidth;
      }
  
      public int getSwitchPadding() {
          return this.mSwitchPadding;
      }
  
      public CharSequence getTextOff() {
          return this.mTextOff;
      }
  
      public CharSequence getTextOn() {
          return this.mTextOn;
      }
  
      public Drawable getThumbDrawable() {
          return this.mThumbDrawable;
      }
  
      /* access modifiers changed from: protected */
      public final float getThumbPosition() {
          return this.mThumbPosition;
      }
  
      public int getThumbTextPadding() {
          return this.mThumbTextPadding;
      }
  
      public ColorStateList getThumbTintList() {
          return this.mThumbTintList;
      }
  
      public PorterDuff.Mode getThumbTintMode() {
          return this.mThumbTintMode;
      }
  
      public Drawable getTrackDrawable() {
          return this.mTrackDrawable;
      }
  
      public ColorStateList getTrackTintList() {
          return this.mTrackTintList;
      }
  
      public PorterDuff.Mode getTrackTintMode() {
          return this.mTrackTintMode;
      }
  
      public boolean isEmojiCompatEnabled() {
          return getEmojiTextViewHelper().isEnabled();
      }
  
      public void jumpDrawablesToCurrentState() {
          super.jumpDrawablesToCurrentState();
          Drawable drawable = this.mThumbDrawable;
          if (drawable != null) {
              drawable.jumpToCurrentState();
          }
          Drawable drawable2 = this.mTrackDrawable;
          if (drawable2 != null) {
              drawable2.jumpToCurrentState();
          }
          ObjectAnimator objectAnimator = this.mPositionAnimator;
          if (objectAnimator != null && objectAnimator.isStarted()) {
              this.mPositionAnimator.end();
              this.mPositionAnimator = null;
          }
      }
  
      /* access modifiers changed from: protected */
      public int[] onCreateDrawableState(int extraSpace) {
          int[] onCreateDrawableState = super.onCreateDrawableState(extraSpace + 1);
          if (isChecked()) {
              mergeDrawableStates(onCreateDrawableState, CHECKED_STATE_SET);
          }
          return onCreateDrawableState;
      }
  
      /* access modifiers changed from: protected */
      public void onDraw(Canvas canvas) {
          int i;
          Canvas canvas2 = canvas;
          super.onDraw(canvas);
          Rect rect = this.mTempRect;
          Drawable drawable = this.mTrackDrawable;
          if (drawable != null) {
              drawable.getPadding(rect);
          } else {
              rect.setEmpty();
          }
          int i2 = this.mSwitchTop;
          int i3 = this.mSwitchBottom;
          int i4 = rect.top + i2;
          int i5 = i3 - rect.bottom;
          Drawable drawable2 = this.mThumbDrawable;
          if (drawable != null) {
              if (!this.mSplitTrack || drawable2 == null) {
                  drawable.draw(canvas2);
              } else {
                  Rect opticalBounds = DrawableUtils.getOpticalBounds(drawable2);
                  drawable2.copyBounds(rect);
                  rect.left += opticalBounds.left;
                  rect.right -= opticalBounds.right;
                  int save = canvas.save();
                  canvas2.clipRect(rect, Region.Op.DIFFERENCE);
                  drawable.draw(canvas2);
                  canvas2.restoreToCount(save);
              }
          }
          int save2 = canvas.save();
          if (drawable2 != null) {
              drawable2.draw(canvas2);
          }
          Layout layout = getTargetCheckedState() ? this.mOnLayout : this.mOffLayout;
          if (layout != null) {
              int[] drawableState = getDrawableState();
              ColorStateList colorStateList = this.mTextColors;
              if (colorStateList != null) {
                  this.mTextPaint.setColor(colorStateList.getColorForState(drawableState, 0));
              }
              this.mTextPaint.drawableState = drawableState;
              if (drawable2 != null) {
                  Rect bounds = drawable2.getBounds();
                  i = bounds.left + bounds.right;
              } else {
                  i = getWidth();
              }
              canvas2.translate((float) ((i / 2) - (layout.getWidth() / 2)), (float) (((i4 + i5) / 2) - (layout.getHeight() / 2)));
              layout.draw(canvas2);
          }
          canvas2.restoreToCount(save2);
      }
  
      /* access modifiers changed from: package-private */
      public void onEmojiCompatInitializedForSwitchText() {
          setTextOnInternal(this.mTextOn);
          setTextOffInternal(this.mTextOff);
          requestLayout();
      }
  
      public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
          super.onInitializeAccessibilityEvent(event);
          event.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME);
      }
  
      public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
          super.onInitializeAccessibilityNodeInfo(info);
          info.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME);
          if (Build.VERSION.SDK_INT < 30) {
              CharSequence charSequence = isChecked() ? this.mTextOn : this.mTextOff;
              if (!TextUtils.isEmpty(charSequence)) {
                  CharSequence text = info.getText();
                  if (TextUtils.isEmpty(text)) {
                      info.setText(charSequence);
                      return;
                  }
                  StringBuilder sb = new StringBuilder();
                  sb.append(text).append(' ').append(charSequence);
                  info.setText(sb);
              }
          }
      }
  
      /* access modifiers changed from: protected */
      public void onLayout(boolean changed, int left, int top, int right, int bottom) {
          int i;
          int i2;
          int i3;
          int i4;
          super.onLayout(changed, left, top, right, bottom);
          int i5 = 0;
          int i6 = 0;
          if (this.mThumbDrawable != null) {
              Rect rect = this.mTempRect;
              Drawable drawable = this.mTrackDrawable;
              if (drawable != null) {
                  drawable.getPadding(rect);
              } else {
                  rect.setEmpty();
              }
              Rect opticalBounds = DrawableUtils.getOpticalBounds(this.mThumbDrawable);
              i5 = Math.max(0, opticalBounds.left - rect.left);
              i6 = Math.max(0, opticalBounds.right - rect.right);
          }
          if (ViewUtils.isLayoutRtl(this)) {
              i2 = getPaddingLeft() + i5;
              i = ((this.mSwitchWidth + i2) - i5) - i6;
          } else {
              i = (getWidth() - getPaddingRight()) - i6;
              i2 = (i - this.mSwitchWidth) + i5 + i6;
          }
          switch (getGravity() & 112) {
              case 16:
                  int i7 = this.mSwitchHeight;
                  int paddingTop = (((getPaddingTop() + getHeight()) - getPaddingBottom()) / 2) - (i7 / 2);
                  int i8 = i7 + paddingTop;
                  i3 = paddingTop;
                  i4 = i8;
                  break;
              case 80:
                  i4 = getHeight() - getPaddingBottom();
                  i3 = i4 - this.mSwitchHeight;
                  break;
              default:
                  i3 = getPaddingTop();
                  i4 = this.mSwitchHeight + i3;
                  break;
          }
          this.mSwitchLeft = i2;
          this.mSwitchTop = i3;
          this.mSwitchBottom = i4;
          this.mSwitchRight = i;
      }
  
      public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          int i;
          int i2;
          int i3;
          if (this.mShowText) {
              if (this.mOnLayout == null) {
                  this.mOnLayout = makeLayout(this.mTextOnTransformed);
              }
              if (this.mOffLayout == null) {
                  this.mOffLayout = makeLayout(this.mTextOffTransformed);
              }
          }
          Rect rect = this.mTempRect;
          Drawable drawable = this.mThumbDrawable;
          if (drawable != null) {
              drawable.getPadding(rect);
              i2 = (this.mThumbDrawable.getIntrinsicWidth() - rect.left) - rect.right;
              i = this.mThumbDrawable.getIntrinsicHeight();
          } else {
              i2 = 0;
              i = 0;
          }
          this.mThumbWidth = Math.max(this.mShowText ? Math.max(this.mOnLayout.getWidth(), this.mOffLayout.getWidth()) + (this.mThumbTextPadding * 2) : 0, i2);
          Drawable drawable2 = this.mTrackDrawable;
          if (drawable2 != null) {
              drawable2.getPadding(rect);
              i3 = this.mTrackDrawable.getIntrinsicHeight();
          } else {
              rect.setEmpty();
              i3 = 0;
          }
          int i4 = rect.left;
          int i5 = rect.right;
          Drawable drawable3 = this.mThumbDrawable;
          if (drawable3 != null) {
              Rect opticalBounds = DrawableUtils.getOpticalBounds(drawable3);
              i4 = Math.max(i4, opticalBounds.left);
              i5 = Math.max(i5, opticalBounds.right);
          }
          int max = this.mEnforceSwitchWidth ? Math.max(this.mSwitchMinWidth, (this.mThumbWidth * 2) + i4 + i5) : this.mSwitchMinWidth;
          int max2 = Math.max(i3, i);
          this.mSwitchWidth = max;
          this.mSwitchHeight = max2;
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
          if (getMeasuredHeight() < max2) {
              setMeasuredDimension(getMeasuredWidthAndState(), max2);
          }
      }
  
      public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
          super.onPopulateAccessibilityEvent(event);
          CharSequence charSequence = isChecked() ? this.mTextOn : this.mTextOff;
          if (charSequence != null) {
              event.getText().add(charSequence);
          }
      }
  
      public boolean onTouchEvent(MotionEvent ev) {
          this.mVelocityTracker.addMovement(ev);
          switch (ev.getActionMasked()) {
              case 0:
                  float x = ev.getX();
                  float y = ev.getY();
                  if (isEnabled() && hitThumb(x, y)) {
                      this.mTouchMode = 1;
                      this.mTouchX = x;
                      this.mTouchY = y;
                      break;
                  }
              case 1:
              case 3:
                  if (this.mTouchMode != 2) {
                      this.mTouchMode = 0;
                      this.mVelocityTracker.clear();
                      break;
                  } else {
                      stopDrag(ev);
                      super.onTouchEvent(ev);
                      return true;
                  }
              case 2:
                  switch (this.mTouchMode) {
                      case 1:
                          float x2 = ev.getX();
                          float y2 = ev.getY();
                          if (Math.abs(x2 - this.mTouchX) > ((float) this.mTouchSlop) || Math.abs(y2 - this.mTouchY) > ((float) this.mTouchSlop)) {
                              this.mTouchMode = 2;
                              getParent().requestDisallowInterceptTouchEvent(true);
                              this.mTouchX = x2;
                              this.mTouchY = y2;
                              return true;
                          }
                      case 2:
                          float x3 = ev.getX();
                          int thumbScrollRange = getThumbScrollRange();
                          float f = x3 - this.mTouchX;
                          float f2 = thumbScrollRange != 0 ? f / ((float) thumbScrollRange) : f > 0.0f ? 1.0f : -1.0f;
                          if (ViewUtils.isLayoutRtl(this)) {
                              f2 = -f2;
                          }
                          float constrain = constrain(this.mThumbPosition + f2, 0.0f, 1.0f);
                          if (constrain != this.mThumbPosition) {
                              this.mTouchX = x3;
                              setThumbPosition(constrain);
                          }
                          return true;
                  }
                  break;
          }
          return super.onTouchEvent(ev);
      }
  
      public void setAllCaps(boolean allCaps) {
          super.setAllCaps(allCaps);
          getEmojiTextViewHelper().setAllCaps(allCaps);
      }
  
      public void setChecked(boolean checked) {
          super.setChecked(checked);
          boolean checked2 = isChecked();
          if (checked2) {
              setOnStateDescriptionOnRAndAbove();
          } else {
              setOffStateDescriptionOnRAndAbove();
          }
          if (getWindowToken() == null || !ViewCompat.isLaidOut(this)) {
              cancelPositionAnimator();
              setThumbPosition(checked2 ? 1.0f : 0.0f);
              return;
          }
          animateThumbToCheckedState(checked2);
      }
  
      public void setCustomSelectionActionModeCallback(ActionMode.Callback actionModeCallback) {
          super.setCustomSelectionActionModeCallback(TextViewCompat.wrapCustomSelectionActionModeCallback(this, actionModeCallback));
      }
  
      public void setEmojiCompatEnabled(boolean enabled) {
          getEmojiTextViewHelper().setEnabled(enabled);
          setTextOnInternal(this.mTextOn);
          setTextOffInternal(this.mTextOff);
          requestLayout();
      }
  
      /* access modifiers changed from: protected */
      public final void setEnforceSwitchWidth(boolean enforceSwitchWidth) {
          this.mEnforceSwitchWidth = enforceSwitchWidth;
          invalidate();
      }
  
      public void setFilters(InputFilter[] filters) {
          super.setFilters(getEmojiTextViewHelper().getFilters(filters));
      }
  
      public void setShowText(boolean showText) {
          if (this.mShowText != showText) {
              this.mShowText = showText;
              requestLayout();
              if (showText) {
                  setupEmojiCompatLoadCallback();
              }
          }
      }
  
      public void setSplitTrack(boolean splitTrack) {
          this.mSplitTrack = splitTrack;
          invalidate();
      }
  
      public void setSwitchMinWidth(int pixels) {
          this.mSwitchMinWidth = pixels;
          requestLayout();
      }
  
      public void setSwitchPadding(int pixels) {
          this.mSwitchPadding = pixels;
          requestLayout();
      }
  
      public void setSwitchTextAppearance(Context context, int resid) {
          TintTypedArray obtainStyledAttributes = TintTypedArray.obtainStyledAttributes(context, resid, R.styleable.TextAppearance);
          ColorStateList colorStateList = obtainStyledAttributes.getColorStateList(R.styleable.TextAppearance_android_textColor);
          if (colorStateList != null) {
              this.mTextColors = colorStateList;
          } else {
              this.mTextColors = getTextColors();
          }
          int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0);
          if (!(dimensionPixelSize == 0 || ((float) dimensionPixelSize) == this.mTextPaint.getTextSize())) {
              this.mTextPaint.setTextSize((float) dimensionPixelSize);
              requestLayout();
          }
          setSwitchTypefaceByIndex(obtainStyledAttributes.getInt(R.styleable.TextAppearance_android_typeface, -1), obtainStyledAttributes.getInt(R.styleable.TextAppearance_android_textStyle, -1));
          if (obtainStyledAttributes.getBoolean(R.styleable.TextAppearance_textAllCaps, false)) {
              this.mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext());
          } else {
              this.mSwitchTransformationMethod = null;
          }
          setTextOnInternal(this.mTextOn);
          setTextOffInternal(this.mTextOff);
          obtainStyledAttributes.recycle();
      }
  
      public void setSwitchTypeface(Typeface typeface) {
          if ((this.mTextPaint.getTypeface() != null && !this.mTextPaint.getTypeface().equals(typeface)) || (this.mTextPaint.getTypeface() == null && typeface != null)) {
              this.mTextPaint.setTypeface(typeface);
              requestLayout();
              invalidate();
          }
      }
  
      public void setSwitchTypeface(Typeface tf, int style) {
          float f = 0.0f;
          boolean z = false;
          if (style > 0) {
              Typeface tf2 = tf == null ? Typeface.defaultFromStyle(style) : Typeface.create(tf, style);
              setSwitchTypeface(tf2);
              int i = (~(tf2 != null ? tf2.getStyle() : 0)) & style;
              TextPaint textPaint = this.mTextPaint;
              if ((i & 1) != 0) {
                  z = true;
              }
              textPaint.setFakeBoldText(z);
              TextPaint textPaint2 = this.mTextPaint;
              if ((i & 2) != 0) {
                  f = -0.25f;
              }
              textPaint2.setTextSkewX(f);
              return;
          }
          this.mTextPaint.setFakeBoldText(false);
          this.mTextPaint.setTextSkewX(0.0f);
          setSwitchTypeface(tf);
      }
  
      public void setTextOff(CharSequence textOff) {
          setTextOffInternal(textOff);
          requestLayout();
          if (!isChecked()) {
              setOffStateDescriptionOnRAndAbove();
          }
      }
  
      public void setTextOn(CharSequence textOn) {
          setTextOnInternal(textOn);
          requestLayout();
          if (isChecked()) {
              setOnStateDescriptionOnRAndAbove();
          }
      }
  
      public void setThumbDrawable(Drawable thumb) {
          Drawable drawable = this.mThumbDrawable;
          if (drawable != null) {
              drawable.setCallback((Drawable.Callback) null);
          }
          this.mThumbDrawable = thumb;
          if (thumb != null) {
              thumb.setCallback(this);
          }
          requestLayout();
      }
  
      /* access modifiers changed from: package-private */
      public void setThumbPosition(float position) {
          this.mThumbPosition = position;
          invalidate();
      }
  
      public void setThumbResource(int resId) {
          setThumbDrawable(AppCompatResources.getDrawable(getContext(), resId));
      }
  
      public void setThumbTextPadding(int pixels) {
          this.mThumbTextPadding = pixels;
          requestLayout();
      }
  
      public void setThumbTintList(ColorStateList tint) {
          this.mThumbTintList = tint;
          this.mHasThumbTint = true;
          applyThumbTint();
      }
  
      public void setThumbTintMode(PorterDuff.Mode tintMode) {
          this.mThumbTintMode = tintMode;
          this.mHasThumbTintMode = true;
          applyThumbTint();
      }
  
      public void setTrackDrawable(Drawable track) {
          Drawable drawable = this.mTrackDrawable;
          if (drawable != null) {
              drawable.setCallback((Drawable.Callback) null);
          }
          this.mTrackDrawable = track;
          if (track != null) {
              track.setCallback(this);
          }
          requestLayout();
      }
  
      public void setTrackResource(int resId) {
          setTrackDrawable(AppCompatResources.getDrawable(getContext(), resId));
      }
  
      public void setTrackTintList(ColorStateList tint) {
          this.mTrackTintList = tint;
          this.mHasTrackTint = true;
          applyTrackTint();
      }
  
      public void setTrackTintMode(PorterDuff.Mode tintMode) {
          this.mTrackTintMode = tintMode;
          this.mHasTrackTintMode = true;
          applyTrackTint();
      }
  
      public void toggle() {
          setChecked(!isChecked());
      }
  
      /* access modifiers changed from: protected */
      public boolean verifyDrawable(Drawable who) {
          return super.verifyDrawable(who) || who == this.mThumbDrawable || who == this.mTrackDrawable;
      }
  }
  