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.systemui.statusbar.notification;
18 
19 import android.view.View;
20 
21 import androidx.annotation.Nullable;
22 
23 /**
24  * Used to let views that have an alpha not apply the HARDWARE layer type directly, and instead
25  * delegate that to specific children.  This is useful if we want to fake not having overlapping
26  * rendering to avoid layer trashing, when fading out a view that is also changing.
27  */
28 public interface NotificationFadeAware {
29     /**
30      * Calls {@link View#setLayerType} with {@link View#LAYER_TYPE_HARDWARE} if faded and
31      * {@link View#LAYER_TYPE_NONE} otherwise.
32      */
setLayerTypeForFaded(@ullable View view, boolean faded)33     static void setLayerTypeForFaded(@Nullable View view, boolean faded) {
34         if (view != null) {
35             int newLayerType = faded ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE;
36             view.setLayerType(newLayerType, null);
37         }
38     }
39 
40     /**
41      * Used like {@link View#setLayerType} with {@link View#LAYER_TYPE_HARDWARE} or
42      * {@link View#LAYER_TYPE_NONE} except that instead of necessarily affecting this view
43      * specifically, this may delegate the call to child views.
44      *
45      * When set to <code>true</code>, the view has two possible paths:
46      *  1. If a hardware layer is required to ensure correct appearance of this view, then
47      *    set that layer type.
48      *  2. Otherwise, delegate this call to children, who might make that call for themselves.
49      *
50      * When set to <code>false</code>, the view should undo the above, typically by calling
51      *  {@link View#setLayerType} with {@link View#LAYER_TYPE_NONE} on itself and children, and
52      *  delegating to this method on children where implemented.
53      *
54      * When this delegates to {@link View#setLayerType} on this view or a subview, `null` will be
55      * passed for the `paint` argument of that call.
56      */
setNotificationFaded(boolean faded)57     void setNotificationFaded(boolean faded);
58 
59     /**
60      * Interface for the top level notification view that fades and optimizes that through deep
61      * awareness of individual components.
62      */
63     interface FadeOptimizedNotification extends NotificationFadeAware {
64         /** Top-level feature switch */
65         boolean FADE_LAYER_OPTIMIZATION_ENABLED = true;
66 
67         /** Determine if the notification is currently faded. */
isNotificationFaded()68         boolean isNotificationFaded();
69     }
70 }
71