Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5efab6c9 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Optimize use of layers in ripple, update dialog styling" into lmp-preview-dev

parents fc9f55ae 1b6e856e
Loading
Loading
Loading
Loading
+15 −0
Original line number Original line Diff line number Diff line
@@ -46,4 +46,19 @@ please see themes_device_defaults.xml.
    <style name="Theme.Holo.Light.DialogWhenLarge.NoActionBar"
    <style name="Theme.Holo.Light.DialogWhenLarge.NoActionBar"
            parent="@android:style/Theme.Holo.Light.Dialog.NoActionBar.FixedSize">
            parent="@android:style/Theme.Holo.Light.Dialog.NoActionBar.FixedSize">
    </style>
    </style>

    <style name="Theme.Material.DialogWhenLarge"
            parent="@android:style/Theme.Material.Dialog.FixedSize">
        <item name="preferencePanelStyle">@style/PreferencePanel.Dialog</item>
    </style>
    <style name="Theme.Material.DialogWhenLarge.NoActionBar"
            parent="@android:style/Theme.Material.Dialog.NoActionBar.FixedSize">
        <item name="preferencePanelStyle">@style/PreferencePanel.Dialog</item>
    </style>
    <style name="Theme.Material.Light.DialogWhenLarge"
            parent="@android:style/Theme.Material.Light.Dialog.FixedSize">
    </style>
    <style name="Theme.Material.Light.DialogWhenLarge.NoActionBar"
            parent="@android:style/Theme.Material.Light.Dialog.NoActionBar.FixedSize">
    </style>
</resources>
</resources>
+3 −5
Original line number Original line Diff line number Diff line
@@ -296,8 +296,8 @@ please see styles_device_defaults.xml.
        <item name="textAllCaps">@bool/config_actionMenuItemAllCaps</item>
        <item name="textAllCaps">@bool/config_actionMenuItemAllCaps</item>
    </style>
    </style>


    <style name="TextAppearance.Material.WindowTitle" parent="TextAppearance.Material.Headline" />
    <style name="TextAppearance.Material.WindowTitle" parent="TextAppearance.Material.Title" />
    <style name="TextAppearance.Material.DialogWindowTitle" parent="TextAppearance.Material.Headline" />
    <style name="TextAppearance.Material.DialogWindowTitle" parent="TextAppearance.Material.Title" />


    <style name="TextAppearance.Material.CalendarViewWeekDayView" parent="TextAppearance.Material.Small">
    <style name="TextAppearance.Material.CalendarViewWeekDayView" parent="TextAppearance.Material.Small">
        <item name="textStyle">bold</item>
        <item name="textStyle">bold</item>
@@ -966,8 +966,6 @@ please see styles_device_defaults.xml.
        <item name="textAppearance">@style/TextAppearance.Material.DialogWindowTitle</item>
        <item name="textAppearance">@style/TextAppearance.Material.DialogWindowTitle</item>
    </style>
    </style>


    <style name="DialogWindowTitle.Material.Light">
    <style name="DialogWindowTitle.Material.Light" />
        <item name="textAppearance">@style/TextAppearance.Material.DialogWindowTitle</item>
    </style>


