diff --git a/README.md b/README.md index 5d2c5ee..b2095c9 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Button which is visible while user holds it. Main use case is controlling audio Add library as dependency to your `build.gradle`. ``` -compile 'com.dewarder:holdingbutton:0.0.7' +compile 'com.dewarder:holdingbutton:0.0.8' ``` ## How to use diff --git a/holdingbutton/build.gradle b/holdingbutton/build.gradle index ccc83de..d0f5434 100644 --- a/holdingbutton/build.gradle +++ b/holdingbutton/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' ext { - artifactVersion = '0.0.7' + artifactVersion = '0.0.8' artifactName = 'holdingbutton' siteUrl = 'https://github.com/dewarder/HoldingButton' gitUrl = 'https://github.com/dewarder/HoldingButton.git' @@ -110,7 +110,7 @@ bintray { vcsUrl = gitUrl version { name = artifactVersion - desc = 'Add ability to enable/disable HoldingButton' + desc = 'Add ability to intercept expanding animation' released = new Date() vcsTag = "$artifactVersion" } diff --git a/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonLayout.java b/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonLayout.java index 7987341..5e75e8c 100644 --- a/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonLayout.java +++ b/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonLayout.java @@ -36,6 +36,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; +import android.widget.Toast; import java.util.ArrayList; import java.util.List; @@ -60,6 +61,7 @@ public class HoldingButtonLayout extends FrameLayout { private boolean mIsCancel = false; private boolean mIsExpanded = false; + private HoldingButtonTouchListener mTouchListener = new SimpleHoldingButtonTouchListener(); private final DrawableListener mDrawableListener = new DrawableListener(); private final List mListeners = new ArrayList<>(); @@ -178,7 +180,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: { - return isButtonEnabled() && isViewTouched(mHoldingView, ev); + return isButtonEnabled() && shouldInterceptAnimation() && isViewTouched(mHoldingView, ev); } } @@ -191,7 +193,7 @@ public boolean onTouchEvent(MotionEvent event) { switch (action) { case MotionEvent.ACTION_DOWN: { - if (isButtonEnabled() && isViewTouched(mHoldingView, event)) { + if (isButtonEnabled() && shouldInterceptAnimation() && isViewTouched(mHoldingView, event)) { mHoldingView.getLocationInWindow(mHoldingViewLocation); getLocationInWindow(mViewLocation); @@ -284,6 +286,10 @@ protected ViewGroup getDecorView() { return view; } + public void setTouchListener(@NonNull HoldingButtonTouchListener listener) { + mTouchListener = listener; + } + public void addListener(HoldingButtonLayoutListener listener) { mListeners.add(listener); } @@ -292,6 +298,10 @@ public void removeListener(HoldingButtonLayoutListener listener) { mListeners.remove(listener); } + private boolean shouldInterceptAnimation() { + return mTouchListener.onHoldingViewTouched(); + } + private boolean isViewTouched(View view, MotionEvent event) { view.getDrawingRect(mHoldingViewRect); view.getLocationOnScreen(mHoldingViewLocation); @@ -442,6 +452,14 @@ private void notifyOnOffsetChanged(float offset, boolean isCancel) { } } + private class SimpleHoldingButtonTouchListener implements HoldingButtonTouchListener { + + @Override + public boolean onHoldingViewTouched() { + return true; + } + } + private class DrawableListener implements HoldingDrawableListener { @Override diff --git a/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonTouchListener.java b/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonTouchListener.java new file mode 100644 index 0000000..b716518 --- /dev/null +++ b/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonTouchListener.java @@ -0,0 +1,15 @@ +package com.dewarder.holdinglibrary; + +/** + * Interface is used to intercept touch events. + * Can be used for cases when permissions or something else are needed and expanding animation isn't needed + */ +public interface HoldingButtonTouchListener { + + /** + * Indicates that holding view is touched. + * Method is called before any method of `HoldingButtonLayoutListener`. + * @return false - if expanding animation must be canceled, true - if animation must be proceeded + */ + boolean onHoldingViewTouched(); +}