@Override public void morph(@NonNull Params params) { super.morph(params); mProgress = MIN_PROGRESS; mPaint = null; mRectF = null; }
private void finalizeMorphing(@NonNull Params params) { mAnimationInProgress = false; if (params.icon != 0 && params.text != null) { setIconLeft(params.icon); setText(params.text); } else if (params.icon != 0) { setIcon(params.icon); } else if(params.text != null) { setText(params.text); } if (params.animationListener != null) { params.animationListener.onAnimationEnd(); } }
private void initView() { mPadding = new Padding(); mPadding.left = getPaddingLeft(); mPadding.right = getPaddingRight(); mPadding.top = getPaddingTop(); mPadding.bottom = getPaddingBottom(); Resources resources = getResources(); int cornerRadius = (int) resources.getDimension(R.dimen.mb_corner_radius_2); int blue = resources.getColor(R.color.mb_blue); int blueDark = resources.getColor(R.color.mb_blue_dark); StateListDrawable background = new StateListDrawable(); mDrawableNormal = createDrawable(blue, cornerRadius, 0); mDrawablePressed = createDrawable(blueDark, cornerRadius, 0); mColor = blue; mStrokeColor = blue; mCornerRadius = cornerRadius; background.addState(new int[]{android.R.attr.state_pressed}, mDrawablePressed.getGradientDrawable()); background.addState(StateSet.WILD_CARD, mDrawableNormal.getGradientDrawable()); setBackgroundCompat(background); }
@Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = mParams.button.getLayoutParams(); layoutParams.height = val; mParams.button.setLayoutParams(layoutParams); } });
private void morphWithAnimation(@NonNull final Params params) { mAnimationInProgress = true; setText(null); setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); setPadding(mPadding.left, mPadding.top, mPadding.right, mPadding.bottom); MorphingAnimation.Params animationParams = MorphingAnimation.Params.create(this) .color(mColor, params.color) .cornerRadius(mCornerRadius, params.cornerRadius) .strokeWidth(mStrokeWidth, params.strokeWidth) .strokeColor(mStrokeColor, params.strokeColor) .height(getHeight(), params.height) .width(getWidth(), params.width) .duration(params.duration) .listener(new MorphingAnimation.Listener() { @Override public void onAnimationEnd() { finalizeMorphing(params); } }); MorphingAnimation animation = new MorphingAnimation(animationParams); animation.start(); }
public void setTextAndActivateButtons(String path, MorphingButton toSetPathOn, MorphingButton toEnable) { toSetPathOn.setText(path); toSetPathOn.setBackgroundColor(mActivity.getResources().getColor(R.color.mb_green_dark)); toEnable.setEnabled(true); morphToSquare(toEnable, integer()); }
/** * Converts morph button ot square shape * * @param btnMorph the button to be converted * @param duration time period of transition */ public void morphToSquare(final MorphingButton btnMorph, int duration) { MorphingButton.Params square = defaultButton(duration); String text = btnMorph.getText().toString().isEmpty() ? mActivity.getString(R.string.create_pdf) : btnMorph.getText().toString(); square.color(color(R.color.mb_blue)); square.colorPressed(color(R.color.mb_blue_dark)); square.text(text); btnMorph.morph(square); }
private void morphWithoutAnimation(@NonNull Params params) { mDrawableNormal.setColor(params.color); mDrawableNormal.setCornerRadius(params.cornerRadius); mDrawableNormal.setStrokeColor(params.strokeColor); mDrawableNormal.setStrokeWidth(params.strokeWidth); if(params.width != 0 && params.height !=0) { ViewGroup.LayoutParams layoutParams = getLayoutParams(); layoutParams.width = params.width; layoutParams.height = params.height; setLayoutParams(layoutParams); } finalizeMorphing(params); }
public void start() { StrokeGradientDrawable background = mParams.button.getDrawableNormal();
public void initializeButton(MorphingButton button, MorphingButton buttonToDisable) { button.setText(R.string.merge_file_select); button.setBackgroundColor(mActivity.getResources().getColor(R.color.mb_blue)); morphToGrey(buttonToDisable, integer()); buttonToDisable.setEnabled(false); } }
/** * Converts morph button ot square shape * * @param btnMorph the button to be converted * @param duration time period of transition */ public void morphToGrey(final MorphingButton btnMorph, int duration) { MorphingButton.Params square = defaultButton(duration); square.color(color(R.color.mb_gray)); square.colorPressed(color(R.color.mb_gray)); square.text(btnMorph.getText().toString()); btnMorph.morph(square); }
@Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = mParams.button.getLayoutParams(); layoutParams.width = val; mParams.button.setLayoutParams(layoutParams); } });
@Override public void morph(@NonNull Params params) { mIsRunning = false; super.morph(params); }
private void morphToFailure(final MorphingButton btnMorph, int duration) { MorphingButton.Params circle = MorphingButton.Params.create() .duration(duration) .cornerRadius(dimen(R.dimen.mb_height_56)) .width(dimen(R.dimen.mb_height_56)) .height(dimen(R.dimen.mb_height_56)) .color(color(R.color.mb_red)) .colorPressed(color(R.color.mb_red_dark)) .icon(R.drawable.ic_lock); btnMorph.morph(circle); }
private void morphToFailure(final MorphingButton btnMorph, int duration) { MorphingButton.Params circle = MorphingButton.Params.create() .duration(duration) .cornerRadius(dimen(R.dimen.mb_height_56)) .width(dimen(R.dimen.mb_height_56)) .height(dimen(R.dimen.mb_height_56)) .color(color(R.color.mb_red)) .colorPressed(color(R.color.mb_red_dark)) .icon(R.drawable.ic_lock); btnMorph.morph(circle); }
private void morphToSuccess(final MorphingButton btnMorph) { MorphingButton.Params circle = MorphingButton.Params.create() .duration(integer(R.integer.mb_animation)) .cornerRadius(dimen(R.dimen.mb_height_56)) .width(dimen(R.dimen.mb_height_56)) .height(dimen(R.dimen.mb_height_56)) .color(color(R.color.mb_green)) .colorPressed(color(R.color.mb_green_dark)) .icon(R.drawable.ic_done); btnMorph.morph(circle); }
private void morphToSquare(final MorphingButton btnMorph, int duration) { MorphingButton.Params square = MorphingButton.Params.create() .duration(duration) .cornerRadius(dimen(R.dimen.mb_corner_radius_2)) .width(dimen(R.dimen.mb_width_200)) .height(dimen(R.dimen.mb_height_56)) .color(color(R.color.mb_blue)) .colorPressed(color(R.color.mb_blue_dark)) .text(getString(R.string.mb_button)); btnMorph.morph(square); }
private void morphToSuccess(final MorphingButton btnMorph) { MorphingButton.Params circle = MorphingButton.Params.create() .duration(integer(R.integer.mb_animation)) .cornerRadius(dimen(R.dimen.mb_height_56)) .width(dimen(R.dimen.mb_height_56)) .height(dimen(R.dimen.mb_height_56)) .color(color(R.color.mb_green)) .colorPressed(color(R.color.mb_green_dark)) .icon(R.drawable.ic_done); btnMorph.morph(circle); }
private void morphToSquare(final MorphingButton btnMorph, int duration) { MorphingButton.Params square = MorphingButton.Params.create() .duration(duration) .cornerRadius(dimen(R.dimen.mb_corner_radius_2)) .width(dimen(R.dimen.mb_width_100)) .height(dimen(R.dimen.mb_height_56)) .color(color(R.color.mb_blue)) .colorPressed(color(R.color.mb_blue_dark)) .text(getString(R.string.mb_button)); btnMorph.morph(square); }