1 /* 2 * Copyright (C) 2019 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 17 package com.android.launcher3.uioverrides.touchcontrollers; 18 19 import static com.android.launcher3.uioverrides.touchcontrollers.PortraitStatesTouchController.isTouchOverHotseat; 20 21 import android.view.MotionEvent; 22 import android.view.animation.Interpolator; 23 24 import com.android.launcher3.Launcher; 25 import com.android.launcher3.anim.PendingAnimation; 26 import com.android.quickstep.views.RecentsView; 27 import com.android.quickstep.views.TaskView; 28 29 /** 30 * Helper class for {@link PortraitStatesTouchController} that determines swipeable regions and 31 * animations on the overview state that depend on the recents implementation. 32 */ 33 public final class PortraitOverviewStateTouchHelper { 34 35 RecentsView mRecentsView; 36 Launcher mLauncher; 37 PortraitOverviewStateTouchHelper(Launcher launcher)38 public PortraitOverviewStateTouchHelper(Launcher launcher) { 39 mLauncher = launcher; 40 mRecentsView = launcher.getOverviewPanel(); 41 } 42 43 /** 44 * Whether or not {@link PortraitStatesTouchController} should intercept the touch when on the 45 * overview state. 46 * 47 * @param ev the motion event 48 * @return true if we should intercept the motion event 49 */ canInterceptTouch(MotionEvent ev)50 boolean canInterceptTouch(MotionEvent ev) { 51 if (mRecentsView.getTaskViewCount() > 0) { 52 // Allow swiping up in the gap between the hotseat and overview. 53 return ev.getY() >= mRecentsView.getTaskViewAt(0).getBottom(); 54 } else { 55 // If there are no tasks, we only intercept if we're below the hotseat height. 56 return isTouchOverHotseat(mLauncher, ev); 57 } 58 } 59 60 /** 61 * Whether or not swiping down to leave overview state should return to the currently running 62 * task app. 63 * 64 * @return true if going back should take the user to the currently running task 65 */ shouldSwipeDownReturnToApp()66 boolean shouldSwipeDownReturnToApp() { 67 TaskView taskView = mRecentsView.getNextPageTaskView(); 68 return taskView != null && mRecentsView.shouldSwipeDownLaunchApp(); 69 } 70 71 /** 72 * Create the animation for going from overview to the task app via swiping. Should only be 73 * called when {@link #shouldSwipeDownReturnToApp()} returns true. 74 * 75 * @param duration how long the animation should be 76 * @return the animation 77 */ createSwipeDownToTaskAppAnimation(long duration, Interpolator interpolator)78 PendingAnimation createSwipeDownToTaskAppAnimation(long duration, Interpolator interpolator) { 79 mRecentsView.setCurrentPage(mRecentsView.getDestinationPage()); 80 TaskView taskView = mRecentsView.getCurrentPageTaskView(); 81 if (taskView == null) { 82 throw new IllegalStateException("There is no task view to animate to."); 83 } 84 return mRecentsView.createTaskLaunchAnimation(taskView, duration, interpolator); 85 } 86 } 87