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 
52     /**
53      * @deprecated use LauncherOverlayTouchProxy directly
54      */
55     @Deprecated
56     interface LauncherOverlay extends LauncherOverlayTouchProxy {
57 
58         /**
59          * Touch interaction leading to overscroll has begun
60          */
onScrollInteractionBegin()61         void onScrollInteractionBegin();
62 
63         /**
64          * Touch interaction related to overscroll has ended
65          */
onScrollInteractionEnd()66         void onScrollInteractionEnd();
67 
68         /**
69          * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
70          * screen (or in the case of RTL, the rightmost screen).
71          */
onScrollChange(float progress, boolean rtl)72         void onScrollChange(float progress, boolean rtl);
73 
74         /**
75          * Called when the launcher is ready to use the overlay
76          * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
77          */
setOverlayCallbacks(LauncherOverlayCallbacks callbacks)78         void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
79 
80         @Override
onFlingVelocity(float velocity)81         default void onFlingVelocity(float velocity) { }
82 
83         @Override
onOverlayMotionEvent(MotionEvent ev, float scrollProgress)84         default void onOverlayMotionEvent(MotionEvent ev, float scrollProgress) {
85             switch (ev.getAction()) {
86                 case MotionEvent.ACTION_DOWN ->  onScrollInteractionBegin();
87                 case MotionEvent.ACTION_MOVE -> onScrollChange(scrollProgress, false);
88                 case MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> onScrollInteractionEnd();
89             }
90 
91         }
92     }
93 
94     interface LauncherOverlayTouchProxy {
95 
96         /**
97          * Called just before finishing scroll interaction to indicate the fling velocity
98          */
onFlingVelocity(float velocity)99         void onFlingVelocity(float velocity);
100 
101         /**
102          * Called to dispatch various motion events to the overlay
103          */
onOverlayMotionEvent(MotionEvent ev, float scrollProgress)104         void onOverlayMotionEvent(MotionEvent ev, float scrollProgress);
105 
106         /**
107          * Called when the launcher is ready to use the overlay
108          * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
109          */
setOverlayCallbacks(LauncherOverlayCallbacks callbacks)110         default void setOverlayCallbacks(LauncherOverlayCallbacks callbacks) { }
111     }
112 
113     interface LauncherOverlayCallbacks {
114 
onOverlayScrollChanged(float progress)115         void onOverlayScrollChanged(float progress);
116     }
117 }
118