Skip to content

Commit

Permalink
Add ability to enable/disable HoldingButton
Browse files Browse the repository at this point in the history
  • Loading branch information
hluhovskyi committed May 10, 2017
1 parent 3394456 commit ba0adf3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.6'
compile 'com.dewarder:holdingbutton:0.0.7'
```

## How to use
Expand Down Expand Up @@ -80,6 +80,10 @@ compile 'com.dewarder:holdingbutton:0.0.6'

## All XML properties

- `hbl_enabled` (`isButtonEnabled/setButtonEnabled`)

Set enabled or disabled state of button only.

- `hbl_direction` (`getDirection/setDirection`)

Set direction of sliding. Possible directions are `start` (from right to left) and `end` (from left to right).
Expand Down
4 changes: 2 additions & 2 deletions holdingbutton/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

ext {
artifactVersion = '0.0.6'
artifactVersion = '0.0.7'
artifactName = 'holdingbutton'
siteUrl = 'https://github.com/dewarder/HoldingButton'
gitUrl = 'https://github.com/dewarder/HoldingButton.git'
Expand Down Expand Up @@ -110,7 +110,7 @@ bintray {
vcsUrl = gitUrl
version {
name = artifactVersion
desc = 'Add cancel and submit methods'
desc = 'Add ability to enable/disable HoldingButton'
released = new Date()
vcsTag = "$artifactVersion"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class HoldingButtonLayout extends FrameLayout {

private Direction mDirection = Direction.START;
private boolean mAnimateHoldingView = true;
private boolean mButtonEnabled = true;
private boolean mIsCancel = false;
private boolean mIsExpanded = false;

Expand Down Expand Up @@ -102,6 +103,10 @@ private void init(Context context, AttributeSet attrs, @AttrRes int defStyleAttr
defStyleAttr,
defStyleRes);

if (array.hasValue(R.styleable.HoldingButtonLayout_hbl_enabled)) {
setButtonEnabled(array.getBoolean(R.styleable.HoldingButtonLayout_hbl_enabled, true));
}

if (array.hasValue(R.styleable.HoldingButtonLayout_hbl_radius)) {
mHoldingDrawable.setRadius(array.getDimensionPixelSize(R.styleable.HoldingButtonLayout_hbl_radius, 280));
}
Expand Down Expand Up @@ -173,7 +178,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getActionMasked();
switch (action) {
case MotionEvent.ACTION_DOWN: {
return isViewTouched(mHoldingView, ev);
return isButtonEnabled() && isViewTouched(mHoldingView, ev);
}
}

Expand All @@ -186,7 +191,7 @@ public boolean onTouchEvent(MotionEvent event) {

switch (action) {
case MotionEvent.ACTION_DOWN: {
if (isViewTouched(mHoldingView, event)) {
if (isButtonEnabled() && isViewTouched(mHoldingView, event)) {
mHoldingView.getLocationInWindow(mHoldingViewLocation);
getLocationInWindow(mViewLocation);

Expand Down Expand Up @@ -308,6 +313,14 @@ public void submit() {
}
}

public boolean isButtonEnabled() {
return mButtonEnabled;
}

public void setButtonEnabled(boolean enabled) {
mButtonEnabled = enabled;
}

@ColorInt
public int getColor() {
return mHoldingDrawable.getColor();
Expand Down
1 change: 1 addition & 0 deletions holdingbutton/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>

<declare-styleable name="HoldingButtonLayout">
<attr name="hbl_enabled" format="boolean"/>
<attr name="hbl_radius" format="dimension"/>
<attr name="hbl_icon" format="reference"/>
<attr name="hbl_cancel_icon" format="reference"/>
Expand Down

0 comments on commit ba0adf3

Please sign in to comment.