summaryrefslogtreecommitdiff
path: root/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialController.java
blob: 65f3a01149307941ff6b5a424e4877c00d6dbe22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.quickstep.interaction;

import static com.android.app.animation.Interpolators.ACCELERATE;
import static com.android.launcher3.config.FeatureFlags.ENABLE_NEW_GESTURE_NAV_TUTORIAL;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.annotation.TargetApi;
import android.graphics.PointF;
import android.os.Build;
import android.os.Handler;

import androidx.annotation.ColorInt;
import androidx.core.graphics.ColorUtils;

import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.anim.PendingAnimation;
import com.android.quickstep.SwipeUpAnimationLogic;
import com.android.quickstep.interaction.EdgeBackGestureHandler.BackGestureResult;
import com.android.quickstep.interaction.NavBarGestureHandler.NavBarGestureResult;
import com.android.quickstep.util.LottieAnimationColorUtils;

import java.util.ArrayList;
import java.util.Map;

/** A {@link TutorialController} for the Overview tutorial. */
@TargetApi(Build.VERSION_CODES.R)
final class OverviewGestureTutorialController extends SwipeUpGestureTutorialController {

    private static final float LAUNCHER_COLOR_BLENDING_RATIO = 0.4f;

    OverviewGestureTutorialController(OverviewGestureTutorialFragment fragment,
            TutorialType tutorialType) {
        super(fragment, tutorialType);

        // Set the Lottie animation colors specifically for the Overview gesture
        if (ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()) {
            LottieAnimationColorUtils.updateToArgbColors(
                    mAnimatedGestureDemonstration,
                    Map.of(".onSurfaceOverview", fragment.mRootView.mColorOnSurfaceOverview,
                            ".surfaceOverview", fragment.mRootView.mColorSurfaceOverview,
                            ".secondaryOverview", fragment.mRootView.mColorSecondaryOverview));

            LottieAnimationColorUtils.updateToArgbColors(
                    mCheckmarkAnimation,
                    Map.of(".checkmark",
                            Utilities.isDarkTheme(mContext)
                                    ? fragment.mRootView.mColorOnSurfaceOverview
                                    : fragment.mRootView.mColorSecondaryOverview,
                            ".checkmarkBackground", fragment.mRootView.mColorSurfaceOverview));
        }
    }
    @Override
    public int getIntroductionTitle() {
        return ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()
                ? R.string.overview_gesture_tutorial_title
                : R.string.overview_gesture_intro_title;
    }

    @Override
    public int getIntroductionSubtitle() {
        return ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()
                ? R.string.overview_gesture_tutorial_subtitle
                : R.string.overview_gesture_intro_subtitle;
    }

    @Override
    public int getSpokenIntroductionSubtitle() {
        return R.string.overview_gesture_spoken_intro_subtitle;
    }

    @Override
    public int getSuccessFeedbackTitle() {
        return ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()
                ? R.string.overview_gesture_tutorial_success
                : R.string.gesture_tutorial_nice;
    }

    @Override
    public int getSuccessFeedbackSubtitle() {
        return mTutorialFragment.getNumSteps() > 1 && mTutorialFragment.isAtFinalStep()
                ? R.string.overview_gesture_feedback_complete_with_follow_up
                : R.string.overview_gesture_feedback_complete_without_follow_up;
    }

    @Override
    public int getTitleTextAppearance() {
        return R.style.TextAppearance_GestureTutorial_MainTitle_Overview;
    }

    @Override
    public int getSuccessTitleTextAppearance() {
        return R.style.TextAppearance_GestureTutorial_MainTitle_Success_Overview;
    }

    @Override
    public int getDoneButtonTextAppearance() {
        return R.style.TextAppearance_GestureTutorial_ButtonLabel_Overview;
    }

    @Override
    public int getDoneButtonColor() {
        return Utilities.isDarkTheme(mContext)
                ? mTutorialFragment.mRootView.mColorOnSurfaceOverview
                : mTutorialFragment.mRootView.mColorSecondaryOverview;
    }

    @Override
    protected int getMockAppTaskLayoutResId() {
        return mTutorialFragment.isLargeScreen()
                ? R.layout.gesture_tutorial_tablet_mock_conversation_list
                : R.layout.gesture_tutorial_mock_conversation_list;
    }

    @Override
    protected int getGestureLottieAnimationId() {
        return mTutorialFragment.isLargeScreen()
                ? mTutorialFragment.isFoldable()
                    ? R.raw.overview_gesture_tutorial_open_foldable_animation
                    : R.raw.overview_gesture_tutorial_tablet_animation
                : R.raw.overview_gesture_tutorial_animation;
    }

    @ColorInt
    private int getFakeTaskViewStartColor() {
        return mTutorialFragment.mRootView.mColorSurfaceOverview;
    }

    @ColorInt
    private int getFakeTaskViewEndColor() {
        return getMockPreviousAppTaskThumbnailColor();
    }

    @Override
    protected int getFakeTaskViewColor() {
        return isGestureCompleted()
                ? getFakeTaskViewEndColor()
                : getFakeTaskViewStartColor();
    }

    @Override
    protected int getFakeLauncherColor() {
        return ColorUtils.blendARGB(
                mTutorialFragment.mRootView.mColorSurfaceContainer,
                mTutorialFragment.mRootView.mColorOnSurfaceOverview,
                LAUNCHER_COLOR_BLENDING_RATIO);
    }

