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.launcher3.taskbar;
18 
19 import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
20 import static com.android.launcher3.AbstractFloatingView.TYPE_TASKBAR_EDUCATION_DIALOG;
21 
22 import android.content.Context;
23 import android.util.AttributeSet;
24 
25 import com.android.launcher3.AbstractFloatingView;
26 import com.android.launcher3.PagedView;
27 import com.android.launcher3.R;
28 import com.android.launcher3.pageindicators.PageIndicatorDots;
29 import com.android.launcher3.taskbar.TaskbarEduController.TaskbarEduCallbacks;
30 import com.android.launcher3.views.ActivityContext;
31 
32 /** Horizontal carousel of tutorial screens for Taskbar Edu. */
33 public class TaskbarEduPagedView extends PagedView<PageIndicatorDots> {
34 
35     private TaskbarEduView mTaskbarEduView;
36     private TaskbarEduCallbacks mControllerCallbacks;
37 
TaskbarEduPagedView(Context context, AttributeSet attrs)38     public TaskbarEduPagedView(Context context, AttributeSet attrs) {
39         super(context, attrs);
40         setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
41     }
42 
setTaskbarEduView(TaskbarEduView taskbarEduView)43     void setTaskbarEduView(TaskbarEduView taskbarEduView) {
44         mTaskbarEduView = taskbarEduView;
45         mPageIndicator = taskbarEduView.findViewById(R.id.content_page_indicator);
46         initParentViews(taskbarEduView);
47     }
48 
setControllerCallbacks(TaskbarEduCallbacks controllerCallbacks)49     void setControllerCallbacks(TaskbarEduCallbacks controllerCallbacks) {
50         mControllerCallbacks = controllerCallbacks;
51         mControllerCallbacks.onPageChanged(getCurrentPage(), getPageCount());
52     }
53 
54     @Override
getChildGap()55     protected int getChildGap() {
56         return mTaskbarEduView.getPaddingLeft() + mTaskbarEduView.getPaddingRight();
57     }
58 
59     @Override
onScrollChanged(int l, int t, int oldl, int oldt)60     protected void onScrollChanged(int l, int t, int oldl, int oldt) {
61         super.onScrollChanged(l, t, oldl, oldt);
62         if (mMaxScroll > 0) {
63             mPageIndicator.setScroll(l, mMaxScroll);
64         }
65     }
66 
67     @Override
notifyPageSwitchListener(int prevPage)68     protected void notifyPageSwitchListener(int prevPage) {
69         super.notifyPageSwitchListener(prevPage);
70         mControllerCallbacks.onPageChanged(getCurrentPage(), getPageCount());
71     }
72 
73     @Override
canScroll(float absVScroll, float absHScroll)74     protected boolean canScroll(float absVScroll, float absHScroll) {
75         return AbstractFloatingView.getTopOpenViewWithType(
76                 ActivityContext.lookupContext(getContext()),
77                 TYPE_ALL & ~TYPE_TASKBAR_EDUCATION_DIALOG) == null;
78     }
79 }
80