我开发了一个可以为pdf创建文件容器的cordova插件。我的插件具有enterFullscreen()
和exitFUllscreen()
功能。如果我切换到全屏并想要回到defaut文件容器,我想使用后退按钮,但如果我按下后退应用程序关闭。在我的logcat中,我收到此消息:
这是我的插件代码: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);