precise seekbar

This commit is contained in:
Tungstend 2023-07-11 17:09:16 +08:00
parent f8cae4ae46
commit 889ad4410d
12 changed files with 307 additions and 93 deletions

View File

@ -19,7 +19,7 @@ import com.tungsten.fcllibrary.component.dialog.FCLDialog;
import com.tungsten.fcllibrary.component.view.FCLButton;
import com.tungsten.fcllibrary.component.view.FCLEditText;
import com.tungsten.fcllibrary.component.view.FCLLinearLayout;
import com.tungsten.fcllibrary.component.view.FCLSeekBar;
import com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar;
import com.tungsten.fcllibrary.component.view.FCLTabLayout;
import com.tungsten.fcllibrary.component.view.FCLTextView;
@ -66,12 +66,9 @@ public class AddButtonStyleDialog extends FCLDialog implements View.OnClickListe
style.nameProperty().bind(editName.stringProperty());
{
FCLSeekBar textSize = normalStyleLayout.findViewById(R.id.text_size);
FCLSeekBar strokeWidth = normalStyleLayout.findViewById(R.id.stroke_width);
FCLSeekBar cornerRadius = normalStyleLayout.findViewById(R.id.corner_radius);
textSize.addProgressListener();
strokeWidth.addProgressListener();
cornerRadius.addProgressListener();
FCLPreciseSeekBar textSize = normalStyleLayout.findViewById(R.id.text_size);
FCLPreciseSeekBar strokeWidth = normalStyleLayout.findViewById(R.id.stroke_width);
FCLPreciseSeekBar cornerRadius = normalStyleLayout.findViewById(R.id.corner_radius);
FCLTextView textSizeText = normalStyleLayout.findViewById(R.id.text_size_text);
FCLTextView strokeWidthText = normalStyleLayout.findViewById(R.id.stroke_width_text);
@ -179,12 +176,9 @@ public class AddButtonStyleDialog extends FCLDialog implements View.OnClickListe
}
{
FCLSeekBar textSize = pressedStyleLayout.findViewById(R.id.text_size);
FCLSeekBar strokeWidth = pressedStyleLayout.findViewById(R.id.stroke_width);
FCLSeekBar cornerRadius = pressedStyleLayout.findViewById(R.id.corner_radius);
textSize.addProgressListener();
strokeWidth.addProgressListener();
cornerRadius.addProgressListener();
FCLPreciseSeekBar textSize = pressedStyleLayout.findViewById(R.id.text_size);
FCLPreciseSeekBar strokeWidth = pressedStyleLayout.findViewById(R.id.stroke_width);
FCLPreciseSeekBar cornerRadius = pressedStyleLayout.findViewById(R.id.corner_radius);
FCLTextView textSizeText = pressedStyleLayout.findViewById(R.id.text_size_text);
FCLTextView strokeWidthText = pressedStyleLayout.findViewById(R.id.stroke_width_text);

View File

@ -22,7 +22,7 @@ import com.tungsten.fcllibrary.component.dialog.FCLDialog;
import com.tungsten.fcllibrary.component.view.FCLButton;
import com.tungsten.fcllibrary.component.view.FCLEditText;
import com.tungsten.fcllibrary.component.view.FCLLinearLayout;
import com.tungsten.fcllibrary.component.view.FCLSeekBar;
import com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar;
import com.tungsten.fcllibrary.component.view.FCLSpinner;
import com.tungsten.fcllibrary.component.view.FCLTextView;
@ -82,8 +82,7 @@ public class AddDirectionStyleDialog extends FCLDialog implements View.OnClickLi
style.nameProperty().bind(editName.stringProperty());
{
FCLSeekBar interval = buttonStyleLayout.findViewById(R.id.interval);
interval.addProgressListener();
FCLPreciseSeekBar interval = buttonStyleLayout.findViewById(R.id.interval);
FCLTextView intervalText = buttonStyleLayout.findViewById(R.id.interval_text);
@ -132,16 +131,11 @@ public class AddDirectionStyleDialog extends FCLDialog implements View.OnClickLi
}
{
FCLSeekBar rockerSize = rockerStyleLayout.findViewById(R.id.rocker_size);
FCLSeekBar bgStrokeWidth = rockerStyleLayout.findViewById(R.id.bg_stroke_width);
FCLSeekBar bgCornerRadius = rockerStyleLayout.findViewById(R.id.bg_corner_radius);
FCLSeekBar strokeWidth = rockerStyleLayout.findViewById(R.id.stroke_width);
FCLSeekBar cornerRadius = rockerStyleLayout.findViewById(R.id.corner_radius);
rockerSize.addProgressListener();
bgStrokeWidth.addProgressListener();
bgCornerRadius.addProgressListener();
strokeWidth.addProgressListener();
cornerRadius.addProgressListener();
FCLPreciseSeekBar rockerSize = rockerStyleLayout.findViewById(R.id.rocker_size);
FCLPreciseSeekBar bgStrokeWidth = rockerStyleLayout.findViewById(R.id.bg_stroke_width);
FCLPreciseSeekBar bgCornerRadius = rockerStyleLayout.findViewById(R.id.bg_corner_radius);
FCLPreciseSeekBar strokeWidth = rockerStyleLayout.findViewById(R.id.stroke_width);
FCLPreciseSeekBar cornerRadius = rockerStyleLayout.findViewById(R.id.corner_radius);
FCLTextView rockerSizeText = rockerStyleLayout.findViewById(R.id.rocker_size_text);
FCLTextView bgStrokeWidthText = rockerStyleLayout.findViewById(R.id.bg_stroke_width_text);

View File

@ -28,7 +28,7 @@ import com.tungsten.fcllibrary.component.view.FCLButton;
import com.tungsten.fcllibrary.component.view.FCLEditText;
import com.tungsten.fcllibrary.component.view.FCLImageButton;
import com.tungsten.fcllibrary.component.view.FCLLinearLayout;
import com.tungsten.fcllibrary.component.view.FCLSeekBar;
import com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar;
import com.tungsten.fcllibrary.component.view.FCLSpinner;
import com.tungsten.fcllibrary.component.view.FCLSwitch;
import com.tungsten.fcllibrary.component.view.FCLTabLayout;
@ -142,10 +142,8 @@ public class EditViewDialog extends FCLDialog implements View.OnClickListener {
1 : 2));
FXUtils.bindSelection(visibilityTypeSpinner, data.getBaseInfo().visibilityTypeProperty());
FCLSeekBar xPosition = findInfoView(R.id.x_position);
FCLSeekBar yPosition = findInfoView(R.id.y_position);
xPosition.addProgressListener();
yPosition.addProgressListener();
FCLPreciseSeekBar xPosition = findInfoView(R.id.x_position);
FCLPreciseSeekBar yPosition = findInfoView(R.id.y_position);
FCLTextView xPositionText = findInfoView(R.id.x_position_text);
FCLTextView yPositionText = findInfoView(R.id.y_position_text);
@ -200,10 +198,8 @@ public class EditViewDialog extends FCLDialog implements View.OnClickListener {
heightReferenceSpinner.setSelection(data.getBaseInfo().getPercentageHeight().getReference() == BaseInfoData.PercentageSize.Reference.SCREEN_WIDTH ? 0 : 1);
FXUtils.bindSelection(heightReferenceSpinner, data.getBaseInfo().getPercentageHeight().referenceProperty());
FCLSeekBar width = findInfoView(R.id.width);
FCLSeekBar height = findInfoView(R.id.height);
width.addProgressListener();
height.addProgressListener();
FCLPreciseSeekBar width = findInfoView(R.id.width);
FCLPreciseSeekBar height = findInfoView(R.id.height);
FCLTextView widthText = findInfoView(R.id.width_text);
FCLTextView heightText = findInfoView(R.id.height_text);
@ -425,10 +421,8 @@ public class EditViewDialog extends FCLDialog implements View.OnClickListener {
1 : 2));
FXUtils.bindSelection(visibilityTypeSpinner, data.getBaseInfo().visibilityTypeProperty());
FCLSeekBar xPosition = findInfoView(R.id.x_position);
FCLSeekBar yPosition = findInfoView(R.id.y_position);
xPosition.addProgressListener();
yPosition.addProgressListener();
FCLPreciseSeekBar xPosition = findInfoView(R.id.x_position);
FCLPreciseSeekBar yPosition = findInfoView(R.id.y_position);
FCLTextView xPositionText = findInfoView(R.id.x_position_text);
FCLTextView yPositionText = findInfoView(R.id.y_position_text);
@ -473,8 +467,7 @@ public class EditViewDialog extends FCLDialog implements View.OnClickListener {
sizeReferenceSpinner.setSelection(data.getBaseInfo().getPercentageWidth().getReference() == BaseInfoData.PercentageSize.Reference.SCREEN_WIDTH ? 0 : 1);
FXUtils.bindSelection(sizeReferenceSpinner, data.getBaseInfo().getPercentageWidth().referenceProperty());
FCLSeekBar size = findInfoView(R.id.size);
size.addProgressListener();
FCLPreciseSeekBar size = findInfoView(R.id.size);
FCLTextView sizeText = findInfoView(R.id.size_text);

View File

@ -24,9 +24,9 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
android:min="2"
android:max="30"
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
app:min_value="2"
app:max_value="30"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -60,9 +60,9 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
android:min="0"
android:max="100"
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
app:min_value="0"
app:max_value="100"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -96,9 +96,9 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
android:min="0"
android:max="500"
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
app:min_value="0"
app:max_value="500"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"

View File

@ -22,9 +22,9 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
android:min="0"
android:max="200"
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
app:min_value="0"
app:max_value="200"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"

View File

@ -22,9 +22,9 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
android:min="100"
android:max="900"
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
app:min_value="100"
app:max_value="900"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -58,9 +58,9 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
android:min="0"
android:max="50"
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
app:min_value="0"
app:max_value="50"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -94,9 +94,9 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
android:min="0"
android:max="500"
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
app:min_value="0"
app:max_value="500"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -130,9 +130,9 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
android:min="0"
android:max="50"
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
app:min_value="0"
app:max_value="50"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -166,9 +166,9 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
android:min="0"
android:max="500"
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
app:min_value="0"
app:max_value="500"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"

View File

@ -91,11 +91,11 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
android:id="@+id/x_position"
android:min="0"
android:max="1000"
android:layout_width="200dp"
app:min_value="0"
app:max_value="1000"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
@ -127,11 +127,11 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
android:id="@+id/y_position"
android:min="0"
android:max="1000"
android:layout_width="200dp"
app:min_value="0"
app:max_value="1000"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
@ -216,10 +216,10 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
android:id="@+id/width"
android:min="1"
android:layout_width="200dp"
app:min_value="1"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
@ -278,10 +278,10 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
android:id="@+id/height"
android:min="1"
android:layout_width="200dp"
app:min_value="1"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="center"/>

View File

@ -63,11 +63,11 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
android:id="@+id/x_position"
android:min="0"
android:max="1000"
android:layout_width="200dp"
app:min_value="0"
app:max_value="1000"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
@ -99,11 +99,11 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
android:id="@+id/y_position"
android:min="0"
android:max="1000"
android:layout_width="200dp"
app:min_value="0"
app:max_value="1000"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
@ -188,10 +188,10 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.tungsten.fcllibrary.component.view.FCLSeekBar
<com.tungsten.fcllibrary.component.view.FCLPreciseSeekBar
android:id="@+id/size"
android:min="1"
android:layout_width="200dp"
app:min_value="1"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="center"/>

View File

@ -0,0 +1,218 @@
package com.tungsten.fcllibrary.component.view;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.tungsten.fclcore.fakefx.beans.property.BooleanProperty;
import com.tungsten.fclcore.fakefx.beans.property.BooleanPropertyBase;
import com.tungsten.fclcore.fakefx.beans.property.DoubleProperty;
import com.tungsten.fclcore.fakefx.beans.property.IntegerProperty;
import com.tungsten.fclcore.task.Schedulers;
import com.tungsten.fcllibrary.R;
public class FCLPreciseSeekBar extends RelativeLayout {
private FCLImageButton minus;
private FCLImageButton add;
private FCLSeekBar seekBar;
private BooleanProperty visibilityProperty;
private BooleanProperty disableProperty;
public FCLPreciseSeekBar(@NonNull Context context) {
super(context);
init(false, 0, 100);
}
public FCLPreciseSeekBar(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FCLPreciseSeekBar);
boolean autoTint = typedArray.getBoolean(R.styleable.FCLPreciseSeekBar_auto_button_tint, false);
int min = typedArray.getInteger(R.styleable.FCLPreciseSeekBar_min_value, 0);
int max = typedArray.getInteger(R.styleable.FCLPreciseSeekBar_max_value, 100);
typedArray.recycle();
init(autoTint, min, max);
}
public FCLPreciseSeekBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FCLPreciseSeekBar);
boolean autoTint = typedArray.getBoolean(R.styleable.FCLPreciseSeekBar_auto_button_tint, false);
int min = typedArray.getInteger(R.styleable.FCLPreciseSeekBar_min_value, 0);
int max = typedArray.getInteger(R.styleable.FCLPreciseSeekBar_max_value, 100);
typedArray.recycle();
init(autoTint, min, max);
}
@SuppressLint("UseCompatLoadingForDrawables")
private void init(boolean autoTint, int min, int max) {
add = new FCLImageButton(getContext());
minus = new FCLImageButton(getContext());
seekBar = new FCLSeekBar(getContext());
add.setImageDrawable(getContext().getDrawable(R.drawable.ic_baseline_add_24));
minus.setImageDrawable(getContext().getDrawable(R.drawable.ic_baseline_remove_24));
add.setNoPadding(true);
minus.setNoPadding(true);
setAutoTint(autoTint);
seekBar.setMin(min);
seekBar.setMax(max);
seekBar.addProgressListener();
add.setOnClickListener(v -> {
if (seekBar.getProgress() < seekBar.getMax()) {
setProgressValue(seekBar.getProgress() + 1);
}
});
minus.setOnClickListener(v -> {
if (seekBar.getProgress() > seekBar.getMin()) {
setProgressValue(seekBar.getProgress() - 1);
}
});
addView(minus, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
addView(seekBar, new ViewGroup.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT));
addView(add, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
post(() -> add.post(() -> seekBar.post(() -> minus.post(() -> {
if (add.getMeasuredHeight() >= seekBar.getMeasuredHeight()) {
seekBar.setY((add.getMeasuredHeight() - seekBar.getMeasuredHeight()) / 2f);
} else {
add.setY((seekBar.getMeasuredHeight() - add.getMeasuredHeight()) / 2f);
minus.setY((seekBar.getMeasuredHeight() - minus.getMeasuredHeight()) / 2f);
}
minus.setX(0);
add.setX(getMeasuredWidth() - add.getMeasuredWidth());
ViewGroup.LayoutParams layoutParams = seekBar.getLayoutParams();
layoutParams.width = getMeasuredWidth() - (add.getMeasuredWidth() + minus.getMeasuredWidth());
seekBar.setLayoutParams(layoutParams);
seekBar.setX(minus.getMeasuredWidth());
}))));
}
@Override
public void requestLayout() {
super.requestLayout();
post(() -> {
measure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY));
layout(getLeft(), getTop(), getRight(), getBottom());
});
}
public void setMax(int max) {
seekBar.setMax(max);
}
public void setMin(int min) {
seekBar.setMin(min);
}
public void setProgress(int progress) {
seekBar.setProgress(progress);
}
public int getProgress() {
return seekBar.getProgress();
}
public void setAutoTint(boolean autoTint) {
add.setAutoTint(autoTint);
minus.setAutoTint(autoTint);
}
public final void setPercentProgressValue(double percentProgressValue) {
seekBar.setPercentProgressValue(percentProgressValue);
}
public final double getPercentProgressValue() {
return seekBar.getPercentProgressValue();
}
public final DoubleProperty percentProgressProperty() {
return seekBar.percentProgressProperty();
}
public final void setProgressValue(int progressValue) {
seekBar.setProgressValue(progressValue);
}
public final int getProgressValue() {
return seekBar.getProgressValue();
}
public final IntegerProperty progressProperty() {
return seekBar.progressProperty();
}
public final void setVisibilityValue(boolean visibility) {
visibilityProperty().set(visibility);
}
public final boolean getVisibilityValue() {
return visibilityProperty == null || visibilityProperty.get();
}
public final BooleanProperty visibilityProperty() {
if (visibilityProperty == null) {
visibilityProperty = new BooleanPropertyBase() {
public void invalidated() {
Schedulers.androidUIThread().execute(() -> {
boolean visible = get();
setVisibility(visible ? VISIBLE : GONE);
});
}
public Object getBean() {
return this;
}
public String getName() {
return "visibility";
}
};
}
return visibilityProperty;
}
public final void setDisableValue(boolean disableValue) {
disableProperty().set(disableValue);
}
public final boolean getDisableValue() {
return disableProperty == null || disableProperty.get();
}
public final BooleanProperty disableProperty() {
if (disableProperty == null) {
disableProperty = new BooleanPropertyBase() {
public void invalidated() {
Schedulers.androidUIThread().execute(() -> {
boolean disable = get();
add.setEnabled(!disable);
minus.setEnabled(!disable);
seekBar.setEnabled(!disable);
});
}
public Object getBean() {
return this;
}
public String getName() {
return "disable";
}
};
}
return disableProperty;
}
}

View File

@ -0,0 +1,10 @@
<vector
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@android:color/white"
android:pathData="M19,13H5v-2h14v2z"/>
</vector>

View File

@ -32,6 +32,11 @@
<declare-styleable name="FCLTabLayout">
<attr name="follow_theme" format="boolean"/>
</declare-styleable>
<declare-styleable name="FCLPreciseSeekBar">
<attr name="auto_button_tint" format="boolean"/>
<attr name="min_value" format="integer"/>
<attr name="max_value" format="integer"/>
</declare-styleable>
<declare-styleable name="FCLLinearLayout">
<attr name="auto_linear_background_tint" format="boolean"/>
</declare-styleable>