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.NonNull; 25 import androidx.annotation.Nullable; 26 27 import com.android.launcher3.R; 28 import com.android.launcher3.logging.StatsLogManager; 29 import com.android.quickstep.interaction.TutorialController.TutorialType; 30 31 import java.util.ArrayList; 32 33 /** Shows the Home gesture interactive tutorial. */ 34 public class HomeGestureTutorialFragment extends TutorialFragment { 35 HomeGestureTutorialFragment()36 public HomeGestureTutorialFragment() { 37 this(false); 38 } 39 HomeGestureTutorialFragment(boolean fromTutorialMenu)40 public HomeGestureTutorialFragment(boolean fromTutorialMenu) { 41 super(fromTutorialMenu); 42 } 43 44 @NonNull 45 @Override getDefaultTutorialType()46 TutorialType getDefaultTutorialType() { 47 return TutorialType.HOME_NAVIGATION; 48 } 49 50 @Nullable 51 @Override getEdgeAnimationResId()52 Integer getEdgeAnimationResId() { 53 return R.drawable.gesture_tutorial_loop_home; 54 } 55 56 @Nullable 57 @Override createGestureAnimation()58 protected Animator createGestureAnimation() { 59 if (!(mTutorialController instanceof HomeGestureTutorialController)) { 60 return null; 61 } 62 float fingerDotStartTranslationY = (float) mRootView.getFullscreenHeight() / 2; 63 HomeGestureTutorialController controller = 64 (HomeGestureTutorialController) mTutorialController; 65 66 AnimatorSet fingerDotAppearanceAnimator = controller.createFingerDotAppearanceAnimatorSet(); 67 fingerDotAppearanceAnimator.addListener(new AnimatorListenerAdapter() { 68 @Override 69 public void onAnimationStart(Animator animation) { 70 super.onAnimationStart(animation); 71 mFingerDotView.setTranslationY(fingerDotStartTranslationY); 72 } 73 }); 74 75 Animator animationPause = controller.createAnimationPause(); 76 animationPause.addListener(new AnimatorListenerAdapter() { 77 @Override 78 public void onAnimationEnd(Animator animation) { 79 super.onAnimationEnd(animation); 80 controller.resetFakeTaskView(true); 81 } 82 }); 83 ArrayList<Animator> animators = new ArrayList<>(); 84 85 animators.add(fingerDotAppearanceAnimator); 86 animators.add(controller.createFingerDotHomeSwipeAnimator(fingerDotStartTranslationY)); 87 animators.add(controller.createFingerDotDisappearanceAnimatorSet()); 88 animators.add(animationPause); 89 90 AnimatorSet finalAnimation = new AnimatorSet(); 91 finalAnimation.addListener(new AnimatorListenerAdapter() { 92 @Override 93 public void onAnimationCancel(Animator animation) { 94 super.onAnimationCancel(animation); 95 controller.resetFakeTaskView(true); 96 } 97 }); 98 finalAnimation.playSequentially(animators); 99 100 return finalAnimation; 101 } 102 103 @Override createController(TutorialType type)104 TutorialController createController(TutorialType type) { 105 return new HomeGestureTutorialController(this, type); 106 } 107 108 @Override getControllerClass()109 Class<? extends TutorialController> getControllerClass() { 110 return HomeGestureTutorialController.class; 111 } 112 113 @Override onTouch(View view, MotionEvent motionEvent)114 public boolean onTouch(View view, MotionEvent motionEvent) { 115 releaseFeedbackAnimation(); 116 return super.onTouch(view, motionEvent); 117 } 118 119 @Override logTutorialStepShown(@onNull StatsLogManager statsLogManager)120 void logTutorialStepShown(@NonNull StatsLogManager statsLogManager) { 121 statsLogManager.logger().log( 122 StatsLogManager.LauncherEvent.LAUNCHER_GESTURE_TUTORIAL_HOME_STEP_SHOWN); 123 } 124 125 @Override logTutorialStepCompleted(@onNull StatsLogManager statsLogManager)126 void logTutorialStepCompleted(@NonNull StatsLogManager statsLogManager) { 127 statsLogManager.logger().log( 128 StatsLogManager.LauncherEvent.LAUNCHER_GESTURE_TUTORIAL_HOME_STEP_COMPLETED); 129 } 130 } 131