1 /*
2  * Copyright (C) 2019 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.launcher3.graphics;
18 
19 import static android.view.View.VISIBLE;
20 
21 import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
22 import static com.android.launcher3.LauncherState.OVERVIEW;
23 
24 import android.graphics.Rect;
25 import android.view.View;
26 import android.view.ViewGroup;
27 
28 import androidx.annotation.NonNull;
29 import androidx.annotation.Nullable;
30 
31 /**
32  * View scrim which draws behind overview (recent apps).
33  */
34 public class OverviewScrim extends Scrim {
35 
36     private @NonNull View mStableScrimmedView;
37     // Might be higher up if mStableScrimmedView is invisible.
38     private @Nullable View mCurrentScrimmedView;
39 
OverviewScrim(View view)40     public OverviewScrim(View view) {
41         super(view);
42         mStableScrimmedView = mCurrentScrimmedView = mLauncher.getOverviewPanel();
43 
44         onExtractedColorsChanged(mWallpaperColorInfo);
45     }
46 
onInsetsChanged(Rect insets)47     public void onInsetsChanged(Rect insets) {
48         mStableScrimmedView = (OVERVIEW.getVisibleElements(mLauncher) & HOTSEAT_ICONS) != 0
49                 ? mLauncher.getHotseat()
50                 : mLauncher.getOverviewPanel();
51     }
52 
updateCurrentScrimmedView(ViewGroup root)53     public void updateCurrentScrimmedView(ViewGroup root) {
54         // Find the lowest view that is at or above the view we want to show the scrim behind.
55         mCurrentScrimmedView = mStableScrimmedView;
56         int currentIndex = root.indexOfChild(mCurrentScrimmedView);
57         final int childCount = root.getChildCount();
58         while (mCurrentScrimmedView != null && mCurrentScrimmedView.getVisibility() != VISIBLE
59                 && currentIndex < childCount) {
60             currentIndex++;
61             mCurrentScrimmedView = root.getChildAt(currentIndex);
62         }
63     }
64 
65     /**
66      * @return The view to draw the scrim behind, or null if all visible views should be scrimmed.
67      */
getScrimmedView()68     public @Nullable View getScrimmedView() {
69         return mCurrentScrimmedView;
70     }
71 }
72