Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.launcher3.hybridhotseat; |
| 17 | |
Samuel Fufa | 6fd62fd | 2020-06-09 18:10:31 -0700 | [diff] [blame] | 18 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent |
| 19 | .LAUNCHER_HOTSEAT_EDU_ACCEPT; |
| 20 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOTSEAT_EDU_DENY; |
| 21 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOTSEAT_EDU_SEEN; |
Samuel Fufa | b641ac2 | 2020-02-10 17:58:11 -0800 | [diff] [blame] | 22 | |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 23 | import android.animation.PropertyValuesHolder; |
| 24 | import android.content.Context; |
| 25 | import android.content.res.Configuration; |
| 26 | import android.graphics.Rect; |
| 27 | import android.util.AttributeSet; |
| 28 | import android.view.LayoutInflater; |
| 29 | import android.view.View; |
| 30 | import android.widget.Button; |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 31 | import android.widget.TextView; |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 32 | |
Samuel Fufa | 5b2da14 | 2020-05-28 16:55:26 -0700 | [diff] [blame] | 33 | import com.android.launcher3.AbstractFloatingView; |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 34 | import com.android.launcher3.CellLayout; |
| 35 | import com.android.launcher3.DeviceProfile; |
| 36 | import com.android.launcher3.Insettable; |
| 37 | import com.android.launcher3.Launcher; |
| 38 | import com.android.launcher3.R; |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 39 | import com.android.launcher3.anim.Interpolators; |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 40 | import com.android.launcher3.config.FeatureFlags; |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 41 | import com.android.launcher3.model.data.WorkspaceItemInfo; |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 42 | import com.android.launcher3.uioverrides.PredictedAppIcon; |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 43 | import com.android.launcher3.views.AbstractSlideInView; |
| 44 | |
| 45 | import 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 | */ |
| 51 | public class HotseatEduDialog extends AbstractSlideInView implements Insettable { |
| 52 | |
| 53 | private static final int DEFAULT_CLOSE_DURATION = 200; |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 54 | protected static final int FINAL_SCRIM_BG_COLOR = 0x88000000; |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 55 | |
Samuel Fufa | 82bbdac | 2020-03-09 18:24:47 -0700 | [diff] [blame] | 56 | // 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 Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 58 | |
| 59 | private final Rect mInsets = new Rect(); |
| 60 | private View mHotseatWrapper; |
| 61 | private CellLayout mSampleHotseat; |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 62 | private Button mDismissBtn; |
| 63 | |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 64 | 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 Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 91 | mSampleHotseat.setGridSize(grid.numShownHotseatIcons, 1); |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 92 | mSampleHotseat.setPadding(padding.left, 0, padding.right, 0); |
| 93 | |
| 94 | Button turnOnBtn = findViewById(R.id.turn_predictions_on); |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 95 | turnOnBtn.setOnClickListener(this::onAccept); |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 96 | |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 97 | mDismissBtn = findViewById(R.id.no_thanks); |
| 98 | mDismissBtn.setOnClickListener(this::onDismiss); |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 99 | |
Samuel Fufa | 82bbdac | 2020-03-09 18:24:47 -0700 | [diff] [blame] | 100 | // 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 Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 107 | private void onAccept(View v) { |
Samuel Fufa | 82bbdac | 2020-03-09 18:24:47 -0700 | [diff] [blame] | 108 | mHotseatEduController.migrate(); |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 109 | handleClose(true); |
Samuel Fufa | 0068e18 | 2020-03-24 18:34:12 -0700 | [diff] [blame] | 110 | |
| 111 | mHotseatEduController.moveHotseatItems(); |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 112 | mHotseatEduController.finishOnboarding(); |
thiruram | c6a38ba | 2020-06-16 18:58:13 -0700 | [diff] [blame] | 113 | mLauncher.getStatsLogManager().logger().log(LAUNCHER_HOTSEAT_EDU_ACCEPT); |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 116 | private void onDismiss(View v) { |
Samuel Fufa | 0068e18 | 2020-03-24 18:34:12 -0700 | [diff] [blame] | 117 | mHotseatEduController.showDimissTip(); |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 118 | mHotseatEduController.finishOnboarding(); |
thiruram | c6a38ba | 2020-06-16 18:58:13 -0700 | [diff] [blame] | 119 | mLauncher.getStatsLogManager().logger().log(LAUNCHER_HOTSEAT_EDU_DENY); |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 120 | handleClose(true); |
| 121 | } |
| 122 | |
| 123 | @Override |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 124 | 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 Fufa | be40b29 | 2020-05-18 12:50:29 -0700 | [diff] [blame] | 134 | 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 Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 153 | 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 Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 175 | @Override |
| 176 | protected int getScrimColor(Context context) { |
| 177 | return FINAL_SCRIM_BG_COLOR; |
| 178 | } |
| 179 | |
| 180 | private void populatePreview(List<WorkspaceItemInfo> predictions) { |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 181 | for (int i = 0; i < mLauncher.getDeviceProfile().numShownHotseatIcons; i++) { |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 182 | WorkspaceItemInfo info = predictions.get(i); |
| 183 | PredictedAppIcon icon = PredictedAppIcon.createIcon(mSampleHotseat, info); |
| 184 | icon.setEnabled(false); |
Samuel Fufa | 6eaf989 | 2020-04-01 11:40:40 -0700 | [diff] [blame] | 185 | icon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 186 | 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 Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 192 | /** |
| 193 | * Opens User education dialog with a list of suggested apps |
| 194 | */ |
| 195 | public void show(List<WorkspaceItemInfo> predictions) { |
| 196 | if (getParent() != null |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 197 | || predictions.size() < mLauncher.getDeviceProfile().numShownHotseatIcons |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 198 | || mHotseatEduController == null) { |
| 199 | return; |
| 200 | } |
Samuel Fufa | 5b2da14 | 2020-05-28 16:55:26 -0700 | [diff] [blame] | 201 | AbstractFloatingView.closeAllOpenViews(mLauncher); |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 202 | attachToContainer(); |
thiruram | c6a38ba | 2020-06-16 18:58:13 -0700 | [diff] [blame] | 203 | mLauncher.getStatsLogManager().logger().log(LAUNCHER_HOTSEAT_EDU_SEEN); |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 204 | animateOpen(); |
| 205 | populatePreview(predictions); |
| 206 | } |
| 207 | |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 208 | /** |
| 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 | } |