blob: 02ed57d4be22502df2c2c94e36eeaffaecded710 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.window;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
import com.android.window.flags.Flags;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Dispatcher to register {@link OnBackInvokedCallback} instances for handling
* back invocations.
*
* It also provides interfaces to update the attributes of {@link OnBackInvokedCallback}.
* Attribute updates are proactively pushed to the window manager if they change the dispatch
* target (a.k.a. the callback to be invoked next), or its behavior.
*/
public interface OnBackInvokedDispatcher {
/** @hide */
String TAG = "OnBackInvokedDispatcher";
/** @hide */
boolean DEBUG = false;
/** @hide */
@IntDef({
PRIORITY_DEFAULT,
PRIORITY_OVERLAY,
PRIORITY_SYSTEM_NAVIGATION_OBSERVER,
})
@Retention(RetentionPolicy.SOURCE)
@interface Priority{}
/**
* Priority level of {@link OnBackInvokedCallback}s for overlays such as menus and
* navigation drawers that should receive back dispatch before non-overlays.
*/
int PRIORITY_OVERLAY = 1000000;
/**
* Default priority level of {@link OnBackInvokedCallback}s.
*/
int PRIORITY_DEFAULT = 0;
/**
* Priority level of {@link OnBackInvokedCallback}s registered by the system.
*
* System back animation will play when the callback to receive dispatch has this priority.
* @hide
*/
int PRIORITY_SYSTEM = -1;
/**
* Priority level of {@link OnBackInvokedCallback}s designed to observe system-level back
* handling.
*
* <p>Callbacks registered with this priority do not consume back events. They receive back
* events whenever the system handles a back navigation and have no impact on the normal back
* navigation flow. Useful for logging or analytics.
*
* <p>Only one callback with {@link #PRIORITY_SYSTEM_NAVIGATION_OBSERVER} can be registered at a
* time.
*/
@FlaggedApi(Flags.FLAG_PREDICTIVE_BACK_PRIORITY_SYSTEM_NAVIGATION_OBSERVER)
int PRIORITY_SYSTEM_NAVIGATION_OBSERVER = -2;
/**
* Registers a {@link OnBackInvokedCallback}.
*
* Within the same priority level, callbacks are invoked in the reverse order in which
* they are registered. Higher priority callbacks are invoked before lower priority ones.
*
* @param priority The priority of the callback.
* @param callback The callback to be registered. If the callback instance has been already
* registered, the existing instance (no matter its priority) will be
* unregistered and registered again.
* @throws IllegalArgumentException if the priority is negative.
*/
@SuppressLint({"ExecutorRegistration"})
void registerOnBackInvokedCallback(
@Priority @IntRange(from = 0) int priority, @NonNull OnBackInvokedCallback callback);
/**
* Unregisters a {@link OnBackInvokedCallback}.
*
* @param callback The callback to be unregistered. Does nothing if the callback has not been
* registered.
*/
void unregisterOnBackInvokedCallback(@NonNull OnBackInvokedCallback callback);
/**
* Registers a {@link OnBackInvokedCallback} with system priority.
* @hide
*/
default void registerSystemOnBackInvokedCallback(@NonNull OnBackInvokedCallback callback) { }
/**
* Sets an {@link ImeOnBackInvokedDispatcher} to forward {@link OnBackInvokedCallback}s
* from IME to the app process to be registered on the app window.
*
* Only call this on the IME window. Create the {@link ImeOnBackInvokedDispatcher} from
* the application process and override
* {@link ImeOnBackInvokedDispatcher#getReceivingDispatcher()} to point to the app
* window's {@link WindowOnBackInvokedDispatcher}.
*
* @hide
*/
default void setImeOnBackInvokedDispatcher(
@NonNull ImeOnBackInvokedDispatcher imeDispatcher) { }
}
|