diff --git a/FCL/src/main/java/com/tungsten/fcl/ui/download/RemoteModInfoPage.java b/FCL/src/main/java/com/tungsten/fcl/ui/download/RemoteModInfoPage.java index 09b27128f..34371de14 100644 --- a/FCL/src/main/java/com/tungsten/fcl/ui/download/RemoteModInfoPage.java +++ b/FCL/src/main/java/com/tungsten/fcl/ui/download/RemoteModInfoPage.java @@ -243,9 +243,7 @@ private SimpleMultimap> sortV } } return false; - }).forEach(v -> { - classifiedVersions.put(recommendedVersion, v); - }); + }).forEach(v -> classifiedVersions.put(recommendedVersion, v)); } return classifiedVersions; } diff --git a/FCLLibrary/src/main/java/com/tungsten/fcllibrary/component/view/FCLNumberSeekBar.java b/FCLLibrary/src/main/java/com/tungsten/fcllibrary/component/view/FCLNumberSeekBar.java index 7df25fbad..573227cf3 100644 --- a/FCLLibrary/src/main/java/com/tungsten/fcllibrary/component/view/FCLNumberSeekBar.java +++ b/FCLLibrary/src/main/java/com/tungsten/fcllibrary/component/view/FCLNumberSeekBar.java @@ -6,6 +6,9 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.drawable.ShapeDrawable; +import android.graphics.drawable.shapes.OvalShape; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.MotionEvent; @@ -14,7 +17,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.AppCompatSeekBar; import com.tungsten.fclcore.fakefx.beans.property.BooleanProperty; @@ -40,6 +42,8 @@ public class FCLNumberSeekBar extends AppCompatSeekBar { private Paint textPaint; private String suffix; private GestureDetector gestureDetector; + private ShapeDrawable thumbDrawable; + private Rect textBounds; private final IntegerProperty theme = new IntegerPropertyBase() { @@ -115,12 +119,10 @@ private void init(AttributeSet attrs) { suffix = Optional.ofNullable(typedArray.getString(R.styleable.FCLNumberSeekBar_suffix)).orElse(""); typedArray.recycle(); } - setThumb(AppCompatResources.getDrawable(getContext(), R.drawable.transparent)); textPaint = new Paint(); textPaint.setColor(Color.WHITE); textPaint.setTextSize(40); textPaint.setTextAlign(Paint.Align.CENTER); - gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTap(@NonNull MotionEvent e) { @@ -137,6 +139,25 @@ public boolean onDoubleTap(@NonNull MotionEvent e) { dialog.show(); return true; } + + @Override + public boolean onSingleTapUp(@NonNull MotionEvent e) { + if (e.getX() >= computeThumbX() - textBounds.width() / 2f && e.getX() <= computeThumbX() + textBounds.width() / 2f) { + EditDialog dialog = new EditDialog(getContext(), s -> { + try { + int i = Integer.parseInt(s); + if (i >= getMin() && i <= getMax()) { + setProgress(i); + } + } catch (Throwable ignore) { + } + }); + dialog.getEditText().setInputType(EditorInfo.TYPE_NUMBER_FLAG_DECIMAL); + dialog.show(); + return true; + } + return false; + } }); } @@ -275,12 +296,19 @@ public String getName() { @Override protected synchronized void onDraw(Canvas canvas) { super.onDraw(canvas); - - float width = getWidth() - getPaddingStart() - getPaddingEnd(); - float progressRatio = (float) (getProgress() - getMin()) / (getMax() - getMin()); - float thumbX = getPaddingStart() + (width * progressRatio); + if (thumbDrawable == null) { + textBounds = new Rect(); + textPaint.getTextBounds(getMax() + suffix, 0, (getMax() + suffix).length(), textBounds); + thumbDrawable = new ShapeDrawable(); + thumbDrawable.setShape(new OvalShape()); + thumbDrawable.getPaint().setColor(Color.TRANSPARENT); + thumbDrawable.setIntrinsicHeight(getHeight()); + thumbDrawable.setIntrinsicWidth(textBounds.width()); + setThumb(thumbDrawable); + } + textPaint.setTextSize(getHeight() / 1.5f); float textY = getHeight() / 2f - (textPaint.descent() + textPaint.ascent()) / 2f; - canvas.drawText(getProgress() + suffix, thumbX, textY, textPaint); + canvas.drawText(getProgress() + suffix, computeThumbX(), textY, textPaint); } @Override @@ -290,4 +318,10 @@ public boolean onTouchEvent(MotionEvent event) { } return super.onTouchEvent(event); } + + private float computeThumbX() { + float width = getWidth() - getPaddingStart() - getPaddingEnd(); + float progressRatio = (float) (getProgress() - getMin()) / (getMax() - getMin()); + return getPaddingStart() + (width * progressRatio); + } }