• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.launcher3.taskbar;
17 
18 import android.view.LayoutInflater;
19 import android.view.View;
20 import android.view.ViewGroup;
21 
22 import com.android.launcher3.DeviceProfile;
23 import com.android.launcher3.R;
24 import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext;
25 import com.android.launcher3.taskbar.overlay.TaskbarOverlayController;
26 import com.android.launcher3.util.DisplayController;
27 
28 import com.airbnb.lottie.LottieAnimationView;
29 
30 import java.io.PrintWriter;
31 
32 /** Handles the Taskbar Education flow. */
33 public class TaskbarEduController implements TaskbarControllers.LoggableTaskbarController {
34 
35     private final TaskbarActivityContext mActivity;
36 
37     // Initialized in init.
38     TaskbarControllers mControllers;
39 
40     private TaskbarEduView mTaskbarEduView;
41     private TaskbarEduPagedView mPagedView;
42 
TaskbarEduController(TaskbarActivityContext activity)43     public TaskbarEduController(TaskbarActivityContext activity) {
44         mActivity = activity;
45     }
46 
init(TaskbarControllers controllers)47     public void init(TaskbarControllers controllers) {
48         mControllers = controllers;
49     }
50 
showEdu()51     void showEdu() {
52         TaskbarOverlayController overlayController = mControllers.taskbarOverlayController;
53         TaskbarOverlayContext overlayContext = overlayController.requestWindow();
54         LayoutInflater layoutInflater = overlayContext.getLayoutInflater();
55 
56         mTaskbarEduView = (TaskbarEduView) layoutInflater.inflate(
57                 R.layout.taskbar_edu, overlayContext.getDragLayer(), false);
58         mPagedView = mTaskbarEduView.findViewById(R.id.content);
59         layoutInflater.inflate(
60                 DisplayController.isTransientTaskbar(overlayContext)
61                         ? R.layout.taskbar_edu_pages_transient
62                         : R.layout.taskbar_edu_pages_persistent,
63                 mPagedView,
64                 true);
65 
66         // Provide enough room for taskbar.
67         View startButton = mTaskbarEduView.findViewById(R.id.edu_start_button);
68         ViewGroup.MarginLayoutParams layoutParams =
69                 (ViewGroup.MarginLayoutParams) startButton.getLayoutParams();
70         DeviceProfile dp = overlayContext.getDeviceProfile();
71         layoutParams.bottomMargin += dp.taskbarHeight + dp.taskbarBottomMargin;
72 
73         mTaskbarEduView.init(new TaskbarEduCallbacks());
74 
75         mControllers.navbarButtonsViewController.setSlideInViewVisible(true);
76         mTaskbarEduView.setOnCloseBeginListener(
77                 () -> mControllers.navbarButtonsViewController.setSlideInViewVisible(false));
78         mTaskbarEduView.addOnCloseListener(() -> mTaskbarEduView = null);
79         mTaskbarEduView.show();
80     }
81 
82     @Override
dumpLogs(String prefix, PrintWriter pw)83     public void dumpLogs(String prefix, PrintWriter pw) {
84         pw.println(prefix + "TaskbarEduController:");
85         pw.println(prefix + "\tisShowingEdu=" + (mTaskbarEduView != null));
86     }
87 
88     /**
89      * Callbacks for {@link TaskbarEduView} to interact with its controller.
90      */
91     class TaskbarEduCallbacks {
onPageChanged(int prevPage, int currentPage, int pageCount)92         void onPageChanged(int prevPage, int currentPage, int pageCount) {
93             // Reset previous pages' animation.
94             LottieAnimationView prevAnimation = mPagedView.getChildAt(prevPage)
95                     .findViewById(R.id.animation);
96             prevAnimation.cancelAnimation();
97             prevAnimation.setFrame(0);
98 
99             mPagedView.getChildAt(currentPage)
100                     .<LottieAnimationView>findViewById(R.id.animation)
101                     .playAnimation();
102 
103             if (currentPage == 0) {
104                 mTaskbarEduView.updateStartButton(R.string.taskbar_edu_close,
105                         v -> mTaskbarEduView.close(true /* animate */));
106             } else {
107                 mTaskbarEduView.updateStartButton(R.string.taskbar_edu_previous,
108                         v -> mTaskbarEduView.snapToPage(currentPage - 1));
109             }
110             if (currentPage == pageCount - 1) {
111                 mTaskbarEduView.updateEndButton(R.string.taskbar_edu_done,
112                         v -> mTaskbarEduView.close(true /* animate */));
113             } else {
114                 mTaskbarEduView.updateEndButton(R.string.taskbar_edu_next,
115                         v -> mTaskbarEduView.snapToPage(currentPage + 1));
116             }
117         }
118 
getIconLayoutBoundsWidth()119         int getIconLayoutBoundsWidth() {
120             return mControllers.taskbarViewController.getIconLayoutWidth();
121         }
122 
getOpenDuration()123         int getOpenDuration() {
124             return mControllers.taskbarOverlayController.getOpenDuration();
125         }
126 
getCloseDuration()127         int getCloseDuration() {
128             return mControllers.taskbarOverlayController.getCloseDuration();
129         }
130     }
131 }
132