diff --git a/bubbleseekbar/src/main/java/com/xw/repo/BubbleConfigBuilder.java b/bubbleseekbar/src/main/java/com/xw/repo/BubbleConfigBuilder.java index f431109..9b12faf 100644 --- a/bubbleseekbar/src/main/java/com/xw/repo/BubbleConfigBuilder.java +++ b/bubbleseekbar/src/main/java/com/xw/repo/BubbleConfigBuilder.java @@ -48,6 +48,8 @@ public class BubbleConfigBuilder { boolean hideBubble; boolean rtl; + BubbleSeekBar.BubbleValueToTextConverter bubbleValueToTextConverter; + private BubbleSeekBar mBubbleSeekBar; BubbleConfigBuilder(BubbleSeekBar bubbleSeekBar) { @@ -228,6 +230,11 @@ public BubbleConfigBuilder rtl() { return this; } + public BubbleConfigBuilder bubbleValueToTextConverter (BubbleSeekBar.BubbleValueToTextConverter converter) { + this.bubbleValueToTextConverter = converter; + return this; + } + public float getMin() { return min; } @@ -359,4 +366,8 @@ public boolean isHideBubble() { public boolean isRtl() { return rtl; } + + public BubbleSeekBar.BubbleValueToTextConverter getBubbleValueToTextConverter() { + return bubbleValueToTextConverter; + } } diff --git a/bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java b/bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java index 3b99bd1..9b70178 100644 --- a/bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java +++ b/bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java @@ -125,6 +125,8 @@ public class BubbleSeekBar extends View { private float mPreSecValue; // previous SectionValue private BubbleConfigBuilder mConfigBuilder; // config attributes + private BubbleValueToTextConverter mBubbleValueToTextConverter; + public BubbleSeekBar(Context context) { this(context, null); } @@ -205,8 +207,8 @@ public BubbleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { // init BubbleView mBubbleView = new BubbleView(context); - mBubbleView.setProgressText(isShowProgressInFloat ? - String.valueOf(getProgressFloat()) : String.valueOf(getProgress())); + mBubbleValueToTextConverter = new DefaultBubbleValueToTextConverter(); + mBubbleView.setProgressText(mBubbleValueToTextConverter.convertValueToText(this, getProgress(), getProgressFloat(), isShowProgressInFloat)); mLayoutParams = new WindowManager.LayoutParams(); mLayoutParams.gravity = Gravity.START | Gravity.TOP; @@ -721,8 +723,8 @@ public boolean onTouchEvent(MotionEvent event) { mBubbleCenterRawX = calculateCenterRawXofBubbleView(); mLayoutParams.x = (int) (mBubbleCenterRawX + 0.5f); mWindowManager.updateViewLayout(mBubbleView, mLayoutParams); - mBubbleView.setProgressText(isShowProgressInFloat ? - String.valueOf(getProgressFloat()) : String.valueOf(getProgress())); + mBubbleView.setProgressText(mBubbleValueToTextConverter.convertValueToText(this, getProgress(), getProgressFloat(), isShowProgressInFloat)); + } invalidate(); @@ -856,8 +858,8 @@ public void onAnimationStart(Animator animation) { mWindowManager.addView(mBubbleView, mLayoutParams); } }).start(); - mBubbleView.setProgressText(isShowProgressInFloat ? - String.valueOf(getProgressFloat()) : String.valueOf(getProgress())); + mBubbleView.setProgressText(mBubbleValueToTextConverter.convertValueToText(this, getProgress(), getProgressFloat(), isShowProgressInFloat)); + } /** @@ -897,8 +899,7 @@ public void onAnimationUpdate(ValueAnimator animation) { mBubbleCenterRawX = calculateCenterRawXofBubbleView(); mLayoutParams.x = (int) (mBubbleCenterRawX + 0.5f); mWindowManager.updateViewLayout(mBubbleView, mLayoutParams); - mBubbleView.setProgressText(isShowProgressInFloat ? - String.valueOf(getProgressFloat()) : String.valueOf(getProgress())); + mBubbleView.setProgressText(mBubbleValueToTextConverter.convertValueToText(BubbleSeekBar.this, getProgress(), getProgressFloat(), isShowProgressInFloat)); } invalidate(); @@ -1158,6 +1159,7 @@ void config(BubbleConfigBuilder builder) { mAlwaysShowBubbleDelay = builder.alwaysShowBubbleDelay; isHideBubble = builder.hideBubble; isRtl = builder.rtl; + mBubbleValueToTextConverter = builder.bubbleValueToTextConverter; initConfigByPriority(); calculateRadiusOfBubble(); @@ -1210,6 +1212,7 @@ public BubbleConfigBuilder getConfigBuilder() { mConfigBuilder.alwaysShowBubbleDelay = mAlwaysShowBubbleDelay; mConfigBuilder.hideBubble = isHideBubble; mConfigBuilder.rtl = isRtl; + mConfigBuilder.bubbleValueToTextConverter = mBubbleValueToTextConverter; return mConfigBuilder; } @@ -1231,8 +1234,7 @@ protected void onRestoreInstanceState(Parcelable state) { super.onRestoreInstanceState(bundle.getParcelable("save_instance")); if (mBubbleView != null) { - mBubbleView.setProgressText(isShowProgressInFloat ? - String.valueOf(getProgressFloat()) : String.valueOf(getProgress())); + mBubbleView.setProgressText(mBubbleValueToTextConverter.convertValueToText(BubbleSeekBar.this, getProgress(), getProgressFloat(), isShowProgressInFloat)); } setProgress(mProgress); @@ -1305,6 +1307,13 @@ public interface CustomSectionTextArray { SparseArray onCustomize(int sectionCount, @NonNull SparseArray array); } + /** + * Customize the value text that is displayed inside the bubble. Works fine with maximal five characters + */ + public interface BubbleValueToTextConverter { + String convertValueToText(BubbleSeekBar bubbleSeekBar, int progress, float progressFloat, Boolean isShowProgressInFloat); + } + /*********************************************************************************************** ************************************** custom bubble view *********************************** **********************************************************************************************/ diff --git a/bubbleseekbar/src/main/java/com/xw/repo/DefaultBubbleValueToTextConverter.java b/bubbleseekbar/src/main/java/com/xw/repo/DefaultBubbleValueToTextConverter.java new file mode 100644 index 0000000..9c80f81 --- /dev/null +++ b/bubbleseekbar/src/main/java/com/xw/repo/DefaultBubbleValueToTextConverter.java @@ -0,0 +1,13 @@ +package com.xw.repo; + +/** + * Created by ewojahn on 07.12.17. + */ + +public class DefaultBubbleValueToTextConverter implements BubbleSeekBar.BubbleValueToTextConverter { + @Override + public String convertValueToText(BubbleSeekBar bubbleSeekBar, int progress, float progressFloat, Boolean isShowProgressInFloat) { + return isShowProgressInFloat ? + String.valueOf(progressFloat) : String.valueOf(progress); + } +}