    @Override
    protected int getHotseatIconColor() {
        return mTutorialFragment.mRootView.mColorOnSurfaceOverview;
    }

    @Override
    protected int getMockPreviousAppTaskThumbnailColor() {
        return ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()
                ? mTutorialFragment.mRootView.mColorSurfaceContainer
                : mContext.getResources().getColor(
                        R.color.gesture_tutorial_fake_previous_task_view_color);
    }

    @Override
    public void onBackGestureAttempted(BackGestureResult result) {
        if (isGestureCompleted()) {
            return;
        }
        switch (mTutorialType) {
            case OVERVIEW_NAVIGATION:
                switch (result) {
                    case BACK_COMPLETED_FROM_LEFT:
                    case BACK_COMPLETED_FROM_RIGHT:
                    case BACK_CANCELLED_FROM_LEFT:
                    case BACK_CANCELLED_FROM_RIGHT:
                    case BACK_NOT_STARTED_TOO_FAR_FROM_EDGE:
                        resetTaskViews();
                        showFeedback(R.string.overview_gesture_feedback_swipe_too_far_from_edge);
                        break;
                }
                break;
            case OVERVIEW_NAVIGATION_COMPLETE:
                if (result == BackGestureResult.BACK_COMPLETED_FROM_LEFT
                        || result == BackGestureResult.BACK_COMPLETED_FROM_RIGHT) {
                    mTutorialFragment.close();
                }
                break;
        }
    }

    @Override
    public void onNavBarGestureAttempted(NavBarGestureResult result, PointF finalVelocity) {
        if (isGestureCompleted()) {
            return;
        }
        switch (mTutorialType) {
            case OVERVIEW_NAVIGATION:
                switch (result) {
                    case HOME_GESTURE_COMPLETED: {
                        animateFakeTaskViewHome(finalVelocity, () -> {
                            showFeedback(R.string.overview_gesture_feedback_home_detected);
                            resetFakeTaskView(true);
                        });
                        break;
                    }
                    case HOME_NOT_STARTED_TOO_FAR_FROM_EDGE:
                    case OVERVIEW_NOT_STARTED_TOO_FAR_FROM_EDGE:
                        resetTaskViews();
                        showFeedback(R.string.overview_gesture_feedback_swipe_too_far_from_edge);
                        break;
                    case OVERVIEW_GESTURE_COMPLETED:
                        setGestureCompleted();
                        mTutorialFragment.releaseFeedbackAnimation();
                        animateTaskViewToOverview(ENABLE_NEW_GESTURE_NAV_TUTORIAL.get());
                        onMotionPaused(true /*arbitrary value*/);
                        if (!ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()) {
                            showSuccessFeedback();
                        }
                        break;
                    case HOME_OR_OVERVIEW_NOT_STARTED_WRONG_SWIPE_DIRECTION:
                    case HOME_OR_OVERVIEW_CANCELLED:
                        fadeOutFakeTaskView(false, null);
                        showFeedback(R.string.overview_gesture_feedback_wrong_swipe_direction);
                        break;
                }
                break;
            case OVERVIEW_NAVIGATION_COMPLETE:
                if (result == NavBarGestureResult.HOME_GESTURE_COMPLETED) {
                    mTutorialFragment.close();
                }
                break;
        }
    }

    /**
     * runnable executed with slight delay to ease the swipe animation after landing on overview
     */
    public void animateTaskViewToOverview(boolean animateDelayedSuccessFeedback) {
        PendingAnimation anim = new PendingAnimation(TASK_VIEW_END_ANIMATION_DURATION_MILLIS);
        anim.setFloat(mTaskViewSwipeUpAnimation
                .getCurrentShift(), AnimatedFloat.VALUE, 1, ACCELERATE);

        if (animateDelayedSuccessFeedback) {
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    new Handler().postDelayed(
                            () -> fadeOutFakeTaskView(
                                    /* toOverviewFirst= */ true,
                                    /* animatePreviousTask= */ false,
                                    /* resetViews= */ false,
                                    /* updateListener= */ v -> mFakeTaskView.setBackgroundColor(
                                            ColorUtils.blendARGB(
                                                    getFakeTaskViewStartColor(),
                                                    getFakeTaskViewEndColor(),
                                                    v.getAnimatedFraction())),
                                    /* onEndRunnable= */ () -> {
                                        showSuccessFeedback();
                                        resetTaskViews();
                                    }),
                            TASK_VIEW_FILL_SCREEN_ANIMATION_DELAY_MILLIS);
                }
            });
        }

        ArrayList<Animator> animators = new ArrayList<>();

        if (mTutorialFragment.isLargeScreen()) {
            Animator multiRowAnimation = mFakePreviousTaskView.createAnimationToMultiRowLayout();

            if (multiRowAnimation != null) {
                multiRowAnimation.setDuration(TASK_VIEW_END_ANIMATION_DURATION_MILLIS);
                animators.add(multiRowAnimation);
            }
        }
        animators.add(anim.buildAnim());

        AnimatorSet animset = new AnimatorSet();
        animset.playTogether(animators);
        animset.start();
        mRunningWindowAnim = SwipeUpAnimationLogic.RunningWindowAnim.wrap(animset);
    }
}