2017-07-27 44 views
0

我開發了一個cordova插件,可以爲pdf創建一個文件容器。我的插件具有功能enterFullscreen()exitFUllscreen()。如果我切換到全屏並希望返回到默認文件容器,我想使用此按鈕,但如果我按下後按鈕應用程序關閉。在我的logcat我得到這個消息:Cordova backbutton在使用自己的插件後破壞了CordovaActivity

enter image description here

這裏是我的插件代碼:JAVA

/** 
* Enters the fullscreen mode of a Container. 
* 
* @param {Container} _container The Container which should enter the fullscreen mode. 
* @param {boolean} _enableFullscreen True for enabling fullscreen mode, false for disabling. 
*/ 
private void setContainerFullscreen(final Container _container,final boolean _enableFullscreen) 
{ 
    Log.d(LOGTAG,"FileViewer -> enterFullscreen of container with id: " + _container.id()); 

    this.cordova.getActivity().runOnUiThread(new Runnable() 
    { 
     @Override 
     public void run() 
     { 
      _container.enableFullscreen(_enableFullscreen); 

      FrameLayout containerLayout = _container.containerFrameLayout(); 

      /* first we must call removeView() then addView(), because the updateView() function don't work with fullscreen mode. 
      //todo I must check this later. 
      call a exception.*/ 
      mainLayout.removeView(containerLayout); 
      mainLayout.addView(containerLayout,containerLayout.getLayoutParams()); 
     } 
    }); 
} 

這裏的容器類

/** 
* Enables fullscreen mode for this Container. 
* 
* @param {boolean} _enable True for enabling fullscreen mode, false for disabling. 
*/ 
public void enableFullscreen(boolean _enable) 
{ 
    this.isFullscreen = _enable; 

    if (this.isFullscreen && this.isVisible) 
    { // Sets the size of the parentlayout to fullscreen. 
     this.containerFrameLayout.setLayoutParams(mainLayout.getLayoutParams()); 
     this.enableToolbar(true); 
    } 
    else if (!this.isFullscreen && this.isVisible) 
    { // Sets the size back to the values before it went into fullscreen mode. 
     FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.containerRect.right-this.containerRect.left,this.containerRect.bottom-this.containerRect.top); 
     layoutParams.leftMargin = this.containerRect.left; 
     layoutParams.topMargin = this.containerRect.top; 
     layoutParams.gravity = 0; 

     this.containerFrameLayout.setLayoutParams(layoutParams); 
     this.enableToolbar(false); 
    } 
} 

這裏是javascript代碼:

// backbutton support for android in fullscreen mode 
document.addEventListener("backbutton", Ext.bind(function(_event){ 
    if (this.fullScreen) 
    { 
     //console.log("We are in fullscreen!"); 
     this.fileViewerPlugin.exitFullscreen(); 
     this.fullScreen=false; 
     _event.preventDefault(); 
    } 
    else 
    { 
     navigator.app.exitApp(); 
    } 
},this), false); 

回答

0

你看到的是back-button原始行爲。您應該使用override這種行爲,例如this guide

+0

我這樣做在我的JavaScript – Tarasov