質問

i have (i think) a small problem with the childbrowser plugin, the problem is the following;

All of the Childbrowser code works ok, it connects to the externa webpage on our server and i run it in full screen mode (so no navigation bar / na buttons etc.) and i am looking for the code to place on our webpage that closes the window.

What code do i need to place to close the childbrowser window on the webpage? on the webpage is just a image "Home" when i click that one i want to close the childbrowser session. Is that even possible?

Thanks a lot of all your help in advance,

Ewald

役に立ちましたか?

解決 2

As mentioned by a kind person in an email, this would be the code to add in the webpage:

use the below code on the click event of the home button in the online html page:

window.plugins.childBrowser.close(); 

or the other option added to the plugin:

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

what detects if the clidbrowser finds the exit.html page and then returns (closes) to the app

hope it will help you as well as it did for me

他のヒント

I think I know what you mean. Here's my quick hack. It involves modifying your ChildBrowser.java. Before you get into the code, let me just explain this will basically move the close button into the webview of the ChildBrowser. But it's not hovering to the top-right. So the button will move when you scroll down in the ChildBrowser.

I also removed the other buttons such as the forward, back and the address URL textfield. This is specifically for the ShowWebPage function.

    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 "";
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top