Skip to content

Commit db70448

Browse files
committed
Disabling button will now grey it out
1 parent 57358bb commit db70448

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

proswipebutton/src/main/java/in/shadowfax/proswipebutton/ProSwipeButton.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,26 +217,28 @@ public void onAnimationUpdate(ValueAnimator animation) {
217217
}
218218

219219
private void startFwdAnim() {
220-
TranslateAnimation animation = new TranslateAnimation(0, getMeasuredWidth(), 0, 0);
221-
animation.setInterpolator(new AccelerateDecelerateInterpolator());
222-
animation.setDuration(1000);
223-
animation.setAnimationListener(new Animation.AnimationListener() {
224-
@Override
225-
public void onAnimationStart(Animation animation) {
220+
if (isEnabled()) {
221+
TranslateAnimation animation = new TranslateAnimation(0, getMeasuredWidth(), 0, 0);
222+
animation.setInterpolator(new AccelerateDecelerateInterpolator());
223+
animation.setDuration(1000);
224+
animation.setAnimationListener(new Animation.AnimationListener() {
225+
@Override
226+
public void onAnimationStart(Animation animation) {
226227

227-
}
228+
}
228229

229-
@Override
230-
public void onAnimationEnd(Animation animation) {
231-
startHintInitAnim();
232-
}
230+
@Override
231+
public void onAnimationEnd(Animation animation) {
232+
startHintInitAnim();
233+
}
233234

234-
@Override
235-
public void onAnimationRepeat(Animation animation) {
235+
@Override
236+
public void onAnimationRepeat(Animation animation) {
236237

237-
}
238-
});
239-
arrowHintContainer.startAnimation(animation);
238+
}
239+
});
240+
arrowHintContainer.startAnimation(animation);
241+
}
240242
}
241243

242244
/**
@@ -336,6 +338,19 @@ public void updateBackground() {
336338
}
337339
}
338340

341+
@Override
342+
public void setEnabled(boolean enabled) {
343+
super.setEnabled(enabled);
344+
if (!enabled) {
345+
gradientDrawable.setColor(ContextCompat.getColor(context, R.color.proswipebtn_disabled_grey));
346+
updateBackground();
347+
this.setAlpha(0.5f);
348+
} else {
349+
setBackgroundColor(getBackgroundColor());
350+
this.setAlpha(1f);
351+
}
352+
}
353+
339354
private void showProgressBar() {
340355
progressBar = new ProgressBar(context);
341356
progressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, android.R.color.white), android.graphics.PorterDuff.Mode.SRC_IN);

proswipebutton/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<resources>
33
<color name="proswipebtn_translucent_white">#33ffffff</color>
44
<color name="proswipebtn_red">#F15824</color>
5+
<color name="proswipebtn_disabled_grey">#939393</color>
56
</resources>

0 commit comments

Comments
 (0)