2012-09-12 60 views
2

我有(我認爲)與childbrowser插件的一個小問題,問題是以下;兒童瀏覽器在全屏幕與關閉按鈕在網頁

所有的Childbrowser代碼工作正常,它連接到我們的服務器上的外部網頁,我以全屏模式運行它(所以沒有導航欄/ na按鈕等),我正在尋找代碼放置我們關閉窗口的網頁。

我需要什麼代碼來關閉網頁上的子瀏覽器窗口?在網頁上只是一個圖像「家」,當我點擊那個我想關閉子瀏覽器會話。這甚至有可能嗎?

非常感謝事先你的幫助,

埃瓦爾德

回答

0

正如一個善良的人在電子郵件中提到的那樣,這將是在網頁中添加代碼:

使用下方的Home鍵在網上HTML頁面的點擊事件代碼:

window.plugins.childBrowser.close(); 

或其他選項添加到插件:

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

如果clidbrowser發現exit.html頁面,然後返回(關閉)的應用程序

希望它會幫助你,以及它爲我做的

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 ""; 
}