全屏幕的儿童浏览器与网页上的关闭按钮

时间:2012-09-12 10:03:27

标签: cordova childbrowser

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

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

我需要放置哪些代码才能关闭网页上的子浏览器窗口?当我点击那个我要关闭子浏览器会话时,在网页上只是一个图像“Home”。这甚至可能吗?

提前感谢您的所有帮助,

Ewald的

2 个答案:

答案 0 :(得分:1)

我想我知道你的意思。这是我的快速黑客。它涉及修改您的ChildBrowser.java。在你进入代码之前,让我解释一下这基本上会将关闭按钮移动到ChildBrowser的webview中。但它没有徘徊在右上角。因此,当您在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 "";
}

答案 1 :(得分: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页面然后返回(关闭)到应用程序

希望它能帮助你,也能帮助你