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

[BUG] All the curves and radius elements are squared in Android 9.0 #23

Open
Akshshr opened this issue Sep 7, 2018 · 3 comments
Open

Comments

@Akshshr
Copy link

Akshshr commented Sep 7, 2018

No description provided.

@Camerash
Copy link

Camerash commented Sep 14, 2018

This is due to the intended behavioral changes of Path drawings and how the system handles the drawing of XFerModes paints in Android Pie.
More information can be found in this bug tracker: https://issuetracker.google.com/issues/111819103

I have managed to create a temporary solution for Android Pie.

First create a class that extends ViewOutlineProvider:

import android.annotation.TargetApi;
import android.graphics.Outline;
import android.os.Build;
import android.view.View;
import android.view.ViewOutlineProvider;

@TargetApi(Build.VERSION_CODES.P)
public class ProgressOutlineProvider extends ViewOutlineProvider{
    private float radius = -1;

    @Override
    public void getOutline(View view, Outline outline) {
        if(radius != -1) {
            outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), radius);
        }
    }

    public void updateProgress(float maxRadius, float progress) {
        this.radius = maxRadius - maxRadius * (1 - progress);
    }
}

Then modify the onCreate method of your activity:

public class CollapsingDemoActivity extends AppCompatActivity {

    private ProgressOutlineProvider pop;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collapsing);

        final ScalingLayout sl = findViewById(R.id.scalingLayout);

        sl.setListener(new ScalingLayoutListener() {
            @Override
            public void onCollapsed() {}

            @Override
            public void onExpanded() {}

            @Override
            public void onProgress(float progress) {
                if(pop != null) { pop.updateProgress(sl.getSettings().getMaxRadius(), progress); }
            }
        });

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            pop = new ProgressOutlineProvider();
            sl.setOutlineProvider(pop);
            sl.setClipToOutline(true);

            sl.post(new Runnable() {
                @TargetApi(Build.VERSION_CODES.P)
                @Override
                public void run() {
                    pop.updateProgress(sl.getSettings().getMaxRadius(), 1);
                    sl.invalidateOutline();
                }
            });
        }
    }
}

Works flawlessly for now

@Akshshr
Copy link
Author

Akshshr commented Sep 18, 2018

@Camerash thats a cool way of solving it!
Sucks they changed the behavior of this

@iammert is this going to be changed on a library level or left along?

@arunavo4
Copy link

arunavo4 commented Oct 23, 2018

@Camerash where to make the changes in the library .... can anyone provide the guide?
want to do it in a library level

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