Prevent exit fullscreen mode from closing application (#823)

* (android) wrap custom view in FrameLayout

Wraps the custom view in a FrameLayout in order
to capture key events and redirect them to SystemWebView's
dispatchKeyEvent.

* Update framework/src/org/apache/cordova/CordovaWebViewImpl.java

Co-Authored-By: エリス <erisu@users.noreply.github.com>

* Update framework/src/org/apache/cordova/CordovaWebViewImpl.java

Co-Authored-By: エリス <erisu@users.noreply.github.com>

* Update framework/src/org/apache/cordova/CordovaWebViewImpl.java

Co-Authored-By: エリス <erisu@users.noreply.github.com>

* remove empty line below @override

Co-authored-by: Norman Breau <norman@normanbreau.com>
Co-authored-by: エリス <erisu@users.noreply.github.com>
This commit is contained in:
João Gonçalves 2020-04-14 19:48:06 +01:00 committed by GitHub
parent 8d47cd73c0
commit 71f63d7b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -244,6 +244,21 @@ public class CordovaWebViewImpl implements CordovaWebView {
}
}
private static class WrapperView extends FrameLayout {
private final CordovaWebViewEngine engine;
public WrapperView(Context context, CordovaWebViewEngine engine) {
super(context);
this.engine = engine;
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
return engine.getView().dispatchKeyEvent(event);
}
}
@Override
@Deprecated
public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
@ -255,13 +270,16 @@ public class CordovaWebViewImpl implements CordovaWebView {
return;
}
WrapperView wrapperView = new WrapperView(getContext(), engine);
wrapperView.addView(view);
// Store the view and its callback for later (to kill it properly)
mCustomView = view;
mCustomView = wrapperView;
mCustomViewCallback = callback;
// Add the custom view to its container.
ViewGroup parent = (ViewGroup) engine.getView().getParent();
parent.addView(view, new FrameLayout.LayoutParams(
parent.addView(wrapperView, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER));