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

Commit abf49c12 authored by Josh's avatar Josh
Browse files

Fixed clipping of qs focus state

Ripple drawable uses some custom draw logic that clips its layers
should they attempt to draw outside of its bound. So I've moved focus
layer of qs tile background to overlay - now focus state will be
rendered as an overlay of the view, avoiding any issues with clipping.

Test: Manual test - go/sysui-pkt-manual-testing
Fixes: 340897219
Flag: ACONFIG com.android.systemui.qs_tile_focus_state TRUNKFOOD
Change-Id: I287cec0ebec97c2494b14ce6c6fde20baf57dd92
parent d95cbf18
Loading
Loading
Loading
Loading
+5 −25
Original line number Diff line number Diff line
@@ -15,16 +15,10 @@
  -->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/qs_tile_ripple_color">
    <!-- We don't really use the ripple effect here, but changing it to LayerDrawable causes
         performance regression, see: b/339412453.
         Since this ripple has just one layer inside, we can try to remove that extra "background"
         layer. However this should only be done when the flag
         com.android.systemui.qs_tile_focus_state has completed all its stages and this drawable
         fully replaces the previous one to ensure consistency with code sections searching for
         specific ids in drawable hierarchy 
         -->
    <item
        android:id="@id/background">
        android:id="@android:id/mask"
        android:drawable="@drawable/qs_tile_background_shape" />
    <item android:id="@id/background">
        <layer-list>
            <item
                android:id="@+id/qs_tile_background_base"
@@ -32,22 +26,8 @@
            <item android:id="@+id/qs_tile_background_overlay">
                <selector>
                    <item
                        android:state_hovered="true"
                        android:drawable="@drawable/qs_tile_background_shape" />
                </selector>
            </item>
            <!-- In the layer below we have negative insets because we need the focus outline
                 to draw outside the bounds, around the main background. We use 5dp because
                 the outline stroke is 3dp and the required padding is 2dp.-->
            <item
                android:top="-5dp"
                android:right="-5dp"
                android:left="-5dp"
                android:bottom="-5dp">
                <selector>
                    <item
                        android:state_focused="true"
                        android:drawable="@drawable/qs_tile_focused_background"/>
                        android:drawable="@drawable/qs_tile_background_shape"
                        android:state_hovered="true" />
                </selector>
            </item>
        </layer-list>
+11 −7
Original line number Diff line number Diff line
@@ -13,10 +13,14 @@
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"

<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:inset="-5dp">
    <shape xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
        android:shape="rectangle">
        <corners android:radius="30dp" />
    <stroke android:width="3dp" android:color="?androidprv:attr/materialColorSecondaryFixed"/>
        <stroke
            android:width="3dp"
            android:color="?androidprv:attr/materialColorSecondaryFixed" />
    </shape>
</inset>
 No newline at end of file
+15 −2
Original line number Diff line number Diff line
@@ -148,7 +148,8 @@ open class QSTileViewImpl @JvmOverloads constructor(
     */
    protected var showRippleEffect = true

    private lateinit var qsTileBackground: LayerDrawable
    private lateinit var qsTileBackground: RippleDrawable
    private lateinit var qsTileFocusBackground: Drawable
    private lateinit var backgroundDrawable: LayerDrawable
    private lateinit var backgroundBaseDrawable: Drawable
    private lateinit var backgroundOverlayDrawable: Drawable
@@ -313,10 +314,11 @@ open class QSTileViewImpl @JvmOverloads constructor(

    private fun createTileBackground(): Drawable {
        qsTileBackground = if (Flags.qsTileFocusState()) {
            mContext.getDrawable(R.drawable.qs_tile_background_flagged) as LayerDrawable
            mContext.getDrawable(R.drawable.qs_tile_background_flagged) as RippleDrawable
        } else {
            mContext.getDrawable(R.drawable.qs_tile_background) as RippleDrawable
        }
        qsTileFocusBackground = mContext.getDrawable(R.drawable.qs_tile_focused_background)!!
        backgroundDrawable =
            qsTileBackground.findDrawableByLayerId(R.id.background) as LayerDrawable
        backgroundBaseDrawable =
@@ -332,6 +334,17 @@ open class QSTileViewImpl @JvmOverloads constructor(
        updateHeight()
    }

    override fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect)
        if (Flags.qsTileFocusState()) {
            if (gainFocus) {
                qsTileFocusBackground.setBounds(0, 0, width, height)
                overlay.add(qsTileFocusBackground)
            } else {
                overlay.clear()
            }
        }
    }
    private fun updateHeight() {
        // TODO(b/332900989): Find a more robust way of resetting the tile if not reset by the
        //  launch animation.