1809 lines
		
	
	
		
			72 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			1809 lines
		
	
	
		
			72 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package com.google.android.material.slider;
 | |
| 
 | |
| import android.animation.Animator;
 | |
| import android.animation.AnimatorListenerAdapter;
 | |
| import android.animation.TimeInterpolator;
 | |
| import android.animation.ValueAnimator;
 | |
| import android.content.Context;
 | |
| import android.content.res.ColorStateList;
 | |
| import android.content.res.Resources;
 | |
| import android.content.res.TypedArray;
 | |
| import android.graphics.Canvas;
 | |
| import android.graphics.Paint;
 | |
| import android.graphics.PorterDuff;
 | |
| import android.graphics.PorterDuffXfermode;
 | |
| import android.graphics.Rect;
 | |
| import android.graphics.Region;
 | |
| import android.graphics.drawable.Drawable;
 | |
| import android.graphics.drawable.RippleDrawable;
 | |
| import android.os.Build;
 | |
| import android.os.Bundle;
 | |
| import android.os.Parcel;
 | |
| import android.os.Parcelable;
 | |
| import android.util.AttributeSet;
 | |
| import android.util.Log;
 | |
| import android.view.KeyEvent;
 | |
| import android.view.MotionEvent;
 | |
| import android.view.View;
 | |
| import android.view.ViewConfiguration;
 | |
| import android.view.ViewGroup;
 | |
| import android.view.ViewParent;
 | |
| import android.view.accessibility.AccessibilityManager;
 | |
| import android.widget.SeekBar;
 | |
| import androidx.appcompat.content.res.AppCompatResources;
 | |
| import androidx.constraintlayout.core.widgets.analyzer.BasicMeasure;
 | |
| import androidx.core.graphics.drawable.DrawableCompat;
 | |
| import androidx.core.math.MathUtils;
 | |
| import androidx.core.view.ViewCompat;
 | |
| import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
 | |
| import androidx.customview.widget.ExploreByTouchHelper;
 | |
| import com.google.android.material.R;
 | |
| import com.google.android.material.animation.AnimationUtils;
 | |
| import com.google.android.material.drawable.DrawableUtils;
 | |
| import com.google.android.material.internal.DescendantOffsetUtils;
 | |
| import com.google.android.material.internal.ThemeEnforcement;
 | |
| import com.google.android.material.internal.ViewOverlayImpl;
 | |
| import com.google.android.material.internal.ViewUtils;
 | |
| import com.google.android.material.motion.MotionUtils;
 | |
| import com.google.android.material.resources.MaterialResources;
 | |
| import com.google.android.material.shape.MaterialShapeDrawable;
 | |
| import com.google.android.material.shape.ShapeAppearanceModel;
 | |
| import com.google.android.material.slider.BaseOnChangeListener;
 | |
| import com.google.android.material.slider.BaseOnSliderTouchListener;
 | |
| import com.google.android.material.slider.BaseSlider;
 | |
| import com.google.android.material.theme.overlay.MaterialThemeOverlay;
 | |
| import com.google.android.material.tooltip.TooltipDrawable;
 | |
| import java.math.BigDecimal;
 | |
| import java.math.MathContext;
 | |
| import java.util.ArrayList;
 | |
| import java.util.Collections;
 | |
| import java.util.Iterator;
 | |
| import java.util.List;
 | |
