Merge "Remove OnBackInvokedDispatcherOwner interface." into tm-dev am: bf8817d3f0
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17511152 Change-Id: Id99607c81b81330a31383f12222949764d7924fb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -4074,7 +4074,7 @@ package android.app {
|
|||||||
method @Deprecated public void onTabUnselected(android.app.ActionBar.Tab, android.app.FragmentTransaction);
|
method @Deprecated public void onTabUnselected(android.app.ActionBar.Tab, android.app.FragmentTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
@UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
||||||
ctor public Activity();
|
ctor public Activity();
|
||||||
method public void addContentView(android.view.View, android.view.ViewGroup.LayoutParams);
|
method public void addContentView(android.view.View, android.view.ViewGroup.LayoutParams);
|
||||||
method public void closeContextMenu();
|
method public void closeContextMenu();
|
||||||
@@ -5018,7 +5018,7 @@ package android.app {
|
|||||||
method public void onDateSet(android.widget.DatePicker, int, int, int);
|
method public void onDateSet(android.widget.DatePicker, int, int, int);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Dialog implements android.content.DialogInterface android.view.KeyEvent.Callback android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
public class Dialog implements android.content.DialogInterface android.view.KeyEvent.Callback android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
||||||
ctor public Dialog(@NonNull @UiContext android.content.Context);
|
ctor public Dialog(@NonNull @UiContext android.content.Context);
|
||||||
ctor public Dialog(@NonNull @UiContext android.content.Context, @StyleRes int);
|
ctor public Dialog(@NonNull @UiContext android.content.Context, @StyleRes int);
|
||||||
ctor protected Dialog(@NonNull @UiContext android.content.Context, boolean, @Nullable android.content.DialogInterface.OnCancelListener);
|
ctor protected Dialog(@NonNull @UiContext android.content.Context, boolean, @Nullable android.content.DialogInterface.OnCancelListener);
|
||||||
@@ -51087,6 +51087,7 @@ package android.view {
|
|||||||
method public android.media.session.MediaController getMediaController();
|
method public android.media.session.MediaController getMediaController();
|
||||||
method @ColorInt public abstract int getNavigationBarColor();
|
method @ColorInt public abstract int getNavigationBarColor();
|
||||||
method @ColorInt public int getNavigationBarDividerColor();
|
method @ColorInt public int getNavigationBarDividerColor();
|
||||||
|
method @NonNull public android.window.OnBackInvokedDispatcher getOnBackInvokedDispatcher();
|
||||||
method public android.transition.Transition getReenterTransition();
|
method public android.transition.Transition getReenterTransition();
|
||||||
method public android.transition.Transition getReturnTransition();
|
method public android.transition.Transition getReturnTransition();
|
||||||
method @Nullable public android.view.AttachedSurfaceControl getRootSurfaceControl();
|
method @Nullable public android.view.AttachedSurfaceControl getRootSurfaceControl();
|
||||||
@@ -57991,10 +57992,6 @@ package android.window {
|
|||||||
field public static final int PRIORITY_OVERLAY = 1000000; // 0xf4240
|
field public static final int PRIORITY_OVERLAY = 1000000; // 0xf4240
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnBackInvokedDispatcherOwner {
|
|
||||||
method @NonNull public android.window.OnBackInvokedDispatcher getOnBackInvokedDispatcher();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface SplashScreen {
|
public interface SplashScreen {
|
||||||
method public void clearOnExitAnimationListener();
|
method public void clearOnExitAnimationListener();
|
||||||
method public void setOnExitAnimationListener(@NonNull android.window.SplashScreen.OnExitAnimationListener);
|
method public void setOnExitAnimationListener(@NonNull android.window.SplashScreen.OnExitAnimationListener);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ package android {
|
|||||||
|
|
||||||
package android.app {
|
package android.app {
|
||||||
|
|
||||||
@UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
@UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
||||||
method public final boolean addDumpable(@NonNull android.util.Dumpable);
|
method public final boolean addDumpable(@NonNull android.util.Dumpable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ package android.accounts {
|
|||||||
|
|
||||||
package android.app {
|
package android.app {
|
||||||
|
|
||||||
@UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
@UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
||||||
method public void convertFromTranslucent();
|
method public void convertFromTranslucent();
|
||||||
method public boolean convertToTranslucent(android.app.Activity.TranslucentConversionListener, android.app.ActivityOptions);
|
method public boolean convertToTranslucent(android.app.Activity.TranslucentConversionListener, android.app.ActivityOptions);
|
||||||
method @Deprecated public boolean isBackgroundVisibleBehind();
|
method @Deprecated public boolean isBackgroundVisibleBehind();
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ package android.animation {
|
|||||||
|
|
||||||
package android.app {
|
package android.app {
|
||||||
|
|
||||||
@UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.window.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
@UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
|
||||||
method public final boolean addDumpable(@NonNull android.util.Dumpable);
|
method public final boolean addDumpable(@NonNull android.util.Dumpable);
|
||||||
method public void dumpInternal(@NonNull String, @Nullable java.io.FileDescriptor, @NonNull java.io.PrintWriter, @Nullable String[]);
|
method public void dumpInternal(@NonNull String, @Nullable java.io.FileDescriptor, @NonNull java.io.PrintWriter, @Nullable String[]);
|
||||||
method public void onMovedToDisplay(int, android.content.res.Configuration);
|
method public void onMovedToDisplay(int, android.content.res.Configuration);
|
||||||
|
|||||||
@@ -148,7 +148,6 @@ import android.widget.Toast;
|
|||||||
import android.widget.Toolbar;
|
import android.widget.Toolbar;
|
||||||
import android.window.OnBackInvokedCallback;
|
import android.window.OnBackInvokedCallback;
|
||||||
import android.window.OnBackInvokedDispatcher;
|
import android.window.OnBackInvokedDispatcher;
|
||||||
import android.window.OnBackInvokedDispatcherOwner;
|
|
||||||
import android.window.SplashScreen;
|
import android.window.SplashScreen;
|
||||||
import android.window.WindowOnBackInvokedDispatcher;
|
import android.window.WindowOnBackInvokedDispatcher;
|
||||||
|
|
||||||
@@ -749,8 +748,7 @@ public class Activity extends ContextThemeWrapper
|
|||||||
Window.Callback, KeyEvent.Callback,
|
Window.Callback, KeyEvent.Callback,
|
||||||
OnCreateContextMenuListener, ComponentCallbacks2,
|
OnCreateContextMenuListener, ComponentCallbacks2,
|
||||||
Window.OnWindowDismissedCallback,
|
Window.OnWindowDismissedCallback,
|
||||||
ContentCaptureManager.ContentCaptureClient,
|
ContentCaptureManager.ContentCaptureClient {
|
||||||
OnBackInvokedDispatcherOwner {
|
|
||||||
private static final String TAG = "Activity";
|
private static final String TAG = "Activity";
|
||||||
private static final boolean DEBUG_LIFECYCLE = false;
|
private static final boolean DEBUG_LIFECYCLE = false;
|
||||||
|
|
||||||
@@ -8993,12 +8991,11 @@ public class Activity extends ContextThemeWrapper
|
|||||||
* @throws IllegalStateException if this Activity is not visual.
|
* @throws IllegalStateException if this Activity is not visual.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
|
||||||
public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
|
public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
|
||||||
if (mWindow == null) {
|
if (mWindow == null) {
|
||||||
throw new IllegalStateException("OnBackInvokedDispatcher are not available on "
|
throw new IllegalStateException("OnBackInvokedDispatcher are not available on "
|
||||||
+ "non-visual activities");
|
+ "non-visual activities");
|
||||||
}
|
}
|
||||||
return ((OnBackInvokedDispatcherOwner) mWindow).getOnBackInvokedDispatcher();
|
return mWindow.getOnBackInvokedDispatcher();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ import android.view.WindowManager;
|
|||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
import android.window.OnBackInvokedCallback;
|
import android.window.OnBackInvokedCallback;
|
||||||
import android.window.OnBackInvokedDispatcher;
|
import android.window.OnBackInvokedDispatcher;
|
||||||
import android.window.OnBackInvokedDispatcherOwner;
|
|
||||||
import android.window.WindowOnBackInvokedDispatcher;
|
import android.window.WindowOnBackInvokedDispatcher;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
@@ -98,8 +97,7 @@ import java.lang.ref.WeakReference;
|
|||||||
* </div>
|
* </div>
|
||||||
*/
|
*/
|
||||||
public class Dialog implements DialogInterface, Window.Callback,
|
public class Dialog implements DialogInterface, Window.Callback,
|
||||||
KeyEvent.Callback, OnCreateContextMenuListener, Window.OnWindowDismissedCallback,
|
KeyEvent.Callback, OnCreateContextMenuListener, Window.OnWindowDismissedCallback {
|
||||||
OnBackInvokedDispatcherOwner {
|
|
||||||
private static final String TAG = "Dialog";
|
private static final String TAG = "Dialog";
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
private Activity mOwnerActivity;
|
private Activity mOwnerActivity;
|
||||||
@@ -1469,8 +1467,7 @@ public class Dialog implements DialogInterface, Window.Callback,
|
|||||||
* Returns null if the dialog is not attached to a window with a decor.
|
* Returns null if the dialog is not attached to a window with a decor.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
|
||||||
public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
|
public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
|
||||||
return ((OnBackInvokedDispatcherOwner) mWindow).getOnBackInvokedDispatcher();
|
return mWindow.getOnBackInvokedDispatcher();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,6 @@ import android.widget.Scroller;
|
|||||||
import android.window.ClientWindowFrames;
|
import android.window.ClientWindowFrames;
|
||||||
import android.window.OnBackInvokedCallback;
|
import android.window.OnBackInvokedCallback;
|
||||||
import android.window.OnBackInvokedDispatcher;
|
import android.window.OnBackInvokedDispatcher;
|
||||||
import android.window.OnBackInvokedDispatcherOwner;
|
|
||||||
import android.window.SurfaceSyncer;
|
import android.window.SurfaceSyncer;
|
||||||
import android.window.WindowOnBackInvokedDispatcher;
|
import android.window.WindowOnBackInvokedDispatcher;
|
||||||
|
|
||||||
@@ -240,7 +239,7 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
@SuppressWarnings({"EmptyCatchBlock", "PointlessBooleanExpression"})
|
@SuppressWarnings({"EmptyCatchBlock", "PointlessBooleanExpression"})
|
||||||
public final class ViewRootImpl implements ViewParent,
|
public final class ViewRootImpl implements ViewParent,
|
||||||
View.AttachInfo.Callbacks, ThreadedRenderer.DrawCallbacks,
|
View.AttachInfo.Callbacks, ThreadedRenderer.DrawCallbacks,
|
||||||
AttachedSurfaceControl, OnBackInvokedDispatcherOwner {
|
AttachedSurfaceControl {
|
||||||
private static final String TAG = "ViewRootImpl";
|
private static final String TAG = "ViewRootImpl";
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
private static final boolean LOCAL_LOGV = false;
|
private static final boolean LOCAL_LOGV = false;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ import android.transition.TransitionManager;
|
|||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.View.OnApplyWindowInsetsListener;
|
import android.view.View.OnApplyWindowInsetsListener;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
|
import android.window.OnBackInvokedDispatcher;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -2798,4 +2799,12 @@ public abstract class Window {
|
|||||||
public @Nullable AttachedSurfaceControl getRootSurfaceControl() {
|
public @Nullable AttachedSurfaceControl getRootSurfaceControl() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link OnBackInvokedDispatcher} instance associated with this window.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
|
||||||
|
throw new RuntimeException("Not implemented. Must override in a subclass.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,23 +18,22 @@ package android.window;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.view.View;
|
import android.view.Window;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback allowing applications to handle back events in place of the system.
|
* Callback allowing applications to handle back events in place of the system.
|
||||||
* <p>
|
* <p>
|
||||||
* Callback instances can be added to and removed from {@link OnBackInvokedDispatcher}, held
|
* Callback instances can be added to and removed from {@link OnBackInvokedDispatcher}, which
|
||||||
* by classes that implement {@link OnBackInvokedDispatcherOwner} (such as {@link Activity},
|
* is held at window level and accessible through {@link Activity#getOnBackInvokedDispatcher()},
|
||||||
* {@link Dialog} and {@link View}).
|
* {@link Dialog#getOnBackInvokedDispatcher()} and {@link Window#getOnBackInvokedDispatcher()}.
|
||||||
* <p>
|
* <p>
|
||||||
* Under the hood callbacks are registered at window level. When back is triggered,
|
* When back is triggered, callbacks on the in-focus window are invoked in reverse order in which
|
||||||
* callbacks on the in-focus window are invoked in reverse order in which they are added
|
* they are added within the same priority. Between different priorities, callbacks with higher
|
||||||
* within the same priority. Between different pirorities, callbacks with higher priority
|
* priority are invoked first.
|
||||||
* are invoked first.
|
|
||||||
* <p>
|
* <p>
|
||||||
* This replaces {@link Activity#onBackPressed()}, {@link Dialog#onBackPressed()} and
|
* This replaces {@link Activity#onBackPressed()}, {@link Dialog#onBackPressed()} and
|
||||||
* {@link android.view.KeyEvent#KEYCODE_BACK}
|
* {@link android.view.KeyEvent#KEYCODE_BACK}
|
||||||
*
|
* <p>
|
||||||
* @see OnBackInvokedDispatcher#registerOnBackInvokedCallback(int, OnBackInvokedCallback)
|
* @see OnBackInvokedDispatcher#registerOnBackInvokedCallback(int, OnBackInvokedCallback)
|
||||||
* registerOnBackInvokedCallback(priority, OnBackInvokedCallback)
|
* registerOnBackInvokedCallback(priority, OnBackInvokedCallback)
|
||||||
* to specify callback priority.
|
* to specify callback priority.
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.NonNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class that provides an {@link OnBackInvokedDispatcher} that allows you to register
|
|
||||||
* an {@link OnBackInvokedCallback} for handling the system back invocation behavior.
|
|
||||||
*/
|
|
||||||
public interface OnBackInvokedDispatcherOwner {
|
|
||||||
/**
|
|
||||||
* Returns the {@link OnBackInvokedDispatcher} that should dispatch the back invocation
|
|
||||||
* to its registered {@link OnBackInvokedCallback}s.
|
|
||||||
* Returns null when the root view is not attached to a window or a view tree with a decor.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
OnBackInvokedDispatcher getOnBackInvokedDispatcher();
|
|
||||||
}
|
|
||||||
@@ -28,8 +28,8 @@ import java.util.List;
|
|||||||
* {@link OnBackInvokedDispatcher} only used to hold callbacks while an actual
|
* {@link OnBackInvokedDispatcher} only used to hold callbacks while an actual
|
||||||
* dispatcher becomes available. <b>It does not dispatch the back events</b>.
|
* dispatcher becomes available. <b>It does not dispatch the back events</b>.
|
||||||
* <p>
|
* <p>
|
||||||
* Once the actual {@link OnBackInvokedDispatcherOwner} becomes available,
|
* Once the actual {@link OnBackInvokedDispatcher} becomes available,
|
||||||
* {@link #setActualDispatcherOwner(OnBackInvokedDispatcherOwner)} needs to
|
* {@link #setActualDispatcher(OnBackInvokedDispatcher)} needs to
|
||||||
* be called and this {@link ProxyOnBackInvokedDispatcher} will pass the callback registrations
|
* be called and this {@link ProxyOnBackInvokedDispatcher} will pass the callback registrations
|
||||||
* onto it.
|
* onto it.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -48,14 +48,14 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
|
|||||||
*/
|
*/
|
||||||
private final List<Pair<OnBackInvokedCallback, Integer>> mCallbacks = new ArrayList<>();
|
private final List<Pair<OnBackInvokedCallback, Integer>> mCallbacks = new ArrayList<>();
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
private OnBackInvokedDispatcherOwner mActualDispatcherOwner = null;
|
private OnBackInvokedDispatcher mActualDispatcher = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerOnBackInvokedCallback(
|
public void registerOnBackInvokedCallback(
|
||||||
int priority, @NonNull OnBackInvokedCallback callback) {
|
int priority, @NonNull OnBackInvokedCallback callback) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, String.format("Proxy: register %s. actualDispatcherOwner=%s", callback,
|
Log.v(TAG, String.format("Proxy register %s. mActualDispatcher=%s", callback,
|
||||||
mActualDispatcherOwner));
|
mActualDispatcher));
|
||||||
}
|
}
|
||||||
if (priority < 0) {
|
if (priority < 0) {
|
||||||
throw new IllegalArgumentException("Application registered OnBackInvokedCallback "
|
throw new IllegalArgumentException("Application registered OnBackInvokedCallback "
|
||||||
@@ -74,13 +74,12 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
|
|||||||
@NonNull OnBackInvokedCallback callback) {
|
@NonNull OnBackInvokedCallback callback) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, String.format("Proxy unregister %s. Actual=%s", callback,
|
Log.v(TAG, String.format("Proxy unregister %s. Actual=%s", callback,
|
||||||
mActualDispatcherOwner));
|
mActualDispatcher));
|
||||||
}
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mCallbacks.removeIf((p) -> p.first.equals(callback));
|
mCallbacks.removeIf((p) -> p.first.equals(callback));
|
||||||
if (mActualDispatcherOwner != null) {
|
if (mActualDispatcher != null) {
|
||||||
mActualDispatcherOwner.getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(
|
mActualDispatcher.unregisterOnBackInvokedCallback(callback);
|
||||||
callback);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,9 +88,8 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
|
|||||||
@NonNull OnBackInvokedCallback callback, int priority) {
|
@NonNull OnBackInvokedCallback callback, int priority) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mCallbacks.add(Pair.create(callback, priority));
|
mCallbacks.add(Pair.create(callback, priority));
|
||||||
if (mActualDispatcherOwner != null) {
|
if (mActualDispatcher != null) {
|
||||||
mActualDispatcherOwner.getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
|
mActualDispatcher.registerOnBackInvokedCallback(priority, callback);
|
||||||
priority, callback);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,34 +101,30 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
|
|||||||
* proxy dispatcher.
|
* proxy dispatcher.
|
||||||
*/
|
*/
|
||||||
private void transferCallbacksToDispatcher() {
|
private void transferCallbacksToDispatcher() {
|
||||||
if (mActualDispatcherOwner == null) {
|
if (mActualDispatcher == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
OnBackInvokedDispatcher dispatcher =
|
|
||||||
mActualDispatcherOwner.getOnBackInvokedDispatcher();
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, String.format("Proxy: transferring %d pending callbacks to %s",
|
Log.v(TAG, String.format("Proxy transferring %d callbacks to %s", mCallbacks.size(),
|
||||||
mCallbacks.size(), dispatcher));
|
mActualDispatcher));
|
||||||
}
|
}
|
||||||
for (Pair<OnBackInvokedCallback, Integer> callbackPair : mCallbacks) {
|
for (Pair<OnBackInvokedCallback, Integer> callbackPair : mCallbacks) {
|
||||||
int priority = callbackPair.second;
|
int priority = callbackPair.second;
|
||||||
if (priority >= 0) {
|
if (priority >= 0) {
|
||||||
dispatcher.registerOnBackInvokedCallback(priority, callbackPair.first);
|
mActualDispatcher.registerOnBackInvokedCallback(priority, callbackPair.first);
|
||||||
} else {
|
} else {
|
||||||
dispatcher.registerSystemOnBackInvokedCallback(callbackPair.first);
|
mActualDispatcher.registerSystemOnBackInvokedCallback(callbackPair.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCallbacks.clear();
|
mCallbacks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearCallbacksOnDispatcher() {
|
private void clearCallbacksOnDispatcher() {
|
||||||
if (mActualDispatcherOwner == null) {
|
if (mActualDispatcher == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
OnBackInvokedDispatcher onBackInvokedDispatcher =
|
|
||||||
mActualDispatcherOwner.getOnBackInvokedDispatcher();
|
|
||||||
for (Pair<OnBackInvokedCallback, Integer> callback : mCallbacks) {
|
for (Pair<OnBackInvokedCallback, Integer> callback : mCallbacks) {
|
||||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(callback.first);
|
mActualDispatcher.unregisterOnBackInvokedCallback(callback.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +132,7 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
|
|||||||
* Resets this {@link ProxyOnBackInvokedDispatcher} so it loses track of the currently
|
* Resets this {@link ProxyOnBackInvokedDispatcher} so it loses track of the currently
|
||||||
* registered callbacks.
|
* registered callbacks.
|
||||||
* <p>
|
* <p>
|
||||||
* Using this method means that when setting a new {@link OnBackInvokedDispatcherOwner}, the
|
* Using this method means that when setting a new {@link OnBackInvokedDispatcher}, the
|
||||||
* callbacks registered on the old one won't be removed from it and won't be registered on
|
* callbacks registered on the old one won't be removed from it and won't be registered on
|
||||||
* the new one.
|
* the new one.
|
||||||
*/
|
*/
|
||||||
@@ -152,28 +146,26 @@ public class ProxyOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the actual {@link OnBackInvokedDispatcherOwner} that will provides the
|
* Sets the actual {@link OnBackInvokedDispatcher} onto which the callbacks will be registered.
|
||||||
* {@link OnBackInvokedDispatcher} onto which the callbacks will be registered.
|
|
||||||
* <p>
|
* <p>
|
||||||
* If any dispatcher owner was already present, all the callbacks that were added via this
|
* If any dispatcher was already present, all the callbacks that were added via this
|
||||||
* {@link ProxyOnBackInvokedDispatcher} will be unregistered from the old one and registered
|
* {@link ProxyOnBackInvokedDispatcher} will be unregistered from the old one and registered
|
||||||
* on the new one if it is not null.
|
* on the new one if it is not null.
|
||||||
* <p>
|
* <p>
|
||||||
* If you do not wish for the previously registered callbacks to be reassigned to the new
|
* If you do not wish for the previously registered callbacks to be reassigned to the new
|
||||||
* dispatcher, {@link #reset} must be called beforehand.
|
* dispatcher, {@link #reset} must be called beforehand.
|
||||||
*/
|
*/
|
||||||
public void setActualDispatcherOwner(
|
public void setActualDispatcher(@Nullable OnBackInvokedDispatcher actualDispatcher) {
|
||||||
@Nullable OnBackInvokedDispatcherOwner actualDispatcherOwner) {
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, String.format("Proxy setActual %s. Current %s",
|
Log.v(TAG, String.format("Proxy setActual %s. Current %s",
|
||||||
actualDispatcherOwner, mActualDispatcherOwner));
|
actualDispatcher, mActualDispatcher));
|
||||||
}
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (actualDispatcherOwner == mActualDispatcherOwner) {
|
if (actualDispatcher == mActualDispatcher) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
clearCallbacksOnDispatcher();
|
clearCallbacksOnDispatcher();
|
||||||
mActualDispatcherOwner = actualDispatcherOwner;
|
mActualDispatcher = actualDispatcher;
|
||||||
transferCallbacksToDispatcher();
|
transferCallbacksToDispatcher();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,6 @@ import android.widget.ImageView;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.window.OnBackInvokedDispatcher;
|
import android.window.OnBackInvokedDispatcher;
|
||||||
import android.window.OnBackInvokedDispatcherOwner;
|
|
||||||
import android.window.ProxyOnBackInvokedDispatcher;
|
import android.window.ProxyOnBackInvokedDispatcher;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
@@ -137,8 +136,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class PhoneWindow extends Window implements MenuBuilder.Callback,
|
public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
||||||
OnBackInvokedDispatcherOwner {
|
|
||||||
|
|
||||||
private final static String TAG = "PhoneWindow";
|
private final static String TAG = "PhoneWindow";
|
||||||
|
|
||||||
@@ -2153,7 +2151,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback,
|
|||||||
/** Notify when decor view is attached to window and {@link ViewRootImpl} is available. */
|
/** Notify when decor view is attached to window and {@link ViewRootImpl} is available. */
|
||||||
void onViewRootImplSet(ViewRootImpl viewRoot) {
|
void onViewRootImplSet(ViewRootImpl viewRoot) {
|
||||||
viewRoot.setActivityConfigCallback(mActivityConfigCallback);
|
viewRoot.setActivityConfigCallback(mActivityConfigCallback);
|
||||||
mProxyOnBackInvokedDispatcher.setActualDispatcherOwner(viewRoot);
|
mProxyOnBackInvokedDispatcher.setActualDispatcher(viewRoot.getOnBackInvokedDispatcher());
|
||||||
applyDecorFitsSystemWindows();
|
applyDecorFitsSystemWindows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user