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.common.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 velocityX the X velocity computed from the {@link MotionEvent}. 37 * @param velocityY the Y velocity computed from the {@link MotionEvent}. 38 * @param keyAction the original {@link KeyEvent#getAction()} when the event was dispatched to 39 * the process. This is forwarded separately because the input pipeline may mutate 40 * the {#event} action state later. 41 * @param swipeEdge the edge from which the swipe begins. 42 */ onBackMotion( float touchX, float touchY, float velocityX, float velocityY, int keyAction, @BackEvent.SwipeEdge int swipeEdge)43 void onBackMotion( 44 float touchX, 45 float touchY, 46 float velocityX, 47 float velocityY, 48 int keyAction, 49 @BackEvent.SwipeEdge int swipeEdge); 50 51 /** 52 * Sets whether the back gesture is past the trigger threshold or not. 53 */ setTriggerBack(boolean triggerBack)54 void setTriggerBack(boolean triggerBack); 55 56 /** 57 * Sets the threshold values that define edge swipe behavior.<br> 58 * <br> 59 * <h1>How does {@code nonLinearFactor} work?</h1> 60 * <pre> 61 * screen screen screen 62 * width width width 63 * |——————| |————————————| |————————————————————| 64 * A B A B C A 65 * 1 +——————+—————+ 1 +————————————+ 1 +————————————+———————+ 66 * | / | | —/| | | —————/| 67 * | / | | —/ | | ——/ | 68 * | / | | —/ | | ——/ | | 69 * | / | | —/ | | ——/ | | 70 * | / | | —/ | | ——/ | | 71 * |/ | |—/ | |—/ | | 72 * 0 +————————————+ 0 +————————————+ 0 +————————————+———————+ 73 * B B B 74 * </pre> 75 * Three devices with different widths (smaller, equal, and wider) relative to the progress 76 * threshold are shown in the graphs.<br> 77 * - A is the width of the screen<br> 78 * - B is the progress threshold (horizontal swipe distance where progress is linear)<br> 79 * - C equals B + (A - B) * nonLinearFactor<br> 80 * <br> 81 * If A is less than or equal to B, {@code progress} for the swipe distance between:<br> 82 * - [0, A] will scale linearly between [0, 1].<br> 83 * If A is greater than B, {@code progress} for swipe distance between:<br> 84 * - [0, B] will scale linearly between [0, B / C]<br> 85 * - (B, A] will scale non-linearly and reach 1. 86 * 87 * @param linearDistance up to this distance progress continues linearly. B in the graph above. 88 * @param maxDistance distance at which the progress will be 1f. A in the graph above. 89 * @param nonLinearFactor This value is used to calculate the target if the screen is wider 90 * than the progress threshold. 91 */ setSwipeThresholds(float linearDistance, float maxDistance, float nonLinearFactor)92 void setSwipeThresholds(float linearDistance, float maxDistance, float nonLinearFactor); 93 94 /** 95 * Sets the system bar listener to control the system bar color. 96 * @param customizer the controller to control system bar color. 97 */ setStatusBarCustomizer(StatusBarCustomizer customizer)98 void setStatusBarCustomizer(StatusBarCustomizer customizer); 99 } 100