/** * Creates the root view of the fragement, set title, the version number and the listener for the * download button. * * @return The fragment's root view. */ @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = getLayoutView(); versionHelper = new VersionHelper(versionInfo.toString(), this); TextView nameLabel = (TextView) view.findViewById(UpdateView.NAME_LABEL_ID); nameLabel.setText(getAppName()); TextView versionLabel = (TextView) view.findViewById(UpdateView.VERSION_LABEL_ID); versionLabel.setText( "Version " + versionHelper.getVersionString() + "\n" + versionHelper.getFileInfoString()); Button updateButton = (Button) view.findViewById(UpdateView.UPDATE_BUTTON_ID); updateButton.setOnClickListener(this); WebView webView = (WebView) view.findViewById(UpdateView.WEB_VIEW_ID); webView.clearCache(true); webView.destroyDrawingCache(); webView.loadDataWithBaseURL( Constants.BASE_URL, versionHelper.getReleaseNotes(), "text/html", "utf-8", null); return view; }
public void clearSelf() { web.stopLoading(); web.clearHistory(); web.clearMatches(); web.clearFormData(); web.destroyDrawingCache(); web = null; CookieManager cm = CookieManager.getInstance(); cm.removeAllCookie(); }
@Override public void onDestroy() { super.onDestroy(); if (mWebView != null) { removeViewInLayout(mWebView); mWebView.destroyDrawingCache(); mWebView.destroy(); mWebView = null; } ((CycleControllerActivity) getContext()).getCycleController().unregister(this, false); }
@SuppressLint({"NewApi", "SetJavaScriptEnabled"}) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 隐藏actionBar // getActionBar().hide(); bootLayout = (FrameLayout) findViewById(R.id.bootLayout); // bootLayout.setVisibility(View.INVISIBLE); // logoLayout=(RelativeLayout)findViewById(R.id.logoLayout); // 启动LOGO尺寸 /*bootLogo=(ImageView)findViewById(R.id.bootLogo); ViewGroup.LayoutParams para = bootLogo.getLayoutParams(); para.width = para.height = this.getWindowManager().getDefaultDisplay().getWidth()/2; bootLogo.setLayoutParams(para);*/ /*RelativeLayout.LayoutParams mp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT); mp.topMargin =this.getWindowManager().getDefaultDisplay().getHeight()/20; logoLayout.setLayoutParams(mp);*/ mTranslateAnimation = new TranslateAnimation( 0, -this.getWindowManager().getDefaultDisplay().getWidth(), 0, 0); // 移动 mTranslateAnimation.setDuration(500); // mAnimationSet.setFillAfter(true); // mTranslateAnimation.setFillAfter(true); mTranslateAnimation.setAnimationListener( new Animation.AnimationListener() { public void onAnimationStart(Animation animation) {} public void onAnimationEnd(Animation animation) { bootLayout.setVisibility(View.GONE); } public void onAnimationRepeat(Animation animation) {} }); // webView = (WebView) findViewById(R.id.webView); // 禁用cache webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); webView.clearCache(true); webView.destroyDrawingCache(); // 允许JS WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); // 响应JS class DemoJavaScriptInterface111 { // 是否在Web,用来决定返回键的处理办法 @JavascriptInterface public void Set_IsInWeb(boolean v_) { IsInWeb = v_; Log.d("JavascriptInterface", new Boolean(v_).toString()); } // web载入完毕 @JavascriptInterface public void LoadOK() { Log.d("JavascriptInterface", "LoadOK("); Log.d("JavascriptInterface", "AutoUpdateVersion)"); AutoUpdateVersion(); // 放到下边的动画后边的话,就不会执行,好奇怪 // bootLayout.startAnimation(mTranslateAnimation); // bootLayout.setVisibility(View.INVISIBLE); new Thread() { public void run() { // 发送消息,通知handler在主线程中更新UI connectHanlderFive.sendEmptyMessage(0); } }.start(); Log.d("JavascriptInterface", "LoadOK)"); } } webView.addJavascriptInterface(new DemoJavaScriptInterface111(), "Machine"); // alert webView.setWebChromeClient( new WebChromeClient() { @Override public boolean onJsAlert( WebView view, String url, String message, JsResult result) { // Required functionality here // return super.onJsAlert(view, url, message, result); if (message.length() != 0) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("").setMessage(message).show(); result.cancel(); return true; } return false; } }); webView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // 设置点击网页里面的链接还是在当前的webview里跳转 view.loadUrl(url); return true; } }); webView.loadUrl("http://m.nzjcy.gov.cn:81/#app"); // shouldOverrideUrlLoading(webView, "http://m.nzjcy.gov.cn:81/#app"); // 4.0以后不允许主线程new HttpGet() // StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads() // .detectDiskWrites().detectNetwork().penaltyLog().build()); // StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() // .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); }