156 lines
5.9 KiB
Java
156 lines
5.9 KiB
Java
package androidx.appcompat.widget;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.ColorStateList;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.PorterDuff;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.util.AttributeSet;
|
|
import android.widget.SeekBar;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.appcompat.R;
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
public class AppCompatSeekBarHelper extends AppCompatProgressBarHelper {
|
|
private boolean mHasTickMarkTint = false;
|
|
private boolean mHasTickMarkTintMode = false;
|
|
private Drawable mTickMark;
|
|
private ColorStateList mTickMarkTintList = null;
|
|
private PorterDuff.Mode mTickMarkTintMode = null;
|
|
private final SeekBar mView;
|
|
|
|
public AppCompatSeekBarHelper(SeekBar seekBar) {
|
|
super(seekBar);
|
|
this.mView = seekBar;
|
|
}
|
|
|
|
private void applyTickMarkTint() {
|
|
Drawable drawable = this.mTickMark;
|
|
if (drawable == null) {
|
|
return;
|
|
}
|
|
if (this.mHasTickMarkTint || this.mHasTickMarkTintMode) {
|
|
Drawable wrap = DrawableCompat.wrap(drawable.mutate());
|
|
this.mTickMark = wrap;
|
|
if (this.mHasTickMarkTint) {
|
|
DrawableCompat.setTintList(wrap, this.mTickMarkTintList);
|
|
}
|
|
if (this.mHasTickMarkTintMode) {
|
|
DrawableCompat.setTintMode(this.mTickMark, this.mTickMarkTintMode);
|
|
}
|
|
if (this.mTickMark.isStateful()) {
|
|
this.mTickMark.setState(this.mView.getDrawableState());
|
|
}
|
|
}
|
|
}
|
|
|
|
public void drawTickMarks(Canvas canvas) {
|
|
if (this.mTickMark != null) {
|
|
int max = this.mView.getMax();
|
|
int i = 1;
|
|
if (max > 1) {
|
|
int intrinsicWidth = this.mTickMark.getIntrinsicWidth();
|
|
int intrinsicHeight = this.mTickMark.getIntrinsicHeight();
|
|
int i2 = intrinsicWidth >= 0 ? intrinsicWidth / 2 : 1;
|
|
if (intrinsicHeight >= 0) {
|
|
i = intrinsicHeight / 2;
|
|
}
|
|
this.mTickMark.setBounds(-i2, -i, i2, i);
|
|
float width = ((float) ((this.mView.getWidth() - this.mView.getPaddingLeft()) - this.mView.getPaddingRight())) / ((float) max);
|
|
int save = canvas.save();
|
|
canvas.translate((float) this.mView.getPaddingLeft(), (float) (this.mView.getHeight() / 2));
|
|
for (int i3 = 0; i3 <= max; i3++) {
|
|
this.mTickMark.draw(canvas);
|
|
canvas.translate(width, 0.0f);
|
|
}
|
|
canvas.restoreToCount(save);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void drawableStateChanged() {
|
|
Drawable drawable = this.mTickMark;
|
|
if (drawable != null && drawable.isStateful() && drawable.setState(this.mView.getDrawableState())) {
|
|
this.mView.invalidateDrawable(drawable);
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
public Drawable getTickMark() {
|
|
return this.mTickMark;
|
|
}
|
|
|
|
@Nullable
|
|
public ColorStateList getTickMarkTintList() {
|
|
return this.mTickMarkTintList;
|
|
}
|
|
|
|
@Nullable
|
|
public PorterDuff.Mode getTickMarkTintMode() {
|
|
return this.mTickMarkTintMode;
|
|
}
|
|
|
|
public void jumpDrawablesToCurrentState() {
|
|
Drawable drawable = this.mTickMark;
|
|
if (drawable != null) {
|
|
drawable.jumpToCurrentState();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AppCompatProgressBarHelper
|
|
public void loadFromAttributes(AttributeSet attributeSet, int i) {
|
|
super.loadFromAttributes(attributeSet, i);
|
|
Context context = this.mView.getContext();
|
|
int[] iArr = R.styleable.AppCompatSeekBar;
|
|
TintTypedArray obtainStyledAttributes = TintTypedArray.obtainStyledAttributes(context, attributeSet, iArr, i, 0);
|
|
SeekBar seekBar = this.mView;
|
|
ViewCompat.saveAttributeDataForStyleable(seekBar, seekBar.getContext(), iArr, attributeSet, obtainStyledAttributes.getWrappedTypeArray(), i, 0);
|
|
Drawable drawableIfKnown = obtainStyledAttributes.getDrawableIfKnown(R.styleable.AppCompatSeekBar_android_thumb);
|
|
if (drawableIfKnown != null) {
|
|
this.mView.setThumb(drawableIfKnown);
|
|
}
|
|
setTickMark(obtainStyledAttributes.getDrawable(R.styleable.AppCompatSeekBar_tickMark));
|
|
int i2 = R.styleable.AppCompatSeekBar_tickMarkTintMode;
|
|
if (obtainStyledAttributes.hasValue(i2)) {
|
|
this.mTickMarkTintMode = DrawableUtils.parseTintMode(obtainStyledAttributes.getInt(i2, -1), this.mTickMarkTintMode);
|
|
this.mHasTickMarkTintMode = true;
|
|
}
|
|
int i3 = R.styleable.AppCompatSeekBar_tickMarkTint;
|
|
if (obtainStyledAttributes.hasValue(i3)) {
|
|
this.mTickMarkTintList = obtainStyledAttributes.getColorStateList(i3);
|
|
this.mHasTickMarkTint = true;
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
applyTickMarkTint();
|
|
}
|
|
|
|
public void setTickMark(@Nullable Drawable drawable) {
|
|
Drawable drawable2 = this.mTickMark;
|
|
if (drawable2 != null) {
|
|
drawable2.setCallback(null);
|
|
}
|
|
this.mTickMark = drawable;
|
|
if (drawable != null) {
|
|
drawable.setCallback(this.mView);
|
|
DrawableCompat.setLayoutDirection(drawable, ViewCompat.getLayoutDirection(this.mView));
|
|
if (drawable.isStateful()) {
|
|
drawable.setState(this.mView.getDrawableState());
|
|
}
|
|
applyTickMarkTint();
|
|
}
|
|
this.mView.invalidate();
|
|
}
|
|
|
|
public void setTickMarkTintList(@Nullable ColorStateList colorStateList) {
|
|
this.mTickMarkTintList = colorStateList;
|
|
this.mHasTickMarkTint = true;
|
|
applyTickMarkTint();
|
|
}
|
|
|
|
public void setTickMarkTintMode(@Nullable PorterDuff.Mode mode) {
|
|
this.mTickMarkTintMode = mode;
|
|
this.mHasTickMarkTintMode = true;
|
|
applyTickMarkTint();
|
|
}
|
|
}
|