2

我(我认为)childbrowser 插件有一个小问题,问题如下;

所有 Childbrowser 代码都可以正常工作,它连接到我们服务器上的外部网页,我以全屏模式运行它(所以没有导航栏/na 按钮等),我正在寻找放置在我们关闭的网页上的代码窗户。

我需要放置什么代码来关闭网页上的子浏览器窗口?当我单击要关闭子浏览器会话的那个时,网页上只是一个图像“主页”。这甚至可能吗?

非常感谢您提前提供的所有帮助,

埃瓦尔德

4

2 回答 2

1

我想我知道你的意思。这是我的快速破解。它涉及修改您的 ChildBrowser.java。在进入代码之前,让我解释一下这基本上会将关闭按钮移动到 ChildBrowser 的 web 视图中。但它并没有悬停在右上角。因此,当您在 ChildBrowser 中向下滚动时,该按钮将移动。

我还删除了其他按钮,例如前进、后退和地址 URL 文本字段。这是专门针对 ShowWebPage 函数的。

    public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,
                                                        (float) dipValue,
                                                        cordova.getActivity().getResources().getDisplayMetrics()
            );

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    public void onDismiss(DialogInterface dialog) {
                        try {
                            JSONObject obj = new JSONObject();
                            obj.put("type", CLOSE_EVENT);

                            sendUpdate(obj, false);
                        } catch (JSONException e) {
                            Log.d(LOG_TAG, "Should never happen");
                        }
                    }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);
            toolbar.setBackgroundColor(Color.TRANSPARENT);

            // Close button
            ImageButton close = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            close.setId(5);
            try {
                close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(cordova.getActivity());
            webview.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);
            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                webview.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

      private Bitmap loadDrawable(String filename) throws java.io.IOException {
          InputStream input = cordova.getActivity().getAssets().open(filename);
          return BitmapFactory.decodeStream(input);
      }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}
于 2012-12-24T16:56:34.580 回答
0

正如一位好心人在电子邮件中提到的那样,这将是添加到网页中的代码:

在在线 html 页面中的主页按钮的单击事件上使用以下代码:

window.plugins.childBrowser.close(); 

或添加到插件的其他选项:

window.plugins.childBrowser.onLocationChange = function(loc){ if (loc.indexOf("exit.html") >= 0) { window.plugins.childBrowser.close(); } 

什么检测 clidbrowser 是否找到 exit.html 页面然后返回(关闭)到应用程序

希望它能像对我一样对你有帮助

于 2012-09-18T16:46:32.637 回答