| import java.util.Locale;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| abstract class BaseSlider<S extends BaseSlider<S, L, T>, L extends BaseOnChangeListener<S>, T extends BaseOnSliderTouchListener<S>> extends View {
 | |
|     private static final int DEFAULT_LABEL_ANIMATION_ENTER_DURATION = 83;
 | |
|     private static final int DEFAULT_LABEL_ANIMATION_EXIT_DURATION = 117;
 | |
|     private static final String EXCEPTION_ILLEGAL_DISCRETE_VALUE = "Value(%s) must be equal to valueFrom(%s) plus a multiple of stepSize(%s) when using stepSize(%s)";
 | |
|     private static final String EXCEPTION_ILLEGAL_MIN_SEPARATION = "minSeparation(%s) must be greater or equal to 0";
 | |
|     private static final String EXCEPTION_ILLEGAL_MIN_SEPARATION_STEP_SIZE = "minSeparation(%s) must be greater or equal and a multiple of stepSize(%s) when using stepSize(%s)";
 | |
|     private static final String EXCEPTION_ILLEGAL_MIN_SEPARATION_STEP_SIZE_UNIT = "minSeparation(%s) cannot be set as a dimension when using stepSize(%s)";
 | |
|     private static final String EXCEPTION_ILLEGAL_STEP_SIZE = "The stepSize(%s) must be 0, or a factor of the valueFrom(%s)-valueTo(%s) range";
 | |
|     private static final String EXCEPTION_ILLEGAL_VALUE = "Slider value(%s) must be greater or equal to valueFrom(%s), and lower or equal to valueTo(%s)";
 | |
|     private static final String EXCEPTION_ILLEGAL_VALUE_FROM = "valueFrom(%s) must be smaller than valueTo(%s)";
 | |
|     private static final String EXCEPTION_ILLEGAL_VALUE_TO = "valueTo(%s) must be greater than valueFrom(%s)";
 | |
|     private static final int HALO_ALPHA = 63;
 | |
|     private static final int MIN_TOUCH_TARGET_DP = 48;
 | |
|     private static final String TAG = "BaseSlider";
 | |
|     private static final double THRESHOLD = 1.0E-4d;
 | |
|     private static final int TIMEOUT_SEND_ACCESSIBILITY_EVENT = 200;
 | |
|     static final int UNIT_PX = 0;
 | |
|     static final int UNIT_VALUE = 1;
 | |
|     private static final String WARNING_FLOATING_POINT_ERROR = "Floating point value used for %s(%s). Using floats can have rounding errors which may result in incorrect values. Instead, consider using integers with a custom LabelFormatter to display the value correctly.";
 | |
|     private BaseSlider<S, L, T>.AccessibilityEventSender accessibilityEventSender;
 | |
|     private final AccessibilityHelper accessibilityHelper;
 | |
|     private final AccessibilityManager accessibilityManager;
 | |
|     private int activeThumbIdx;
 | |
|     private final Paint activeTicksPaint;
 | |
|     private final Paint activeTrackPaint;
 | |
|     private final List<L> changeListeners;
 | |
|     private Drawable customThumbDrawable;
 | |
|     private List<Drawable> customThumbDrawablesForValues;
 | |
|     private final MaterialShapeDrawable defaultThumbDrawable;
 | |
|     private int defaultThumbRadius;
 | |
|     private int defaultTickActiveRadius;
 | |
|     private int defaultTickInactiveRadius;
 | |
|     private int defaultTrackHeight;
 | |
|     private boolean dirtyConfig;
 | |
|     private int focusedThumbIdx;
 | |
|     private boolean forceDrawCompatHalo;
 | |
|     private LabelFormatter formatter;
 | |
|     private ColorStateList haloColor;
 | |
|     private final Paint haloPaint;
 | |
|     private int haloRadius;
 | |
|     private final Paint inactiveTicksPaint;
 | |
|     private final Paint inactiveTrackPaint;
 | |
|     private boolean isLongPress;
 | |
|     private int labelBehavior;
 | |
|     private int labelPadding;
 | |
|     private int labelStyle;
 | |
|     private final List<TooltipDrawable> labels;
 | |
|     private boolean labelsAreAnimatedIn;
 | |
|     private ValueAnimator labelsInAnimator;
 | |
|     private ValueAnimator labelsOutAnimator;
 | |
|     private MotionEvent lastEvent;
 | |
|     private int minTouchTargetSize;
 | |
|     private int minTrackSidePadding;
 | |
|     private int minWidgetHeight;
 | |
|     private final int scaledTouchSlop;
 | |
|     private int separationUnit;
 | |
|     private float stepSize;
 | |
|     private boolean thumbIsPressed;
 | |
|     private final Paint thumbPaint;
 | |
|     private int thumbRadius;
 | |
|     private int tickActiveRadius;
 | |
|     private ColorStateList tickColorActive;
 | |
|     private ColorStateList tickColorInactive;
 | |
|     private int tickInactiveRadius;
 | |
|     private boolean tickVisible;
 | |
|     private float[] ticksCoordinates;
 | |
|     private float touchDownX;
 | |
|     private final List<T> touchListeners;
 | |
|     private float touchPosition;
 | |
|     private ColorStateList trackColorActive;
 | |
|     private ColorStateList trackColorInactive;
 | |
|     private int trackHeight;
 | |
|     private int trackSidePadding;
 | |
|     private int trackWidth;
 | |
|     private float valueFrom;
 | |
|     private float valueTo;
 | |
|     private ArrayList<Float> values;
 | |
|     private int widgetHeight;
 | |
|     static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_Slider;
 | |
|     private static final int LABEL_ANIMATION_ENTER_DURATION_ATTR = R.attr.motionDurationMedium4;
 | |
|     private static final int LABEL_ANIMATION_EXIT_DURATION_ATTR = R.attr.motionDurationShort3;
 | |
|     private static final int LABEL_ANIMATION_ENTER_EASING_ATTR = R.attr.motionEasingEmphasizedInterpolator;
 | |
|     private static final int LABEL_ANIMATION_EXIT_EASING_ATTR = R.attr.motionEasingEmphasizedAccelerateInterpolator;
 | |
| 
 | |
|     private float calculateStepIncrement() {
 | |
|         float f = this.stepSize;
 | |
|         if (f == 0.0f) {
 | |
|             return 1.0f;
 | |
|         }
 | |
|         return f;
 | |
|     }
 | |
| 
 | |
|     private float dimenToValue(float f) {
 | |
|         if (f == 0.0f) {
 | |
|             return 0.0f;
 | |
|         }
 | |
|         float f2 = (f - this.trackSidePadding) / this.trackWidth;
 | |
|         float f3 = this.valueFrom;
 | |
|         return (f2 * (f3 - this.valueTo)) + f3;
 | |
|     }
 | |
| 
 | |
|     private boolean shouldAlwaysShowLabel() {
 | |
|         return this.labelBehavior == 3;
 | |
|     }
 | |
| 
 | |
|     void forceDrawCompatHalo(boolean z) {
 | |
|         this.forceDrawCompatHalo = z;
 | |
|     }
 | |
| 
 | |
|     public int getActiveThumbIndex() {
 | |
|         return this.activeThumbIdx;
 | |
|     }
 | |
| 
 | |
|     public int getFocusedThumbIndex() {
 | |
|         return this.focusedThumbIdx;
 | |
|     }
 | |
| 
 | |
|     public int getHaloRadius() {
 | |
|         return this.haloRadius;
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getHaloTintList() {
 | |
|         return this.haloColor;
 | |
|     }
 | |
| 
 | |
|     public int getLabelBehavior() {
 | |
|         return this.labelBehavior;
 | |
|     }
 | |
| 
 | |
|     protected float getMinSeparation() {
 | |
|         return 0.0f;
 | |
|     }
 | |
| 
 | |
|     public float getStepSize() {
 | |
|         return this.stepSize;
 | |
|     }
 | |
| 
 | |
|     public int getThumbRadius() {
 | |
|         return this.thumbRadius;
 | |
|     }
 | |
| 
 | |
|     public int getTickActiveRadius() {
 | |
|         return this.tickActiveRadius;
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getTickActiveTintList() {
 | |
|         return this.tickColorActive;
 | |
|     }
 | |
| 
 | |
|     public int getTickInactiveRadius() {
 | |
|         return this.tickInactiveRadius;
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getTickInactiveTintList() {
 | |
|         return this.tickColorInactive;
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getTrackActiveTintList() {
 | |
|         return this.trackColorActive;
 | |
|     }
 | |
| 
 | |
|     public int getTrackHeight() {
 | |
|         return this.trackHeight;
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getTrackInactiveTintList() {
 | |
|         return this.trackColorInactive;
 | |
|     }
 | |
| 
 | |
|     public int getTrackSidePadding() {
 | |
|         return this.trackSidePadding;
 | |
|     }
 | |
| 
 | |
|     public int getTrackWidth() {
 | |
|         return this.trackWidth;
 | |
|     }
 | |
| 
 | |
|     public float getValueFrom() {
 | |
|         return this.valueFrom;
 | |
|     }
 | |
| 
 | |
|     public float getValueTo() {
 | |
|         return this.valueTo;
 | |
|     }
 | |
| 
 | |
|     public boolean hasLabelFormatter() {
 | |
|         return this.formatter != null;
 | |
|     }
 | |
| 
 | |
|     public boolean isTickVisible() {
 | |
|         return this.tickVisible;
 | |
|     }
 | |
| 
 | |
|     protected void setActiveThumbIndex(int i) {
 | |
|         this.activeThumbIdx = i;
 | |
|     }
 | |
| 
 | |
|     public void setLabelFormatter(LabelFormatter labelFormatter) {
 | |
|         this.formatter = labelFormatter;
 | |
|     }
 | |
| 
 | |
|     public BaseSlider(Context context) {
 | |
|         this(context, null);
 | |
|     }
 | |
| 
 | |
|     public BaseSlider(Context context, AttributeSet attributeSet) {
 | |
|         this(context, attributeSet, R.attr.sliderStyle);
 | |
|     }
 | |
| 
 | |
|     public BaseSlider(Context context, AttributeSet attributeSet, int i) {
 | |
|         super(MaterialThemeOverlay.wrap(context, attributeSet, i, DEF_STYLE_RES), attributeSet, i);
 | |
|         this.labels = new ArrayList();
 | |
|         this.changeListeners = new ArrayList();
 | |
|         this.touchListeners = new ArrayList();
 | |
|         this.labelsAreAnimatedIn = false;
 | |
|         this.thumbIsPressed = false;
 | |
|         this.values = new ArrayList<>();
 | |
|         this.activeThumbIdx = -1;
 | |
|         this.focusedThumbIdx = -1;
 | |
|         this.stepSize = 0.0f;
 | |
|         this.tickVisible = true;
 | |
|         this.isLongPress = false;
 | |
|         MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable();
 | |
|         this.defaultThumbDrawable = materialShapeDrawable;
 | |
|         this.customThumbDrawablesForValues = Collections.emptyList();
 | |
|         this.separationUnit = 0;
 | |
|         Context context2 = getContext();
 | |
|         Paint paint = new Paint();
 | |
|         this.inactiveTrackPaint = paint;
 | |
|         paint.setStyle(Paint.Style.STROKE);
 | |
|         paint.setStrokeCap(Paint.Cap.ROUND);
 | |
|         Paint paint2 = new Paint();
 | |
|         this.activeTrackPaint = paint2;
 | |
|         paint2.setStyle(Paint.Style.STROKE);
 | |
|         paint2.setStrokeCap(Paint.Cap.ROUND);
 | |
|         Paint paint3 = new Paint(1);
 | |
|         this.thumbPaint = paint3;
 | |
|         paint3.setStyle(Paint.Style.FILL);
 | |
|         paint3.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
 | |
|         Paint paint4 = new Paint(1);
 | |
|         this.haloPaint = paint4;
 | |
|         paint4.setStyle(Paint.Style.FILL);
 | |
|         Paint paint5 = new Paint();
 | |
|         this.inactiveTicksPaint = paint5;
 | |
|         paint5.setStyle(Paint.Style.STROKE);
 | |
|         paint5.setStrokeCap(Paint.Cap.ROUND);
 | |
|         Paint paint6 = new Paint();
 | |
|         this.activeTicksPaint = paint6;
 | |
|         paint6.setStyle(Paint.Style.STROKE);
 | |
|         paint6.setStrokeCap(Paint.Cap.ROUND);
 | |
|         loadResources(context2.getResources());
 | |
|         processAttributes(context2, attributeSet, i);
 | |
|         setFocusable(true);
 | |
|         setClickable(true);
 | |
|         materialShapeDrawable.setShadowCompatibilityMode(2);
 | |
|         this.scaledTouchSlop = ViewConfiguration.get(context2).getScaledTouchSlop();
 | |
|         AccessibilityHelper accessibilityHelper = new AccessibilityHelper(this);
 | |
|         this.accessibilityHelper = accessibilityHelper;
 | |
|         ViewCompat.setAccessibilityDelegate(this, accessibilityHelper);
 | |
|         this.accessibilityManager = (AccessibilityManager) getContext().getSystemService("accessibility");
 | |
|     }
 | |
| 
 | |
|     private void loadResources(Resources resources) {
 | |
|         this.minWidgetHeight = resources.getDimensionPixelSize(R.dimen.mtrl_slider_widget_height);
 | |
|         int dimensionPixelOffset = resources.getDimensionPixelOffset(R.dimen.mtrl_slider_track_side_padding);
 | |
|         this.minTrackSidePadding = dimensionPixelOffset;
 | |
|         this.trackSidePadding = dimensionPixelOffset;
 | |
|         this.defaultThumbRadius = resources.getDimensionPixelSize(R.dimen.mtrl_slider_thumb_radius);
 | |
|         this.defaultTrackHeight = resources.getDimensionPixelSize(R.dimen.mtrl_slider_track_height);
 | |
|         this.defaultTickActiveRadius = resources.getDimensionPixelSize(R.dimen.mtrl_slider_tick_radius);
 | |
|         this.defaultTickInactiveRadius = resources.getDimensionPixelSize(R.dimen.mtrl_slider_tick_radius);
 | |
|         this.labelPadding = resources.getDimensionPixelSize(R.dimen.mtrl_slider_label_padding);
 | |
|     }
 | |
| 
 | |
|     private void processAttributes(Context context, AttributeSet attributeSet, int i) {
 | |
|         TypedArray obtainStyledAttributes = ThemeEnforcement.obtainStyledAttributes(context, attributeSet, R.styleable.Slider, i, DEF_STYLE_RES, new int[0]);
 | |
|         this.labelStyle = obtainStyledAttributes.getResourceId(R.styleable.Slider_labelStyle, R.style.Widget_MaterialComponents_Tooltip);
 | |
|         this.valueFrom = obtainStyledAttributes.getFloat(R.styleable.Slider_android_valueFrom, 0.0f);
 | |
|         this.valueTo = obtainStyledAttributes.getFloat(R.styleable.Slider_android_valueTo, 1.0f);
 | |
|         setValues(Float.valueOf(this.valueFrom));
 | |
|         this.stepSize = obtainStyledAttributes.getFloat(R.styleable.Slider_android_stepSize, 0.0f);
 | |
|         this.minTouchTargetSize = (int) Math.ceil(obtainStyledAttributes.getDimension(R.styleable.Slider_minTouchTargetSize, (float) Math.ceil(ViewUtils.dpToPx(getContext(), 48))));
 | |
|         boolean hasValue = obtainStyledAttributes.hasValue(R.styleable.Slider_trackColor);
 | |
|         int i2 = hasValue ? R.styleable.Slider_trackColor : R.styleable.Slider_trackColorInactive;
 | |
|         int i3 = hasValue ? R.styleable.Slider_trackColor : R.styleable.Slider_trackColorActive;
 | |
|         ColorStateList colorStateList = MaterialResources.getColorStateList(context, obtainStyledAttributes, i2);
 | |
|         if (colorStateList == null) {
 | |
|             colorStateList = AppCompatResources.getColorStateList(context, R.color.material_slider_inactive_track_color);
 | |
|         }
 | |
|         setTrackInactiveTintList(colorStateList);
 | |
|         ColorStateList colorStateList2 = MaterialResources.getColorStateList(context, obtainStyledAttributes, i3);
 | |
|         if (colorStateList2 == null) {
 | |
|             colorStateList2 = AppCompatResources.getColorStateList(context, R.color.material_slider_active_track_color);
 | |
|         }
 | |
|         setTrackActiveTintList(colorStateList2);
 | |
|         this.defaultThumbDrawable.setFillColor(MaterialResources.getColorStateList(context, obtainStyledAttributes, R.styleable.Slider_thumbColor));
 | |
|         if (obtainStyledAttributes.hasValue(R.styleable.Slider_thumbStrokeColor)) {
 | |
|             setThumbStrokeColor(MaterialResources.getColorStateList(context, obtainStyledAttributes, R.styleable.Slider_thumbStrokeColor));
 | |
|         }
 | |
|         setThumbStrokeWidth(obtainStyledAttributes.getDimension(R.styleable.Slider_thumbStrokeWidth, 0.0f));
 | |
|         ColorStateList colorStateList3 = MaterialResources.getColorStateList(context, obtainStyledAttributes, R.styleable.Slider_haloColor);
 | |
|         if (colorStateList3 == null) {
 | |
|             colorStateList3 = AppCompatResources.getColorStateList(context, R.color.material_slider_halo_color);
 | |
|         }
 | |
|         setHaloTintList(colorStateList3);
 | |
|         this.tickVisible = obtainStyledAttributes.getBoolean(R.styleable.Slider_tickVisible, true);
 | |
|         boolean hasValue2 = obtainStyledAttributes.hasValue(R.styleable.Slider_tickColor);
 | |
|         int i4 = hasValue2 ? R.styleable.Slider_tickColor : R.styleable.Slider_tickColorInactive;
 | |
|         int i5 = hasValue2 ? R.styleable.Slider_tickColor : R.styleable.Slider_tickColorActive;
 | |
|         ColorStateList colorStateList4 = MaterialResources.getColorStateList(context, obtainStyledAttributes, i4);
 | |
|         if (colorStateList4 == null) {
 | |
|             colorStateList4 = AppCompatResources.getColorStateList(context, R.color.material_slider_inactive_tick_marks_color);
 | |
|         }
 | |
|         setTickInactiveTintList(colorStateList4);
 | |
|         ColorStateList colorStateList5 = MaterialResources.getColorStateList(context, obtainStyledAttributes, i5);
 | |
|         if (colorStateList5 == null) {
 | |
|             colorStateList5 = AppCompatResources.getColorStateList(context, R.color.material_slider_active_tick_marks_color);
 | |
|         }
 | |
|         setTickActiveTintList(colorStateList5);
 | |
|         setThumbRadius(obtainStyledAttributes.getDimensionPixelSize(R.styleable.Slider_thumbRadius, 0));
 | |
|         setHaloRadius(obtainStyledAttributes.getDimensionPixelSize(R.styleable.Slider_haloRadius, 0));
 | |
|         setThumbElevation(obtainStyledAttributes.getDimension(R.styleable.Slider_thumbElevation, 0.0f));
 | |
|         setTrackHeight(obtainStyledAttributes.getDimensionPixelSize(R.styleable.Slider_trackHeight, 0));
 | |
|         setTickActiveRadius(obtainStyledAttributes.getDimensionPixelSize(R.styleable.Slider_tickRadiusActive, 0));
 | |
|         setTickInactiveRadius(obtainStyledAttributes.getDimensionPixelSize(R.styleable.Slider_tickRadiusInactive, 0));
 | |
|         setLabelBehavior(obtainStyledAttributes.getInt(R.styleable.Slider_labelBehavior, 0));
 | |
|         if (!obtainStyledAttributes.getBoolean(R.styleable.Slider_android_enabled, true)) {
 | |
|             setEnabled(false);
 | |
|         }
 | |
|         obtainStyledAttributes.recycle();
 | |
|     }
 | |
| 
 | |
|     private boolean maybeIncreaseTrackSidePadding() {
 | |
|         int max = this.minTrackSidePadding + Math.max(Math.max(Math.max(this.thumbRadius - this.defaultThumbRadius, 0), Math.max((this.trackHeight - this.defaultTrackHeight) / 2, 0)), Math.max(Math.max(this.tickActiveRadius - this.defaultTickActiveRadius, 0), Math.max(this.tickInactiveRadius - this.defaultTickInactiveRadius, 0)));
 | |
|         if (this.trackSidePadding == max) {
 | |
|             return false;
 | |
|         }
 | |
|         this.trackSidePadding = max;
 | |
|         if (!ViewCompat.isLaidOut(this)) {
 | |
|             return true;
 | |
|         }
 | |
|         updateTrackWidth(getWidth());
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     private void validateValueFrom() {
 | |
|         if (this.valueFrom >= this.valueTo) {
 | |
|             throw new IllegalStateException(String.format(EXCEPTION_ILLEGAL_VALUE_FROM, Float.valueOf(this.valueFrom), Float.valueOf(this.valueTo)));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void validateValueTo() {
 | |
|         if (this.valueTo <= this.valueFrom) {
 | |
|             throw new IllegalStateException(String.format(EXCEPTION_ILLEGAL_VALUE_TO, Float.valueOf(this.valueTo), Float.valueOf(this.valueFrom)));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private boolean valueLandsOnTick(float f) {
 | |
|         return isMultipleOfStepSize(f - this.valueFrom);
 | |
|     }
 | |
| 
 | |
|     private boolean isMultipleOfStepSize(float f) {
 | |
|         double doubleValue = new BigDecimal(Float.toString(f)).divide(new BigDecimal(Float.toString(this.stepSize)), MathContext.DECIMAL64).doubleValue();
 | |
|         return Math.abs(((double) Math.round(doubleValue)) - doubleValue) < THRESHOLD;
 | |
|     }
 | |
| 
 | |
|     private void validateStepSize() {
 | |
|         if (this.stepSize > 0.0f && !valueLandsOnTick(this.valueTo)) {
 | |
|             throw new IllegalStateException(String.format(EXCEPTION_ILLEGAL_STEP_SIZE, Float.valueOf(this.stepSize), Float.valueOf(this.valueFrom), Float.valueOf(this.valueTo)));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void validateValues() {
 | |
|         Iterator<Float> it = this.values.iterator();
 | |
|         while (it.hasNext()) {
 | |
|             Float next = it.next();
 | |
|             if (next.floatValue() < this.valueFrom || next.floatValue() > this.valueTo) {
 | |
|                 throw new IllegalStateException(String.format(EXCEPTION_ILLEGAL_VALUE, next, Float.valueOf(this.valueFrom), Float.valueOf(this.valueTo)));
 | |
|             }
 | |
|             if (this.stepSize > 0.0f && !valueLandsOnTick(next.floatValue())) {
 | |
|                 throw new IllegalStateException(String.format(EXCEPTION_ILLEGAL_DISCRETE_VALUE, next, Float.valueOf(this.valueFrom), Float.valueOf(this.stepSize), Float.valueOf(this.stepSize)));
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void validateMinSeparation() {
 | |
|         float minSeparation = getMinSeparation();
 | |
|         if (minSeparation < 0.0f) {
 | |
|             throw new IllegalStateException(String.format(EXCEPTION_ILLEGAL_MIN_SEPARATION, Float.valueOf(minSeparation)));
 | |
|         }
 | |
|         float f = this.stepSize;
 | |
|         if (f <= 0.0f || minSeparation <= 0.0f) {
 | |
|             return;
 | |
|         }
 | |
|         if (this.separationUnit != 1) {
 | |
|             throw new IllegalStateException(String.format(EXCEPTION_ILLEGAL_MIN_SEPARATION_STEP_SIZE_UNIT, Float.valueOf(minSeparation), Float.valueOf(this.stepSize)));
 | |
|         }
 | |
|         if (minSeparation < f || !isMultipleOfStepSize(minSeparation)) {
 | |
|             throw new IllegalStateException(String.format(EXCEPTION_ILLEGAL_MIN_SEPARATION_STEP_SIZE, Float.valueOf(minSeparation), Float.valueOf(this.stepSize), Float.valueOf(this.stepSize)));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void warnAboutFloatingPointError() {
 | |
|         float f = this.stepSize;
 | |
|         if (f == 0.0f) {
 | |
|             return;
 | |
|         }
 | |
|         if (((int) f) != f) {
 | |
|             Log.w(TAG, String.format(WARNING_FLOATING_POINT_ERROR, "stepSize", Float.valueOf(f)));
 | |
|         }
 | |
|         float f2 = this.valueFrom;
 | |
|         if (((int) f2) != f2) {
 | |
|             Log.w(TAG, String.format(WARNING_FLOATING_POINT_ERROR, "valueFrom", Float.valueOf(f2)));
 | |
|         }
 | |
|         float f3 = this.valueTo;
 | |
|         if (((int) f3) != f3) {
 | |
|             Log.w(TAG, String.format(WARNING_FLOATING_POINT_ERROR, "valueTo", Float.valueOf(f3)));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void validateConfigurationIfDirty() {
 | |
|         if (this.dirtyConfig) {
 | |
|             validateValueFrom();
 | |
|             validateValueTo();
 | |
|             validateStepSize();
 | |
|             validateValues();
 | |
|             validateMinSeparation();
 | |
|             warnAboutFloatingPointError();
 | |
|             this.dirtyConfig = false;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setValueFrom(float f) {
 | |
|         this.valueFrom = f;
 | |
|         this.dirtyConfig = true;
 | |
|         postInvalidate();
 | |
|     }
 | |
| 
 | |
|     public void setValueTo(float f) {
 | |
|         this.valueTo = f;
 | |
|         this.dirtyConfig = true;
 | |
|         postInvalidate();
 | |
|     }
 | |
| 
 | |
|     List<Float> getValues() {
 | |
|         return new ArrayList(this.values);
 | |
|     }
 | |
| 
 | |
|     void setValues(Float... fArr) {
 | |
|         ArrayList<Float> arrayList = new ArrayList<>();
 | |
|         Collections.addAll(arrayList, fArr);
 | |
|         setValuesInternal(arrayList);
 | |
|     }
 | |
| 
 | |
|     void setValues(List<Float> list) {
 | |
|         setValuesInternal(new ArrayList<>(list));
 | |
|     }
 | |
| 
 | |
|     private void setValuesInternal(ArrayList<Float> arrayList) {
 | |
|         if (arrayList.isEmpty()) {
 | |
|             throw new IllegalArgumentException("At least one value must be set");
 | |
|         }
 | |
|         Collections.sort(arrayList);
 | |
|         if (this.values.size() == arrayList.size() && this.values.equals(arrayList)) {
 | |
|             return;
 | |
|         }
 | |
|         this.values = arrayList;
 | |
|         this.dirtyConfig = true;
 | |
|         this.focusedThumbIdx = 0;
 | |
|         updateHaloHotspot();
 | |
|         createLabelPool();
 | |
|         dispatchOnChangedProgrammatically();
 | |
|         postInvalidate();
 | |
|     }
 | |
| 
 | |
|     private void createLabelPool() {
 | |
|         if (this.labels.size() > this.values.size()) {
 | |
|             List<TooltipDrawable> subList = this.labels.subList(this.values.size(), this.labels.size());
 | |
|             for (TooltipDrawable tooltipDrawable : subList) {
 | |
|                 if (ViewCompat.isAttachedToWindow(this)) {
 | |
|                     detachLabelFromContentView(tooltipDrawable);
 | |
|                 }
 | |
|             }
 | |
|             subList.clear();
 | |
|         }
 | |
|         while (true) {
 | |
|             if (this.labels.size() >= this.values.size()) {
 | |
|                 break;
 | |
|             }
 | |
|             TooltipDrawable createFromAttributes = TooltipDrawable.createFromAttributes(getContext(), null, 0, this.labelStyle);
 | |
|             this.labels.add(createFromAttributes);
 | |
|             if (ViewCompat.isAttachedToWindow(this)) {
 | |
|                 attachLabelToContentView(createFromAttributes);
 | |
|             }
 | |
|         }
 | |
|         int i = this.labels.size() != 1 ? 1 : 0;
 | |
|         Iterator<TooltipDrawable> it = this.labels.iterator();
 | |
|         while (it.hasNext()) {
 | |
|             it.next().setStrokeWidth(i);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setStepSize(float f) {
 | |
|         if (f < 0.0f) {
 | |
|             throw new IllegalArgumentException(String.format(EXCEPTION_ILLEGAL_STEP_SIZE, Float.valueOf(f), Float.valueOf(this.valueFrom), Float.valueOf(this.valueTo)));
 | |
|         }
 | |
|         if (this.stepSize != f) {
 | |
|             this.stepSize = f;
 | |
|             this.dirtyConfig = true;
 | |
|             postInvalidate();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     void setCustomThumbDrawable(int i) {
 | |
|         setCustomThumbDrawable(getResources().getDrawable(i));
 | |
|     }
 | |
| 
 | |
|     void setCustomThumbDrawable(Drawable drawable) {
 | |
|         this.customThumbDrawable = initializeCustomThumbDrawable(drawable);
 | |
|         this.customThumbDrawablesForValues.clear();
 | |
|         postInvalidate();
 | |
|     }
 | |
| 
 | |
|     void setCustomThumbDrawablesForValues(int... iArr) {
 | |
|         Drawable[] drawableArr = new Drawable[iArr.length];
 | |
|         for (int i = 0; i < iArr.length; i++) {
 | |
|             drawableArr[i] = getResources().getDrawable(iArr[i]);
 | |
|         }
 | |
|         setCustomThumbDrawablesForValues(drawableArr);
 | |
|     }
 | |
| 
 | |
|     void setCustomThumbDrawablesForValues(Drawable... drawableArr) {
 | |
|         this.customThumbDrawable = null;
 | |
|         this.customThumbDrawablesForValues = new ArrayList();
 | |
|         for (Drawable drawable : drawableArr) {
 | |
|             this.customThumbDrawablesForValues.add(initializeCustomThumbDrawable(drawable));
 | |
|         }
 | |
|         postInvalidate();
 | |
|     }
 | |
| 
 | |
|     private Drawable initializeCustomThumbDrawable(Drawable drawable) {
 | |
|         Drawable newDrawable = drawable.mutate().getConstantState().newDrawable();
 | |
|         adjustCustomThumbDrawableBounds(newDrawable);
 | |
|         return newDrawable;
 | |
|     }
 | |
| 
 | |
|     private void adjustCustomThumbDrawableBounds(Drawable drawable) {
 | |
|         int i = this.thumbRadius * 2;
 | |
|         int intrinsicWidth = drawable.getIntrinsicWidth();
 | |
|         int intrinsicHeight = drawable.getIntrinsicHeight();
 | |
|         if (intrinsicWidth == -1 && intrinsicHeight == -1) {
 | |
|             drawable.setBounds(0, 0, i, i);
 | |
|         } else {
 | |
|             float max = i / Math.max(intrinsicWidth, intrinsicHeight);
 | |
|             drawable.setBounds(0, 0, (int) (intrinsicWidth * max), (int) (intrinsicHeight * max));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setFocusedThumbIndex(int i) {
 | |
|         if (i < 0 || i >= this.values.size()) {
 | |
|             throw new IllegalArgumentException("index out of range");
 | |
|         }
 | |
|         this.focusedThumbIdx = i;
 | |
|         this.accessibilityHelper.requestKeyboardFocusForVirtualView(i);
 | |
|         postInvalidate();
 | |
|     }
 | |
| 
 | |
|     public void addOnChangeListener(L l) {
 | |
|         this.changeListeners.add(l);
 | |
|     }
 | |
| 
 | |
|     public void removeOnChangeListener(L l) {
 | |
|         this.changeListeners.remove(l);
 | |
|     }
 | |
| 
 | |
|     public void clearOnChangeListeners() {
 | |
|         this.changeListeners.clear();
 | |
|     }
 | |
| 
 | |
|     public void addOnSliderTouchListener(T t) {
 | |
|         this.touchListeners.add(t);
 | |
|     }
 | |
| 
 | |
|     public void removeOnSliderTouchListener(T t) {
 | |
|         this.touchListeners.remove(t);
 | |
|     }
 | |
| 
 | |
|     public void clearOnSliderTouchListeners() {
 | |
|         this.touchListeners.clear();
 | |
|     }
 | |
| 
 | |
|     public float getThumbElevation() {
 | |
|         return this.defaultThumbDrawable.getElevation();
 | |
|     }
 | |
| 
 | |
|     public void setThumbElevation(float f) {
 | |
|         this.defaultThumbDrawable.setElevation(f);
 | |
|     }
 | |
| 
 | |
|     public void setThumbElevationResource(int i) {
 | |
|         setThumbElevation(getResources().getDimension(i));
 | |
|     }
 | |
| 
 | |
|     public void setThumbRadius(int i) {
 | |
|         if (i == this.thumbRadius) {
 | |
|             return;
 | |
|         }
 | |
|         this.thumbRadius = i;
 | |
|         this.defaultThumbDrawable.setShapeAppearanceModel(ShapeAppearanceModel.builder().setAllCorners(0, this.thumbRadius).build());
 | |
|         MaterialShapeDrawable materialShapeDrawable = this.defaultThumbDrawable;
 | |
|         int i2 = this.thumbRadius;
 | |
|         materialShapeDrawable.setBounds(0, 0, i2 * 2, i2 * 2);
 | |
|         Drawable drawable = this.customThumbDrawable;
 | |
|         if (drawable != null) {
 | |
|             adjustCustomThumbDrawableBounds(drawable);
 | |
|         }
 | |
|         Iterator<Drawable> it = this.customThumbDrawablesForValues.iterator();
 | |
|         while (it.hasNext()) {
 | |
|             adjustCustomThumbDrawableBounds(it.next());
 | |
|         }
 | |
|         updateWidgetLayout();
 | |
|     }
 | |
| 
 | |
|     public void setThumbRadiusResource(int i) {
 | |
|         setThumbRadius(getResources().getDimensionPixelSize(i));
 | |
|     }
 | |
| 
 | |
|     public void setThumbStrokeColor(ColorStateList colorStateList) {
 | |
|         this.defaultThumbDrawable.setStrokeColor(colorStateList);
 | |
|         postInvalidate();
 | |
|     }
 | |
| 
 | |
|     public void setThumbStrokeColorResource(int i) {
 | |
|         if (i != 0) {
 | |
|             setThumbStrokeColor(AppCompatResources.getColorStateList(getContext(), i));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getThumbStrokeColor() {
 | |
|         return this.defaultThumbDrawable.getStrokeColor();
 | |
|     }
 | |
| 
 | |
|     public void setThumbStrokeWidth(float f) {
 | |
|         this.defaultThumbDrawable.setStrokeWidth(f);
 | |
|         postInvalidate();
 | |
|     }
 | |
| 
 | |
|     public void setThumbStrokeWidthResource(int i) {
 | |
|         if (i != 0) {
 | |
|             setThumbStrokeWidth(getResources().getDimension(i));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public float getThumbStrokeWidth() {
 | |
|         return this.defaultThumbDrawable.getStrokeWidth();
 | |
|     }
 | |
| 
 | |
|     public void setHaloRadius(int i) {
 | |
|         if (i == this.haloRadius) {
 | |
|             return;
 | |
|         }
 | |
|         this.haloRadius = i;
 | |
|         Drawable background = getBackground();
 | |
|         if (!shouldDrawCompatHalo() && (background instanceof RippleDrawable)) {
 | |
|             DrawableUtils.setRippleDrawableRadius((RippleDrawable) background, this.haloRadius);
 | |
|         } else {
 | |
|             postInvalidate();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setHaloRadiusResource(int i) {
 | |
|         setHaloRadius(getResources().getDimensionPixelSize(i));
 | |
|     }
 | |
| 
 | |
|     public void setLabelBehavior(int i) {
 | |
|         if (this.labelBehavior != i) {
 | |
|             this.labelBehavior = i;
 | |
|             requestLayout();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setTrackHeight(int i) {
 | |
|         if (this.trackHeight != i) {
 | |
|             this.trackHeight = i;
 | |
|             invalidateTrack();
 | |
|             updateWidgetLayout();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setTickActiveRadius(int i) {
 | |
|         if (this.tickActiveRadius != i) {
 | |
|             this.tickActiveRadius = i;
 | |
|             this.activeTicksPaint.setStrokeWidth(i * 2);
 | |
|             updateWidgetLayout();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setTickInactiveRadius(int i) {
 | |
|         if (this.tickInactiveRadius != i) {
 | |
|             this.tickInactiveRadius = i;
 | |
|             this.inactiveTicksPaint.setStrokeWidth(i * 2);
 | |
|             updateWidgetLayout();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void updateWidgetLayout() {
 | |
|         boolean maybeIncreaseWidgetHeight = maybeIncreaseWidgetHeight();
 | |
|         boolean maybeIncreaseTrackSidePadding = maybeIncreaseTrackSidePadding();
 | |
|         if (maybeIncreaseWidgetHeight) {
 | |
|             requestLayout();
 | |
|         } else if (maybeIncreaseTrackSidePadding) {
 | |
|             postInvalidate();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private boolean maybeIncreaseWidgetHeight() {
 | |
|         int max = Math.max(this.minWidgetHeight, Math.max(this.trackHeight + getPaddingTop() + getPaddingBottom(), (this.thumbRadius * 2) + getPaddingTop() + getPaddingBottom()));
 | |
|         if (max == this.widgetHeight) {
 | |
|             return false;
 | |
|         }
 | |
|         this.widgetHeight = max;
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     public void setHaloTintList(ColorStateList colorStateList) {
 | |
|         if (colorStateList.equals(this.haloColor)) {
 | |
|             return;
 | |
|         }
 | |
|         this.haloColor = colorStateList;
 | |
|         Drawable background = getBackground();
 | |
|         if (!shouldDrawCompatHalo() && (background instanceof RippleDrawable)) {
 | |
|             ((RippleDrawable) background).setColor(colorStateList);
 | |
|             return;
 | |
|         }
 | |
|         this.haloPaint.setColor(getColorForState(colorStateList));
 | |
|         this.haloPaint.setAlpha(63);
 | |
|         invalidate();
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getThumbTintList() {
 | |
|         return this.defaultThumbDrawable.getFillColor();
 | |
|     }
 | |
| 
 | |
|     public void setThumbTintList(ColorStateList colorStateList) {
 | |
|         if (colorStateList.equals(this.defaultThumbDrawable.getFillColor())) {
 | |
|             return;
 | |
|         }
 | |
|         this.defaultThumbDrawable.setFillColor(colorStateList);
 | |
|         invalidate();
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getTickTintList() {
 | |
|         if (this.tickColorInactive.equals(this.tickColorActive)) {
 | |
|             return this.tickColorActive;
 | |
|         }
 | |
|         throw new IllegalStateException("The inactive and active ticks are different colors. Use the getTickColorInactive() and getTickColorActive() methods instead.");
 | |
|     }
 | |
| 
 | |
|     public void setTickTintList(ColorStateList colorStateList) {
 | |
|         setTickInactiveTintList(colorStateList);
 | |
|         setTickActiveTintList(colorStateList);
 | |
|     }
 | |
| 
 | |
|     public void setTickActiveTintList(ColorStateList colorStateList) {
 | |
|         if (colorStateList.equals(this.tickColorActive)) {
 | |
|             return;
 | |
|         }
 | |
|         this.tickColorActive = colorStateList;
 | |
|         this.activeTicksPaint.setColor(getColorForState(colorStateList));
 | |
|         invalidate();
 | |
|     }
 | |
| 
 | |
|     public void setTickInactiveTintList(ColorStateList colorStateList) {
 | |
|         if (colorStateList.equals(this.tickColorInactive)) {
 | |
|             return;
 | |
|         }
 | |
|         this.tickColorInactive = colorStateList;
 | |
|         this.inactiveTicksPaint.setColor(getColorForState(colorStateList));
 | |
|         invalidate();
 | |
|     }
 | |
| 
 | |
|     public void setTickVisible(boolean z) {
 | |
|         if (this.tickVisible != z) {
 | |
|             this.tickVisible = z;
 | |
|             postInvalidate();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getTrackTintList() {
 | |
|         if (this.trackColorInactive.equals(this.trackColorActive)) {
 | |
|             return this.trackColorActive;
 | |
|         }
 | |
|         throw new IllegalStateException("The inactive and active parts of the track are different colors. Use the getInactiveTrackColor() and getActiveTrackColor() methods instead.");
 | |
|     }
 | |
| 
 | |
|     public void setTrackTintList(ColorStateList colorStateList) {
 | |
|         setTrackInactiveTintList(colorStateList);
 | |
|         setTrackActiveTintList(colorStateList);
 | |
|     }
 | |
| 
 | |
|     public void setTrackActiveTintList(ColorStateList colorStateList) {
 | |
|         if (colorStateList.equals(this.trackColorActive)) {
 | |
|             return;
 | |
|         }
 | |
|         this.trackColorActive = colorStateList;
 | |
|         this.activeTrackPaint.setColor(getColorForState(colorStateList));
 | |
|         invalidate();
 | |
|     }
 | |
| 
 | |
|     public void setTrackInactiveTintList(ColorStateList colorStateList) {
 | |
|         if (colorStateList.equals(this.trackColorInactive)) {
 | |
|             return;
 | |
|         }
 | |
|         this.trackColorInactive = colorStateList;
 | |
|         this.inactiveTrackPaint.setColor(getColorForState(colorStateList));
 | |
|         invalidate();
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected void onVisibilityChanged(View view, int i) {
 | |
|         ViewOverlayImpl contentViewOverlay;
 | |
|         super.onVisibilityChanged(view, i);
 | |
|         if (i == 0 || (contentViewOverlay = ViewUtils.getContentViewOverlay(this)) == null) {
 | |
|             return;
 | |
|         }
 | |
|         Iterator<TooltipDrawable> it = this.labels.iterator();
 | |
|         while (it.hasNext()) {
 | |
|             contentViewOverlay.remove(it.next());
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public void setEnabled(boolean z) {
 | |
|         super.setEnabled(z);
 | |
|         setLayerType(z ? 0 : 2, null);
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected void onAttachedToWindow() {
 | |
|         super.onAttachedToWindow();
 | |
|         Iterator<TooltipDrawable> it = this.labels.iterator();
 | |
|         while (it.hasNext()) {
 | |
|             attachLabelToContentView(it.next());
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void attachLabelToContentView(TooltipDrawable tooltipDrawable) {
 | |
|         tooltipDrawable.setRelativeToView(ViewUtils.getContentView(this));
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected void onDetachedFromWindow() {
 | |
|         BaseSlider<S, L, T>.AccessibilityEventSender accessibilityEventSender = this.accessibilityEventSender;
 | |
|         if (accessibilityEventSender != null) {
 | |
|             removeCallbacks(accessibilityEventSender);
 | |
|         }
 | |
|         this.labelsAreAnimatedIn = false;
 | |
|         Iterator<TooltipDrawable> it = this.labels.iterator();
 | |
|         while (it.hasNext()) {
 | |
|             detachLabelFromContentView(it.next());
 | |
|         }
 | |
|         super.onDetachedFromWindow();
 | |
|     }
 | |
| 
 | |
|     private void detachLabelFromContentView(TooltipDrawable tooltipDrawable) {
 | |
|         ViewOverlayImpl contentViewOverlay = ViewUtils.getContentViewOverlay(this);
 | |
|         if (contentViewOverlay != null) {
 | |
|             contentViewOverlay.remove(tooltipDrawable);
 | |
|             tooltipDrawable.detachView(ViewUtils.getContentView(this));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected void onMeasure(int i, int i2) {
 | |
|         super.onMeasure(i, View.MeasureSpec.makeMeasureSpec(this.widgetHeight + ((this.labelBehavior == 1 || shouldAlwaysShowLabel()) ? this.labels.get(0).getIntrinsicHeight() : 0), BasicMeasure.EXACTLY));
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected void onSizeChanged(int i, int i2, int i3, int i4) {
 | |
|         updateTrackWidth(i);
 | |
|         updateHaloHotspot();
 | |
|     }
 | |
| 
 | |
|     private void maybeCalculateTicksCoordinates() {
 | |
|         if (this.stepSize <= 0.0f) {
 | |
|             return;
 | |
|         }
 | |
|         validateConfigurationIfDirty();
 | |
|         int min = Math.min((int) (((this.valueTo - this.valueFrom) / this.stepSize) + 1.0f), (this.trackWidth / (this.trackHeight * 2)) + 1);
 | |
|         float[] fArr = this.ticksCoordinates;
 | |
|         if (fArr == null || fArr.length != min * 2) {
 | |
|             this.ticksCoordinates = new float[min * 2];
 | |
|         }
 | |
|         float f = this.trackWidth / (min - 1);
 | |
|         for (int i = 0; i < min * 2; i += 2) {
 | |
|             float[] fArr2 = this.ticksCoordinates;
 | |
|             fArr2[i] = this.trackSidePadding + ((i / 2.0f) * f);
 | |
|             fArr2[i + 1] = calculateTrackCenter();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void updateTrackWidth(int i) {
 | |
|         this.trackWidth = Math.max(i - (this.trackSidePadding * 2), 0);
 | |
|         maybeCalculateTicksCoordinates();
 | |
|     }
 | |
| 
 | |
|     /* JADX INFO: Access modifiers changed from: private */
 | |
|     public void updateHaloHotspot() {
 | |
|         if (shouldDrawCompatHalo() || getMeasuredWidth() <= 0) {
 | |
|             return;
 | |
|         }
 | |
|         Drawable background = getBackground();
 | |
|         if (background instanceof RippleDrawable) {
 | |
|             int normalizeValue = (int) ((normalizeValue(this.values.get(this.focusedThumbIdx).floatValue()) * this.trackWidth) + this.trackSidePadding);
 | |
|             int calculateTrackCenter = calculateTrackCenter();
 | |
|             int i = this.haloRadius;
 | |
|             DrawableCompat.setHotspotBounds(background, normalizeValue - i, calculateTrackCenter - i, normalizeValue + i, calculateTrackCenter + i);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private int calculateTrackCenter() {
 | |
|         return (this.widgetHeight / 2) + ((this.labelBehavior == 1 || shouldAlwaysShowLabel()) ? this.labels.get(0).getIntrinsicHeight() : 0);
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected void onDraw(Canvas canvas) {
 | |
|         if (this.dirtyConfig) {
 | |
|             validateConfigurationIfDirty();
 | |
|             maybeCalculateTicksCoordinates();
 | |
|         }
 | |
|         super.onDraw(canvas);
 | |
|         int calculateTrackCenter = calculateTrackCenter();
 | |
|         drawInactiveTrack(canvas, this.trackWidth, calculateTrackCenter);
 | |
|         if (((Float) Collections.max(getValues())).floatValue() > this.valueFrom) {
 | |
|             drawActiveTrack(canvas, this.trackWidth, calculateTrackCenter);
 | |
|         }
 | |
|         maybeDrawTicks(canvas);
 | |
|         if ((this.thumbIsPressed || isFocused()) && isEnabled()) {
 | |
|             maybeDrawCompatHalo(canvas, this.trackWidth, calculateTrackCenter);
 | |
|         }
 | |
|         if ((this.activeThumbIdx != -1 || shouldAlwaysShowLabel()) && isEnabled()) {
 | |
|             ensureLabelsAdded();
 | |
|         } else {
 | |
|             ensureLabelsRemoved();
 | |
|         }
 | |
|         drawThumbs(canvas, this.trackWidth, calculateTrackCenter);
 | |
|     }
 | |
| 
 | |
|     private float[] getActiveRange() {
 | |
|         float floatValue = ((Float) Collections.max(getValues())).floatValue();
 | |
|         float floatValue2 = ((Float) Collections.min(getValues())).floatValue();
 | |
|         if (this.values.size() == 1) {
 | |
|             floatValue2 = this.valueFrom;
 | |
|         }
 | |
|         float normalizeValue = normalizeValue(floatValue2);
 | |
|         float normalizeValue2 = normalizeValue(floatValue);
 | |
|         return isRtl() ? new float[]{normalizeValue2, normalizeValue} : new float[]{normalizeValue, normalizeValue2};
 | |
|     }
 | |
| 
 | |
|     private void drawInactiveTrack(Canvas canvas, int i, int i2) {
 | |
|         float[] activeRange = getActiveRange();
 | |
|         float f = i;
 | |
|         float f2 = this.trackSidePadding + (activeRange[1] * f);
 | |
|         if (f2 < r1 + i) {
 | |
|             float f3 = i2;
 | |
|             canvas.drawLine(f2, f3, r1 + i, f3, this.inactiveTrackPaint);
 | |
|         }
 | |
|         int i3 = this.trackSidePadding;
 | |
|         float f4 = i3 + (activeRange[0] * f);
 | |
|         if (f4 > i3) {
 | |
|             float f5 = i2;
 | |
|             canvas.drawLine(i3, f5, f4, f5, this.inactiveTrackPaint);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private float normalizeValue(float f) {
 | |
|         float f2 = this.valueFrom;
 | |
|         float f3 = (f - f2) / (this.valueTo - f2);
 | |
|         return isRtl() ? 1.0f - f3 : f3;
 | |
|     }
 | |
| 
 | |
|     private void drawActiveTrack(Canvas canvas, int i, int i2) {
 | |
|         float[] activeRange = getActiveRange();
 | |
|         int i3 = this.trackSidePadding;
 | |
|         float f = i;
 | |
|         float f2 = i2;
 | |
|         canvas.drawLine(i3 + (activeRange[0] * f), f2, i3 + (activeRange[1] * f), f2, this.activeTrackPaint);
 | |
|     }
 | |
| 
 | |
|     private void maybeDrawTicks(Canvas canvas) {
 | |
|         if (!this.tickVisible || this.stepSize <= 0.0f) {
 | |
|             return;
 | |
|         }
 | |
|         float[] activeRange = getActiveRange();
 | |
|         int pivotIndex = pivotIndex(this.ticksCoordinates, activeRange[0]);
 | |
|         int pivotIndex2 = pivotIndex(this.ticksCoordinates, activeRange[1]);
 | |
|         int i = pivotIndex * 2;
 | |
|         canvas.drawPoints(this.ticksCoordinates, 0, i, this.inactiveTicksPaint);
 | |
|         int i2 = pivotIndex2 * 2;
 | |
|         canvas.drawPoints(this.ticksCoordinates, i, i2 - i, this.activeTicksPaint);
 | |
|         float[] fArr = this.ticksCoordinates;
 | |
|         canvas.drawPoints(fArr, i2, fArr.length - i2, this.inactiveTicksPaint);
 | |
|     }
 | |
| 
 | |
|     private void drawThumbs(Canvas canvas, int i, int i2) {
 | |
|         for (int i3 = 0; i3 < this.values.size(); i3++) {
 | |
|             float floatValue = this.values.get(i3).floatValue();
 | |
|             Drawable drawable = this.customThumbDrawable;
 | |
|             if (drawable != null) {
 | |
|                 drawThumbDrawable(canvas, i, i2, floatValue, drawable);
 | |
|             } else if (i3 < this.customThumbDrawablesForValues.size()) {
 | |
|                 drawThumbDrawable(canvas, i, i2, floatValue, this.customThumbDrawablesForValues.get(i3));
 | |
|             } else {
 | |
|                 if (!isEnabled()) {
 | |
|                     canvas.drawCircle(this.trackSidePadding + (normalizeValue(floatValue) * i), i2, this.thumbRadius, this.thumbPaint);
 | |
|                 }
 | |
|                 drawThumbDrawable(canvas, i, i2, floatValue, this.defaultThumbDrawable);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void drawThumbDrawable(Canvas canvas, int i, int i2, float f, Drawable drawable) {
 | |
|         canvas.save();
 | |
|         canvas.translate((this.trackSidePadding + ((int) (normalizeValue(f) * i))) - (drawable.getBounds().width() / 2.0f), i2 - (drawable.getBounds().height() / 2.0f));
 | |
|         drawable.draw(canvas);
 | |
|         canvas.restore();
 | |
|     }
 | |
| 
 | |
|     private void maybeDrawCompatHalo(Canvas canvas, int i, int i2) {
 | |
|         if (shouldDrawCompatHalo()) {
 | |
|             int normalizeValue = (int) (this.trackSidePadding + (normalizeValue(this.values.get(this.focusedThumbIdx).floatValue()) * i));
 | |
|             if (Build.VERSION.SDK_INT < 28) {
 | |
|                 int i3 = this.haloRadius;
 | |
|                 canvas.clipRect(normalizeValue - i3, i2 - i3, normalizeValue + i3, i3 + i2, Region.Op.UNION);
 | |
|             }
 | |
|             canvas.drawCircle(normalizeValue, i2, this.haloRadius, this.haloPaint);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private boolean shouldDrawCompatHalo() {
 | |
|         return this.forceDrawCompatHalo || !(getBackground() instanceof RippleDrawable);
 | |
|     }
 | |
| 
 | |
|     /* JADX WARN: Code restructure failed: missing block: B:11:0x0033, code lost:
 | |
|     
 | |
|         if (r2 != 3) goto L47;
 | |
|      */
 | |
|     @Override // android.view.View
 | |
|     /*
 | |
|         Code decompiled incorrectly, please refer to instructions dump.
 | |
|         To view partially-correct add '--show-bad-code' argument
 | |
|     */
 | |
|     public boolean onTouchEvent(android.view.MotionEvent r6) {
 | |
|         /*
 | |
|             Method dump skipped, instructions count: 248
 | |
|             To view this dump add '--comments-level debug' option
 | |
|         */
 | |
|         throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.slider.BaseSlider.onTouchEvent(android.view.MotionEvent):boolean");
 | |
|     }
 | |
| 
 | |
|     private static int pivotIndex(float[] fArr, float f) {
 | |
|         return Math.round(f * ((fArr.length / 2) - 1));
 | |
|     }
 | |
| 
 | |
|     private double snapPosition(float f) {
 | |
|         float f2 = this.stepSize;
 | |
|         if (f2 <= 0.0f) {
 | |
|             return f;
 | |
|         }
 | |
|         return Math.round(f * r0) / ((int) ((this.valueTo - this.valueFrom) / f2));
 | |
|     }
 | |
| 
 | |
|     protected boolean pickActiveThumb() {
 | |
|         if (this.activeThumbIdx != -1) {
 | |
|             return true;
 | |
|         }
 | |
|         float valueOfTouchPositionAbsolute = getValueOfTouchPositionAbsolute();
 | |
|         float valueToX = valueToX(valueOfTouchPositionAbsolute);
 | |
|         this.activeThumbIdx = 0;
 | |
|         float abs = Math.abs(this.values.get(0).floatValue() - valueOfTouchPositionAbsolute);
 | |
|         for (int i = 1; i < this.values.size(); i++) {
 | |
|             float abs2 = Math.abs(this.values.get(i).floatValue() - valueOfTouchPositionAbsolute);
 | |
|             float valueToX2 = valueToX(this.values.get(i).floatValue());
 | |
|             if (Float.compare(abs2, abs) > 1) {
 | |
|                 break;
 | |
|             }
 | |
|             boolean z = !isRtl() ? valueToX2 - valueToX >= 0.0f : valueToX2 - valueToX <= 0.0f;
 | |
|             if (Float.compare(abs2, abs) < 0) {
 | |
|                 this.activeThumbIdx = i;
 | |
|             } else {
 | |
|                 if (Float.compare(abs2, abs) != 0) {
 | |
|                     continue;
 | |
|                 } else {
 | |
|                     if (Math.abs(valueToX2 - valueToX) < this.scaledTouchSlop) {
 | |
|                         this.activeThumbIdx = -1;
 | |
|                         return false;
 | |
|                     }
 | |
|                     if (z) {
 | |
|                         this.activeThumbIdx = i;
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             abs = abs2;
 | |
|         }
 | |
|         return this.activeThumbIdx != -1;
 | |
|     }
 | |
| 
 | |
|     private float getValueOfTouchPositionAbsolute() {
 | |
|         float f = this.touchPosition;
 | |
|         if (isRtl()) {
 | |
|             f = 1.0f - f;
 | |
|         }
 | |
|         float f2 = this.valueTo;
 | |
|         float f3 = this.valueFrom;
 | |
|         return (f * (f2 - f3)) + f3;
 | |
|     }
 | |
| 
 | |
|     private boolean snapTouchPosition() {
 | |
|         return snapActiveThumbToValue(getValueOfTouchPosition());
 | |
|     }
 | |
| 
 | |
|     private boolean snapActiveThumbToValue(float f) {
 | |
|         return snapThumbToValue(this.activeThumbIdx, f);
 | |
|     }
 | |
| 
 | |
|     /* JADX INFO: Access modifiers changed from: private */
 | |
|     public boolean snapThumbToValue(int i, float f) {
 | |
|         this.focusedThumbIdx = i;
 | |
|         if (Math.abs(f - this.values.get(i).floatValue()) < THRESHOLD) {
 | |
|             return false;
 | |
|         }
 | |
|         this.values.set(i, Float.valueOf(getClampedValue(i, f)));
 | |
|         dispatchOnChangedFromUser(i);
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     private float getClampedValue(int i, float f) {
 | |
|         float minSeparation = getMinSeparation();
 | |
|         if (this.separationUnit == 0) {
 | |
|             minSeparation = dimenToValue(minSeparation);
 | |
|         }
 | |
|         if (isRtl()) {
 | |
|             minSeparation = -minSeparation;
 | |
|         }
 | |
|         int i2 = i + 1;
 | |
|         int i3 = i - 1;
 | |
|         return MathUtils.clamp(f, i3 < 0 ? this.valueFrom : this.values.get(i3).floatValue() + minSeparation, i2 >= this.values.size() ? this.valueTo : this.values.get(i2).floatValue() - minSeparation);
 | |
|     }
 | |
| 
 | |
|     protected void setSeparationUnit(int i) {
 | |
|         this.separationUnit = i;
 | |
|         this.dirtyConfig = true;
 | |
|         postInvalidate();
 | |
|     }
 | |
| 
 | |
|     private float getValueOfTouchPosition() {
 | |
|         double snapPosition = snapPosition(this.touchPosition);
 | |
|         if (isRtl()) {
 | |
|             snapPosition = 1.0d - snapPosition;
 | |
|         }
 | |
|         float f = this.valueTo;
 | |
|         return (float) ((snapPosition * (f - r3)) + this.valueFrom);
 | |
|     }
 | |
| 
 | |
|     private float valueToX(float f) {
 | |
|         return (normalizeValue(f) * this.trackWidth) + this.trackSidePadding;
 | |
|     }
 | |
| 
 | |
|     private static float getAnimatorCurrentValueOrDefault(ValueAnimator valueAnimator, float f) {
 | |
|         if (valueAnimator == null || !valueAnimator.isRunning()) {
 | |
|             return f;
 | |
|         }
 | |
|         float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
 | |
|         valueAnimator.cancel();
 | |
|         return floatValue;
 | |
|     }
 | |
| 
 | |
|     private ValueAnimator createLabelAnimator(boolean z) {
 | |
|         int resolveThemeDuration;
 | |
|         TimeInterpolator resolveThemeInterpolator;
 | |
|         ValueAnimator ofFloat = ValueAnimator.ofFloat(getAnimatorCurrentValueOrDefault(z ? this.labelsOutAnimator : this.labelsInAnimator, z ? 0.0f : 1.0f), z ? 1.0f : 0.0f);
 | |
|         if (z) {
 | |
|             resolveThemeDuration = MotionUtils.resolveThemeDuration(getContext(), LABEL_ANIMATION_ENTER_DURATION_ATTR, 83);
 | |
|             resolveThemeInterpolator = MotionUtils.resolveThemeInterpolator(getContext(), LABEL_ANIMATION_ENTER_EASING_ATTR, AnimationUtils.DECELERATE_INTERPOLATOR);
 | |
|         } else {
 | |
|             resolveThemeDuration = MotionUtils.resolveThemeDuration(getContext(), LABEL_ANIMATION_EXIT_DURATION_ATTR, 117);
 | |
|             resolveThemeInterpolator = MotionUtils.resolveThemeInterpolator(getContext(), LABEL_ANIMATION_EXIT_EASING_ATTR, AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR);
 | |
|         }
 | |
|         ofFloat.setDuration(resolveThemeDuration);
 | |
|         ofFloat.setInterpolator(resolveThemeInterpolator);
 | |
|         ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.google.android.material.slider.BaseSlider.1
 | |
|             @Override // android.animation.ValueAnimator.AnimatorUpdateListener
 | |
|             public void onAnimationUpdate(ValueAnimator valueAnimator) {
 | |
|                 float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
 | |
|                 Iterator it = BaseSlider.this.labels.iterator();
 | |
|                 while (it.hasNext()) {
 | |
|                     ((TooltipDrawable) it.next()).setRevealFraction(floatValue);
 | |
|                 }
 | |
|                 ViewCompat.postInvalidateOnAnimation(BaseSlider.this);
 | |
|             }
 | |
|         });
 | |
|         return ofFloat;
 | |
|     }
 | |
| 
 | |
|     private void ensureLabelsRemoved() {
 | |
|         if (this.labelsAreAnimatedIn) {
 | |
|             this.labelsAreAnimatedIn = false;
 | |
|             ValueAnimator createLabelAnimator = createLabelAnimator(false);
 | |
|             this.labelsOutAnimator = createLabelAnimator;
 | |
|             this.labelsInAnimator = null;
 | |
|             createLabelAnimator.addListener(new AnimatorListenerAdapter() { // from class: com.google.android.material.slider.BaseSlider.2
 | |
|                 @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
 | |
|                 public void onAnimationEnd(Animator animator) {
 | |
|                     super.onAnimationEnd(animator);
 | |
|                     ViewOverlayImpl contentViewOverlay = ViewUtils.getContentViewOverlay(BaseSlider.this);
 | |
|                     Iterator it = BaseSlider.this.labels.iterator();
 | |
|                     while (it.hasNext()) {
 | |
|                         contentViewOverlay.remove((TooltipDrawable) it.next());
 | |
|                     }
 | |
|                 }
 | |
|             });
 | |
|             this.labelsOutAnimator.start();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void ensureLabelsAdded() {
 | |
|         if (this.labelBehavior == 2) {
 | |
|             return;
 | |
|         }
 | |
|         if (!this.labelsAreAnimatedIn) {
 | |
|             this.labelsAreAnimatedIn = true;
 | |
|             ValueAnimator createLabelAnimator = createLabelAnimator(true);
 | |
|             this.labelsInAnimator = createLabelAnimator;
 | |
|             this.labelsOutAnimator = null;
 | |
|             createLabelAnimator.start();
 | |
|         }
 | |
|         Iterator<TooltipDrawable> it = this.labels.iterator();
 | |
|         for (int i = 0; i < this.values.size() && it.hasNext(); i++) {
 | |
|             if (i != this.focusedThumbIdx) {
 | |
|                 setValueForLabel(it.next(), this.values.get(i).floatValue());
 | |
|             }
 | |
|         }
 | |
|         if (!it.hasNext()) {
 | |
|             throw new IllegalStateException(String.format("Not enough labels(%d) to display all the values(%d)", Integer.valueOf(this.labels.size()), Integer.valueOf(this.values.size())));
 | |
|         }
 | |
|         setValueForLabel(it.next(), this.values.get(this.focusedThumbIdx).floatValue());
 | |
|     }
 | |
| 
 | |
|     /* JADX INFO: Access modifiers changed from: private */
 | |
|     public String formatValue(float f) {
 | |
|         if (hasLabelFormatter()) {
 | |
|             return this.formatter.getFormattedValue(f);
 | |
|         }
 | |
|         return String.format(((float) ((int) f)) == f ? "%.0f" : "%.2f", Float.valueOf(f));
 | |
|     }
 | |
| 
 | |
|     private void setValueForLabel(TooltipDrawable tooltipDrawable, float f) {
 | |
|         tooltipDrawable.setText(formatValue(f));
 | |
|         int normalizeValue = (this.trackSidePadding + ((int) (normalizeValue(f) * this.trackWidth))) - (tooltipDrawable.getIntrinsicWidth() / 2);
 | |
|         int calculateTrackCenter = calculateTrackCenter() - (this.labelPadding + this.thumbRadius);
 | |
|         tooltipDrawable.setBounds(normalizeValue, calculateTrackCenter - tooltipDrawable.getIntrinsicHeight(), tooltipDrawable.getIntrinsicWidth() + normalizeValue, calculateTrackCenter);
 | |
|         Rect rect = new Rect(tooltipDrawable.getBounds());
 | |
|         DescendantOffsetUtils.offsetDescendantRect(ViewUtils.getContentView(this), this, rect);
 | |
|         tooltipDrawable.setBounds(rect);
 | |
|         ViewUtils.getContentViewOverlay(this).add(tooltipDrawable);
 | |
|     }
 | |
| 
 | |
|     private void invalidateTrack() {
 | |
|         this.inactiveTrackPaint.setStrokeWidth(this.trackHeight);
 | |
|         this.activeTrackPaint.setStrokeWidth(this.trackHeight);
 | |
|     }
 | |
| 
 | |
|     private boolean isInVerticalScrollingContainer() {
 | |
|         for (ViewParent parent = getParent(); parent instanceof ViewGroup; parent = parent.getParent()) {
 | |
|             ViewGroup viewGroup = (ViewGroup) parent;
 | |
|             if ((viewGroup.canScrollVertically(1) || viewGroup.canScrollVertically(-1)) && viewGroup.shouldDelayChildPressedState()) {
 | |
|                 return true;
 | |
|             }
 | |
|         }
 | |
|         return false;
 | |
|     }
 | |
| 
 | |
|     private static boolean isMouseEvent(MotionEvent motionEvent) {
 | |
|         return motionEvent.getToolType(0) == 3;
 | |
|     }
 | |
| 
 | |
|     private boolean isPotentialVerticalScroll(MotionEvent motionEvent) {
 | |
|         return !isMouseEvent(motionEvent) && isInVerticalScrollingContainer();
 | |
|     }
 | |
| 
 | |
|     private void dispatchOnChangedProgrammatically() {
 | |
|         for (L l : this.changeListeners) {
 | |
|             Iterator<Float> it = this.values.iterator();
 | |
|             while (it.hasNext()) {
 | |
|                 l.onValueChange(this, it.next().floatValue(), false);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void dispatchOnChangedFromUser(int i) {
 | |
|         Iterator<L> it = this.changeListeners.iterator();
 | |
|         while (it.hasNext()) {
 | |
|             it.next().onValueChange(this, this.values.get(i).floatValue(), true);
 | |
|         }
 | |
|         AccessibilityManager accessibilityManager = this.accessibilityManager;
 | |
|         if (accessibilityManager == null || !accessibilityManager.isEnabled()) {
 | |
|             return;
 | |
|         }
 | |
|         scheduleAccessibilityEventSender(i);
 | |
|     }
 | |
| 
 | |
|     private void onStartTrackingTouch() {
 | |
|         Iterator<T> it = this.touchListeners.iterator();
 | |
|         while (it.hasNext()) {
 | |
|             it.next().onStartTrackingTouch(this);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void onStopTrackingTouch() {
 | |
|         Iterator<T> it = this.touchListeners.iterator();
 | |
|         while (it.hasNext()) {
 | |
|             it.next().onStopTrackingTouch(this);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected void drawableStateChanged() {
 | |
|         super.drawableStateChanged();
 | |
|         this.inactiveTrackPaint.setColor(getColorForState(this.trackColorInactive));
 | |
|         this.activeTrackPaint.setColor(getColorForState(this.trackColorActive));
 | |
|         this.inactiveTicksPaint.setColor(getColorForState(this.tickColorInactive));
 | |
|         this.activeTicksPaint.setColor(getColorForState(this.tickColorActive));
 | |
|         for (TooltipDrawable tooltipDrawable : this.labels) {
 | |
|             if (tooltipDrawable.isStateful()) {
 | |
|                 tooltipDrawable.setState(getDrawableState());
 | |
|             }
 | |
|         }
 | |
|         if (this.defaultThumbDrawable.isStateful()) {
 | |
|             this.defaultThumbDrawable.setState(getDrawableState());
 | |
|         }
 | |
|         this.haloPaint.setColor(getColorForState(this.haloColor));
 | |
|         this.haloPaint.setAlpha(63);
 | |
|     }
 | |
| 
 | |
|     private int getColorForState(ColorStateList colorStateList) {
 | |
|         return colorStateList.getColorForState(getDrawableState(), colorStateList.getDefaultColor());
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View, android.view.KeyEvent.Callback
 | |
|     public boolean onKeyDown(int i, KeyEvent keyEvent) {
 | |
|         if (!isEnabled()) {
 | |
|             return super.onKeyDown(i, keyEvent);
 | |
|         }
 | |
|         if (this.values.size() == 1) {
 | |
|             this.activeThumbIdx = 0;
 | |
|         }
 | |
|         if (this.activeThumbIdx == -1) {
 | |
|             Boolean onKeyDownNoActiveThumb = onKeyDownNoActiveThumb(i, keyEvent);
 | |
|             return onKeyDownNoActiveThumb != null ? onKeyDownNoActiveThumb.booleanValue() : super.onKeyDown(i, keyEvent);
 | |
|         }
 | |
|         this.isLongPress |= keyEvent.isLongPress();
 | |
|         Float calculateIncrementForKey = calculateIncrementForKey(i);
 | |
|         if (calculateIncrementForKey != null) {
 | |
|             if (snapActiveThumbToValue(this.values.get(this.activeThumbIdx).floatValue() + calculateIncrementForKey.floatValue())) {
 | |
|                 updateHaloHotspot();
 | |
|                 postInvalidate();
 | |
|             }
 | |
|             return true;
 | |
|         }
 | |
|         if (i != 23) {
 | |
|             if (i == 61) {
 | |
|                 if (keyEvent.hasNoModifiers()) {
 | |
|                     return moveFocus(1);
 | |
|                 }
 | |
|                 if (keyEvent.isShiftPressed()) {
 | |
|                     return moveFocus(-1);
 | |
|                 }
 | |
|                 return false;
 | |
|             }
 | |
|             if (i != 66) {
 | |
|                 return super.onKeyDown(i, keyEvent);
 | |
|             }
 | |
|         }
 | |
|         this.activeThumbIdx = -1;
 | |
|         postInvalidate();
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     private Boolean onKeyDownNoActiveThumb(int i, KeyEvent keyEvent) {
 | |
|         if (i == 61) {
 | |
|             if (keyEvent.hasNoModifiers()) {
 | |
|                 return Boolean.valueOf(moveFocus(1));
 | |
|             }
 | |
|             if (keyEvent.isShiftPressed()) {
 | |
|                 return Boolean.valueOf(moveFocus(-1));
 | |
|             }
 | |
|             return false;
 | |
|         }
 | |
|         if (i != 66) {
 | |
|             if (i != 81) {
 | |
|                 if (i == 69) {
 | |
|                     moveFocus(-1);
 | |
|                     return true;
 | |
|                 }
 | |
|                 if (i != 70) {
 | |
|                     switch (i) {
 | |
|                         case 21:
 | |
|                             moveFocusInAbsoluteDirection(-1);
 | |
|                             break;
 | |
|                         case 22:
 | |
|                             moveFocusInAbsoluteDirection(1);
 | |
|                             break;
 | |
|                     }
 | |
|                     return true;
 | |
|                 }
 | |
|             }
 | |
|             moveFocus(1);
 | |
|             return true;
 | |
|         }
 | |
|         this.activeThumbIdx = this.focusedThumbIdx;
 | |
|         postInvalidate();
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View, android.view.KeyEvent.Callback
 | |
|     public boolean onKeyUp(int i, KeyEvent keyEvent) {
 | |
|         this.isLongPress = false;
 | |
|         return super.onKeyUp(i, keyEvent);
 | |
|     }
 | |
| 
 | |
|     final boolean isRtl() {
 | |
|         return ViewCompat.getLayoutDirection(this) == 1;
 | |
|     }
 | |
| 
 | |
|     private boolean moveFocus(int i) {
 | |
|         int i2 = this.focusedThumbIdx;
 | |
|         int clamp = (int) MathUtils.clamp(i2 + i, 0L, this.values.size() - 1);
 | |
|         this.focusedThumbIdx = clamp;
 | |
|         if (clamp == i2) {
 | |
|             return false;
 | |
|         }
 | |
|         if (this.activeThumbIdx != -1) {
 | |
|             this.activeThumbIdx = clamp;
 | |
|         }
 | |
|         updateHaloHotspot();
 | |
|         postInvalidate();
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     private boolean moveFocusInAbsoluteDirection(int i) {
 | |
|         if (isRtl()) {
 | |
|             i = i == Integer.MIN_VALUE ? Integer.MAX_VALUE : -i;
 | |
|         }
 | |
|         return moveFocus(i);
 | |
|     }
 | |
| 
 | |
|     private Float calculateIncrementForKey(int i) {
 | |
|         float calculateStepIncrement = this.isLongPress ? calculateStepIncrement(20) : calculateStepIncrement();
 | |
|         if (i == 21) {
 | |
|             if (!isRtl()) {
 | |
|                 calculateStepIncrement = -calculateStepIncrement;
 | |
|             }
 | |
|             return Float.valueOf(calculateStepIncrement);
 | |
|         }
 | |
|         if (i == 22) {
 | |
|             if (isRtl()) {
 | |
|                 calculateStepIncrement = -calculateStepIncrement;
 | |
|             }
 | |
|             return Float.valueOf(calculateStepIncrement);
 | |
|         }
 | |
|         if (i == 69) {
 | |
|             return Float.valueOf(-calculateStepIncrement);
 | |
|         }
 | |
|         if (i == 70 || i == 81) {
 | |
|             return Float.valueOf(calculateStepIncrement);
 | |
|         }
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
|     /* JADX INFO: Access modifiers changed from: private */
 | |
|     public float calculateStepIncrement(int i) {
 | |
|         float calculateStepIncrement = calculateStepIncrement();
 | |
|         return (this.valueTo - this.valueFrom) / calculateStepIncrement <= i ? calculateStepIncrement : Math.round(r1 / r4) * calculateStepIncrement;
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected void onFocusChanged(boolean z, int i, Rect rect) {
 | |
|         super.onFocusChanged(z, i, rect);
 | |
|         if (!z) {
 | |
|             this.activeThumbIdx = -1;
 | |
|             this.accessibilityHelper.clearKeyboardFocusForVirtualView(this.focusedThumbIdx);
 | |
|         } else {
 | |
|             focusThumbOnFocusGained(i);
 | |
|             this.accessibilityHelper.requestKeyboardFocusForVirtualView(this.focusedThumbIdx);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void focusThumbOnFocusGained(int i) {
 | |
|         if (i == 1) {
 | |
|             moveFocus(Integer.MAX_VALUE);
 | |
|             return;
 | |
|         }
 | |
|         if (i == 2) {
 | |
|             moveFocus(Integer.MIN_VALUE);
 | |
|         } else if (i == 17) {
 | |
|             moveFocusInAbsoluteDirection(Integer.MAX_VALUE);
 | |
|         } else {
 | |
|             if (i != 66) {
 | |
|                 return;
 | |
|             }
 | |
|             moveFocusInAbsoluteDirection(Integer.MIN_VALUE);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     final int getAccessibilityFocusedVirtualViewId() {
 | |
|         return this.accessibilityHelper.getAccessibilityFocusedVirtualViewId();
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public CharSequence getAccessibilityClassName() {
 | |
|         return SeekBar.class.getName();
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public boolean dispatchHoverEvent(MotionEvent motionEvent) {
 | |
|         return this.accessibilityHelper.dispatchHoverEvent(motionEvent) || super.dispatchHoverEvent(motionEvent);
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public boolean dispatchKeyEvent(KeyEvent keyEvent) {
 | |
|         return super.dispatchKeyEvent(keyEvent);
 | |
|     }
 | |
| 
 | |
|     private void scheduleAccessibilityEventSender(int i) {
 | |
|         BaseSlider<S, L, T>.AccessibilityEventSender accessibilityEventSender = this.accessibilityEventSender;
 | |
|         if (accessibilityEventSender == null) {
 | |
|             this.accessibilityEventSender = new AccessibilityEventSender();
 | |
|         } else {
 | |
|             removeCallbacks(accessibilityEventSender);
 | |
|         }
 | |
|         this.accessibilityEventSender.setVirtualViewId(i);
 | |
|         postDelayed(this.accessibilityEventSender, 200L);
 | |
|     }
 | |
| 
 | |
|     private class AccessibilityEventSender implements Runnable {
 | |
|         int virtualViewId;
 | |
| 
 | |
|         void setVirtualViewId(int i) {
 | |
|             this.virtualViewId = i;
 | |
|         }
 | |
| 
 | |
|         private AccessibilityEventSender() {
 | |
|             this.virtualViewId = -1;
 | |
|         }
 | |
| 
 | |
|         @Override // java.lang.Runnable
 | |
|         public void run() {
 | |
|             BaseSlider.this.accessibilityHelper.sendEventForVirtualView(this.virtualViewId, 4);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected Parcelable onSaveInstanceState() {
 | |
|         SliderState sliderState = new SliderState(super.onSaveInstanceState());
 | |
|         sliderState.valueFrom = this.valueFrom;
 | |
|         sliderState.valueTo = this.valueTo;
 | |
|         sliderState.values = new ArrayList<>(this.values);
 | |
|         sliderState.stepSize = this.stepSize;
 | |
|         sliderState.hasFocus = hasFocus();
 | |
|         return sliderState;
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected void onRestoreInstanceState(Parcelable parcelable) {
 | |
|         SliderState sliderState = (SliderState) parcelable;
 | |
|         super.onRestoreInstanceState(sliderState.getSuperState());
 | |
|         this.valueFrom = sliderState.valueFrom;
 | |
|         this.valueTo = sliderState.valueTo;
 | |
|         setValuesInternal(sliderState.values);
 | |
|         this.stepSize = sliderState.stepSize;
 | |
|         if (sliderState.hasFocus) {
 | |
|             requestFocus();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class SliderState extends View.BaseSavedState {
 | |
|         public static final Parcelable.Creator<SliderState> CREATOR = new Parcelable.Creator<SliderState>() { // from class: com.google.android.material.slider.BaseSlider.SliderState.1
 | |
|             /* JADX WARN: Can't rename method to resolve collision */
 | |
|             @Override // android.os.Parcelable.Creator
 | |
|             public SliderState createFromParcel(Parcel parcel) {
 | |
|                 return new SliderState(parcel);
 | |
|             }
 | |
| 
 | |
|             /* JADX WARN: Can't rename method to resolve collision */
 | |
|             @Override // android.os.Parcelable.Creator
 | |
|             public SliderState[] newArray(int i) {
 | |
|                 return new SliderState[i];
 | |
|             }
 | |
|         };
 | |
|         boolean hasFocus;
 | |
|         float stepSize;
 | |
|         float valueFrom;
 | |
|         float valueTo;
 | |
|         ArrayList<Float> values;
 | |
| 
 | |
|         SliderState(Parcelable parcelable) {
 | |
|             super(parcelable);
 | |
|         }
 | |
| 
 | |
|         private SliderState(Parcel parcel) {
 | |
|             super(parcel);
 | |
|             this.valueFrom = parcel.readFloat();
 | |
|             this.valueTo = parcel.readFloat();
 | |
|             ArrayList<Float> arrayList = new ArrayList<>();
 | |
|             this.values = arrayList;
 | |
|             parcel.readList(arrayList, Float.class.getClassLoader());
 | |
|             this.stepSize = parcel.readFloat();
 | |
|             this.hasFocus = parcel.createBooleanArray()[0];
 | |
|         }
 | |
| 
 | |
|         @Override // android.view.View.BaseSavedState, android.view.AbsSavedState, android.os.Parcelable
 | |
|         public void writeToParcel(Parcel parcel, int i) {
 | |
|             super.writeToParcel(parcel, i);
 | |
|             parcel.writeFloat(this.valueFrom);
 | |
|             parcel.writeFloat(this.valueTo);
 | |
|             parcel.writeList(this.values);
 | |
|             parcel.writeFloat(this.stepSize);
 | |
|             parcel.writeBooleanArray(new boolean[]{this.hasFocus});
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     void updateBoundsForVirtualViewId(int i, Rect rect) {
 | |
|         int normalizeValue = this.trackSidePadding + ((int) (normalizeValue(getValues().get(i).floatValue()) * this.trackWidth));
 | |
|         int calculateTrackCenter = calculateTrackCenter();
 | |
|         int i2 = this.thumbRadius;
 | |
|         int i3 = this.minTouchTargetSize;
 | |
|         if (i2 <= i3) {
 | |
|             i2 = i3;
 | |
|         }
 | |
|         int i4 = i2 / 2;
 | |
|         rect.set(normalizeValue - i4, calculateTrackCenter - i4, normalizeValue + i4, calculateTrackCenter + i4);
 | |
|     }
 | |
| 
 | |
|     private static class AccessibilityHelper extends ExploreByTouchHelper {
 | |
|         private final BaseSlider<?, ?, ?> slider;
 | |
|         final Rect virtualViewBounds;
 | |
| 
 | |
|         AccessibilityHelper(BaseSlider<?, ?, ?> baseSlider) {
 | |
|             super(baseSlider);
 | |
|             this.virtualViewBounds = new Rect();
 | |
|             this.slider = baseSlider;
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.customview.widget.ExploreByTouchHelper
 | |
|         protected int getVirtualViewAt(float f, float f2) {
 | |
|             for (int i = 0; i < this.slider.getValues().size(); i++) {
 | |
|                 this.slider.updateBoundsForVirtualViewId(i, this.virtualViewBounds);
 | |
|                 if (this.virtualViewBounds.contains((int) f, (int) f2)) {
 | |
|                     return i;
 | |
|                 }
 | |
|             }
 | |
|             return -1;
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.customview.widget.ExploreByTouchHelper
 | |
|         protected void getVisibleVirtualViews(List<Integer> list) {
 | |
|             for (int i = 0; i < this.slider.getValues().size(); i++) {
 | |
|                 list.add(Integer.valueOf(i));
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.customview.widget.ExploreByTouchHelper
 | |
|         protected void onPopulateNodeForVirtualView(int i, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
 | |
|             accessibilityNodeInfoCompat.addAction(AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SET_PROGRESS);
 | |
|             List<Float> values = this.slider.getValues();
 | |
|             float floatValue = values.get(i).floatValue();
 | |
|             float valueFrom = this.slider.getValueFrom();
 | |
|             float valueTo = this.slider.getValueTo();
 | |
|             if (this.slider.isEnabled()) {
 | |
|                 if (floatValue > valueFrom) {
 | |
|                     accessibilityNodeInfoCompat.addAction(8192);
 | |
|                 }
 | |
|                 if (floatValue < valueTo) {
 | |
|                     accessibilityNodeInfoCompat.addAction(4096);
 | |
|                 }
 | |
|             }
 | |
|             accessibilityNodeInfoCompat.setRangeInfo(AccessibilityNodeInfoCompat.RangeInfoCompat.obtain(1, valueFrom, valueTo, floatValue));
 | |
|             accessibilityNodeInfoCompat.setClassName(SeekBar.class.getName());
 | |
|             StringBuilder sb = new StringBuilder();
 | |
|             if (this.slider.getContentDescription() != null) {
 | |
|                 sb.append(this.slider.getContentDescription());
 | |
|                 sb.append(",");
 | |
|             }
 | |
|             String formatValue = this.slider.formatValue(floatValue);
 | |
|             String string = this.slider.getContext().getString(R.string.material_slider_value);
 | |
|             if (values.size() > 1) {
 | |
|                 string = startOrEndDescription(i);
 | |
|             }
 | |
|             sb.append(String.format(Locale.US, "%s, %s", string, formatValue));
 | |
|             accessibilityNodeInfoCompat.setContentDescription(sb.toString());
 | |
|             this.slider.updateBoundsForVirtualViewId(i, this.virtualViewBounds);
 | |
|             accessibilityNodeInfoCompat.setBoundsInParent(this.virtualViewBounds);
 | |
|         }
 | |
| 
 | |
|         private String startOrEndDescription(int i) {
 | |
|             if (i == this.slider.getValues().size() - 1) {
 | |
|                 return this.slider.getContext().getString(R.string.material_slider_range_end);
 | |
|             }
 | |
|             return i == 0 ? this.slider.getContext().getString(R.string.material_slider_range_start) : "";
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.customview.widget.ExploreByTouchHelper
 | |
|         protected boolean onPerformActionForVirtualView(int i, int i2, Bundle bundle) {
 | |
|             if (!this.slider.isEnabled()) {
 | |
|                 return false;
 | |
|             }
 | |
|             if (i2 == 4096 || i2 == 8192) {
 | |
|                 float calculateStepIncrement = this.slider.calculateStepIncrement(20);
 | |
|                 if (i2 == 8192) {
 | |
|                     calculateStepIncrement = -calculateStepIncrement;
 | |
|                 }
 | |
|                 if (this.slider.isRtl()) {
 | |
|                     calculateStepIncrement = -calculateStepIncrement;
 | |
|                 }
 | |
|                 if (!this.slider.snapThumbToValue(i, MathUtils.clamp(this.slider.getValues().get(i).floatValue() + calculateStepIncrement, this.slider.getValueFrom(), this.slider.getValueTo()))) {
 | |
|                     return false;
 | |
|                 }
 | |
|                 this.slider.updateHaloHotspot();
 | |
|                 this.slider.postInvalidate();
 | |
|                 invalidateVirtualView(i);
 | |
|                 return true;
 | |
|             }
 | |
|             if (i2 == 16908349 && bundle != null && bundle.containsKey(AccessibilityNodeInfoCompat.ACTION_ARGUMENT_PROGRESS_VALUE)) {
 | |
|                 if (this.slider.snapThumbToValue(i, bundle.getFloat(AccessibilityNodeInfoCompat.ACTION_ARGUMENT_PROGRESS_VALUE))) {
 | |
|                     this.slider.updateHaloHotspot();
 | |
|                     this.slider.postInvalidate();
 | |
|                     invalidateVirtualView(i);
 | |
|                     return true;
 | |
|                 }
 | |
|             }
 | |
|             return false;
 | |
|         }
 | |
|     }
 | |
| }
 |