1 /*
2  * Copyright (C) 2017 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 android.content.Context;
19 import android.graphics.Rect;
20 import android.util.AttributeSet;
21 import android.view.MotionEvent;
22 
23 import com.android.launcher3.Launcher;
24 import com.android.launcher3.LauncherState;
25 import com.android.launcher3.statemanager.StateManager.StateListener;
26 import com.android.launcher3.views.WorkEduView;
27 
28 /**
29  * AllAppsContainerView with launcher specific callbacks
30  */
31 public class LauncherAllAppsContainerView extends AllAppsContainerView {
32 
33     private final Launcher mLauncher;
34 
35     private StateListener<LauncherState> mWorkTabListener;
36 
LauncherAllAppsContainerView(Context context)37     public LauncherAllAppsContainerView(Context context) {
38         this(context, null);
39     }
40 
LauncherAllAppsContainerView(Context context, AttributeSet attrs)41     public LauncherAllAppsContainerView(Context context, AttributeSet attrs) {
42         this(context, attrs, 0);
43     }
44 
LauncherAllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr)45     public LauncherAllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
46         super(context, attrs, defStyleAttr);
47         mLauncher = Launcher.getLauncher(context);
48     }
49 
50     @Override
onInterceptTouchEvent(MotionEvent ev)51     public boolean onInterceptTouchEvent(MotionEvent ev) {
52         // The AllAppsContainerView houses the QSB and is hence visible from the Workspace
53         // Overview states. We shouldn't intercept for the scrubber in these cases.
54         if (!mLauncher.isInState(LauncherState.ALL_APPS)) {
55             mTouchHandler = null;
56             return false;
57         }
58 
59         return super.onInterceptTouchEvent(ev);
60     }
61 
62     @Override
onTouchEvent(MotionEvent ev)63     public boolean onTouchEvent(MotionEvent ev) {
64         if (!mLauncher.isInState(LauncherState.ALL_APPS)) {
65             return false;
66         }
67         return super.onTouchEvent(ev);
68     }
69 
70     @Override
setInsets(Rect insets)71     public void setInsets(Rect insets) {
72         super.setInsets(insets);
73         mLauncher.getAllAppsController()
74                 .setScrollRangeDelta(mSearchUiManager.getScrollRangeDelta(insets));
75     }
76 
77     @Override
setupHeader()78     public void setupHeader() {
79         super.setupHeader();
80         if (mWorkTabListener != null && !mUsingTabs) {
81             mLauncher.getStateManager().removeStateListener(mWorkTabListener);
82         }
83     }
84 
85     @Override
onTabChanged(int pos)86     public void onTabChanged(int pos) {
87         super.onTabChanged(pos);
88         if (mUsingTabs) {
89             if (pos == AdapterHolder.WORK) {
90                 WorkEduView.showWorkEduIfNeeded(mLauncher);
91             } else {
92                 mWorkTabListener = WorkEduView.showEduFlowIfNeeded(mLauncher, mWorkTabListener);
93             }
94         }
95     }
96 }
97