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

Commit c2e84179 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topics "presubmit-am-3fca48eecdb74a8e96804b9a78256e56",...

Merge changes from topics "presubmit-am-3fca48eecdb74a8e96804b9a78256e56", "presubmit-am-563ae16077714dd0a7da266e4a698052", "presubmit-am-9cc0354ba3f24063b26fb042cc9dbf89" into tm-dev

* changes:
  [Media TTT] Fix the generic icon on the receiver chip by making it smaller so it fits in the circle.
  [Media TTT] Add a ripple to the undo button.
  [Media TTT] Update the error message string.
parents 77472b3e 497007a1
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -14,9 +14,14 @@
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
-->
<shape
<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
    android:color="?android:textColorPrimary">
    <item android:id="@android:id/background">
        <shape>
            <solid android:color="?androidprv:attr/colorAccentPrimary"/>
            <corners android:radius="24dp" />
        </shape>
    </item>
</ripple>
+3 −0
Original line number Diff line number Diff line
@@ -1008,6 +1008,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>
+1 −1
Original line number Diff line number Diff line
@@ -2184,7 +2184,7 @@
    <!-- Text informing the user that their media is now playing on this device. [CHAR LIMIT=50] -->
    <string name="media_transfer_playing_this_device">Playing on this phone</string>
    <!-- Text informing the user that the media transfer has failed because something went wrong. [CHAR LIMIT=50] -->
    <string name="media_transfer_failed">Something went wrong</string>
    <string name="media_transfer_failed">Something went wrong. Try again.</string>

    <!-- Error message indicating that a control timed out while waiting for an update [CHAR_LIMIT=30] -->
    <string name="controls_error_timeout">Inactive, check app</string>
+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
)
Loading