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.quickstep.interaction;
17 
18 import android.animation.Animator;
19 import android.animation.AnimatorListenerAdapter;
20 import android.animation.AnimatorSet;
21 import android.view.MotionEvent;
22 import android.view.View;
23 
24 import androidx.annotation.Nullable;
25 
26 import com.android.launcher3.R;
27 import com.android.quickstep.interaction.TutorialController.TutorialType;
28 
29 import java.util.ArrayList;
30 
31 /** Shows the Home gesture interactive tutorial. */
32 public class HomeGestureTutorialFragment extends TutorialFragment {
33 
34     @Nullable
35     @Override
getEdgeAnimationResId()36     Integer getEdgeAnimationResId() {
37         return R.drawable.gesture_tutorial_loop_home;
38     }
39 
40     @Nullable
41     @Override
createGestureAnimation()42     protected Animator createGestureAnimation() {
43         if (!(mTutorialController instanceof HomeGestureTutorialController)) {
44             return null;
45         }
46         float fingerDotStartTranslationY = (float) mRootView.getFullscreenHeight() / 2;
47         HomeGestureTutorialController controller =
48                 (HomeGestureTutorialController) mTutorialController;
49 
50         AnimatorSet fingerDotAppearanceAnimator = controller.createFingerDotAppearanceAnimatorSet();
51         fingerDotAppearanceAnimator.addListener(new AnimatorListenerAdapter() {
52             @Override
53             public void onAnimationStart(Animator animation) {
54                 super.onAnimationStart(animation);
55                 mFingerDotView.setTranslationY(fingerDotStartTranslationY);
56             }
57         });
58 
59         Animator animationPause = controller.createAnimationPause();
60         animationPause.addListener(new AnimatorListenerAdapter() {
61             @Override
62             public void onAnimationEnd(Animator animation) {
63                 super.onAnimationEnd(animation);
64                 controller.resetFakeTaskView(true);
65             }
66         });
67         ArrayList<Animator> animators = new ArrayList<>();
68 
69         animators.add(fingerDotAppearanceAnimator);
70         animators.add(controller.createFingerDotHomeSwipeAnimator(fingerDotStartTranslationY));
71         animators.add(controller.createFingerDotDisappearanceAnimatorSet());
72         animators.add(animationPause);
73 
74         AnimatorSet finalAnimation = new AnimatorSet();
75         finalAnimation.addListener(new AnimatorListenerAdapter() {
76             @Override
77             public void onAnimationCancel(Animator animation) {
78                 super.onAnimationCancel(animation);
79                 controller.resetFakeTaskView(true);
80             }
81         });
82         finalAnimation.playSequentially(animators);
83 
84         return finalAnimation;
85     }
86 
87     @Override
createController(TutorialType type)88     TutorialController createController(TutorialType type) {
89         return new HomeGestureTutorialController(this, type);
90     }
91 
92     @Override
getControllerClass()93     Class<? extends TutorialController> getControllerClass() {
94         return HomeGestureTutorialController.class;
95     }
96 
97     @Override
onTouch(View view, MotionEvent motionEvent)98     public boolean onTouch(View view, MotionEvent motionEvent) {
99         releaseFeedbackAnimation();
100         return super.onTouch(view, motionEvent);
101     }
102 }
103