• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.wm.shell.back;
18 
19 import android.view.KeyEvent;
20 import android.view.MotionEvent;
21 import android.window.BackEvent;
22 
23 import com.android.wm.shell.shared.annotations.ExternalThread;
24 
25 /**
26  * Interface for external process to get access to the Back animation related methods.
27  */
28 @ExternalThread
29 public interface BackAnimation {
30 
31     /**
32      * Called when a {@link MotionEvent} is generated by a back gesture.
33      *
34      * @param touchX the X touch position of the {@link MotionEvent}.
35      * @param touchY the Y touch position of the {@link MotionEvent}.
36      * @param keyAction the original {@link KeyEvent#getAction()} when the event was dispatched to
37      *               the process. This is forwarded separately because the input pipeline may mutate
38      *               the {#event} action state later.
39      * @param swipeEdge the edge from which the swipe begins.
40      */
onBackMotion( float touchX, float touchY, int keyAction, @BackEvent.SwipeEdge int swipeEdge)41     void onBackMotion(
42             float touchX,
43             float touchY,
44             int keyAction,
45             @BackEvent.SwipeEdge int swipeEdge);
46 
47     /**
48      * Called when the back swipe threshold is crossed.
49      */
onThresholdCrossed()50     void onThresholdCrossed();
51 
52     /**
53      * Sets whether the back gesture is past the trigger threshold or not.
54      */
setTriggerBack(boolean triggerBack)55     void setTriggerBack(boolean triggerBack);
56 
57     /**
58      * Sets the threshold values that define edge swipe behavior.<br>
59      * <br>
60      * <h1>How does {@code nonLinearFactor} work?</h1>
61      * <pre>
62      *     screen              screen              screen
63      *     width               width               width
64      *    |——————|            |————————————|      |————————————————————|
65      *           A     B                   A                   B  C    A
66      *  1 +——————+—————+    1 +————————————+    1 +————————————+———————+
67      *    |     /      |      |          —/|      |            | —————/|
68      *    |    /       |      |        —/  |      |           ——/      |
69      *    |   /        |      |      —/    |      |        ——/ |       |
70      *    |  /         |      |    —/      |      |     ——/    |       |
71      *    | /          |      |  —/        |      |  ——/       |       |
72      *    |/           |      |—/          |      |—/          |       |
73      *  0 +————————————+    0 +————————————+    0 +————————————+———————+
74      *                 B                   B                   B
75      * </pre>
76      * Three devices with different widths (smaller, equal, and wider) relative to the progress
77      * threshold are shown in the graphs.<br>
78      * - A is the width of the screen<br>
79      * - B is the progress threshold (horizontal swipe distance where progress is linear)<br>
80      * - C equals B + (A - B) * nonLinearFactor<br>
81      * <br>
82      * If A is less than or equal to B, {@code progress} for the swipe distance between:<br>
83      * - [0, A] will scale linearly between [0, 1].<br>
84      * If A is greater than B, {@code progress} for swipe distance between:<br>
85      * - [0, B] will scale linearly between [0, B / C]<br>
86      * - (B, A] will scale non-linearly and reach 1.
87      *
88      * @param linearDistance up to this distance progress continues linearly. B in the graph above.
89      * @param maxDistance distance at which the progress will be 1f. A in the graph above.
90      * @param nonLinearFactor This value is used to calculate the target if the screen is wider
91      *                        than the progress threshold.
92      */
setSwipeThresholds(float linearDistance, float maxDistance, float nonLinearFactor)93     void setSwipeThresholds(float linearDistance, float maxDistance, float nonLinearFactor);
94 
95     /**
96      * Sets the system bar listener to control the system bar color.
97      * @param customizer the controller to control system bar color.
98      */
setStatusBarCustomizer(StatusBarCustomizer customizer)99     void setStatusBarCustomizer(StatusBarCustomizer customizer);
100 
101     /**
102      * Set a callback to pilfer pointers.
103      * @param pilferCallback the callback to pilfer pointers.
104      */
setPilferPointerCallback(Runnable pilferCallback)105     void setPilferPointerCallback(Runnable pilferCallback);
106 
107     /**
108      * Set a callback to requestTopUi.
109      * @param topUiRequest the callback to requestTopUi.
110      */
setTopUiRequestCallback(TopUiRequest topUiRequest)111     void setTopUiRequestCallback(TopUiRequest topUiRequest);
112 
113     /**
114      * Callback to request SysUi to call
115      * {@link android.app.IActivityManager#setHasTopUi(boolean)}.
116      */
117     interface TopUiRequest {
118 
119         /**
120          * Request {@link android.app.IActivityManager#setHasTopUi(boolean)} to be called.
121          * @param requestTopUi  whether topUi should be requested or not
122          * @param tag           tag of the request-source
123          */
requestTopUi(boolean requestTopUi, String tag)124         void requestTopUi(boolean requestTopUi, String tag);
125     }
126 }
127