use of android.webkit.WebView in project AgentWeb by Justson.
the class DefaultWebCreator method createGroupWithWeb.
private ViewGroup createGroupWithWeb() {
Activity mActivity = this.mActivity;
FrameLayout mFrameLayout = new FrameLayout(mActivity);
WebView mWebView = null;
if (this.mWebView != null) {
mWebView = this.mWebView;
AgentWebConfig.WEBVIEW_TYPE = AgentWebConfig.WEBVIEW_CUSTOM_TYPE;
} else if (AgentWebConfig.isKikatOrBelowKikat) {
mWebView = new AgentWebView(mActivity.getApplicationContext());
AgentWebConfig.WEBVIEW_TYPE = AgentWebConfig.WEBVIEW_AGENTWEB_SAFE_TYPE;
} else {
mWebView = new WebView(mActivity.getApplicationContext());
AgentWebConfig.WEBVIEW_TYPE = AgentWebConfig.WEBVIEW_DEFAULT_TYPE;
}
FrameLayout.LayoutParams mLayoutParams = new FrameLayout.LayoutParams(-1, -1);
mFrameLayout.addView(this.mWebView = mWebView, mLayoutParams);
LogUtils.i("Info", " webView:" + (this.mWebView instanceof AgentWebView));
if (isNeedDefaultProgress) {
FrameLayout.LayoutParams lp = null;
WebProgress mWebProgress = new WebProgress(mActivity);
if (height_dp > 0)
lp = new FrameLayout.LayoutParams(-2, AgentWebUtils.dp2px(mActivity, height_dp));
else
lp = mWebProgress.offerLayoutParams();
if (color != -1)
mWebProgress.setColor(color);
lp.gravity = Gravity.TOP;
mFrameLayout.addView((View) (this.mBaseProgressSpec = mWebProgress), lp);
} else if (!isNeedDefaultProgress && progressView != null) {
// FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(-2, -2);
mFrameLayout.addView((View) (this.mBaseProgressSpec = (BaseProgressSpec) progressView), progressView.offerLayoutParams());
}
return mFrameLayout;
}
use of android.webkit.WebView in project AgentWeb by Justson.
the class AgentWebView method trySetWebDebuggEnabled.
/**
* Android 4.4 KitKat 使用Chrome DevTools 远程调试WebView
* WebView.setWebContentsDebuggingEnabled(true);
* http://blog.csdn.net/t12x3456/article/details/14225235
*/
@TargetApi(19)
protected void trySetWebDebuggEnabled() {
if (LogUtils.isDebug() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
Class<?> clazz = WebView.class;
Method method = clazz.getMethod("setWebContentsDebuggingEnabled", boolean.class);
method.invoke(null, true);
} catch (Throwable e) {
if (LogUtils.isDebug()) {
e.printStackTrace();
}
}
}
}
use of android.webkit.WebView in project weex-example by KalicyZhou.
the class WXWebView method initWebView.
private void initWebView(WebView wv) {
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
WXLogUtils.v("tag", "onPageOverride " + url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WXLogUtils.v("tag", "onPageStarted " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageStart(url);
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
WXLogUtils.v("tag", "onPageFinished " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
}
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (mOnErrorListener != null) {
//mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
mOnErrorListener.onError("error", "page error");
}
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "http error");
}
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "ssl error");
}
}
});
wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
showWebView(newProgress == 100);
showProgressBar(newProgress != 100);
WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (mOnPageListener != null) {
mOnPageListener.onReceivedTitle(view.getTitle());
}
}
});
}
use of android.webkit.WebView in project android_frameworks_base by DirtyUnicorns.
the class WebViewFragment method onCreateView.
/**
* Called to instantiate the view. Creates and returns the WebView.
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (mWebView != null) {
mWebView.destroy();
}
mWebView = new WebView(getContext());
mIsWebViewAvailable = true;
return mWebView;
}
use of android.webkit.WebView in project android_frameworks_base by DirtyUnicorns.
the class CaptivePortalLoginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCm = ConnectivityManager.from(this);
mNetwork = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
mCaptivePortal = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL);
mUserAgent = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT);
mUrl = getUrl();
if (mUrl == null) {
// getUrl() failed to parse the url provided in the intent: bail out in a way that
// at least provides network access.
done(Result.WANTED_AS_IS);
return;
}
if (DBG) {
Log.d(TAG, String.format("onCreate for %s", mUrl.toString()));
}
// Also initializes proxy system properties.
mCm.bindProcessToNetwork(mNetwork);
// Proxy system properties must be initialized before setContentView is called because
// setContentView initializes the WebView logic which in turn reads the system properties.
setContentView(R.layout.activity_captive_portal_login);
getActionBar().setDisplayShowHomeEnabled(false);
// Exit app if Network disappears.
final NetworkCapabilities networkCapabilities = mCm.getNetworkCapabilities(mNetwork);
if (networkCapabilities == null) {
finishAndRemoveTask();
return;
}
mNetworkCallback = new NetworkCallback() {
@Override
public void onLost(Network lostNetwork) {
if (mNetwork.equals(lostNetwork))
done(Result.UNWANTED);
}
};
final NetworkRequest.Builder builder = new NetworkRequest.Builder();
for (int transportType : networkCapabilities.getTransportTypes()) {
builder.addTransportType(transportType);
}
mCm.registerNetworkCallback(builder.build(), mNetworkCallback);
final WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.clearCache(true);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
mWebViewClient = new MyWebViewClient();
myWebView.setWebViewClient(mWebViewClient);
myWebView.setWebChromeClient(new MyWebChromeClient());
// Start initial page load so WebView finishes loading proxy settings.
// Actual load of mUrl is initiated by MyWebViewClient.
myWebView.loadData("", "text/html", null);
}
Aggregations