Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/unfold/UnfoldBackgroundController.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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.wm.shell.unfold;
18
19 import static android.graphics.Color.blue;
20 import static android.graphics.Color.green;
21 import static android.graphics.Color.red;
22 import static android.view.Display.DEFAULT_DISPLAY;
23
24 import android.annotation.NonNull;
25 import android.content.Context;
26 import android.view.SurfaceControl;
27
28 import com.android.wm.shell.R;
29 import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
30
31 /**
32 * Controls background color layer for the unfold animations
33 */
34 public class UnfoldBackgroundController {
35
36 private static final int BACKGROUND_LAYER_Z_INDEX = -1;
37
38 private final RootTaskDisplayAreaOrganizer mRootTaskDisplayAreaOrganizer;
39 private final float[] mBackgroundColor;
40 private SurfaceControl mBackgroundLayer;
41
42 public UnfoldBackgroundController(
43 @NonNull Context context,
44 @NonNull RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) {
45 mRootTaskDisplayAreaOrganizer = rootTaskDisplayAreaOrganizer;
46 mBackgroundColor = getBackgroundColor(context);
47 }
48
49 /**
50 * Ensures that unfold animation background color layer is present,
51 * @param transaction where we should add the background if it is not added
52 */
53 public void ensureBackground(@NonNull SurfaceControl.Transaction transaction) {
54 if (mBackgroundLayer != null) return;
55
56 SurfaceControl.Builder colorLayerBuilder = new SurfaceControl.Builder()
57 .setName("app-unfold-background")
58 .setCallsite("AppUnfoldTransitionController")
59 .setColorLayer();
60 mRootTaskDisplayAreaOrganizer.attachToDisplayArea(DEFAULT_DISPLAY, colorLayerBuilder);
61 mBackgroundLayer = colorLayerBuilder.build();
62
63 transaction
64 .setColor(mBackgroundLayer, mBackgroundColor)
65 .show(mBackgroundLayer)
66 .setLayer(mBackgroundLayer, BACKGROUND_LAYER_Z_INDEX);
67 }
68
69 /**
70 * Ensures that the background is not visible
71 * @param transaction as part of which the removal will happen if needed
72 */
73 public void removeBackground(@NonNull SurfaceControl.Transaction transaction) {
74 if (mBackgroundLayer == null) return;
75 if (mBackgroundLayer.isValid()) {
76 transaction.remove(mBackgroundLayer);
77 }
78 mBackgroundLayer = null;
79 }
80
81 private float[] getBackgroundColor(Context context) {
82 int colorInt = context.getResources().getColor(R.color.taskbar_background);
83 return new float[]{
84 (float) red(colorInt) / 255.0F,
85 (float) green(colorInt) / 255.0F,
86 (float) blue(colorInt) / 255.0F
87 };
88 }
89 }