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

Commit 58e50903 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Phase out config_roundedCornerMultipleRadius" into tm-dev am: 76fa901b

parents f11dab52 76fa901b
Loading
Loading
Loading
Loading
+22 −8
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
    private val debugTransparentRegionPaint: Paint?
    private val tempRect: Rect = Rect()

    private var hasTopRoundedCorner = false
    private var hasBottomRoundedCorner = false
    private var roundedCornerTopSize = 0
    private var roundedCornerBottomSize = 0
    private var roundedCornerDrawableTop: Drawable? = null
@@ -300,7 +302,7 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
    }

    private fun drawRoundedCorners(canvas: Canvas) {
        if (roundedCornerTopSize == 0 && roundedCornerBottomSize == 0) {
        if (!hasTopRoundedCorner && !hasBottomRoundedCorner) {
            return
        }
        var degree: Int
@@ -312,9 +314,11 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
            canvas.translate(
                    getRoundedCornerTranslationX(degree).toFloat(),
                    getRoundedCornerTranslationY(degree).toFloat())
            if (i == RoundedCorner.POSITION_TOP_LEFT || i == RoundedCorner.POSITION_TOP_RIGHT) {
            if (hasTopRoundedCorner && (i == RoundedCorner.POSITION_TOP_LEFT ||
                            i == RoundedCorner.POSITION_TOP_RIGHT)) {
                drawRoundedCorner(canvas, roundedCornerDrawableTop, roundedCornerTopSize)
            } else {
            } else if (hasBottomRoundedCorner && (i == RoundedCorner.POSITION_BOTTOM_LEFT ||
                            i == RoundedCorner.POSITION_BOTTOM_RIGHT)) {
                drawRoundedCorner(canvas, roundedCornerDrawableBottom, roundedCornerBottomSize)
            }
            canvas.restore()
@@ -366,14 +370,24 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
    }

    /**
     * Update the rounded corner size.
     * Update the rounded corner existence and size.
     */
    fun updateRoundedCornerSize(top: Int, bottom: Int) {
        if (roundedCornerTopSize == top && roundedCornerBottomSize == bottom) {
    fun updateRoundedCornerExistenceAndSize(
        hasTop: Boolean,
        hasBottom: Boolean,
        topSize: Int,
        bottomSize: Int
    ) {
        if (hasTopRoundedCorner == hasTop &&
                hasBottomRoundedCorner == hasBottom &&
                roundedCornerBottomSize == bottomSize &&
                roundedCornerBottomSize == bottomSize) {
            return
        }
        roundedCornerTopSize = top
        roundedCornerBottomSize = bottom
        hasTopRoundedCorner = hasTop
        hasBottomRoundedCorner = hasBottom
        roundedCornerTopSize = topSize
        roundedCornerBottomSize = bottomSize
        updateRoundedCornerDrawableBounds()

        // Use requestLayout() to trigger transparent region recalculated
+10 −13
Original line number Diff line number Diff line
@@ -132,9 +132,6 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
    private final ThreadFactory mThreadFactory;
    private final DecorProviderFactory mDotFactory;

    //TODO: These are piecemeal being updated to Points for now to support non-square rounded
    // corners. for now it is only supposed when reading the intrinsic size from the drawables with
    // mIsRoundedCornerMultipleRadius is set
    @VisibleForTesting
    protected RoundedCornerResDelegate mRoundedCornerResDelegate;
    @VisibleForTesting
@@ -406,7 +403,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab

                    if (mScreenDecorHwcLayer != null) {
                        updateHwLayerRoundedCornerDrawable();
                        updateHwLayerRoundedCornerSize();
                        updateHwLayerRoundedCornerExistAndSize();
                    }

                    updateOverlayProviderViews();
@@ -699,7 +696,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
        mScreenDecorHwcWindow.addView(mScreenDecorHwcLayer, new FrameLayout.LayoutParams(
                MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.START));
        mWindowManager.addView(mScreenDecorHwcWindow, getHwcWindowLayoutParams());
        updateHwLayerRoundedCornerSize();
        updateHwLayerRoundedCornerExistAndSize();
        updateHwLayerRoundedCornerDrawable();
        mScreenDecorHwcWindow.getViewTreeObserver().addOnPreDrawListener(
                new ValidatingPreDrawListener(mScreenDecorHwcWindow));
@@ -961,7 +958,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
            if (mScreenDecorHwcLayer != null) {
                mScreenDecorHwcLayer.pendingRotationChange = false;
                mScreenDecorHwcLayer.updateRotation(mRotation);
                updateHwLayerRoundedCornerSize();
                updateHwLayerRoundedCornerExistAndSize();
                updateHwLayerRoundedCornerDrawable();
            }
            updateLayoutParams();
@@ -1090,7 +1087,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
                overlay.onReloadResAndMeasure(filterIds, mProviderRefreshToken, mRotation,
                        mDisplayUniqueId);
            }
            updateHwLayerRoundedCornerSize();
            updateHwLayerRoundedCornerExistAndSize();
        });
    }

@@ -1108,15 +1105,15 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
        mScreenDecorHwcLayer.updateRoundedCornerDrawable(topDrawable, bottomDrawable);
    }

    private void updateHwLayerRoundedCornerSize() {
    private void updateHwLayerRoundedCornerExistAndSize() {
        if (mScreenDecorHwcLayer == null) {
            return;
        }

        final int topWidth = mRoundedCornerResDelegate.getTopRoundedSize().getWidth();
        final int bottomWidth = mRoundedCornerResDelegate.getBottomRoundedSize().getWidth();

        mScreenDecorHwcLayer.updateRoundedCornerSize(topWidth, bottomWidth);
        mScreenDecorHwcLayer.updateRoundedCornerExistenceAndSize(
                mRoundedCornerResDelegate.getHasTop(),
                mRoundedCornerResDelegate.getHasBottom(),
                mRoundedCornerResDelegate.getTopRoundedSize().getWidth(),
                mRoundedCornerResDelegate.getBottomRoundedSize().getWidth());
    }

    @VisibleForTesting
+3 −4
Original line number Diff line number Diff line
@@ -25,8 +25,7 @@ class RoundedCornerDecorProviderFactory(

    override val hasProviders: Boolean
        get() = roundedCornerResDelegate.run {
            // We don't consider isMultipleRadius here because it makes no sense if size is zero.
            topRoundedSize.width > 0 || bottomRoundedSize.width > 0
            hasTop || hasBottom
        }

    override fun onDisplayUniqueIdChanged(displayUniqueId: String?) {
@@ -35,8 +34,8 @@ class RoundedCornerDecorProviderFactory(

    override val providers: List<DecorProvider>
    get() {
        val hasTop = roundedCornerResDelegate.topRoundedSize.width > 0
        val hasBottom = roundedCornerResDelegate.bottomRoundedSize.width > 0
        val hasTop = roundedCornerResDelegate.hasTop
        val hasBottom = roundedCornerResDelegate.hasBottom
        return when {
            hasTop && hasBottom -> listOf(
                RoundedCornerDecorProviderImpl(
+17 −58
Original line number Diff line number Diff line
@@ -37,10 +37,11 @@ class RoundedCornerResDelegate(

    private var reloadToken: Int = 0

    var isMultipleRadius: Boolean = false
    var hasTop: Boolean = false
        private set

    private var roundedDrawable: Drawable? = null
    var hasBottom: Boolean = false
        private set

    var topRoundedDrawable: Drawable? = null
        private set
@@ -48,8 +49,6 @@ class RoundedCornerResDelegate(
    var bottomRoundedDrawable: Drawable? = null
        private set

    private var roundedSize = Size(0, 0)

    var topRoundedSize = Size(0, 0)
        private set

@@ -83,53 +82,32 @@ class RoundedCornerResDelegate(

    private fun reloadRes() {
        val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId)
        isMultipleRadius = getIsMultipleRadius(configIdx)

        roundedDrawable = getDrawable(
                displayConfigIndex = configIdx,
                arrayResId = R.array.config_roundedCornerDrawableArray,
                backupDrawableId = R.drawable.rounded
        )
        val hasDefaultRadius = RoundedCorners.getRoundedCornerRadius(res, displayUniqueId) > 0
        hasTop = hasDefaultRadius ||
                (RoundedCorners.getRoundedCornerTopRadius(res, displayUniqueId) > 0)
        hasBottom = hasDefaultRadius ||
                (RoundedCorners.getRoundedCornerBottomRadius(res, displayUniqueId) > 0)

        topRoundedDrawable = getDrawable(
                displayConfigIndex = configIdx,
                arrayResId = R.array.config_roundedCornerTopDrawableArray,
                backupDrawableId = R.drawable.rounded_corner_top
        ) ?: roundedDrawable
        )
        bottomRoundedDrawable = getDrawable(
                displayConfigIndex = configIdx,
                arrayResId = R.array.config_roundedCornerBottomDrawableArray,
                backupDrawableId = R.drawable.rounded_corner_bottom
        ) ?: roundedDrawable
        )
    }

    private fun reloadMeasures(roundedSizeFactor: Int? = null) {
        // If config_roundedCornerMultipleRadius set as true, ScreenDecorations respect the
        // (width, height) size of drawable/rounded.xml instead of rounded_corner_radius
        if (isMultipleRadius) {
            roundedSize = Size(
                    roundedDrawable?.intrinsicWidth ?: 0,
                    roundedDrawable?.intrinsicHeight ?: 0)
        topRoundedDrawable?.let {
            topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
        }
        bottomRoundedDrawable?.let {
            bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
        }
        } else {
            val defaultRadius = RoundedCorners.getRoundedCornerRadius(res, displayUniqueId)
            val topRadius = RoundedCorners.getRoundedCornerTopRadius(res, displayUniqueId)
            val bottomRadius = RoundedCorners.getRoundedCornerBottomRadius(res, displayUniqueId)
            roundedSize = Size(defaultRadius, defaultRadius)
            topRoundedSize = Size(topRadius, topRadius)
            bottomRoundedSize = Size(bottomRadius, bottomRadius)
        }

        if (topRoundedSize.width == 0) {
            topRoundedSize = roundedSize
        }
        if (bottomRoundedSize.width == 0) {
            bottomRoundedSize = roundedSize
        }

        if (roundedSizeFactor != null && roundedSizeFactor > 0) {
            val length: Int = (roundedSizeFactor * density).toInt()
@@ -146,25 +124,6 @@ class RoundedCornerResDelegate(
        reloadMeasures(factor)
    }

    /**
     * Gets whether the rounded corners are multiple radii for current display.
     *
     * Loads the default config {@link R.bool#config_roundedCornerMultipleRadius} if
     * {@link com.android.internal.R.array#config_displayUniqueIdArray} is not set.
     */
    private fun getIsMultipleRadius(displayConfigIndex: Int): Boolean {
        val isMultipleRadius: Boolean
        res.obtainTypedArray(R.array.config_roundedCornerMultipleRadiusArray).let { array ->
            isMultipleRadius = if (displayConfigIndex >= 0 && displayConfigIndex < array.length()) {
                array.getBoolean(displayConfigIndex, false)
            } else {
                res.getBoolean(R.bool.config_roundedCornerMultipleRadius)
            }
            array.recycle()
        }
        return isMultipleRadius
    }

    private fun getDrawable(
        displayConfigIndex: Int,
        @ArrayRes arrayResId: Int,
@@ -184,8 +143,8 @@ class RoundedCornerResDelegate(

    override fun dump(pw: PrintWriter, args: Array<out String>) {
        pw.println("RoundedCornerResDelegate state:")
        pw.println("  isMultipleRadius:$isMultipleRadius")
        pw.println("  roundedSize(w,h)=(${roundedSize.width},${roundedSize.height})")
        pw.println("  hasTop=$hasTop")
        pw.println("  hasBottom=$hasBottom")
        pw.println("  topRoundedSize(w,h)=(${topRoundedSize.width},${topRoundedSize.height})")
        pw.println("  bottomRoundedSize(w,h)=(${bottomRoundedSize.width}," +
                "${bottomRoundedSize.height})")
+24 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="3px"
    android:height="3px"
    android:viewportWidth="3"
    android:viewportHeight="3">
    <path
        android:fillColor="#000000"
        android:pathData="M8,0H0v8C0,3.6,3.6,0,8,0z" />
</vector>
Loading