1 /*
2  * 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.quickstep.views
18 
19 import android.content.Context
20 import android.graphics.Canvas
21 import android.graphics.RectF
22 import android.graphics.drawable.Drawable
23 
24 class FloatingFullscreenAppPairBackground(
25         context: Context,
26         floatingView: FloatingAppPairView,
27         private val iconToLaunch: Drawable,
28         dividerPos: Int) :
29         FloatingAppPairBackground(
30                 context,
31                 floatingView,
32                 iconToLaunch,
33                 null /*appIcon2*/,
34                 dividerPos
35 ) {
36 
37     /** Animates the background as if launching a fullscreen task. */
drawnull38     override fun draw(canvas: Canvas) {
39         val progress = floatingView.progress
40 
41         // Since the entire floating app pair surface is scaling up during this animation, we
42         // scale down most of these drawn elements so that they appear the proper size on-screen.
43         val scaleFactorX = floatingView.scaleX
44         val scaleFactorY = floatingView.scaleY
45 
46         // Get the bounds where we will draw the background image
47         val width = bounds.width().toFloat()
48         val height = bounds.height().toFloat()
49 
50         // Get device-specific measurements
51         val cornerRadiusX = deviceCornerRadius / scaleFactorX
52         val cornerRadiusY = deviceCornerRadius / scaleFactorY
53 
54         // Draw background
55         drawCustomRoundedRect(
56                 canvas,
57                 RectF(0f, 0f, width, height),
58                 floatArrayOf(
59                         cornerRadiusX,
60                         cornerRadiusY,
61                         cornerRadiusX,
62                         cornerRadiusY,
63                         cornerRadiusX,
64                         cornerRadiusY,
65                         cornerRadiusX,
66                         cornerRadiusY,
67                 )
68         )
69 
70         // Calculate changing measurements for icon.
71         val changingIconSizeX =
72                 (STARTING_ICON_SIZE_PX +
73                         ((ENDING_ICON_SIZE_PX - STARTING_ICON_SIZE_PX) *
74                                 expandXInterpolator.getInterpolation(progress))) / scaleFactorX
75         val changingIconSizeY =
76                 (STARTING_ICON_SIZE_PX +
77                         ((ENDING_ICON_SIZE_PX - STARTING_ICON_SIZE_PX) *
78                                 expandYInterpolator.getInterpolation(progress))) / scaleFactorY
79 
80         val changingIcon1Left = (width / 2f) - (changingIconSizeX / 2f)
81         val changingIconTop = (height / 2f) - (changingIconSizeY / 2f)
82         val changingIconScaleX = changingIconSizeX / iconToLaunch.bounds.width()
83         val changingIconScaleY = changingIconSizeY / iconToLaunch.bounds.height()
84         val changingIconAlpha =
85                 (255 - (255 * iconFadeInterpolator.getInterpolation(progress))).toInt()
86 
87         // Draw icon
88         canvas.save()
89         canvas.translate(changingIcon1Left, changingIconTop)
90         canvas.scale(changingIconScaleX, changingIconScaleY)
91         iconToLaunch.alpha = changingIconAlpha
92         iconToLaunch.draw(canvas)
93         canvas.restore()
94     }
95 }