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 package com.android.systemui.plugins.shared; 17 18 import android.view.MotionEvent; 19 20 import java.io.PrintWriter; 21 22 /** 23 * Interface to control the overlay on Launcher 24 */ 25 public interface LauncherOverlayManager { 26 onDeviceProvideChanged()27 default void onDeviceProvideChanged() { } 28 onAttachedToWindow()29 default void onAttachedToWindow() { } onDetachedFromWindow()30 default void onDetachedFromWindow() { } 31 dump(String prefix, PrintWriter w)32 default void dump(String prefix, PrintWriter w) { } 33 openOverlay()34 default void openOverlay() { } 35 hideOverlay(boolean animate)36 default void hideOverlay(boolean animate) { 37 hideOverlay(animate ? 200 : 0); 38 } 39 hideOverlay(int duration)40 default void hideOverlay(int duration) { } 41 onActivityStarted()42 default void onActivityStarted() { } 43 onActivityResumed()44 default void onActivityResumed() { } 45 onActivityPaused()46 default void onActivityPaused() { } 47 onActivityStopped()48 default void onActivityStopped() { } 49 onActivityDestroyed()50 default void onActivityDestroyed() { } 51 onDisallowSwipeToMinusOnePage()52 default void onDisallowSwipeToMinusOnePage() {} 53 54 /** 55 * @deprecated use LauncherOverlayTouchProxy directly 56 */ 57 @Deprecated 58 interface LauncherOverlay extends LauncherOverlayTouchProxy { 59 60 /** 61 * Touch interaction leading to overscroll has begun 62 */ onScrollInteractionBegin()63 void onScrollInteractionBegin(); 64 65 /** 66 * Touch interaction related to overscroll has ended 67 */ onScrollInteractionEnd()68 void onScrollInteractionEnd(); 69 70 /** 71 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost 72 * screen (or in the case of RTL, the rightmost screen). 73 */ onScrollChange(float progress, boolean rtl)74 void onScrollChange(float progress, boolean rtl); 75 76 /** 77 * Called when the launcher is ready to use the overlay 78 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay 79 */ setOverlayCallbacks(LauncherOverlayCallbacks callbacks)80 void setOverlayCallbacks(LauncherOverlayCallbacks callbacks); 81 82 @Override onFlingVelocity(float velocity)83 default void onFlingVelocity(float velocity) { } 84 85 @Override onOverlayMotionEvent(MotionEvent ev, float scrollProgress)86 default void onOverlayMotionEvent(MotionEvent ev, float scrollProgress) { 87 switch (ev.getAction()) { 88 case MotionEvent.ACTION_DOWN -> onScrollInteractionBegin(); 89 case MotionEvent.ACTION_MOVE -> onScrollChange(scrollProgress, false); 90 case MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> onScrollInteractionEnd(); 91 } 92 93 } 94 } 95 96 interface LauncherOverlayTouchProxy { 97 98 /** 99 * Called just before finishing scroll interaction to indicate the fling velocity 100 */ onFlingVelocity(float velocity)101 void onFlingVelocity(float velocity); 102 103 /** 104 * Called to dispatch various motion events to the overlay 105 */ onOverlayMotionEvent(MotionEvent ev, float scrollProgress)106 void onOverlayMotionEvent(MotionEvent ev, float scrollProgress); 107 108 /** 109 * Called when the launcher is ready to use the overlay 110 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay 111 */ setOverlayCallbacks(LauncherOverlayCallbacks callbacks)112 default void setOverlayCallbacks(LauncherOverlayCallbacks callbacks) { } 113 } 114 115 interface LauncherOverlayCallbacks { 116 onOverlayScrollChanged(float progress)117 void onOverlayScrollChanged(float progress); 118 } 119 } 120