phonegap底层原理学习和研究(四)

         在phonegap的android开发中主要通过WebView显示相关的本地页面。针对WebView设置的代码如下:

       //创建相关的Web容器

this.appView=newWebView(DroidGap.this);

this.appView.setId(100);

//设置WebView的布局

this.appView.setLayoutParams(newLinearLayout.LayoutParams(

ViewGroup.LayoutParams.FILL_PARENT,

ViewGroup.LayoutParams.FILL_PARENT,

1.0F));

//获取WebView的WebSetting的几个方法以便于后面通过反射注入相关的存储

WebViewReflect.checkCompatibility();

this.appView.setWebChromeClient(newGapClient(DroidGap.this));

this.setWebViewClient(this.appView,newGapViewClient(this));

this.appView.setInitialScale(100);

this.appView.setVerticalScrollBarEnabled(false);

this.appView.requestFocusFromTouch();

//EnableJavaScript

        WebSettings settings = this.appView.getSettings();

       //启用js脚本的运行

settings.setJavaScriptEnabled(true);

        //js是否可以打开窗体

        settings.setJavaScriptCanOpenWindowsAutomatically(true);

settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

//Enabledatabase

settings.setDatabaseEnabled(true);

StringdatabasePath=this.getApplicationContext().getDir("database",Context.MODE_PRIVATE).getPath();

settings.setDatabasePath(databasePath);

//EnableDOMstorage

WebViewReflect.setDomStorage(settings);

//Enablebuilt-ingeolocation

WebViewReflect.setGeolocationEnabled(settings,true);

//Createcallbackserverandpluginmanager

this.callbackServer=newCallbackServer();

this.pluginManager=newPluginManager(this.appView,this);

//AddwebviewbutmakeitinvisiblewhileloadingURL

this.appView.setVisibility(View.INVISIBLE);

root.addView(this.appView);

相关推荐