use of android.webkit.WebChromeClient in project android_frameworks_base by DirtyUnicorns.
the class LooperAcceleration method makeView.
private View makeView() {
LinearLayout layout = new LinearLayout(this);
layout.addView(new IsAcceleratedView(this), LayoutParams.MATCH_PARENT, 60);
if (INCLUDE_WEBVIEW) {
WebView wv = new WebView(this);
wv.setWebViewClient(new WebViewClient());
wv.setWebChromeClient(new WebChromeClient());
wv.loadUrl("http://www.webkit.org/blog-files/3d-transforms/poster-circle.html");
layout.addView(wv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}
return layout;
}
use of android.webkit.WebChromeClient in project WordPress-Android by wordpress-mobile.
the class EditorWebViewAbstract method configureWebView.
@SuppressLint("SetJavaScriptEnabled")
private void configureWebView() {
WebSettings webSettings = this.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDefaultTextEncodingName("utf-8");
this.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("callback") && mJsCallbackReceiver != null) {
String data = URLDecoder.decode(url);
String[] split = data.split(":", 2);
String callbackId = split[0];
String params = (split.length > 1 ? split[1] : "");
mJsCallbackReceiver.executeCallback(callbackId, params);
}
return true;
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
AppLog.e(T.EDITOR, description);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();
if (!URLUtil.isNetworkUrl(url)) {
return super.shouldInterceptRequest(view, request);
}
// Request and add an authorization header for HTTPS resource requests.
// Use https:// when requesting the auth header, in case the resource is incorrectly using http://.
// If an auth header is returned, force https:// for the actual HTTP request.
String authHeader = mAuthHeaderRequestListener.onAuthHeaderRequested(UrlUtils.makeHttps(url));
if (StringUtils.notNullStr(authHeader).length() > 0) {
try {
url = UrlUtils.makeHttps(url);
// Keep any existing request headers from the WebResourceRequest
Map<String, String> headerMap = request.getRequestHeaders();
for (Map.Entry<String, String> entry : mHeaderMap.entrySet()) {
headerMap.put(entry.getKey(), entry.getValue());
}
headerMap.put("Authorization", authHeader);
HttpURLConnection conn = HTTPUtils.setupUrlConnection(url, headerMap);
return new WebResourceResponse(conn.getContentType(), conn.getContentEncoding(), conn.getInputStream());
} catch (IOException e) {
AppLog.e(T.EDITOR, e);
}
}
return super.shouldInterceptRequest(view, request);
}
/**
* Compatibility method for API < 21
*/
@SuppressWarnings("deprecation")
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (!URLUtil.isNetworkUrl(url)) {
return super.shouldInterceptRequest(view, url);
}
// Request and add an authorization header for HTTPS resource requests.
// Use https:// when requesting the auth header, in case the resource is incorrectly using http://.
// If an auth header is returned, force https:// for the actual HTTP request.
String authHeader = mAuthHeaderRequestListener.onAuthHeaderRequested(UrlUtils.makeHttps(url));
if (StringUtils.notNullStr(authHeader).length() > 0) {
try {
url = UrlUtils.makeHttps(url);
Map<String, String> headerMap = new HashMap<>(mHeaderMap);
headerMap.put("Authorization", authHeader);
HttpURLConnection conn = HTTPUtils.setupUrlConnection(url, headerMap);
return new WebResourceResponse(conn.getContentType(), conn.getContentEncoding(), conn.getInputStream());
} catch (IOException e) {
AppLog.e(T.EDITOR, e);
}
}
return super.shouldInterceptRequest(view, url);
}
});
this.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(@NonNull ConsoleMessage cm) {
if (cm.messageLevel() == MessageLevel.ERROR) {
if (mErrorListener != null) {
mErrorListener.onJavaScriptError(cm.sourceId(), cm.lineNumber(), cm.message());
}
AppLog.e(T.EDITOR, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
} else {
AppLog.d(T.EDITOR, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
}
return true;
}
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
AppLog.d(T.EDITOR, message);
if (mErrorListener != null) {
mErrorListener.onJavaScriptAlert(url, message);
}
return true;
}
});
}
use of android.webkit.WebChromeClient in project WordPress-Android by wordpress-mobile.
the class ReaderVideoViewerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reader_activity_video_player);
mWebView = (WebView) findViewById(R.id.web_view);
mProgress = (ProgressBar) findViewById(R.id.progress);
mWebView.setBackgroundColor(Color.TRANSPARENT);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setUserAgentString(WordPress.getUserAgent());
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if (progress == 100) {
mProgress.setVisibility(View.GONE);
} else {
mProgress.setProgress(progress);
if (mProgress.getVisibility() != View.VISIBLE) {
mProgress.setVisibility(View.VISIBLE);
}
}
}
});
if (savedInstanceState == null) {
mVideoUrl = getIntent().getStringExtra(ReaderConstants.ARG_VIDEO_URL);
mWebView.loadUrl(mVideoUrl);
} else {
mVideoUrl = savedInstanceState.getString(ReaderConstants.ARG_VIDEO_URL);
mWebView.restoreState(savedInstanceState);
}
}
use of android.webkit.WebChromeClient in project LookLook by xinghongfei.
the class ZhihuDescribeActivity method initView.
private void initView() {
mToolbar.setTitleMargin(20, 20, 0, 10);
mToolbar.setNavigationIcon(R.drawable.ic_arrow_back);
mToolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mNest.smoothScrollTo(0, 0);
}
});
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expandImageAndFinish();
}
});
mTranslateYTextView.setText(title);
WebSettings settings = wvZhihu.getSettings();
settings.setJavaScriptEnabled(true);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true);
//settings.setUseWideViewPort(true);造成文字太小
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setAppCachePath(getCacheDir().getAbsolutePath() + "/webViewCache");
settings.setAppCacheEnabled(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
wvZhihu.setWebChromeClient(new WebChromeClient());
}
use of android.webkit.WebChromeClient in project AisenWeiBo by wangdan.
the class BrowserActivity method onCreate.
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ui_browser);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setTitle("");
progressbar.setIndeterminate(true);
WebSettings setting = mWebView.getSettings();
setting.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, final String url) {
if (!url.startsWith("http://") && !url.startsWith("https://"))
view.loadUrl("http://" + url);
else
view.loadUrl(url);
return true;
}
});
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress < 100) {
progressbar.setVisibility(View.VISIBLE);
} else if (newProgress == 100) {
progressbar.setVisibility(View.GONE);
invalidateOptionsMenu();
}
progressbar.setProgress(newProgress);
super.onProgressChanged(view, newProgress);
}
});
setting.setJavaScriptCanOpenWindowsAutomatically(true);
if (savedInstanceState == null) {
String url = null;
String action = getIntent().getAction();
if (Intent.ACTION_VIEW.equalsIgnoreCase(action) && getIntent().getData() != null) {
url = getIntent().getData().toString();
} else {
url = getIntent().getStringExtra("url");
}
if (url.startsWith("aisen://"))
url = url.replace("aisen://", "");
mWebView.loadUrl(url);
}
}
Aggregations