Skip to content

Commit

Permalink
v1.6:
Browse files Browse the repository at this point in the history
 ① deal with onSizeChanged;
 ② 解决部分由java代码设置属性的bug。
  • Loading branch information
woxingxiao committed Jan 3, 2017
1 parent 546d86d commit 567edd5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ public BubbleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
mBubbleView.setProgressText(isShowProgressInFloat ?
String.valueOf(getProgressInFloat()) : String.valueOf(getProgress()));

calculateRadiusOfBubble();
}

/**
* 根据min、max计算气泡半径
*/
private void calculateRadiusOfBubble() {
mPaint.setTextSize(mBubbleTextSize);

// 计算滑到两端气泡里文字需要显示的宽度,比较取最大值为气泡的半径
String text = mMin < 0 ? "-" + mMin : "" + mMin;
mPaint.getTextBounds(text, 0, text.length(), mRectText);
Expand Down Expand Up @@ -683,6 +691,9 @@ public void setMin(int min) {

mMin = min;
mDelta = mMax - mMin;

calculateRadiusOfBubble();

postInvalidate();
}

Expand All @@ -691,7 +702,18 @@ public int getMax() {
}

public void setMax(int max) {
if (mMax == max || max < mMin) {
return;
}

mMax = max;
mDelta = mMax - mMin;

if (mProgress > mMax) {
mProgress = mMax;
}
calculateRadiusOfBubble();

postInvalidate();
}

Expand Down Expand Up @@ -812,6 +834,11 @@ public void setSectionCount(int sectionCount) {
if (mSectionCount <= 0 || mSectionCount > mMax - mMin) {
mSectionCount = 10;
}
if (mSectionCount > mDelta) {
isShowProgressInFloat = true;

calculateRadiusOfBubble();
}

requestLayout();
}
Expand Down Expand Up @@ -921,8 +948,16 @@ public boolean isShowProgressInFloat() {
}

public void setShowProgressInFloat(boolean showProgressInFloat) {
if (mSectionCount > mDelta) {
isShowProgressInFloat = true;
return;
}

if (isShowProgressInFloat != showProgressInFloat) {
isShowProgressInFloat = showProgressInFloat;

calculateRadiusOfBubble();

postInvalidate();
}
}
Expand Down

0 comments on commit 567edd5

Please sign in to comment.