</resources>
</resources>
+2 −2
Original line number Original line Diff line number Diff line
@@ -236,7 +236,7 @@ class Ripple {
        // Cache the paint alpha so we can restore it later.
        // Cache the paint alpha so we can restore it later.
        final int paintAlpha = p.getAlpha();
        final int paintAlpha = p.getAlpha();


        final int outerAlpha = (int) (255 * mOuterOpacity + 0.5f);
        final int outerAlpha = (int) (paintAlpha * mOuterOpacity + 0.5f);
        if (outerAlpha > 0 && mOuterRadius > 0) {
        if (outerAlpha > 0 && mOuterRadius > 0) {
            p.setAlpha(outerAlpha);
            p.setAlpha(outerAlpha);
            p.setStyle(Style.FILL);
            p.setStyle(Style.FILL);
@@ -244,7 +244,7 @@ class Ripple {
            hasContent = true;
            hasContent = true;
        }
        }


        final int alpha = (int) (255 * mOpacity + 0.5f);
        final int alpha = (int) (paintAlpha * mOpacity + 0.5f);
        final float radius = MathUtils.lerp(0, mOuterRadius, mTweenRadius);
        final float radius = MathUtils.lerp(0, mOuterRadius, mTweenRadius);
        if (alpha > 0 && radius > 0) {
        if (alpha > 0 && radius > 0) {
            final float x = MathUtils.lerp(mStartingX - mBounds.exactCenterX(), mOuterX, mTweenX);
            final float x = MathUtils.lerp(mStartingX - mBounds.exactCenterX(), mOuterX, mTweenX);
+25 −23
Original line number Original line Diff line number Diff line
@@ -172,16 +172,20 @@ public class RippleDrawable extends LayerDrawable {
    protected boolean onStateChange(int[] stateSet) {
    protected boolean onStateChange(int[] stateSet) {
        super.onStateChange(stateSet);
        super.onStateChange(stateSet);


        // TODO: This would make more sense in a StateListDrawable.
        boolean active = false;
        boolean active = false;
        boolean enabled = false;
        final int N = stateSet.length;
        final int N = stateSet.length;
        for (int i = 0; i < N; i++) {
        for (int i = 0; i < N; i++) {
            if (stateSet[i] == R.attr.state_enabled) {
                enabled = true;
            }
            if (stateSet[i] == R.attr.state_focused
            if (stateSet[i] == R.attr.state_focused
                    || stateSet[i] == R.attr.state_pressed) {
                    || stateSet[i] == R.attr.state_pressed) {
                active = true;
                active = true;
                break;
            }
            }
        }
        }
        setActive(active);
        setActive(active && enabled);


        // Update the paint color. Only applicable when animated in software.
        // Update the paint color. Only applicable when animated in software.
        if (mRipplePaint != null && mState.mTint != null) {
        if (mRipplePaint != null && mState.mTint != null) {
@@ -471,16 +475,21 @@ public class RippleDrawable extends LayerDrawable {


    @Override
    @Override
    public void draw(Canvas canvas) {
    public void draw(Canvas canvas) {
        final Rect bounds = isProjected() ? getDirtyBounds() : getBounds();
        final boolean isProjected = isProjected();
        final boolean hasMask = mMask != null;
        final boolean drawNonMaskContent = mLayerState.mNum > (hasMask ? 1 : 0);
        final boolean drawMask = hasMask && mMask.getOpacity() != PixelFormat.OPAQUE;
        final Rect bounds = isProjected ? getDirtyBounds() : getBounds();


        // Draw the content into a layer first.
        // If we have content, draw it into a layer first.
        final int contentLayer = drawContentLayer(canvas, bounds, SRC_OVER);
        final int contentLayer = drawNonMaskContent ?
                drawContentLayer(canvas, bounds, SRC_OVER) : -1;


        // Next, draw the ripples into a layer.
        // Next, try to draw the ripples (into a layer if necessary).
        final int rippleLayer = drawRippleLayer(canvas, bounds, mState.mTintXfermode);
        final int rippleLayer = drawRippleLayer(canvas, bounds, mState.mTintXfermode);


        // If we have ripples, draw the masking layer.
        // If we have ripples and a non-opaque mask, draw the masking layer.
        if (rippleLayer >= 0) {
        if (rippleLayer >= 0 && drawMask) {
            drawMaskingLayer(canvas, bounds, DST_IN);
            drawMaskingLayer(canvas, bounds, DST_IN);
        }
        }


@@ -524,17 +533,14 @@ public class RippleDrawable extends LayerDrawable {
    }
    }


    private int drawContentLayer(Canvas canvas, Rect bounds, PorterDuffXfermode mode) {
    private int drawContentLayer(Canvas canvas, Rect bounds, PorterDuffXfermode mode) {
        final int count = mLayerState.mNum;
        // TODO: We don't need a layer if all the content is opaque.
        if (count == 0 || (mMask != null && count == 1)) {
            return -1;
        }

        final Paint maskingPaint = getMaskingPaint(mode);
        final Paint maskingPaint = getMaskingPaint(mode);
        final int restoreToCount = canvas.saveLayer(bounds.left, bounds.top,
        final int restoreToCount = canvas.saveLayer(bounds.left, bounds.top,
                bounds.right, bounds.bottom, maskingPaint);
                bounds.right, bounds.bottom, maskingPaint);


        // Draw everything except the mask.
        // Draw everything except the mask.
        final ChildDrawable[] array = mLayerState.mChildren;
        final ChildDrawable[] array = mLayerState.mChildren;
        final int count = mLayerState.mNum;
        for (int i = 0; i < count; i++) {
        for (int i = 0; i < count; i++) {
            if (array[i].mId != R.id.mask) {
            if (array[i].mId != R.id.mask) {
                array[i].mDrawable.draw(canvas);
                array[i].mDrawable.draw(canvas);
@@ -559,14 +565,15 @@ public class RippleDrawable extends LayerDrawable {
            rippleARGB = Color.TRANSPARENT;
            rippleARGB = Color.TRANSPARENT;
        }
        }


        final int rippleAlpha = Color.alpha(rippleARGB);
        final int rippleColor = rippleARGB | (0xFF << 24);
        if (mRipplePaint == null) {
        if (mRipplePaint == null) {
            mRipplePaint = new Paint();
            mRipplePaint = new Paint();
            mRipplePaint.setAntiAlias(true);
            mRipplePaint.setAntiAlias(true);
        }
        }

        final int rippleAlpha = Color.alpha(rippleARGB);
        final Paint ripplePaint = mRipplePaint;
        final Paint ripplePaint = mRipplePaint;
        ripplePaint.setColor(rippleColor);
        ripplePaint.setColor(rippleARGB);
        ripplePaint.setAlpha(0xFF);


        boolean drewRipples = false;
        boolean drewRipples = false;
        int restoreToCount = -1;
        int restoreToCount = -1;
@@ -584,7 +591,6 @@ public class RippleDrawable extends LayerDrawable {
                maskingPaint.setAlpha(rippleAlpha);
                maskingPaint.setAlpha(rippleAlpha);
                restoreToCount = canvas.saveLayer(bounds.left, bounds.top,
                restoreToCount = canvas.saveLayer(bounds.left, bounds.top,
                        bounds.right, bounds.bottom, maskingPaint);
                        bounds.right, bounds.bottom, maskingPaint);
                maskingPaint.setAlpha(255);


                restoreTranslate = canvas.save();
                restoreTranslate = canvas.save();
                // Translate the canvas to the current hotspot bounds.
                // Translate the canvas to the current hotspot bounds.
@@ -609,18 +615,13 @@ public class RippleDrawable extends LayerDrawable {
    }
    }


    private int drawMaskingLayer(Canvas canvas, Rect bounds, PorterDuffXfermode mode) {
    private int drawMaskingLayer(Canvas canvas, Rect bounds, PorterDuffXfermode mode) {
        final Drawable mask = mMask;
        if (mask == null) {
            return -1;
        }

        final int restoreToCount = canvas.saveLayer(bounds.left, bounds.top,
        final int restoreToCount = canvas.saveLayer(bounds.left, bounds.top,
                bounds.right, bounds.bottom, getMaskingPaint(mode));
                bounds.right, bounds.bottom, getMaskingPaint(mode));


        // Ensure that DST_IN blends using the entire layer.
        // Ensure that DST_IN blends using the entire layer.
        canvas.drawColor(Color.TRANSPARENT);
        canvas.drawColor(Color.TRANSPARENT);


        mask.draw(canvas);
        mMask.draw(canvas);


        return restoreToCount;
        return restoreToCount;
    }
    }
@@ -630,6 +631,7 @@ public class RippleDrawable extends LayerDrawable {
            mMaskingPaint = new Paint();
            mMaskingPaint = new Paint();
        }
        }
        mMaskingPaint.setXfermode(xfermode);
        mMaskingPaint.setXfermode(xfermode);
        mMaskingPaint.setAlpha(0xFF);
        return mMaskingPaint;
        return mMaskingPaint;
    }
    }