1 /*
2  * Copyright (C) 2018 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 package com.android.launcher3.allapps;
17 
18 import static android.view.View.INVISIBLE;
19 import static android.view.View.VISIBLE;
20 
21 import android.graphics.Rect;
22 import android.view.View;
23 
24 import com.android.launcher3.DeviceProfile;
25 import com.android.systemui.plugins.AllAppsRow;
26 
27 /**
28  * Wrapper over an {@link AllAppsRow} plugin with {@link FloatingHeaderRow} interface so that
29  * it can be easily added in {@link FloatingHeaderView}.
30  */
31 public class PluginHeaderRow implements FloatingHeaderRow {
32 
33     private final AllAppsRow mPlugin;
34     final View mView;
35 
PluginHeaderRow(AllAppsRow plugin, FloatingHeaderView parent)36     PluginHeaderRow(AllAppsRow plugin, FloatingHeaderView parent) {
37         mPlugin = plugin;
38         mView = mPlugin.setup(parent);
39     }
40 
41     @Override
setup(FloatingHeaderView parent, FloatingHeaderRow[] allRows, boolean tabsHidden)42     public void setup(FloatingHeaderView parent, FloatingHeaderRow[] allRows,
43             boolean tabsHidden) { }
44 
45     @Override
setInsets(Rect insets, DeviceProfile grid)46     public void setInsets(Rect insets, DeviceProfile grid) { }
47 
48     @Override
getExpectedHeight()49     public int getExpectedHeight() {
50         return mPlugin.getExpectedHeight();
51     }
52 
53     @Override
shouldDraw()54     public boolean shouldDraw() {
55         return true;
56     }
57 
58     @Override
hasVisibleContent()59     public boolean hasVisibleContent() {
60         return true;
61     }
62 
63     @Override
setVerticalScroll(int scroll, boolean isScrolledOut)64     public void setVerticalScroll(int scroll, boolean isScrolledOut) {
65         mView.setVisibility(isScrolledOut ? INVISIBLE : VISIBLE);
66         if (!isScrolledOut) {
67             mView.setTranslationY(scroll);
68         }
69     }
70 
71     @Override
getTypeClass()72     public Class<PluginHeaderRow> getTypeClass() {
73         return PluginHeaderRow.class;
74     }
75 
76     @Override
getFocusedChild()77     public View getFocusedChild() {
78         return null;
79     }
80 }