mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-13 17:37:16 +01:00
238 lines
8.2 KiB
Java
238 lines
8.2 KiB
Java
package com.reactnativecommunity.slider;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
import android.util.AttributeSet;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.view.accessibility.AccessibilityManager;
|
|
import androidx.appcompat.widget.AppCompatSeekBar;
|
|
import com.facebook.react.modules.i18nmanager.I18nUtil;
|
|
import java.net.URL;
|
|
import java.util.List;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.Executors;
|
|
import javax.annotation.Nullable;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes9.dex */
|
|
public class ReactSlider extends AppCompatSeekBar {
|
|
private static int DEFAULT_TOTAL_STEPS = 128;
|
|
private boolean isSliding;
|
|
private List<String> mAccessibilityIncrements;
|
|
private String mAccessibilityUnits;
|
|
private int mLowerLimit;
|
|
private double mMaxValue;
|
|
private double mMinValue;
|
|
private double mRealLowerLimit;
|
|
private double mRealUpperLimit;
|
|
private double mStep;
|
|
private double mStepCalculated;
|
|
private int mUpperLimit;
|
|
private double mValue;
|
|
|
|
public ReactSlider(Context context, @Nullable AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.mMinValue = 0.0d;
|
|
this.mMaxValue = 0.0d;
|
|
this.mValue = 0.0d;
|
|
this.isSliding = false;
|
|
this.mStep = 0.0d;
|
|
this.mStepCalculated = 0.0d;
|
|
this.mRealLowerLimit = -9.223372036854776E18d;
|
|
this.mRealUpperLimit = 9.223372036854776E18d;
|
|
super.setLayoutDirection(I18nUtil.getInstance().isRTL(context) ? 1 : 0);
|
|
disableStateListAnimatorIfNeeded();
|
|
}
|
|
|
|
private BitmapDrawable getBitmapDrawable(final String str) {
|
|
try {
|
|
return (BitmapDrawable) Executors.newSingleThreadExecutor().submit(new Callable<BitmapDrawable>() { // from class: com.reactnativecommunity.slider.ReactSlider.2
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // java.util.concurrent.Callable
|
|
public BitmapDrawable call() {
|
|
Bitmap decodeStream;
|
|
try {
|
|
if (!str.startsWith("http://") && !str.startsWith("https://") && !str.startsWith("file://") && !str.startsWith("asset://") && !str.startsWith("data:")) {
|
|
decodeStream = BitmapFactory.decodeResource(ReactSlider.this.getResources(), ReactSlider.this.getResources().getIdentifier(str, "drawable", ReactSlider.this.getContext().getPackageName()));
|
|
return new BitmapDrawable(ReactSlider.this.getResources(), decodeStream);
|
|
}
|
|
decodeStream = BitmapFactory.decodeStream(new URL(str).openStream());
|
|
return new BitmapDrawable(ReactSlider.this.getResources(), decodeStream);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
}).get();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private double getStepValue() {
|
|
double d = this.mStep;
|
|
return d > 0.0d ? d : this.mStepCalculated;
|
|
}
|
|
|
|
private int getTotalSteps() {
|
|
return (int) Math.ceil((this.mMaxValue - this.mMinValue) / getStepValue());
|
|
}
|
|
|
|
private void updateAll() {
|
|
if (this.mStep == 0.0d) {
|
|
this.mStepCalculated = (this.mMaxValue - this.mMinValue) / DEFAULT_TOTAL_STEPS;
|
|
}
|
|
setMax(getTotalSteps());
|
|
setKeyProgressIncrement(1);
|
|
updateLowerLimit();
|
|
updateUpperLimit();
|
|
updateValue();
|
|
}
|
|
|
|
private void updateLowerLimit() {
|
|
double max = Math.max(this.mRealLowerLimit, this.mMinValue);
|
|
double d = this.mMinValue;
|
|
int round = (int) Math.round(((max - d) / (this.mMaxValue - d)) * getTotalSteps());
|
|
int i = this.mUpperLimit;
|
|
if (round > i) {
|
|
return;
|
|
}
|
|
this.mLowerLimit = Math.min(round, i);
|
|
}
|
|
|
|
private void updateUpperLimit() {
|
|
double min = Math.min(this.mRealUpperLimit, this.mMaxValue);
|
|
double d = this.mMinValue;
|
|
int round = (int) Math.round(((min - d) / (this.mMaxValue - d)) * getTotalSteps());
|
|
if (this.mLowerLimit > round) {
|
|
return;
|
|
}
|
|
this.mUpperLimit = round;
|
|
}
|
|
|
|
private void updateValue() {
|
|
double d = this.mValue;
|
|
double d2 = this.mMinValue;
|
|
setProgress((int) Math.round(((d - d2) / (this.mMaxValue - d2)) * getTotalSteps()));
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void announceForAccessibility(CharSequence charSequence) {
|
|
Context context = getContext();
|
|
final AccessibilityManager accessibilityManager = (AccessibilityManager) context.getSystemService("accessibility");
|
|
if (accessibilityManager.isEnabled()) {
|
|
final AccessibilityEvent obtain = AccessibilityEvent.obtain();
|
|
obtain.setEventType(16384);
|
|
obtain.setClassName(getClass().getName());
|
|
obtain.setPackageName(context.getPackageName());
|
|
obtain.getText().add(charSequence);
|
|
new Timer().schedule(new TimerTask() { // from class: com.reactnativecommunity.slider.ReactSlider.1
|
|
@Override // java.util.TimerTask, java.lang.Runnable
|
|
public void run() {
|
|
accessibilityManager.sendAccessibilityEvent(obtain);
|
|
}
|
|
}, 1000L);
|
|
}
|
|
}
|
|
|
|
public int getLowerLimit() {
|
|
return this.mLowerLimit;
|
|
}
|
|
|
|
public int getUpperLimit() {
|
|
return this.mUpperLimit;
|
|
}
|
|
|
|
public int getValidProgressValue(int i) {
|
|
return i < getLowerLimit() ? getLowerLimit() : i > getUpperLimit() ? getUpperLimit() : i;
|
|
}
|
|
|
|
public boolean isSliding() {
|
|
return this.isSliding;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onPopulateAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
|
super.onPopulateAccessibilityEvent(accessibilityEvent);
|
|
if (accessibilityEvent.getEventType() == 32768 || (accessibilityEvent.getEventType() == 4 && isAccessibilityFocused())) {
|
|
setupAccessibility((int) this.mValue);
|
|
}
|
|
}
|
|
|
|
public void setAccessibilityIncrements(List<String> list) {
|
|
this.mAccessibilityIncrements = list;
|
|
}
|
|
|
|
public void setAccessibilityUnits(String str) {
|
|
this.mAccessibilityUnits = str;
|
|
}
|
|
|
|
public void setLowerLimit(double d) {
|
|
this.mRealLowerLimit = d;
|
|
updateLowerLimit();
|
|
}
|
|
|
|
public void setMaxValue(double d) {
|
|
this.mMaxValue = d;
|
|
updateAll();
|
|
}
|
|
|
|
public void setMinValue(double d) {
|
|
this.mMinValue = d;
|
|
updateAll();
|
|
}
|
|
|
|
public void setStep(double d) {
|
|
this.mStep = d;
|
|
updateAll();
|
|
}
|
|
|
|
public void setThumbImage(String str) {
|
|
if (str == null) {
|
|
setThumb(getThumb());
|
|
} else {
|
|
setThumb(getBitmapDrawable(str));
|
|
setSplitTrack(false);
|
|
}
|
|
}
|
|
|
|
public void setUpperLimit(double d) {
|
|
this.mRealUpperLimit = d;
|
|
updateUpperLimit();
|
|
}
|
|
|
|
public void setValue(double d) {
|
|
this.mValue = d;
|
|
updateValue();
|
|
}
|
|
|
|
public void setupAccessibility(int i) {
|
|
List<String> list;
|
|
if (this.mAccessibilityUnits == null || (list = this.mAccessibilityIncrements) == null || list.size() - 1 != ((int) this.mMaxValue)) {
|
|
return;
|
|
}
|
|
String str = this.mAccessibilityIncrements.get(i);
|
|
int length = this.mAccessibilityUnits.length();
|
|
String str2 = this.mAccessibilityUnits;
|
|
if (str != null && Integer.parseInt(str) == 1) {
|
|
str2 = str2.substring(0, length - 1);
|
|
}
|
|
announceForAccessibility(str + " " + str2);
|
|
}
|
|
|
|
public double toRealProgress(int i) {
|
|
return i == getMax() ? this.mMaxValue : (i * getStepValue()) + this.mMinValue;
|
|
}
|
|
|
|
public void isSliding(boolean z) {
|
|
this.isSliding = z;
|
|
}
|
|
|
|
private void disableStateListAnimatorIfNeeded() {
|
|
}
|
|
}
|