public static void Initialize( final int id, final float x, final float y, final float dx, final float dy) { final JNIActivity activity = JNIActivity.GetActivity(); activity.runOnUiThread( new Runnable() { @Override public void run() { if (views.containsKey(id)) { Log.d(TAG, String.format("WebView with id %d already initialized", id)); return; } WebView webView = new WebView(activity); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( new FrameLayout.MarginLayoutParams((int) (dx + 0.5f), (int) (dy + 0.5f))); params.leftMargin = (int) x; params.topMargin = (int) y; params.width = (int) (dx + 0.5f); params.height = (int) (dy + 0.5f); webView.setWebViewClient(new InternalViewClient(id)); webView.getSettings().setJavaScriptEnabled(true); activity.addContentView(webView, params); views.put(id, webView); } }); }
@Override public boolean shouldOverrideUrlLoading(WebView view, final String url) { FutureTask<Integer> task = PostOnUrlChangeTask(url); while (!task.isDone()) { Thread.yield(); } int res = 0; try { res = task.get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } /*enum eAction { PROCESS_IN_WEBVIEW = 0, PROCESS_IN_SYSTEM_BROWSER, NO_PROCESS, ACTIONS_COUNT };*/ if (res == 0) { return false; } else if (res == 1) { Intent exWeb = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); JNIActivity.GetActivity().startActivity(exWeb); return true; } return true; }
protected static void RelinkNativeControls() { for (WebView view : views.values()) { ViewGroup viewGroup = (ViewGroup) view.getParent(); viewGroup.removeView(view); JNIActivity.GetActivity().addContentView(view, view.getLayoutParams()); } }
@Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); JNIActivity.GetActivity() .PostEventToGL( new Runnable() { @Override public void run() { OnPageLoaded(id); } }); };
public static void OpenURL(final int id, final String url) { final JNIActivity activity = JNIActivity.GetActivity(); activity.runOnUiThread( new Runnable() { @Override public void run() { if (!views.containsKey(id)) { Log.d(TAG, String.format("Unknown view id %d", id)); return; } WebView webView = views.get(id); webView.loadUrl(url); } }); }
public static void SetVisible(final int id, final boolean isVisible) { final JNIActivity activity = JNIActivity.GetActivity(); activity.runOnUiThread( new Runnable() { @Override public void run() { if (!views.containsKey(id)) { Log.d(TAG, String.format("Unknown view id %d", id)); return; } WebView view = views.get(id); view.setVisibility(isVisible ? WebView.VISIBLE : WebView.INVISIBLE); } }); }
public static void SetBackgroundTransparency(final int id, final boolean enabled) { final JNIActivity activity = JNIActivity.GetActivity(); activity.runOnUiThread( new Runnable() { @Override public void run() { if (!views.containsKey(id)) { Log.d(TAG, String.format("Unknown view id %d", id)); return; } WebView view = views.get(id); view.setBackgroundColor((enabled ? Color.TRANSPARENT : Color.WHITE)); } }); }
public static void OpenFromBuffer(final int id, final String data, final String baseUrl) { final JNIActivity activity = JNIActivity.GetActivity(); activity.runOnUiThread( new Runnable() { @Override public void run() { if (!views.containsKey(id)) { Log.d(TAG, String.format("Unknown view id %d", id)); return; } WebView webView = views.get(id); webView.loadDataWithBaseURL(baseUrl, data, "text/html", "utf-8", null); } }); }
public static void Deinitialize(final int id) { final JNIActivity activity = JNIActivity.GetActivity(); activity.runOnUiThread( new Runnable() { @Override public void run() { if (!views.containsKey(id)) { Log.d(TAG, String.format("Unknown view id %d", id)); return; } WebView view = views.get(id); views.remove(id); ((ViewGroup) view.getParent()).removeView(view); } }); }
FutureTask<Integer> PostOnUrlChangeTask(final String url) { Callable<Integer> urlChanged = new Callable<Integer>() { @Override public Integer call() throws Exception { return OnUrlChange(id, url); } }; if (url.contains("code")) Log.d("shouldOverrideUrlLoading", url); FutureTask<Integer> task = new FutureTask<Integer>(urlChanged); JNIActivity.GetActivity().PostEventToGL(task); return task; }
public static void SetRect( final int id, final float x, final float y, final float dx, final float dy) { final JNIActivity activity = JNIActivity.GetActivity(); activity.runOnUiThread( new Runnable() { @Override public void run() { if (!views.containsKey(id)) { Log.d(TAG, String.format("Unknown view id %d", id)); return; } WebView view = views.get(id); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams(); params.leftMargin = (int) x; params.topMargin = (int) y; params.width = (int) (dx + 0.5f); params.height = (int) (dy + 0.5f); view.setLayoutParams(params); } }); }
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { int res = OnUrlChange(id, url); /*enum eAction { PROCESS_IN_WEBVIEW = 0, PROCESS_IN_SYSTEM_BROWSER, NO_PROCESS, ACTIONS_COUNT };*/ if (res == 0) { return false; } else if (res == 1) { final JNIActivity activity = JNIActivity.GetActivity(); WebView webView = new WebView(activity); webView.loadUrl(url); return true; } return true; }