Android Open Source - Common-Library Web View Dialog From Project Back to project page Common-Library .
License The source code is released under:
Apache License
If you think the Android project Common-Library listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.morgan.library.widget;
/ * f r o m w w w . j a v a 2 s . c o m * /
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.http.SslError;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import com.morgan.library.R;
/**
* ??WebView?Dialog.???????Url.
*
* @author Morgan.Ji
*
*/
public class WebViewDialog extends Dialog {
static final FrameLayout.LayoutParams FILL = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
private String mUrl;
private WebView mWebView;
private RelativeLayout webViewContainer;
private RelativeLayout mContent;
public WebViewDialog(Context context, String url) {
super (context, R.style.webView_style);
mUrl = url;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mContent = new RelativeLayout(getContext());
setUpWebView();
DisplayMetrics metrics = new DisplayMetrics();
getWindow().getWindowManager().getDefaultDisplay().getMetrics(metrics);
addContentView(mContent, new LayoutParams(metrics.widthPixels,
LayoutParams.MATCH_PARENT));
}
@SuppressLint("SetJavaScriptEnabled" )
private void setUpWebView() {
webViewContainer = new RelativeLayout(getContext());
mWebView = new WebView(getContext());
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WeiboWebViewClient());
mWebView.loadUrl(mUrl);
mWebView.setLayoutParams(FILL);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.clearHistory();
mWebView.clearFormData();
mWebView.clearCache(true);
mWebView.setVisibility(View.INVISIBLE);
webViewContainer.addView(mWebView);
mContent.addView(webViewContainer);
}
private class WeiboWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
dismiss();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mContent.setBackgroundColor(Color.TRANSPARENT);
mWebView.setVisibility(View.VISIBLE);
}
public void onReceivedSslError(WebView view, SslErrorHandler handler,
SslError error) {
handler.proceed();
}
}
}
Java Source Code List com.morgan.library.app.APPContext.java com.morgan.library.app.AppManager.java com.morgan.library.app.BaseActivity.java com.morgan.library.app.BaseFragmentActivity.java com.morgan.library.app.BaseListActivity.java com.morgan.library.app.BaseScreenShotActivity.java com.morgan.library.app.CommonApplication.java com.morgan.library.async.CustomAsyncTask.java com.morgan.library.async.Destroyable.java com.morgan.library.async.IFeedback.java com.morgan.library.async.TaskManager.java com.morgan.library.model.NetResult.java com.morgan.library.model.SpinnerItem.java com.morgan.library.model.WeatherType.java com.morgan.library.model.Weather.java com.morgan.library.net.ApiClient.java com.morgan.library.net.ApiManager.java com.morgan.library.net.ApiUrl.java com.morgan.library.net.IApiClient.java com.morgan.library.net.JsonUtils.java com.morgan.library.net.MockApiClient.java com.morgan.library.service.LocationManager.java com.morgan.library.service.WeatherManager.java com.morgan.library.snippet.CookieShare.java com.morgan.library.snippet.CustomService.java com.morgan.library.snippet.ExceptionCatcher.java com.morgan.library.snippet.ProxyUsage.java com.morgan.library.snippet.SocketClient.java com.morgan.library.snippet.SocketServer.java com.morgan.library.snippet.UDPClient.java com.morgan.library.snippet.UDPServer.java com.morgan.library.snippet.XMLAnalyze.java com.morgan.library.task.GetWeatherTask.java com.morgan.library.utils.AppUtils.java com.morgan.library.utils.DateUtils.java com.morgan.library.utils.DensityUtils.java com.morgan.library.utils.FileUtils.java com.morgan.library.utils.GB2Alpha.java com.morgan.library.utils.HttpClientUtil.java com.morgan.library.utils.HttpClientUtils.java com.morgan.library.utils.HttpURLUtil.java com.morgan.library.utils.ImageUtils.java com.morgan.library.utils.KeyBoardUtils.java com.morgan.library.utils.LocationUtils.java com.morgan.library.utils.Logger.java com.morgan.library.utils.NetUtils.java com.morgan.library.utils.PhoneUtils.java com.morgan.library.utils.SDCardUtils.java com.morgan.library.utils.StrUtils.java com.morgan.library.widget.AutoHideMenuWidget.java com.morgan.library.widget.BadgeView.java com.morgan.library.widget.CityPickerWidget.java com.morgan.library.widget.CustomGridView.java com.morgan.library.widget.CustomListView.java com.morgan.library.widget.CustomToast.java com.morgan.library.widget.CustomViewPager.java com.morgan.library.widget.DatePickerWidget.java com.morgan.library.widget.DirectionScrollView.java com.morgan.library.widget.FallBallView.java com.morgan.library.widget.HeightPickerWidget.java com.morgan.library.widget.InterceptPressLayout.java com.morgan.library.widget.ItalicTextView.java com.morgan.library.widget.PopupMenuWidget.java com.morgan.library.widget.PullToRefreshListView.java com.morgan.library.widget.ScreenShotView.java com.morgan.library.widget.SexPickerWidget.java com.morgan.library.widget.SlideUpOpenWidget.java com.morgan.library.widget.SwipeListView.java com.morgan.library.widget.TimePickerWidget.java com.morgan.library.widget.TouchZoomImageView.java com.morgan.library.widget.WaitScreenWidget.java com.morgan.library.widget.WebViewDialog.java com.morgan.library.widget.WeightPickerWidget.java com.morgan.library.widget.calendar.CalendarGridView.java com.morgan.library.widget.calendar.CalendarScrollView.java com.morgan.library.widget.calendar.CalendarViewFlipper.java com.morgan.library.widget.calendar.CalendarWidget.java com.morgan.library.widget.numberpicker.NumberPicker.java com.morgan.library.widget.numberpicker.Scroller.java com.morgan.library.widget.slidemenu.ScrollDetectorFactory.java com.morgan.library.widget.slidemenu.ScrollDetectors.java com.morgan.library.widget.slidemenu.SlideMenu.java