Skip to content

Commit

Permalink
fixed to make mVideoView receive events.
Browse files Browse the repository at this point in the history
  • Loading branch information
KojiNakamaru committed Dec 5, 2023
1 parent a7339e4 commit a312f01
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import com.unity3d.player.*;
import java.lang.reflect.Method;
Expand All @@ -16,7 +17,7 @@
public class CUnityPlayerActivity
extends UnityPlayerActivity
{
private List<WebView> _webViews = new ArrayList<WebView>();
private List<CWebViewPlugin> _webViewPlugins = new ArrayList<CWebViewPlugin>();
private List<Rect> _masks = new ArrayList<Rect>();

@Override
Expand Down Expand Up @@ -51,22 +52,23 @@ public boolean dispatchTouchEvent(MotionEvent event) {
}
}
}
for (WebView webView : _webViews) {
for (CWebViewPlugin webViewPlugin : _webViewPlugins) {
// cf. https://stackoverflow.com/questions/17845545/custom-viewgroup-dispatchtouchevent-doesnt-work-correctly/17845670#17845670
MotionEvent cp = MotionEvent.obtain(event);
cp.offsetLocation(-webView.getLeft(), -webView.getTop());
webView.dispatchTouchEvent(cp);
View view = (webViewPlugin.mVideoView != null) ? webViewPlugin.mVideoView : webViewPlugin.mWebView;
cp.offsetLocation(-view.getLeft(), -view.getTop());
view.dispatchTouchEvent(cp);
cp.recycle();
}
return ret;
}

void add(WebView webView) {
_webViews.add(webView);
void add(CWebViewPlugin webViewPlugin) {
_webViewPlugins.add(webViewPlugin);
}

void remove(WebView webView) {
_webViews.remove(webView);
void remove(CWebViewPlugin webViewPlugin) {
_webViewPlugins.remove(webViewPlugin);
}

public void clearMasks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public class CWebViewPlugin {
private static boolean forceBringToFront;
private static FrameLayout layout = null;
private Queue<String> mMessages = new ArrayDeque<String>();
private WebView mWebView;
private View mVideoView;
WebView mWebView;
View mVideoView;
private OnGlobalLayoutListener mGlobalLayoutListener;
private CWebViewPluginInterface mWebViewPlugin;
private int progress;
Expand Down Expand Up @@ -556,7 +556,7 @@ public boolean onTouch(View view, MotionEvent event) {
LayoutParams.MATCH_PARENT,
Gravity.NO_GRAVITY));
mWebView = webView;
((CUnityPlayerActivity)a).add(mWebView);
((CUnityPlayerActivity)a).add(self);
}});

final View activityRootView = a.getWindow().getDecorView().getRootView();
Expand Down Expand Up @@ -605,7 +605,7 @@ public void onGlobalLayout() {

public void Destroy() {
final Activity a = UnityPlayer.currentActivity;
((CUnityPlayerActivity)a).remove(mWebView);
((CUnityPlayerActivity)a).remove(this);
if (CWebViewPlugin.isDestroyed(a)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import com.unity3d.player.*;
import java.lang.reflect.Method;
Expand All @@ -16,7 +17,7 @@
public class CUnityPlayerActivity
extends UnityPlayerActivity
{
private List<WebView> _webViews = new ArrayList<WebView>();
private List<CWebViewPlugin> _webViewPlugins = new ArrayList<CWebViewPlugin>();
private List<Rect> _masks = new ArrayList<Rect>();

@Override
Expand Down Expand Up @@ -51,22 +52,23 @@ public boolean dispatchTouchEvent(MotionEvent event) {
}
}
}
for (WebView webView : _webViews) {
for (CWebViewPlugin webViewPlugin : _webViewPlugins) {
// cf. https://stackoverflow.com/questions/17845545/custom-viewgroup-dispatchtouchevent-doesnt-work-correctly/17845670#17845670
MotionEvent cp = MotionEvent.obtain(event);
cp.offsetLocation(-webView.getLeft(), -webView.getTop());
webView.dispatchTouchEvent(cp);
View view = (webViewPlugin.mVideoView != null) ? webViewPlugin.mVideoView : webViewPlugin.mWebView;
cp.offsetLocation(-view.getLeft(), -view.getTop());
view.dispatchTouchEvent(cp);
cp.recycle();
}
return ret;
}

void add(WebView webView) {
_webViews.add(webView);
void add(CWebViewPlugin webViewPlugin) {
_webViewPlugins.add(webViewPlugin);
}

void remove(WebView webView) {
_webViews.remove(webView);
void remove(CWebViewPlugin webViewPlugin) {
_webViewPlugins.remove(webViewPlugin);
}

public void clearMasks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public class CWebViewPlugin extends Fragment {
private static boolean forceBringToFront;
private static FrameLayout layout = null;
private Queue<String> mMessages = new ArrayDeque<String>();
private WebView mWebView;
private View mVideoView;
WebView mWebView;
View mVideoView;
private OnGlobalLayoutListener mGlobalLayoutListener;
private CWebViewPluginInterface mWebViewPlugin;
private int progress;
Expand Down Expand Up @@ -810,7 +810,7 @@ public boolean onTouch(View view, MotionEvent event) {
LayoutParams.MATCH_PARENT,
Gravity.NO_GRAVITY));
mWebView = webView;
((CUnityPlayerActivity)a).add(mWebView);
((CUnityPlayerActivity)a).add(self);
}});

final View activityRootView = a.getWindow().getDecorView().getRootView();
Expand Down Expand Up @@ -922,7 +922,7 @@ private File createImageFile() throws IOException {
public void Destroy() {
final Activity a = UnityPlayer.currentActivity;
final CWebViewPlugin self = this;
((CUnityPlayerActivity)a).remove(mWebView);
((CUnityPlayerActivity)a).remove(self);
mMessages.clear();
if (CWebViewPlugin.isDestroyed(a)) {
return;
Expand Down

0 comments on commit a312f01

Please sign in to comment.