Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative fix for Unity 5.6 that does not require the setZOrderOnTop fix. #212

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions plugins/Android/src/net/gree/unitywebview/CWebViewPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.webkit.JavascriptInterface;
Expand All @@ -38,6 +40,7 @@
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.PopupWindow;

import java.net.HttpURLConnection;
import java.net.URL;
Expand Down Expand Up @@ -71,6 +74,7 @@ public void call(final String method, final String message) {
}

public class CWebViewPlugin {
private static PopupWindow popup = null;
private static FrameLayout layout = null;
private WebView mWebView;
private CWebViewPluginInterface mWebViewPlugin;
Expand Down Expand Up @@ -204,14 +208,31 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
}

if (layout == null) {
//Get width & height of Display
Display display = a.getWindowManager().getDefaultDisplay();
Point screen = new Point();
display.getSize(screen);

layout = new FrameLayout(a);
a.addContentView(
layout,
new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
layout.setFocusable(true);
layout.setFocusableInTouchMode(true);

//Create a fullscreen popup
popup = new PopupWindow(layout, screen.x, screen.y);
popup.setTouchInterceptor( new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//Bubble trough the popup
a.dispatchTouchEvent(event);
return false;
}
});

//See: https://github.com/googleads/googleads-mobile-unity/blob/master/source/android-library/app/src/main/java/com/google/unity/ads/Banner.java#L195
int visibilityFlags = a.getWindow().getAttributes().flags;
popup.getContentView().setSystemUiVisibility(visibilityFlags);

popup.showAtLocation(a.getWindow().getDecorView().getRootView(), Gravity.NO_GRAVITY, 0, 0);
}
layout.addView(
webView,
Expand Down Expand Up @@ -260,6 +281,12 @@ public void Destroy() {
layout.removeView(mWebView);
mWebView.destroy();
mWebView = null;

if(layout.getChildCount() == 0) {
popup.dismiss();
popup = null;
layout = null;
}
}});
}

Expand Down