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

Commit 497007a1 authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Media TTT] Fix the generic icon on the receiver chip by making it

smaller so it fits in the circle.

Bug: 213577806
Test: manual (see screenshots in attached bug)
Test: media.taptotransfer tests
Change-Id: I71fe3946e2ef64ec8bf0e4471b0b84517b7d060c
parent 17384a09
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1005,6 +1005,9 @@
    <!-- Media tap-to-transfer chip for receiver device -->
    <dimen name="media_ttt_chip_size_receiver">100dp</dimen>
    <dimen name="media_ttt_icon_size_receiver">95dp</dimen>
    <!-- Since the generic icon isn't circular, we need to scale it down so it still fits within
         the circular chip. -->
    <dimen name="media_ttt_generic_icon_size_receiver">70dp</dimen>

    <!-- Window magnification -->
    <dimen name="magnification_border_drag_size">35dp</dimen>
+6 −4
Original line number Diff line number Diff line
@@ -128,19 +128,21 @@ class MediaTttCommandLineHelper @Inject constructor(
                    as StatusBarManager
            val routeInfo = MediaRoute2Info.Builder("id", "Test Name")
                .addFeature("feature")
                .setPackageName(TEST_PACKAGE_NAME)
                .build()
            if (args.size >= 2 && args[1] == "useAppIcon=true") {
                routeInfo.setPackageName(TEST_PACKAGE_NAME)
            }

            statusBarManager.updateMediaTapToTransferReceiverDisplay(
                    displayState,
                    routeInfo,
                    routeInfo.build(),
                    null,
                    null
                )
        }

        override fun help(pw: PrintWriter) {
            pw.println("Usage: adb shell cmd statusbar $RECEIVER_COMMAND <chipState>")
            pw.println("Usage: adb shell cmd statusbar $RECEIVER_COMMAND " +
                    "<chipState> useAppIcon=[true|false]")
        }
    }
}
+36 −16
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.LinearLayout
import com.android.internal.widget.CachingIconView
import com.android.settingslib.Utils
import com.android.systemui.R
@@ -136,6 +137,11 @@ abstract class MediaTttChipControllerCommon<T : ChipInfoCommon>(
     */
    abstract fun updateChipView(chipInfo: T, currentChipView: ViewGroup)

    /**
     * Returns the size that the icon should be, or null if no size override is needed.
     */
    open fun getIconSize(isAppIcon: Boolean): Int? = null

    /**
     * An internal method to set the icon on the view.
     *
@@ -151,35 +157,47 @@ abstract class MediaTttChipControllerCommon<T : ChipInfoCommon>(
        appNameOverride: CharSequence? = null,
    ) {
        val appIconView = currentChipView.requireViewById<CachingIconView>(R.id.app_icon)
        val appInfo = getAppInfo(appPackageName)
        appIconView.contentDescription = appNameOverride ?: appInfo.appName
        appIconView.setImageDrawable(appIconDrawableOverride ?: appInfo.appIcon)
        val iconInfo = getIconInfo(appPackageName)

        getIconSize(iconInfo.isAppIcon)?.let { size ->
            val lp = appIconView.layoutParams
            lp.width = size
            lp.height = size
            appIconView.layoutParams = lp
        }

        appIconView.contentDescription = appNameOverride ?: iconInfo.iconName
        appIconView.setImageDrawable(appIconDrawableOverride ?: iconInfo.icon)
    }

    /**
     * Returns the app name and icon of the app playing media, or a default name and icon if we
     * can't find the app name/icon.
     * Returns the information needed to display the icon.
     *
     * The information will either contain app name and icon of the app playing media, or a default
     * name and icon if we can't find the app name/icon.
     */
    private fun getAppInfo(appPackageName: String?): AppInfo {
    private fun getIconInfo(appPackageName: String?): IconInfo {
        if (appPackageName != null) {
            try {
                return AppInfo(
                    appName = context.packageManager.getApplicationInfo(
                return IconInfo(
                    iconName = context.packageManager.getApplicationInfo(
                        appPackageName, PackageManager.ApplicationInfoFlags.of(0)
                    ).loadLabel(context.packageManager).toString(),
                    appIcon = context.packageManager.getApplicationIcon(appPackageName)
                    icon = context.packageManager.getApplicationIcon(appPackageName),
                    isAppIcon = true
                )
            } catch (e: PackageManager.NameNotFoundException) {
                Log.w(TAG, "Cannot find package $appPackageName", e)
            }
        }
        return AppInfo(
            appName = context.getString(R.string.media_output_dialog_unknown_launch_app_name),
            appIcon = context.resources.getDrawable(R.drawable.ic_cast).apply {
        return IconInfo(
            iconName = context.getString(R.string.media_output_dialog_unknown_launch_app_name),
            icon = context.resources.getDrawable(R.drawable.ic_cast).apply {
                this.setTint(
                    Utils.getColorAttrDefaultColor(context, android.R.attr.textColorPrimary)
                )
            }
            },
            isAppIcon = false
        )
    }

@@ -203,7 +221,9 @@ object MediaTttRemovalReason {
    const val REASON_SCREEN_TAP = "SCREEN_TAP"
}

private data class AppInfo(
    val appName: String,
    val appIcon: Drawable
private data class IconInfo(
    val iconName: String,
    val icon: Drawable,
    /** True if [icon] is the app's icon, and false if [icon] is some generic default icon. */
    val isAppIcon: Boolean
)
+9 −0
Original line number Diff line number Diff line
@@ -127,6 +127,15 @@ class MediaTttChipControllerReceiver @Inject constructor(
                chipInfo.appNameOverride
        )
    }

    override fun getIconSize(isAppIcon: Boolean): Int? =
        context.resources.getDimensionPixelSize(
            if (isAppIcon) {
                R.dimen.media_ttt_icon_size_receiver
            } else {
                R.dimen.media_ttt_generic_icon_size_receiver
            }
        )
}

data class ChipReceiverInfo(
+26 −8
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
    }

    @Test
    fun displayChip_nullAppIconDrawableAndNullPackageName_stillHasIcon() {
    fun setIcon_nullAppIconDrawableAndNullPackageName_stillHasIcon() {
        controllerCommon.displayChip(getState())
        val chipView = getChipView()

@@ -204,7 +204,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
    }

    @Test
    fun displayChip_nullAppIconDrawableAndInvalidPackageName_stillHasIcon() {
    fun setIcon_nullAppIconDrawableAndInvalidPackageName_stillHasIcon() {
        controllerCommon.displayChip(getState())
        val chipView = getChipView()

@@ -226,7 +226,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
    }

    @Test
    fun displayChip_hasAppIconDrawable_iconIsDrawable() {
    fun setIcon_hasAppIconDrawable_iconIsDrawable() {
        controllerCommon.displayChip(getState())
        val chipView = getChipView()

@@ -237,7 +237,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
    }

    @Test
    fun displayChip_nullAppNameAndNullPackageName_stillHasContentDescription() {
    fun setIcon_nullAppNameAndNullPackageName_stillHasContentDescription() {
        controllerCommon.displayChip(getState())
        val chipView = getChipView()

@@ -247,7 +247,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
    }

    @Test
    fun displayChip_nullAppNameAndInvalidPackageName_stillHasContentDescription() {
    fun setIcon_nullAppNameAndInvalidPackageName_stillHasContentDescription() {
        controllerCommon.displayChip(getState())
        val chipView = getChipView()

@@ -259,7 +259,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
    }

    @Test
    fun displayChip_nullAppName_iconContentDescriptionIsFromPackageName() {
    fun setIcon_nullAppName_iconContentDescriptionIsFromPackageName() {
        controllerCommon.displayChip(getState())
        val chipView = getChipView()

@@ -269,7 +269,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
    }

    @Test
    fun displayChip_hasAppName_iconContentDescriptionIsAppNameOverride() {
    fun setIcon_hasAppName_iconContentDescriptionIsAppNameOverride() {
        controllerCommon.displayChip(getState())
        val chipView = getChipView()

@@ -279,6 +279,21 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
        assertThat(chipView.getAppIconView().contentDescription).isEqualTo(appName)
    }

    @Test
    fun setIcon_iconSizeMatchesGetIconSize() {
        controllerCommon.displayChip(getState())
        val chipView = getChipView()

        controllerCommon.setIcon(chipView, PACKAGE_NAME)
        chipView.measure(
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
        )

        assertThat(chipView.getAppIconView().measuredWidth).isEqualTo(ICON_SIZE)
        assertThat(chipView.getAppIconView().measuredHeight).isEqualTo(ICON_SIZE)
    }

    @Test
    fun tapGestureDetected_outsideViewBounds_viewHidden() {
        controllerCommon.displayChip(getState())
@@ -344,6 +359,8 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
        override fun updateChipView(chipInfo: ChipInfo, currentChipView: ViewGroup) {

        }

        override fun getIconSize(isAppIcon: Boolean): Int? = ICON_SIZE
    }

    inner class ChipInfo : ChipInfoCommon {
@@ -354,3 +371,4 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
private const val PACKAGE_NAME = "com.android.systemui"
private const val APP_NAME = "Fake App Name"
private const val TIMEOUT_MS = 10000L
private const val ICON_SIZE = 47
 No newline at end of file
Loading