Skip to content

Commit

Permalink
fix: fix Scroll conflict
Browse files Browse the repository at this point in the history
add: make padding attributes efective
  • Loading branch information
“gujinjie” committed Feb 21, 2017
1 parent 73fefdc commit 993b55e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
52 changes: 44 additions & 8 deletions RangeSeekBar/src/main/java/com/jaygoo/widget/RangeSeekbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);

heightNeeded = mThumbSize + mCursorTextHeight + (int)mHintBGHeight + 2 * DEFALT_PADDING + mHintBGPadding;
heightNeeded = mThumbSize + mCursorTextHeight + (int)mHintBGHeight + 2 * DEFALT_PADDING
+ mHintBGPadding + getPaddingTop() + getPaddingBottom();

/**
* onMeasure传入的widthMeasureSpec和heightMeasureSpec不是一般的尺寸数值,而是将模式和尺寸组合在一起的数值
Expand Down Expand Up @@ -210,10 +211,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// Calculates the position of the progress bar and initializes the positions of
// the two buttons based on it

lineLeft = 2 * DEFALT_PADDING;
lineRight = w - 2 * DEFALT_PADDING;
lineTop = (int)mHintBGHeight+ mThumbSize/2 -mSeekbarHight/2 + DEFALT_PADDING;
lineBottom = lineTop + mSeekbarHight;
lineLeft = 2 * DEFALT_PADDING + (int)(mHintBGWith/2) + getPaddingLeft();
lineRight = w - lineLeft - getPaddingRight();
lineTop = (int)mHintBGHeight+ mThumbSize/2 -mSeekbarHight/2 + DEFALT_PADDING + getPaddingTop();
lineBottom = lineTop + mSeekbarHight - getPaddingBottom();
lineWidth = lineRight - lineLeft;
line.set(lineLeft, lineTop, lineRight, lineBottom);
lineCorners = (int) ((lineBottom - lineTop) * 0.45f);
Expand Down Expand Up @@ -720,8 +721,11 @@ public float[] getCurrentRange() {
}
}

public void setEnable(boolean isEnable){
this.isEnable = isEnable;

@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
this.isEnable = enabled;
}

public void setProgress(String progress){
Expand Down Expand Up @@ -765,6 +769,12 @@ public boolean onTouchEvent(MotionEvent event) {
touchResult = true;

}

//Intercept parent TouchEvent
if(getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}

return touchResult;
case MotionEvent.ACTION_MOVE:

Expand Down Expand Up @@ -812,6 +822,11 @@ public boolean onTouchEvent(MotionEvent event) {
}
leftSB.slide(percent);
leftSB.isShowingHint = true;

//Intercept parent TouchEvent
if(getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}
} else if (currTouch == rightSB) {
if (cellsCount > 1) {
if (x > lineRight) {
Expand Down Expand Up @@ -847,12 +862,28 @@ public boolean onTouchEvent(MotionEvent event) {
callback.onRangeChanged(this, result[0], result[1],true);
}
invalidate();

//Intercept parent TouchEvent
if(getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}
break;
case MotionEvent.ACTION_CANCEL:
if (mSeekBarMode == 2) {
rightSB.isShowingHint = false;
}
leftSB.isShowingHint = false;

if (callback != null) {
float[] result = getCurrentRange();
callback.onRangeChanged(this, result[0], result[1],false);
}

//Intercept parent TouchEvent
if(getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}

break;
case MotionEvent.ACTION_UP:
if (mSeekBarMode == 2) {
Expand All @@ -863,7 +894,12 @@ public boolean onTouchEvent(MotionEvent event) {

if (callback != null) {
float[] result = getCurrentRange();
callback.onRangeChanged(this, result[0], result[1],true);
callback.onRangeChanged(this, result[0], result[1],false);
}

//Intercept parent TouchEvent
if(getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion RangeSeekBar/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#2ed184</color>
<color name="colorSeekBarDefalut">#c3c3c3</color>
<color name="colorSeekBarDefault">#c3c3c3</color>

</resources>
3 changes: 3 additions & 0 deletions app/src/main/java/com/jaygoo/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.jaygoo.widget.RangeSeekbar;
Expand All @@ -12,6 +13,7 @@ public class MainActivity extends AppCompatActivity {
private RangeSeekbar seekbar2;
private TextView tv2;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -41,4 +43,5 @@ public void onRangeChanged(RangeSeekbar view, float min, float max, boolean isFr
});

}

}
20 changes: 10 additions & 10 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
app:markTextArray="@array/markArray"
app:lineColorSelected="@color/colorAccent"
app:seekBarResId="@drawable/seekbar_thumb"
app:lineColorEdge="@color/colorSeekBarDefalut"
app:lineColorEdge="@color/colorSeekBarDefault"
app:cellMode="number"
app:seekBarMode="single"
/>
Expand All @@ -30,28 +30,27 @@
<com.jaygoo.widget.RangeSeekbar
android:id="@+id/seekbar2"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_height="70dp"
app:markTextArray="@array/markArray"
app:lineColorSelected="@color/colorPrimary"
app:lineColorEdge="@color/colorSeekBarDefalut"
app:lineColorEdge="@color/colorSeekBarDefault"
app:textPadding="17dp"
app:textSize="14sp"
app:min="-20"
app:min="0"
app:max="100"
app:thumbPrimaryColor="@color/colorSeekBarDefalut"
app:thumbPrimaryColor="@color/colorSeekBarDefault"
app:thumbSecondaryColor="@color/colorAccent"
app:seekbarHight="2dp"
app:thumbSize="20dp"
app:thumbSize="13dp"
app:cellMode="number"
app:seekBarMode="rangle"
app:seekBarMode="single"
/>
<com.jaygoo.widget.RangeSeekbar
android:id="@+id/seekbar3"
android:layout_width="match_parent"
android:layout_height="120dp"
app:markTextArray="@array/negativeMarkArray"
app:lineColorSelected="@color/colorAccent"
app:lineColorEdge="@color/colorSeekBarDefalut"
app:lineColorEdge="@color/colorSeekBarDefault"
app:textPadding="17dp"
app:textSize="16sp"
app:min="-100"
Expand All @@ -69,7 +68,7 @@
android:layout_height="80dp"
app:markTextArray="@array/wordsArray"
app:lineColorSelected="@color/colorPrimary"
app:lineColorEdge="@color/colorSeekBarDefalut"
app:lineColorEdge="@color/colorSeekBarDefault"
app:textPadding="17dp"
app:cells="4"
app:hideProgressHint="true"
Expand All @@ -80,4 +79,5 @@
app:cellMode="other"
app:seekBarMode="single"
/>

</LinearLayout>

0 comments on commit 993b55e

Please sign in to comment.