-
-
Save KaustubhPatange/5614830f15faf1834cecbb5d57e137a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. | |
class NativePreImeInputStage ... { | |
... | |
@Override | |
protected int onProcess(QueuedInputEvent q) { | |
... | |
// If the new back dispatch is enabled, intercept KEYCODE_BACK before it reaches the | |
// view tree or IME, and invoke the appropriate {@link OnBackInvokedCallback}. | |
if (isBack(event) ... ) { | |
OnBackInvokedCallback topCallback = getOnBackInvokedDispatcher().getTopCallback(); // check below code | |
if (event.getAction() == KeyEvent.ACTION_UP) { | |
if (topCallback != null) { | |
topCallback.onBackInvoked(); // <-- Called here | |
return FINISH_HANDLED; | |
} | |
} | |
} | |
... | |
} | |
... | |
} | |
// 2. | |
class WindowOnBackInvokedDispatcher ... { | |
... | |
// This method is only available in WindowOnBackInvokedDispatcher & it returns the | |
// latest `onBackInvokedCallback` registered through `registerOnBackInvokedCallback`. | |
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; | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment