Skip to content

Commit

Permalink
1.0.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Home authored and Home committed Nov 4, 2018
1 parent 6bf32cd commit 4471ec7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.createRadius;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.defineRadiusForPosition;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.getBackground;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.isInViewBounds;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.isInBounds;

/**
* Created by Robert Apikyan on 9/8/2017.
Expand All @@ -29,6 +29,7 @@ public class SegmentViewHolderImpl extends SegmentViewHolder<CharSequence> {
private TextView itemTV;
private float[] radius;
private ValueAnimator va;
private int[] windowLocation;

private final ValueAnimator.AnimatorUpdateListener bgAnimListener = new ValueAnimator.AnimatorUpdateListener() {
@Override
Expand All @@ -55,7 +56,9 @@ public boolean onTouch(View v, MotionEvent event) {
event.getAction() == MotionEvent.ACTION_POINTER_UP ||
event.getAction() == MotionEvent.ACTION_OUTSIDE) {

if (!isInViewBounds(event.getX(), event.getY(), getSectionView())) {
if (!isInBounds(event.getX(), event.getY(), windowLocation[0], windowLocation[1],
getSectionView().getMeasuredWidth(), getSectionView().getMeasuredHeight())) {

setBackground(isSelected() ? getSelectedBackground() : getUnSelectedBackground());
}
}
Expand All @@ -72,6 +75,7 @@ public SegmentViewHolderImpl(@NonNull View sectionView) {

@Override
protected void onSegmentBind(CharSequence segmentData) {
initScreenLocation();
itemTV.setText(segmentData);
if (isRadiusForEverySegment()) {
radius = createRadius(getTopLeftRadius(), getTopRightRadius(), getBottomRightRadius(), getBottomLeftRadius());
Expand All @@ -87,6 +91,11 @@ protected void onSegmentBind(CharSequence segmentData) {
ViewGroup.MarginLayoutParams.class.cast(itemTV.getLayoutParams()).setMargins(getSegmentHorizontalMargin(), getSegmentVerticalMargin(), getSegmentHorizontalMargin(), getSegmentVerticalMargin());
}

private void initScreenLocation() {
windowLocation = new int[2];
getSectionView().getLocationOnScreen(windowLocation);
}

@Override
public void onSegmentSelected(boolean isSelected, boolean isReselected) {
super.onSegmentSelected(isSelected, isReselected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public static ValueAnimator createBackgroundAnimation(int argbStart, int argbEnd
return ValueAnimator.ofObject(ArgbEvaluator.getInstance(), argbStart, argbEnd);
}

public static boolean isInViewBounds(float touchX, float touchY, View view){
return touchX >= view.getX() && touchX <= view.getX()+view.getMeasuredWidth() && // in x bounds
touchY >= view.getY() && touchY <=view.getY() + view.getMeasuredHeight();
public static boolean isInBounds(float touchX, float touchY, float viewX, float viewY, float viewW, float viewH) {
return touchX >= viewX && touchX <= viewX + viewW && // in x bounds
touchY >= viewY && touchY <= viewY + viewH;
}
}

0 comments on commit 4471ec7

Please sign in to comment.