Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stroke width in API or have better internals to support Kotlin #83

Open
Tolriq opened this issue Oct 28, 2018 · 4 comments
Open

Comments

@Tolriq
Copy link

Tolriq commented Oct 28, 2018

Currently the library does not support stroke width and you said you do not want to implement it. (#61)

The problem is that the current code is filled with protected / private constructors and prevent expanding the library from Kotlin to implement this.

In Java it's relatively simple to achieve, in Kotlin we need to copy and convert 90% of the code :(

To see the issue just convert:

package me.zhanghai.android.materialprogressbar;

import android.graphics.Paint;

public class SingleCircularProgressDrawable2dp extends SingleCircularProgressDrawable {

    SingleCircularProgressDrawable2dp(int style) {
        super(style);
        setShowBackground(false);
    }

    @Override
    protected void onPreparePaint(Paint paint) {
        super.onPreparePaint(paint);
        paint.setStrokeWidth(2);
    }
}

to kotlin and see all the errors about package private / protected :(

This is not cool to have to maintain java code in a full kotlin project just for this use case :(

@zhanghai
Copy link
Owner

zhanghai commented Nov 1, 2018

There are several issues with supporting a stroke width:

  • The stroke width on the paint is not actually a DP value - rather its a fraction of the overall size(e.g. 48 or 42), and the actual stroke width will be dependant on the minWidth and maxWidth of the ProgressBar as the drawable will be scaled. I don't know what's a good way to expose this as an API.

  • Changing width means changing the hard-coded size (42) of the non-padded version of the drawable, which would require a small refactor of the drawing logic. And more importantly, the static style which contains min/maxWidth attribute will also need to be dynamic to ensure consistent scaling, which isn't feasible.

All in all, I'm kinda unsure how to expose it as an API of this library.

@Tolriq
Copy link
Author

Tolriq commented Nov 1, 2018

Hum yes I understand that the need is relatively specific :(

My use case is quite simple and I could probably write a custom component but since I already use your nice library and it can fit the need I'd prefer reuse it.

Progress over the FAB to indicate resume point.
image

If it's not possible to expose do you think there's a way to improve library extensions via Kotlin?

Current private / protected way prevent doing simple inheritance in Kotlin while it works fine in Java.

@arungoyal
Copy link

Any update on this issue with newer version

@Tolriq
Copy link
Author

Tolriq commented Feb 14, 2019

I personally wrote a custom component to fit the need. Issue could probably be close, even if allowing easier customization from Kotlin would be a nice addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants