1 /*
<lambda>null2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.communal.widgets
18 
19 import android.app.ActivityOptions
20 import android.app.PendingIntent
21 import android.content.Intent
22 import android.view.View
23 import android.widget.RemoteViews
24 import com.android.systemui.animation.ActivityTransitionAnimator
25 import com.android.systemui.communal.util.InteractionHandlerDelegate
26 import com.android.systemui.dagger.SysUISingleton
27 import com.android.systemui.plugins.ActivityStarter
28 import javax.inject.Inject
29 
30 @SysUISingleton
31 class WidgetInteractionHandler
32 @Inject
33 constructor(
34     private val activityStarter: ActivityStarter,
35 ) : RemoteViews.InteractionHandler {
36 
37     private val delegate = InteractionHandlerDelegate(
38         findViewToAnimate = { view -> view is CommunalAppWidgetHostView },
39         intentStarter = this::startIntent,
40     )
41 
42     override fun onInteraction(
43         view: View,
44         pendingIntent: PendingIntent,
45         response: RemoteViews.RemoteResponse
46     ): Boolean = delegate.onInteraction(view, pendingIntent, response)
47 
48 
49     private fun startIntent(
50         pendingIntent: PendingIntent,
51         fillInIntent: Intent,
52         extraOptions: ActivityOptions,
53         controller: ActivityTransitionAnimator.Controller?
54     ): Boolean {
55         activityStarter.startPendingIntentMaybeDismissingKeyguard(
56             pendingIntent,
57             /* dismissShade = */ false,
58             /* intentSentUiThreadCallback = */ null,
59             controller,
60             fillInIntent,
61             extraOptions.toBundle(),
62         )
63         return true
64     }
65 }
66