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