1 /*
2  * Copyright (C) 2022 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.animation
18 
19 import android.view.View
20 
21 /** A piece of UI that can be expanded into a Dialog or an Activity. */
22 interface Expandable {
23     /**
24      * Create an [ActivityLaunchAnimator.Controller] that can be used to expand this [Expandable]
25      * into an Activity, or return `null` if this [Expandable] should not be animated (e.g. if it is
26      * currently not attached or visible).
27      *
28      * @param cujType the CUJ type from the [com.android.internal.jank.InteractionJankMonitor]
29      *   associated to the launch that will use this controller.
30      */
31     fun activityLaunchController(cujType: Int? = null): ActivityLaunchAnimator.Controller?
32 
33     /**
34      * Create a [DialogLaunchAnimator.Controller] that can be used to expand this [Expandable] into
35      * a Dialog, or return `null` if this [Expandable] should not be animated (e.g. if it is
36      * currently not attached or visible).
37      */
38     fun dialogLaunchController(cuj: DialogCuj? = null): DialogLaunchAnimator.Controller?
39 
40     companion object {
41         /**
42          * Create an [Expandable] that will animate [view] when expanded.
43          *
44          * Note: The background of [view] should be a (rounded) rectangle so that it can be properly
45          * animated.
46          */
47         @JvmStatic
48         fun fromView(view: View): Expandable {
49             return object : Expandable {
50                 override fun activityLaunchController(
51                     cujType: Int?,
52                 ): ActivityLaunchAnimator.Controller? {
53                     return ActivityLaunchAnimator.Controller.fromView(view, cujType)
54                 }
55 
56                 override fun dialogLaunchController(
57                     cuj: DialogCuj?
58                 ): DialogLaunchAnimator.Controller? {
59                     return DialogLaunchAnimator.Controller.fromView(view, cuj)
60                 }
61             }
62         }
63     }
64 }
65