mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-11 13:45:48 -04:00
refactor(customseekbar): implement seekBarIncrement attribute
This commit is contained in:
parent
b3df2645e5
commit
dcbb1e010e
@ -2,9 +2,14 @@ package com.kdt;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import net.kdt.pojavlaunch.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seekbar with ability to handle ranges and increments
|
* Seekbar with ability to handle ranges and increments
|
||||||
*/
|
*/
|
||||||
@ -19,22 +24,22 @@ public class CustomSeekbar extends SeekBar {
|
|||||||
|
|
||||||
public CustomSeekbar(Context context) {
|
public CustomSeekbar(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setup();
|
setup(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomSeekbar(Context context, AttributeSet attrs) {
|
public CustomSeekbar(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
setup();
|
setup(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomSeekbar(Context context, AttributeSet attrs, int defStyleAttr) {
|
public CustomSeekbar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
setup();
|
setup(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomSeekbar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
public CustomSeekbar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
setup();
|
setup(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIncrement(int increment) {
|
public void setIncrement(int increment) {
|
||||||
@ -75,7 +80,11 @@ public class CustomSeekbar extends SeekBar {
|
|||||||
mListener = l;
|
mListener = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup() {
|
public void setup(@Nullable AttributeSet attrs) {
|
||||||
|
try (TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.CustomSeekbar)) {
|
||||||
|
mIncrement = attributes.getInt(R.styleable.CustomSeekbar_seekBarIncrement, 1);
|
||||||
|
}
|
||||||
|
|
||||||
super.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
super.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||||
/** Store the previous progress to prevent double calls with increments */
|
/** Store the previous progress to prevent double calls with increments */
|
||||||
private int previousProgress = 0;
|
private int previousProgress = 0;
|
||||||
|
@ -123,7 +123,6 @@ public abstract class QuickSettingSideDialog extends com.kdt.SideDialogView {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mGyroSensitivityBar.setRange(25, 300);
|
mGyroSensitivityBar.setRange(25, 300);
|
||||||
mGyroSensitivityBar.setIncrement(mGyroSensitivityBar.getContext().getResources().getInteger(R.integer.gyro_speed_seekbar_increment));
|
|
||||||
mGyroSensitivityBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
|
mGyroSensitivityBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
|
||||||
PREF_GYRO_SENSITIVITY = progress / 100f;
|
PREF_GYRO_SENSITIVITY = progress / 100f;
|
||||||
mEditor.putInt("gyroSensitivity", progress);
|
mEditor.putInt("gyroSensitivity", progress);
|
||||||
@ -133,7 +132,6 @@ public abstract class QuickSettingSideDialog extends com.kdt.SideDialogView {
|
|||||||
setSeekTextPercent(mGyroSensitivityText, mGyroSensitivityBar.getProgress());
|
setSeekTextPercent(mGyroSensitivityText, mGyroSensitivityBar.getProgress());
|
||||||
|
|
||||||
mMouseSpeedBar.setRange(25, 300);
|
mMouseSpeedBar.setRange(25, 300);
|
||||||
mMouseSpeedBar.setIncrement(mMouseSpeedBar.getContext().getResources().getInteger(R.integer.mouse_speed_seekbar_increment));
|
|
||||||
mMouseSpeedBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
|
mMouseSpeedBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
|
||||||
PREF_MOUSESPEED = progress / 100f;
|
PREF_MOUSESPEED = progress / 100f;
|
||||||
mEditor.putInt("mousespeed", progress);
|
mEditor.putInt("mousespeed", progress);
|
||||||
@ -143,7 +141,6 @@ public abstract class QuickSettingSideDialog extends com.kdt.SideDialogView {
|
|||||||
setSeekTextPercent(mMouseSpeedText, mMouseSpeedBar.getProgress());
|
setSeekTextPercent(mMouseSpeedText, mMouseSpeedBar.getProgress());
|
||||||
|
|
||||||
mGestureDelayBar.setRange(100, 1000);
|
mGestureDelayBar.setRange(100, 1000);
|
||||||
mGestureDelayBar.setIncrement(mGestureDelayBar.getContext().getResources().getInteger(R.integer.gesture_delay_seekbar_increment));
|
|
||||||
mGestureDelayBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
|
mGestureDelayBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
|
||||||
PREF_LONGPRESS_TRIGGER = progress;
|
PREF_LONGPRESS_TRIGGER = progress;
|
||||||
mEditor.putInt("timeLongPressTrigger", progress);
|
mEditor.putInt("timeLongPressTrigger", progress);
|
||||||
@ -153,7 +150,6 @@ public abstract class QuickSettingSideDialog extends com.kdt.SideDialogView {
|
|||||||
setSeekTextMillisecond(mGestureDelayText, mGestureDelayBar.getProgress());
|
setSeekTextMillisecond(mGestureDelayText, mGestureDelayBar.getProgress());
|
||||||
|
|
||||||
mResolutionBar.setRange(25, 100);
|
mResolutionBar.setRange(25, 100);
|
||||||
mResolutionBar.setIncrement(mResolutionBar.getContext().getResources().getInteger(R.integer.resolution_seekbar_increment));
|
|
||||||
mResolutionBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
|
mResolutionBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
|
||||||
PREF_SCALE_FACTOR = progress/100f;
|
PREF_SCALE_FACTOR = progress/100f;
|
||||||
mEditor.putInt("resolutionRatio", progress);
|
mEditor.putInt("resolutionRatio", progress);
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="@dimen/_36sdp"
|
android:layout_height="@dimen/_36sdp"
|
||||||
|
|
||||||
|
app:seekBarIncrement="@integer/resolution_seekbar_increment"
|
||||||
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.538"
|
app:layout_constraintHorizontal_bias="0.538"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
@ -92,6 +94,8 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="@dimen/_36sdp"
|
android:layout_height="@dimen/_36sdp"
|
||||||
|
|
||||||
|
app:seekBarIncrement="@integer/gyro_speed_seekbar_increment"
|
||||||
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.538"
|
app:layout_constraintHorizontal_bias="0.538"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
@ -127,6 +131,8 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="@dimen/_36sdp"
|
android:layout_height="@dimen/_36sdp"
|
||||||
|
|
||||||
|
app:seekBarIncrement="@integer/mouse_speed_seekbar_increment"
|
||||||
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.538"
|
app:layout_constraintHorizontal_bias="0.538"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
@ -172,6 +178,8 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="@dimen/_36sdp"
|
android:layout_height="@dimen/_36sdp"
|
||||||
|
|
||||||
|
app:seekBarIncrement="@integer/gesture_delay_seekbar_increment"
|
||||||
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.538"
|
app:layout_constraintHorizontal_bias="0.538"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
7
app_pojavlauncher/src/main/res/values/attributes.xml
Normal file
7
app_pojavlauncher/src/main/res/values/attributes.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<attr name="seekBarIncrement" format="integer" />
|
||||||
|
<declare-styleable name="CustomSeekbar">
|
||||||
|
<attr name="seekBarIncrement" />
|
||||||
|
</declare-styleable>
|
||||||
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user