Loading core/java/android/window/WindowOnBackInvokedDispatcher.java +21 −25 Original line number Diff line number Diff line Loading @@ -76,9 +76,9 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { /** Detaches the dispatcher instance from its window. */ public void detachFromWindow() { clear(); mWindow = null; mWindowSession = null; clear(); } // TODO: Take an Executor for the callback to run on. Loading Loading @@ -165,21 +165,32 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { } else { int priority = mAllCallbacks.get(callback); mWindowSession.setOnBackInvokedCallback( mWindow, new OnBackInvokedCallbackWrapper(callback, priority), priority); mWindow, new OnBackInvokedCallbackWrapper(callback), priority); } } catch (RemoteException e) { Log.e(TAG, "Failed to set OnBackInvokedCallback to WM. Error: " + e); } } private class OnBackInvokedCallbackWrapper extends IOnBackInvokedCallback.Stub { @Override public OnBackInvokedCallback getTopCallback() { if (mAllCallbacks.isEmpty()) { return null; } for (Integer priority : mOnBackInvokedCallbacks.descendingKeySet()) { ArrayList<OnBackInvokedCallback> callbacks = mOnBackInvokedCallbacks.get(priority); if (!callbacks.isEmpty()) { return callbacks.get(callbacks.size() - 1); } } return null; } private static class OnBackInvokedCallbackWrapper extends IOnBackInvokedCallback.Stub { private final OnBackInvokedCallback mCallback; private final @Priority int mPriority; OnBackInvokedCallbackWrapper( @NonNull OnBackInvokedCallback callback, @Priority int priority) { OnBackInvokedCallbackWrapper(@NonNull OnBackInvokedCallback callback) { mCallback = callback; mPriority = priority; } @NonNull Loading @@ -188,18 +199,17 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { } @Override public void onBackStarted() throws RemoteException { public void onBackStarted() { Handler.getMain().post(() -> mCallback.onBackStarted()); } @Override public void onBackProgressed(BackEvent backEvent) throws RemoteException { public void onBackProgressed(BackEvent backEvent) { Handler.getMain().post(() -> mCallback.onBackProgressed(backEvent)); } @Override public void onBackCancelled() throws RemoteException { public void onBackCancelled() { Handler.getMain().post(() -> mCallback.onBackCancelled()); } Loading @@ -209,20 +219,6 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { } } @Override public OnBackInvokedCallback getTopCallback() { if (mAllCallbacks.isEmpty()) { return null; } for (Integer priority : mOnBackInvokedCallbacks.descendingKeySet()) { ArrayList<OnBackInvokedCallback> callbacks = mOnBackInvokedCallbacks.get(priority); if (!callbacks.isEmpty()) { return callbacks.get(callbacks.size() - 1); } } return null; } /** * Returns if the legacy back behavior should be used. * Loading Loading
core/java/android/window/WindowOnBackInvokedDispatcher.java +21 −25 Original line number Diff line number Diff line Loading @@ -76,9 +76,9 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { /** Detaches the dispatcher instance from its window. */ public void detachFromWindow() { clear(); mWindow = null; mWindowSession = null; clear(); } // TODO: Take an Executor for the callback to run on. Loading Loading @@ -165,21 +165,32 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { } else { int priority = mAllCallbacks.get(callback); mWindowSession.setOnBackInvokedCallback( mWindow, new OnBackInvokedCallbackWrapper(callback, priority), priority); mWindow, new OnBackInvokedCallbackWrapper(callback), priority); } } catch (RemoteException e) { Log.e(TAG, "Failed to set OnBackInvokedCallback to WM. Error: " + e); } } private class OnBackInvokedCallbackWrapper extends IOnBackInvokedCallback.Stub { @Override public OnBackInvokedCallback getTopCallback() { if (mAllCallbacks.isEmpty()) { return null; } for (Integer priority : mOnBackInvokedCallbacks.descendingKeySet()) { ArrayList<OnBackInvokedCallback> callbacks = mOnBackInvokedCallbacks.get(priority); if (!callbacks.isEmpty()) { return callbacks.get(callbacks.size() - 1); } } return null; } private static class OnBackInvokedCallbackWrapper extends IOnBackInvokedCallback.Stub { private final OnBackInvokedCallback mCallback; private final @Priority int mPriority; OnBackInvokedCallbackWrapper( @NonNull OnBackInvokedCallback callback, @Priority int priority) { OnBackInvokedCallbackWrapper(@NonNull OnBackInvokedCallback callback) { mCallback = callback; mPriority = priority; } @NonNull Loading @@ -188,18 +199,17 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { } @Override public void onBackStarted() throws RemoteException { public void onBackStarted() { Handler.getMain().post(() -> mCallback.onBackStarted()); } @Override public void onBackProgressed(BackEvent backEvent) throws RemoteException { public void onBackProgressed(BackEvent backEvent) { Handler.getMain().post(() -> mCallback.onBackProgressed(backEvent)); } @Override public void onBackCancelled() throws RemoteException { public void onBackCancelled() { Handler.getMain().post(() -> mCallback.onBackCancelled()); } Loading @@ -209,20 +219,6 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { } } @Override public OnBackInvokedCallback getTopCallback() { if (mAllCallbacks.isEmpty()) { return null; } for (Integer priority : mOnBackInvokedCallbacks.descendingKeySet()) { ArrayList<OnBackInvokedCallback> callbacks = mOnBackInvokedCallbacks.get(priority); if (!callbacks.isEmpty()) { return callbacks.get(callbacks.size() - 1); } } return null; } /** * Returns if the legacy back behavior should be used. * Loading