blob: 20a2487349998b1ed3734bbf6773c10d69aaa70f (
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
|
/*
* Copyright (C) 2019 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.launcher3.uioverrides.touchcontrollers;
import static com.android.launcher3.uioverrides.touchcontrollers.PortraitStatesTouchController.isTouchOverHotseat;
import android.view.MotionEvent;
import com.android.launcher3.Launcher;
import com.android.launcher3.util.PendingAnimation;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;
/**
* Helper class for {@link PortraitStatesTouchController} that determines swipeable regions and
* animations on the overview state that depend on the recents implementation.
*/
public final class PortraitOverviewStateTouchHelper {
RecentsView mRecentsView;
Launcher mLauncher;
public PortraitOverviewStateTouchHelper(Launcher launcher) {
mLauncher = launcher;
mRecentsView = launcher.getOverviewPanel();
}
/**
* Whether or not {@link PortraitStatesTouchController} should intercept the touch when on the
* overview state.
*
* @param ev the motion event
* @return true if we should intercept the motion event
*/
boolean canInterceptTouch(MotionEvent ev) {
if (mRecentsView.getChildCount() > 0) {
// Allow swiping up in the gap between the hotseat and overview.
return ev.getY() >= mRecentsView.getChildAt(0).getBottom();
} else {
// If there are no tasks, we only intercept if we're below the hotseat height.
return isTouchOverHotseat(mLauncher, ev);
}
}
/**
* Whether or not swiping down to leave overview state should return to the currently running
* task app.
*
* @return true if going back should take the user to the currently running task
*/
boolean shouldSwipeDownReturnToApp() {
TaskView taskView = mRecentsView.getTaskViewAt(mRecentsView.getNextPage());
return taskView != null && mRecentsView.shouldSwipeDownLaunchApp();
}
/**
* Create the animation for going from overview to the task app via swiping. Should only be
* called when {@link #shouldSwipeDownReturnToApp()} returns true.
*
* @param duration how long the animation should be
* @return the animation
*/
PendingAnimation createSwipeDownToTaskAppAnimation(long duration) {
mRecentsView.setCurrentPage(mRecentsView.getPageNearestToCenterOfScreen());
TaskView taskView = mRecentsView.getTaskViewAt(mRecentsView.getCurrentPage());
if (taskView == null) {
throw new IllegalStateException("There is no task view to animate to.");
}
return mRecentsView.createTaskLauncherAnimation(taskView, duration);
}
}
|