Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CustomBubbleValueToTextConverter #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bubbleseekbar/src/main/java/com/xw/repo/BubbleConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class BubbleConfigBuilder {
boolean hideBubble;
boolean rtl;

BubbleSeekBar.BubbleValueToTextConverter bubbleValueToTextConverter;

private BubbleSeekBar mBubbleSeekBar;

BubbleConfigBuilder(BubbleSeekBar bubbleSeekBar) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -359,4 +366,8 @@ public boolean isHideBubble() {
public boolean isRtl() {
return rtl;
}

public BubbleSeekBar.BubbleValueToTextConverter getBubbleValueToTextConverter() {
return bubbleValueToTextConverter;
}
}
29 changes: 19 additions & 10 deletions bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));

}

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1158,6 +1159,7 @@ void config(BubbleConfigBuilder builder) {
mAlwaysShowBubbleDelay = builder.alwaysShowBubbleDelay;
isHideBubble = builder.hideBubble;
isRtl = builder.rtl;
mBubbleValueToTextConverter = builder.bubbleValueToTextConverter;

initConfigByPriority();
calculateRadiusOfBubble();
Expand Down Expand Up @@ -1210,6 +1212,7 @@ public BubbleConfigBuilder getConfigBuilder() {
mConfigBuilder.alwaysShowBubbleDelay = mAlwaysShowBubbleDelay;
mConfigBuilder.hideBubble = isHideBubble;
mConfigBuilder.rtl = isRtl;
mConfigBuilder.bubbleValueToTextConverter = mBubbleValueToTextConverter;

return mConfigBuilder;
}
Expand All @@ -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);

Expand Down Expand Up @@ -1305,6 +1307,13 @@ public interface CustomSectionTextArray {
SparseArray<String> onCustomize(int sectionCount, @NonNull SparseArray<String> 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 ***********************************
**********************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}