1 /* 2 * Copyright (C) 2023 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; 18 19 import androidx.annotation.FloatRange; 20 21 /** 22 * Interface that mimics {@link android.window.OnBackInvokedCallback} without dependencies on U's 23 * API such as {@link android.window.BackEvent}. 24 * 25 * <p> Impl can assume below order during a back gesture: 26 * <ol> 27 * <li> [optional] one {@link #onBackStarted()} will be called to start the gesture 28 * <li> zero or multiple {@link #onBackProgressed(float)} will be called during swipe gesture 29 * <li> either one of {@link #onBackInvoked()} or {@link #onBackCancelled()} will be called to end 30 * the gesture 31 */ 32 public interface OnBackPressedHandler { 33 34 /** Called when back has started. */ onBackStarted()35 default void onBackStarted() {} 36 37 /** Called when back is committed. */ onBackInvoked()38 void onBackInvoked(); 39 40 /** Called with back gesture's progress. */ onBackProgressed(@loatRangefrom = 0.0, to = 1.0) float backProgress)41 default void onBackProgressed(@FloatRange(from = 0.0, to = 1.0) float backProgress) {} 42 43 /** Called when user drops the back gesture. */ onBackCancelled()44 default void onBackCancelled() {} 45 } 46