blob: a2ed21143c688d66b0426235e199b645b7bfe5fc [file] [log] [blame]
Samuel Fufaaed008d2019-12-19 10:57:40 -08001/*
2 * Copyright (C) 2020 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 */
16package com.android.launcher3.hybridhotseat;
17
Samuel Fufa6fd62fd2020-06-09 18:10:31 -070018import static com.android.launcher3.logging.StatsLogManager.LauncherEvent
19 .LAUNCHER_HOTSEAT_EDU_ACCEPT;
20import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOTSEAT_EDU_DENY;
21import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOTSEAT_EDU_SEEN;
Samuel Fufab641ac22020-02-10 17:58:11 -080022
Samuel Fufaaed008d2019-12-19 10:57:40 -080023import android.animation.PropertyValuesHolder;
24import android.content.Context;
25import android.content.res.Configuration;
26import android.graphics.Rect;
27import android.util.AttributeSet;
28import android.view.LayoutInflater;
29import android.view.View;
30import android.widget.Button;
Samuel Fufaa4211432020-02-25 18:47:54 -080031import android.widget.TextView;
Samuel Fufaaed008d2019-12-19 10:57:40 -080032
Samuel Fufa5b2da142020-05-28 16:55:26 -070033import com.android.launcher3.AbstractFloatingView;
Samuel Fufaaed008d2019-12-19 10:57:40 -080034import com.android.launcher3.CellLayout;
35import com.android.launcher3.DeviceProfile;
36import com.android.launcher3.Insettable;
37import com.android.launcher3.Launcher;
38import com.android.launcher3.R;
Samuel Fufaaed008d2019-12-19 10:57:40 -080039import com.android.launcher3.anim.Interpolators;
Samuel Fufaa4211432020-02-25 18:47:54 -080040import com.android.launcher3.config.FeatureFlags;
Sunny Goyale396abf2020-04-06 15:11:17 -070041import com.android.launcher3.model.data.WorkspaceItemInfo;
Samuel Fufaaed008d2019-12-19 10:57:40 -080042import com.android.launcher3.uioverrides.PredictedAppIcon;
Samuel Fufaaed008d2019-12-19 10:57:40 -080043import com.android.launcher3.views.AbstractSlideInView;
44
45import java.util.List;
46
47/**
48 * User education dialog for hybrid hotseat. Allows user to migrate hotseat items to a new page in
49 * the workspace and shows predictions on the whole hotseat
50 */
51public class HotseatEduDialog extends AbstractSlideInView implements Insettable {
52
53 private static final int DEFAULT_CLOSE_DURATION = 200;
Samuel Fufaa4211432020-02-25 18:47:54 -080054 protected static final int FINAL_SCRIM_BG_COLOR = 0x88000000;
Samuel Fufaaed008d2019-12-19 10:57:40 -080055
Samuel Fufa82bbdac2020-03-09 18:24:47 -070056 // we use this value to keep track of migration logs as we experiment with different migrations
57 private static final int MIGRATION_EXPERIMENT_IDENTIFIER = 1;
Samuel Fufaaed008d2019-12-19 10:57:40 -080058
59 private final Rect mInsets = new Rect();
60 private View mHotseatWrapper;
61 private CellLayout mSampleHotseat;
Samuel Fufaa4211432020-02-25 18:47:54 -080062 private Button mDismissBtn;
63
Samuel Fufaaed008d2019-12-19 10:57:40 -080064 public void setHotseatEduController(HotseatEduController hotseatEduController) {
65 mHotseatEduController = hotseatEduController;
66 }
67
68 private HotseatEduController mHotseatEduController;
69
70 public HotseatEduDialog(Context context, AttributeSet attr) {
71 this(context, attr, 0);
72 }
73
74 public HotseatEduDialog(Context context, AttributeSet attrs,
75 int defStyleAttr) {
76 super(context, attrs, defStyleAttr);
77 mContent = this;
78 }
79
80
81 @Override
82 protected void onFinishInflate() {
83 super.onFinishInflate();
84 mHotseatWrapper = findViewById(R.id.hotseat_wrapper);
85 mSampleHotseat = findViewById(R.id.sample_prediction);
86
87 DeviceProfile grid = mLauncher.getDeviceProfile();
88 Rect padding = grid.getHotseatLayoutPadding();
89
90 mSampleHotseat.getLayoutParams().height = grid.cellHeightPx;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -070091 mSampleHotseat.setGridSize(grid.numShownHotseatIcons, 1);
Samuel Fufaaed008d2019-12-19 10:57:40 -080092 mSampleHotseat.setPadding(padding.left, 0, padding.right, 0);
93
94 Button turnOnBtn = findViewById(R.id.turn_predictions_on);
Samuel Fufaa4211432020-02-25 18:47:54 -080095 turnOnBtn.setOnClickListener(this::onAccept);
Samuel Fufaaed008d2019-12-19 10:57:40 -080096
Samuel Fufaa4211432020-02-25 18:47:54 -080097 mDismissBtn = findViewById(R.id.no_thanks);
98 mDismissBtn.setOnClickListener(this::onDismiss);
Samuel Fufaaed008d2019-12-19 10:57:40 -080099
Samuel Fufa82bbdac2020-03-09 18:24:47 -0700100 // update ui to reflect which migration method is going to be used
101 if (FeatureFlags.HOTSEAT_MIGRATE_TO_FOLDER.get()) {
102 ((TextView) findViewById(R.id.hotseat_edu_content)).setText(
103 R.string.hotseat_edu_message_migrate_alt);
104 }
Samuel Fufaaed008d2019-12-19 10:57:40 -0800105 }
106
Samuel Fufaa4211432020-02-25 18:47:54 -0800107 private void onAccept(View v) {
Samuel Fufa82bbdac2020-03-09 18:24:47 -0700108 mHotseatEduController.migrate();
Samuel Fufaaed008d2019-12-19 10:57:40 -0800109 handleClose(true);
Samuel Fufa0068e182020-03-24 18:34:12 -0700110
111 mHotseatEduController.moveHotseatItems();
Samuel Fufaaed008d2019-12-19 10:57:40 -0800112 mHotseatEduController.finishOnboarding();
thiruramc6a38ba2020-06-16 18:58:13 -0700113 mLauncher.getStatsLogManager().logger().log(LAUNCHER_HOTSEAT_EDU_ACCEPT);
Samuel Fufaaed008d2019-12-19 10:57:40 -0800114 }
115
Samuel Fufaa4211432020-02-25 18:47:54 -0800116 private void onDismiss(View v) {
Samuel Fufa0068e182020-03-24 18:34:12 -0700117 mHotseatEduController.showDimissTip();
Samuel Fufaaed008d2019-12-19 10:57:40 -0800118 mHotseatEduController.finishOnboarding();
thiruramc6a38ba2020-06-16 18:58:13 -0700119 mLauncher.getStatsLogManager().logger().log(LAUNCHER_HOTSEAT_EDU_DENY);
Samuel Fufaaed008d2019-12-19 10:57:40 -0800120 handleClose(true);
121 }
122
123 @Override
Samuel Fufaaed008d2019-12-19 10:57:40 -0800124 protected boolean isOfType(int type) {
125 return (type & TYPE_ON_BOARD_POPUP) != 0;
126 }
127
128 @Override
129 public void setInsets(Rect insets) {
130 int leftInset = insets.left - mInsets.left;
131 int rightInset = insets.right - mInsets.right;
132 int bottomInset = insets.bottom - mInsets.bottom;
133 mInsets.set(insets);
Samuel Fufabe40b292020-05-18 12:50:29 -0700134 if (mLauncher.getOrientation() == Configuration.ORIENTATION_PORTRAIT) {
135 setPadding(leftInset, getPaddingTop(), rightInset, 0);
136 mHotseatWrapper.setPadding(mHotseatWrapper.getPaddingLeft(), getPaddingTop(),
137 mHotseatWrapper.getPaddingRight(), bottomInset);
138 mHotseatWrapper.getLayoutParams().height =
139 mLauncher.getDeviceProfile().hotseatBarSizePx + insets.bottom;
140
141 } else {
142 setPadding(0, getPaddingTop(), 0, 0);
143 mHotseatWrapper.setPadding(mHotseatWrapper.getPaddingLeft(), getPaddingTop(),
144 mHotseatWrapper.getPaddingRight(),
145 (int) getResources().getDimension(R.dimen.bottom_sheet_edu_padding));
146 ((TextView) findViewById(R.id.hotseat_edu_heading)).setText(
147 R.string.hotseat_edu_title_migrate_landscape);
148 ((TextView) findViewById(R.id.hotseat_edu_content)).setText(
149 R.string.hotseat_edu_message_migrate_landscape);
150 }
Samuel Fufaaed008d2019-12-19 10:57:40 -0800151 }
152
Samuel Fufaaed008d2019-12-19 10:57:40 -0800153 private void animateOpen() {
154 if (mIsOpen || mOpenCloseAnimator.isRunning()) {
155 return;
156 }
157 mIsOpen = true;
158 mOpenCloseAnimator.setValues(
159 PropertyValuesHolder.ofFloat(TRANSLATION_SHIFT, TRANSLATION_SHIFT_OPENED));
160 mOpenCloseAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
161 mOpenCloseAnimator.start();
162 }
163
164 @Override
165 protected void handleClose(boolean animate) {
166 handleClose(true, DEFAULT_CLOSE_DURATION);
167 }
168
169 @Override
170 protected void onConfigurationChanged(Configuration newConfig) {
171 super.onConfigurationChanged(newConfig);
172 handleClose(false);
173 }
174
Samuel Fufaa4211432020-02-25 18:47:54 -0800175 @Override
176 protected int getScrimColor(Context context) {
177 return FINAL_SCRIM_BG_COLOR;
178 }
179
180 private void populatePreview(List<WorkspaceItemInfo> predictions) {
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700181 for (int i = 0; i < mLauncher.getDeviceProfile().numShownHotseatIcons; i++) {
Samuel Fufaaed008d2019-12-19 10:57:40 -0800182 WorkspaceItemInfo info = predictions.get(i);
183 PredictedAppIcon icon = PredictedAppIcon.createIcon(mSampleHotseat, info);
184 icon.setEnabled(false);
Samuel Fufa6eaf9892020-04-01 11:40:40 -0700185 icon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
Samuel Fufaaed008d2019-12-19 10:57:40 -0800186 icon.verifyHighRes();
187 CellLayout.LayoutParams lp = new CellLayout.LayoutParams(i, 0, 1, 1);
188 mSampleHotseat.addViewToCellLayout(icon, i, info.getViewId(), lp, true);
189 }
190 }
191
Samuel Fufaa4211432020-02-25 18:47:54 -0800192 /**
193 * Opens User education dialog with a list of suggested apps
194 */
195 public void show(List<WorkspaceItemInfo> predictions) {
196 if (getParent() != null
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700197 || predictions.size() < mLauncher.getDeviceProfile().numShownHotseatIcons
Samuel Fufaa4211432020-02-25 18:47:54 -0800198 || mHotseatEduController == null) {
199 return;
200 }
Samuel Fufa5b2da142020-05-28 16:55:26 -0700201 AbstractFloatingView.closeAllOpenViews(mLauncher);
Samuel Fufaa4211432020-02-25 18:47:54 -0800202 attachToContainer();
thiruramc6a38ba2020-06-16 18:58:13 -0700203 mLauncher.getStatsLogManager().logger().log(LAUNCHER_HOTSEAT_EDU_SEEN);
Samuel Fufaa4211432020-02-25 18:47:54 -0800204 animateOpen();
205 populatePreview(predictions);
206 }
207
Samuel Fufaaed008d2019-12-19 10:57:40 -0800208 /**
209 * Factory method for HotseatPredictionUserEdu dialog
210 */
211 public static HotseatEduDialog getDialog(Launcher launcher) {
212 LayoutInflater layoutInflater = LayoutInflater.from(launcher);
213 return (HotseatEduDialog) layoutInflater.inflate(
214 R.layout.predicted_hotseat_edu, launcher.getDragLayer(),
215 false);
216
217 }
218}