Skip to content

Commit

Permalink
fix Touch Mode delimiter in recycler view
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel163 committed Oct 11, 2017
1 parent 168155c commit f0e51a1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/main/res/layout/page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
app:drawableRight="@drawable/right"
app:leftText="before"
app:rightText="after"
app:touchMode="delimiter"
app:delimiterPadding="20dp"
app:textColor="@color/colorPrimary"
app:textSize="20sp" />

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void initAttrs(AttributeSet attrs) {
drawableLeft = a.getDrawable(R.styleable.BifacialView_drawableLeft);
drawableRight = a.getDrawable(R.styleable.BifacialView_drawableRight);
delimiterColor = a.getColor(R.styleable.BifacialView_delimiterColor, Color.WHITE);
delimiterWidth = a.getDimensionPixelSize(R.styleable.BifacialView_delimiterWidth,3);
delimiterWidth = a.getDimensionPixelSize(R.styleable.BifacialView_delimiterWidth, 3);
delimiterPadding = a.getDimensionPixelSize(R.styleable.BifacialView_delimiterPadding,
20);
arrowColor = a.getColor(R.styleable.BifacialView_arrowColor, Color.WHITE);
Expand All @@ -107,12 +107,12 @@ private void initAttrs(AttributeSet attrs) {
textColor = a.getColor(R.styleable.BifacialView_textColor, Color.WHITE);
textSize = a.getDimensionPixelSize(R.styleable.BifacialView_textSize,
getContext().getResources().getDimensionPixelSize(R.dimen.text_size));
arrowWidth = a.getDimensionPixelSize(R.styleable.BifacialView_arrowWidth, dpToPx(getContext(),12));
arrowHeight = a.getDimensionPixelSize(R.styleable.BifacialView_arrowHeight, dpToPx(getContext(),10));
arrowWidth = a.getDimensionPixelSize(R.styleable.BifacialView_arrowWidth, dpToPx(getContext(), 12));
arrowHeight = a.getDimensionPixelSize(R.styleable.BifacialView_arrowHeight, dpToPx(getContext(), 10));
arrowMargin = a.getDimensionPixelSize(R.styleable.BifacialView_arrowMargin, dpToPx(getContext(), 5));
arrowStrokeWidth = a.getDimensionPixelSize(R.styleable.BifacialView_arrowStrokeWidth, 5);
arrowFill = a.getBoolean(R.styleable.BifacialView_arrowFill, true);
arrowCornerRadius = a.getDimensionPixelSize(R.styleable.BifacialView_arrowCornerRadius,0);
arrowCornerRadius = a.getDimensionPixelSize(R.styleable.BifacialView_arrowCornerRadius, 0);

if (a.getInteger(R.styleable.BifacialView_touchMode, 0) == 0) {
touchMode = TouchMode.ALL;
Expand Down Expand Up @@ -168,11 +168,14 @@ public boolean onTouchEvent(MotionEvent event) {

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if ((touchMode == TouchMode.DELIMITER) &&
(x > delimiterPosition + delimiterPadding || x < delimiterPosition - delimiterPadding)) {
return false;
// for ViewPager and RecyclerView
if (touchMode == TouchMode.DELIMITER) {
if (x > delimiterPosition + delimiterPadding || x < delimiterPosition - delimiterPadding) {
return false;
} else {
getParent().requestDisallowInterceptTouchEvent(true);
}
}
getParent().requestDisallowInterceptTouchEvent(true);
case MotionEvent.ACTION_MOVE:
isMove = true;
break;
Expand Down Expand Up @@ -222,7 +225,7 @@ protected void onDraw(Canvas canvas) {
if (delimiterPosition < 0) {
delimiterPosition = 0;
}
canvas.clipRect(delimiterPosition + delimiterWidth/2, 0, width, height);
canvas.clipRect(delimiterPosition + delimiterWidth / 2, 0, width, height);
drawableRight.draw(canvas);
}

Expand All @@ -245,17 +248,17 @@ protected void onDraw(Canvas canvas) {

private void recreateArrowLeft() {
arrowLeft.rewind();
arrowLeft.moveTo(delimiterPosition - delimiterWidth/2 - arrowMargin - arrowWidth, height / 2);
arrowLeft.lineTo(delimiterPosition - delimiterWidth/2 - arrowMargin, height / 2 - arrowHeight/2);
arrowLeft.lineTo(delimiterPosition - delimiterWidth/2 - arrowMargin, height / 2 + arrowHeight/2);
arrowLeft.moveTo(delimiterPosition - delimiterWidth / 2 - arrowMargin - arrowWidth, height / 2);
arrowLeft.lineTo(delimiterPosition - delimiterWidth / 2 - arrowMargin, height / 2 - arrowHeight / 2);
arrowLeft.lineTo(delimiterPosition - delimiterWidth / 2 - arrowMargin, height / 2 + arrowHeight / 2);
arrowLeft.close();
}

private void recreateArrowRight() {
arrowRight.rewind();
arrowRight.moveTo(delimiterPosition + delimiterWidth/2 + arrowMargin + arrowWidth, height / 2);
arrowRight.lineTo(delimiterPosition + delimiterWidth/2 + arrowMargin, height / 2 - arrowHeight/2);
arrowRight.lineTo(delimiterPosition + delimiterWidth/2 + arrowMargin, height / 2 + arrowHeight/2);
arrowRight.moveTo(delimiterPosition + delimiterWidth / 2 + arrowMargin + arrowWidth, height / 2);
arrowRight.lineTo(delimiterPosition + delimiterWidth / 2 + arrowMargin, height / 2 - arrowHeight / 2);
arrowRight.lineTo(delimiterPosition + delimiterWidth / 2 + arrowMargin, height / 2 + arrowHeight / 2);
arrowRight.close();
}

Expand Down

0 comments on commit f0e51a1

Please sign in to comment.