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

Commit 7518dab8 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

New button style for Magic Actions

Adds a new drawable and button style for smart actions coming from the
assistant with a specific extra key.

Actual drawable implementation will land on follow-up CL.

Bug: 383567383
Test: atest SmartActionScreenshotTest
Flag: com.android.systemui.notification_magic_actions_treatment
Change-Id: I0ad7e4751df4885a202c9fbdb5663b589a6e81ef
parent 767ff220
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1967,6 +1967,13 @@ public class Notification implements Parcelable
        @SystemApi
        public static final int SEMANTIC_ACTION_CONVERSATION_IS_PHISHING = 12;
        /**
         * {@link #extras} key to a boolean defining if this action requires special visual
         * treatment.
         * @hide
         */
        public static final String EXTRA_IS_MAGIC = "android.extra.IS_MAGIC";
        private final Bundle mExtras;
        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
        private Icon mIcon;
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.
 */

package com.android.systemui.statusbar.notification.row

import android.content.Context
import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.PixelFormat
import android.graphics.drawable.Drawable

/**
 * A background style for smarter-smart-actions.
 *
 * TODO(b/383567383) implement final UX
 */
class MagicActionBackgroundDrawable(context: Context) : Drawable() {

    private var _alpha: Int = 255
    private var _colorFilter: ColorFilter? = null
    private val paint =
        Paint().apply {
            color = context.getColor(com.android.internal.R.color.materialColorPrimaryContainer)
        }

    override fun draw(canvas: Canvas) {
        canvas.drawRect(bounds, paint)
    }

    override fun setAlpha(alpha: Int) {
        _alpha = alpha
        invalidateSelf()
    }

    override fun setColorFilter(colorFilter: ColorFilter?) {
        _colorFilter = colorFilter
        invalidateSelf()
    }

    override fun getOpacity(): Int = PixelFormat.TRANSLUCENT
}
+11 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.view.ViewGroup
import android.view.accessibility.AccessibilityNodeInfo
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction
import android.widget.Button
import com.android.systemui.Flags
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.res.R
import com.android.systemui.shared.system.ActivityManagerWrapper
@@ -52,6 +53,7 @@ import com.android.systemui.statusbar.SmartReplyController
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.headsup.HeadsUpManager
import com.android.systemui.statusbar.notification.logging.NotificationLogger
import com.android.systemui.statusbar.notification.row.MagicActionBackgroundDrawable
import com.android.systemui.statusbar.phone.KeyguardDismissUtil
import com.android.systemui.statusbar.policy.InflatedSmartReplyState.SuppressedActions
import com.android.systemui.statusbar.policy.SmartReplyView.SmartActions
@@ -400,6 +402,15 @@ constructor(
            .apply {
                text = action.title

                if (Flags.notificationMagicActionsTreatment()) {
                    if (
                        smartActions.fromAssistant &&
                            action.extras.getBoolean(Notification.Action.EXTRA_IS_MAGIC, false)
                    ) {
                        background = MagicActionBackgroundDrawable(parent.context)
                    }
                }

                // We received the Icon from the application - so use the Context of the application
                // to
                // reference icon resources.