use of android.webkit.WebResourceRequest in project Reader by TheKeeperOfPie.
the class FragmentWeb method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_web, container, false);
layoutRoot = (RelativeLayout) view;
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.loading_web_page));
toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
toolbar.setOnClickListener(this);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hasExited = true;
mListener.onNavigationBackClick();
}
});
setUpOptionsMenu();
progressBar = (ProgressBar) view.findViewById(R.id.progress_web);
webView = (WebView) view.findViewById(R.id.web);
webView.setBackgroundColor(getResources().getColor(R.color.darkThemeBackground));
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
toolbar.setTitle(url);
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
toolbar.setTitle(view.getTitle());
}
// @Override
// public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Log.d(TAG, "shouldOverrideUrlLoading: " + url);
//
// Intent intent = new Intent(Intent.ACTION_VIEW);
// intent.setData(Uri.parse(url));
// PackageManager packageManager = view.getContext().getPackageManager();
// List<ResolveInfo> listResolveInfo = packageManager.queryIntentActivities(intent, 0);
//
// Log.d(TAG, "listResolveInfo: " + listResolveInfo);
//
// boolean containsAll = true;
//
// for (ResolveInfo info : listResolveInfo) {
//
// boolean contains = false;
// for (ResolveInfo infoDefault : listDefaultWebResolveInfo) {
// if (infoDefault.activityInfo.name.equals(info.activityInfo.name) &&
// infoDefault.activityInfo.targetActivity.equals(info.activityInfo.targetActivity)) {
// contains = true;
// break;
// }
// }
// if (!contains) {
// containsAll = false;
// break;
// }
// }
//
// if (!containsAll) {
// Iterator<ResolveInfo> iterator = listResolveInfo.iterator();
// while (iterator.hasNext()) {
// ResolveInfo info = iterator.next();
// boolean contains = false;
// for (ResolveInfo infoDefault : listDefaultWebResolveInfo) {
// if (infoDefault.activityInfo.name.equals(info.activityInfo.name) &&
// infoDefault.activityInfo.targetActivity.equals(info.activityInfo.targetActivity)) {
// contains = true;
// break;
// }
// }
// if (contains) {
// iterator.remove();
// }
// }
//
// listResolveInfo.removeAll(listDefaultWebResolveInfo);
// Collections.sort(listResolveInfo, new ResolveInfo.DisplayNameComparator(packageManager));
// listResolveInfo.addAll(listDefaultWebResolveInfo);
// showExternalLaunchDialog(url, listResolveInfo, packageManager);
// return true;
// }
// return false;
// }
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Log.e(TAG, "WebView error: " + error);
}
});
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
progressBar.setIndeterminate(false);
progressBar.setProgress(newProgress);
}
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
viewWebFullscreen = view;
viewWebFullscreen.setBackgroundColor(0xFF000000);
customViewCallback = callback;
layoutRoot.addView(viewWebFullscreen, ViewGroup.LayoutParams.MATCH_PARENT);
viewWebFullscreen.bringToFront();
}
@Override
public void onHideCustomView() {
super.onHideCustomView();
layoutRoot.removeView(viewWebFullscreen);
viewWebFullscreen = null;
}
});
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setSupportMultipleWindows(false);
webView.setBackgroundColor(0xFFFFFFFF);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
Log.d(TAG, "savedInstanceState: " + savedInstanceState);
if (savedInstanceState == null) {
webView.loadUrl(url);
} else {
webView.restoreState(savedInstanceState);
}
toolbarActions = (Toolbar) view.findViewById(R.id.toolbar_actions);
toolbarActions.inflateMenu(R.menu.menu_web_search);
toolbarActions.setOnMenuItemClickListener(this);
Menu menuActions = toolbarActions.getMenu();
for (int index = 0; index < menuActions.size(); index++) {
menuActions.getItem(index).getIcon().mutate().setColorFilter(themer.getColorFilterIcon());
}
return view;
}
use of android.webkit.WebResourceRequest in project mobile-center-sdk-android by Microsoft.
the class MSALoginActivity method signIn.
@SuppressWarnings("unused")
public void signIn(View view) {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
checkSignInCompletion(url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
failSignIn(errorCode, description);
}
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
failSignIn(error.getErrorCode(), error.getDescription());
}
});
boolean compactTicket = mAuthType == AuthenticationProvider.Type.MSA_COMPACT;
String responseType = compactTicket ? "token" : "code";
String[] scopes = compactTicket ? SCOPES_COMPACT : SCOPES_DELEGATE;
mWebView.loadUrl(AUTHORIZE_URL + REDIRECT_URI_PARAM + CLIENT_ID_PARAM + "&response_type=" + responseType + "&scope=" + TextUtils.join("+", scopes));
}
use of android.webkit.WebResourceRequest in project MyJapanese by 54wall.
the class WebViewActivity method initWebView.
private void initWebView() {
webView.setWebChromeClient(new MyWebChromeClient(this));
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
webView.loadUrl(url);
progressBar.setVisibility(View.GONE);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
});
webView.clearCache(true);
webView.clearHistory();
webView.getSettings().setJavaScriptEnabled(true);
webView.setHorizontalScrollBarEnabled(false);
webView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getPointerCount() > 1) {
// Multi touch detected
return true;
}
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
{
// save the x
m_downX = event.getX();
}
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
{
// set x so that it doesn't move
event.setLocation(m_downX, event.getY());
}
break;
}
return false;
}
});
}
use of android.webkit.WebResourceRequest in project IbookerEditorAndroid by zrunker.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ibookerEditorView = findViewById(R.id.ibookereditorview);
ibookerEditorView.setIEEditViewBackgroundColor(Color.parseColor("#DDDDDD")).setIEEditViewIbookerEdHint("书客编辑器").setIbookerEditorImgPreviewListener(new IbookerEditorWebView.IbookerEditorImgPreviewListener() {
@Override
public void onIbookerEditorImgPreview(String currentPath, int position, ArrayList<String> imgAllPathList) {
Toast.makeText(MainActivity.this, currentPath + "===" + position + "===" + imgAllPathList.toString(), Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, ImgVPagerActivity.class);
intent.putExtra("currentPath", currentPath);
intent.putExtra("position", position);
intent.putStringArrayListExtra("imgAllPathList", imgAllPathList);
startActivity(intent);
}
}).setIbookerEditorWebViewUrlLoadingListener(new IbookerEditorWebView.IbookerEditorWebViewUrlLoadingListener() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(request.getUrl().toString()));
startActivity(intent);
}
return true;
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
@Override
public void onPageFinished(WebView view, String url) {
}
});
ibookerEditorView.getIbookerEditorVpView().getEditView().getIbookerEd().setText("[链接描述](http://ips.ifeng.com/video19.ifeng.com/video09/2018/09/28/p2749834-102-998769-221938.mp4?ifsign=1&vid=2f24cc82-9236-4289-adcc-5e34ae569cc8&uid=1516537011039_hyemhv7718&from=weMedia_pc&pver=weMediaHTML5Player_v1.0.0&sver=&se=%E9%A3%9E%E7%A2%9F%E8%AF%B4&cat=8622&ptype=8622&platform=pc&sourceType=h5&dt=1538135880000&gid=SLTFYWYkO4jp&sign=16536514b3d291920ac6253872661e9c&tm=1538206173419)\n" + " " + "\"This come from string. You can insert inline formula:\" +\n" + " \" \\\\(ax^2 + bx + c = 0\\\\) \" +\n" + " \"or displayed formula: $$\\\\sum_{i=0}^n i^2 = \\\\frac{(n^2+n)(2n+1)}{6}$$\";" + "### 书客编辑器\n***\n书客编辑器从这里开始,我们的每一次开始,都那么小心翼翼,这一次如果可以的话不妨就现在开始试试。\n\n书客编辑器,简易,高效。轻轻松松记录你的每一刻。\n>书客编辑器不仅仅是为了“还好”而设计\n\n“还好”,那就意味着产品不够好;“很好”,那就意味着还需要努力;产品目标只为“最好”。\n```\nWish you every day to be beautiful.\n```\n书客编辑器期待你的加入!!!\n\n![书客编辑器](http://editor.ibooker.cc/resources/images-logos/ic_launcher_96.png)\n![书客创作](http://www.ibookerfile.cc/upload/images/acontents/1_1519218464761acontentimage.jpg)");
}
use of android.webkit.WebResourceRequest in project WeexErosFramework by bmfe.
the class BMWebView 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() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
WXLogUtils.v("tag", "onPageOverride " + url);
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WXLogUtils.v("tag", "onPageStarted " + url);
if (BMWebView.this.mOnPageListener != null) {
BMWebView.this.mOnPageListener.onPageStart(url);
}
}
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
WXLogUtils.v("tag", "onPageFinished " + url);
if (BMWebView.this.mOnPageListener != null) {
BMWebView.this.mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
}
}
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (BMWebView.this.mOnErrorListener != null) {
BMWebView.this.mOnErrorListener.onError("error", "page error");
}
}
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
if (BMWebView.this.mOnErrorListener != null) {
BMWebView.this.mOnErrorListener.onError("error", "http error");
}
}
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
if (BMWebView.this.mOnErrorListener != null) {
BMWebView.this.mOnErrorListener.onError("error", "ssl error");
}
}
});
wv.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
BMWebView.this.showWebView(newProgress == 100);
BMWebView.this.showProgressBar(newProgress != 100);
WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
}
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (BMWebView.this.mOnPageListener != null) {
BMWebView.this.mOnPageListener.onReceivedTitle(view.getTitle());
}
}
});
}
Aggregations