From 4a40f7a1139edb3fa1ea058d9bce8634a399e112 Mon Sep 17 00:00:00 2001 From: mudar Date: Mon, 11 Sep 2017 13:52:14 -0400 Subject: [PATCH 1/2] Added delimiterPadding attribute New dimension attribute to allow a larger draggable area around the arrows. Defaults to original 20. --- .../main/java/com/ebr163/bifacialview/view/BifacialView.java | 5 ++++- library/src/main/res/values/attrs.xml | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/ebr163/bifacialview/view/BifacialView.java b/library/src/main/java/com/ebr163/bifacialview/view/BifacialView.java index 5651f71..0fb4513 100644 --- a/library/src/main/java/com/ebr163/bifacialview/view/BifacialView.java +++ b/library/src/main/java/com/ebr163/bifacialview/view/BifacialView.java @@ -42,6 +42,7 @@ public enum TouchMode { private int delimiterColor; private int delimiterWidth; + private int delimiterPadding; private int arrowColor; private boolean arrowVisible; private int arrowWidth; @@ -97,6 +98,8 @@ private void initAttrs(AttributeSet attrs) { drawableRight = a.getDrawable(R.styleable.BifacialView_drawableRight); delimiterColor = a.getColor(R.styleable.BifacialView_delimiterColor, Color.WHITE); 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); arrowVisible = a.getBoolean(R.styleable.BifacialView_arrowVisibility, false); leftText = a.getString(R.styleable.BifacialView_leftText); @@ -166,7 +169,7 @@ public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (touchMode == TouchMode.DELIMITER) { - if (x > delimiterPosition + 20 || x < delimiterPosition - 20) { + if (x > delimiterPosition + delimiterPadding || x < delimiterPosition - delimiterPadding) { return false; } else { getParent().requestDisallowInterceptTouchEvent(true); diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index bbe6355..d4bf082 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -5,6 +5,7 @@ + From bc6a236ca20d7e375ce7fa45e64f78e72b80f417 Mon Sep 17 00:00:00 2001 From: mudar Date: Mon, 11 Sep 2017 14:04:12 -0400 Subject: [PATCH 2/2] TouchMode.ALL optimization intercept touch events for both TouchMode vales. In the case of my app, BifacialView is inside a ViewPager. Everything is ok with TouchMode.DELIMITER, but touch gestures were confusing using TouchMode.ALL (BifacialView sets new position, but parent viewPager starts swiping too!). This fixes my bug :) --- .../com/ebr163/bifacialview/view/BifacialView.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/library/src/main/java/com/ebr163/bifacialview/view/BifacialView.java b/library/src/main/java/com/ebr163/bifacialview/view/BifacialView.java index 0fb4513..0ce5a00 100644 --- a/library/src/main/java/com/ebr163/bifacialview/view/BifacialView.java +++ b/library/src/main/java/com/ebr163/bifacialview/view/BifacialView.java @@ -168,22 +168,18 @@ public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - if (touchMode == TouchMode.DELIMITER) { - if (x > delimiterPosition + delimiterPadding || x < delimiterPosition - delimiterPadding) { - return false; - } else { - getParent().requestDisallowInterceptTouchEvent(true); - } + if ((touchMode == TouchMode.DELIMITER) && + (x > delimiterPosition + delimiterPadding || x < delimiterPosition - delimiterPadding)) { + return false; } + getParent().requestDisallowInterceptTouchEvent(true); case MotionEvent.ACTION_MOVE: isMove = true; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: isMove = false; - if (touchMode == TouchMode.DELIMITER) { - getParent().requestDisallowInterceptTouchEvent(false); - } + getParent().requestDisallowInterceptTouchEvent(false); break; } delimiterPosition = (int) (x / 1);