ScalingLayout icon indicating copy to clipboard operation
ScalingLayout copied to clipboard

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

Open Akshshr opened this issue 7 years ago • 3 comments

Akshshr avatar Sep 07 '18 14:09 Akshshr

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

Camerash avatar Sep 14 '18 08:09 Camerash

@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?

Akshshr avatar Sep 18 '18 09:09 Akshshr

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

arunavo4 avatar Oct 23 '18 09:10 arunavo4