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

Commit 171d9f93 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Bring back ripple in tiles

Also, animate the labels color.

Test: manual
Fixes: 172063461
Change-Id: I6d002cd1ffe954cc296347a6adf43df3eee71992
parent 45a1c3a1
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2021 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.
  -->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:attr/colorControlHighlight">
    <item android:id="@android:id/mask"
        android:drawable="@drawable/qs_tile_background_shape" />
    <item android:id="@id/background"
        android:drawable="@drawable/qs_tile_background_shape"/>
</ripple>
 No newline at end of file
+21 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2021 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.
  -->

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="@dimen/qs_corner_radius" />
    <solid android:color="#FFFFFF" />
</shape>
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ class CustomizeTileViewHorizontal(

    override fun handleStateChanged(state: QSTile.State) {
        super.handleStateChanged(state)
        mShowRippleEffect = false
        mSecondLine.visibility = if (showAppLabel) View.VISIBLE else View.GONE
    }

+5 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ public class QSTileView extends QSTileBaseView {
            } else {
                labelColor = mColorLabelUnavailable;
            }
            mLabel.setTextColor(labelColor);
            changeLabelColor(labelColor);
            mState = state.state;
            mLabel.setText(state.label);
        }
@@ -163,6 +163,10 @@ public class QSTileView extends QSTileBaseView {
        mPadLock.setVisibility(state.disabledByPolicy ? View.VISIBLE : View.GONE);
    }

    protected void changeLabelColor(ColorStateList color) {
        mLabel.setTextColor(color);
    }

    protected void handleExpand(boolean dualTarget) {
        mExpandIndicator.setVisibility(dualTarget ? View.VISIBLE : View.GONE);
        mExpandSpace.setVisibility(dualTarget ? View.VISIBLE : View.GONE);
+50 −26
Original line number Diff line number Diff line
@@ -21,8 +21,7 @@ import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.RoundRectShape
import android.graphics.drawable.RippleDrawable
import android.service.quicksettings.Tile.STATE_ACTIVE
import android.view.Gravity
import android.widget.LinearLayout
@@ -38,9 +37,10 @@ open class QSTileViewHorizontal(
    collapsed: Boolean
) : QSTileView(context, icon, collapsed) {

    protected var backgroundDrawable: ShapeDrawable? = null
    protected var colorBackgroundDrawable: Drawable? = null
    private var paintColor = Color.WHITE
    private var paintAnimator: ValueAnimator? = null
    private var labelAnimator: ValueAnimator? = null

    init {
        orientation = HORIZONTAL
@@ -90,38 +90,32 @@ open class QSTileViewHorizontal(
    }

    override fun newTileBackground(): Drawable? {
        val cornerRadius = context.resources
            .getDimensionPixelSize(R.dimen.qs_corner_radius).toFloat()
        backgroundDrawable = ShapeDrawable(createShape(cornerRadius))
        return backgroundDrawable
    }

    private fun createShape(cornerRadius: Float): RoundRectShape {
        val radii = FloatArray(8)
        radii.indices.forEach { radii[it] = cornerRadius }
        return RoundRectShape(radii, null, null)
        val ripple = mContext.getDrawable(R.drawable.qs_tile_background) as RippleDrawable
        colorBackgroundDrawable = ripple.findDrawableByLayerId(R.id.background)
        return ripple
    }

    override fun setClickable(clickable: Boolean) {
        super.setClickable(clickable)
        background = mTileBackground
        background = if (clickable && mShowRippleEffect) {
            mTileBackground
        } else {
            colorBackgroundDrawable
        }
    }

    override fun handleStateChanged(state: QSTile.State) {
        super.handleStateChanged(state)
        if (!mCollapsedView) {
            mSecondLine.setTextColor(mLabel.textColors)
        }
        mLabelContainer.background = null

        val allowAnimations = animationsEnabled() && paintColor != Color.WHITE
        val newColor = getCircleColor(state.state)
        if (allowAnimations) {
            animateToNewState(newColor)
            animateBackground(newColor)
        } else {
            if (newColor != paintColor) {
                clearAnimator()
                backgroundDrawable?.setTintList(ColorStateList.valueOf(newColor))?.also {
                clearBackgroundAnimator()
                colorBackgroundDrawable?.setTintList(ColorStateList.valueOf(newColor))?.also {
                    paintColor = newColor
                }
                paintColor = newColor
@@ -129,14 +123,14 @@ open class QSTileViewHorizontal(
        }
    }

    private fun animateToNewState(newColor: Int) {
        if (newColor != paintColor) {
            clearAnimator()
            paintAnimator = ValueAnimator.ofArgb(paintColor, newColor)
    private fun animateBackground(newBackgroundColor: Int) {
        if (newBackgroundColor != paintColor) {
            clearBackgroundAnimator()
            paintAnimator = ValueAnimator.ofArgb(paintColor, newBackgroundColor)
                .setDuration(QSIconViewImpl.QS_ANIM_LENGTH).apply {
                    addUpdateListener { animation: ValueAnimator ->
                        val c = animation.animatedValue as Int
                        backgroundDrawable?.setTintList(ColorStateList.valueOf(c))?.also {
                        colorBackgroundDrawable?.setTintList(ColorStateList.valueOf(c))?.also {
                            paintColor = c
                        }
                    }
@@ -145,9 +139,39 @@ open class QSTileViewHorizontal(
        }
    }

    private fun clearAnimator() {
    override fun changeLabelColor(color: ColorStateList) {
        val allowAnimations = animationsEnabled()
        val currentColor = mLabel.textColors.defaultColor
        if (currentColor != color.defaultColor) {
            clearLabelAnimator()
            if (allowAnimations) {
                labelAnimator = ValueAnimator.ofArgb(currentColor, color.defaultColor)
                    .setDuration(QSIconViewImpl.QS_ANIM_LENGTH).apply {
                        addUpdateListener {
                            setLabelsColor(ColorStateList.valueOf(it.animatedValue as Int))
                        }
                        start()
                }
            } else {
                setLabelsColor(color)
            }
        }
    }

    private fun setLabelsColor(color: ColorStateList) {
        mLabel.setTextColor(color)
        if (!mCollapsedView) {
            mSecondLine.setTextColor(color)
        }
    }

    private fun clearBackgroundAnimator() {
        paintAnimator?.cancel()?.also { paintAnimator = null }
    }

    private fun clearLabelAnimator() {
        labelAnimator?.cancel()?.also { labelAnimator = null }
    }

    override fun handleExpand(dualTarget: Boolean) {}
}
 No newline at end of file