Skip to content

Commit

Permalink
added enable/disable functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-alexander committed Jan 7, 2016
1 parent 1976268 commit 85c8036
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions likebutton/src/main/java/com/like/LikeButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class LikeButton extends FrameLayout implements View.OnClickListener {
private int iconSize;

private boolean isChecked;


private boolean isEnabled;
private AnimatorSet animatorSet;

private Drawable likeDrawable;
Expand Down Expand Up @@ -127,6 +130,7 @@ private void init(Context context, AttributeSet attrs, int defStyle) {
}
}

setEnabled(array.getBoolean(R.styleable.LikeButton_enabled,true));
Boolean status = array.getBoolean(R.styleable.LikeButton_liked,false);
setLiked(status);
setEffectsViewSize();
Expand All @@ -141,6 +145,10 @@ private void init(Context context, AttributeSet attrs, int defStyle) {
*/
@Override
public void onClick(View v) {

if(!isEnabled)
return;

isChecked = !isChecked;

icon.setImageDrawable(isChecked ? likeDrawable : unLikeDrawable);
Expand Down Expand Up @@ -222,6 +230,9 @@ public void onAnimationCancel(Animator animation) {
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
if(!isEnabled)
return true;

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
icon.animate().scaleX(0.7f).scaleY(0.7f).setDuration(150).setInterpolator(DECCELERATE_INTERPOLATOR);
Expand Down Expand Up @@ -437,4 +448,9 @@ public void setLiked(Boolean status)
icon.setImageDrawable(unLikeDrawable);
}
}

@Override
public void setEnabled(boolean enabled) {
isEnabled = enabled;
}
}
1 change: 1 addition & 0 deletions likebutton/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<attr name="circle_start_color" format="color|reference" />
<attr name="circle_end_color" format="color|reference" />
<attr name="liked" format="boolean"/>
<attr name="enabled" format="boolean"/>
</declare-styleable>
</resources>

0 comments on commit 85c8036

Please sign in to comment.