Java Question Problem with methods in a Wrapper class

Arthur Ávila

Member
Licensed User
I'm trying my first wrap.
I've started with this one: https://github.com/dmytrodanylyk/android-morphing-button

So far, I've had success creating both jar and xml files,
but they are not properly functional.

Specifically, I can't figure how to make the methods on the wrapper class work. The sample code of the library shows
Code: Copy
// inside on click event
MorphingButton.Params circle = MorphingButton.Params.create()
        .duration(500)
        .cornerRadius(dimen(R.dimen.mb_height_56)) // 56 dp
        .width(dimen(R.dimen.mb_height_56)) // 56 dp
        .height(dimen(R.dimen.mb_height_56)) // 56 dp
        .color(color(R.color.green)) // normal state color
        .colorPressed(color(R.color.green_dark)) // pressed state color
        .icon(R.drawable.ic_done); // icon
btnMorph.morph(circle);

I've tried already but I'm not sure how to code on my MorphingButtonWrapper, considering Params class and morph at MorphingButton..
Code: Copy
public static class Params {
        private int cornerRadius;
        private int width;
        private int height;
        private int color;
        private int colorPressed;
        private int duration;
        private int icon;
        private int strokeWidth;
        private int strokeColor;
        private String text;
        private MorphingAnimation.Listener animationListener;

        private Params() {

        }

        public static Params create() {
            return new Params();
        }

        public Params text(@NonNull String text) {
            this.text = text;
            return this;
        }

        public Params icon(@DrawableRes int icon) {
            this.icon = icon;
            return this;
        }

        public Params cornerRadius(int cornerRadius) {
            this.cornerRadius = cornerRadius;
            return this;
        }

        public Params width(int width) {
            this.width = width;
            return this;
        }

        public Params height(int height) {
            this.height = height;
            return this;
        }

        public Params color(int color) {
            this.color = color;
            return this;
        }

        public Params colorPressed(int colorPressed) {
            this.colorPressed = colorPressed;
            return this;
        }

        public Params duration(int duration) {
            this.duration = duration;
            return this;
        }

        public Params strokeWidth(int strokeWidth) {
            this.strokeWidth = strokeWidth;
            return this;
        }

        public Params strokeColor(int strokeColor) {
            this.strokeColor = strokeColor;
            return this;
        }

        public Params animationListener(MorphingAnimation.Listener animationListener) {
            this.animationListener = animationListener;
            return this;
        }
    }

Code: Copy
public void morph(@NonNull Params params) {...
}

I guess I need to set Params and then call morph(Params), but on B4A despite being able to add the view and set params, morph dont work.

Any help will be
appreciated
 
I had some progress, but I'm stuck at the following error
Code: Copy
 error: incompatible types: ParamsWrapper cannot be converted to Params

I'm not sure how should it be initialized in the ParamsWrapper and called at .morph



Code: Copy
public void Initialize() {
            MorphingButton.Params p = MorphingButton.Params.create();
            setObject(p);
        }

Code: Copy
public void morph(ParamsWrapper p) {
      this.getObject().morph(p);
    }

Thanks for the help!

EDIT: It worked with this :)
Code: Copy
    public void morph(MorphingButton.Params p) {   
        this.getObject().morph(p);
    }
 
Last edited:
Back
Top