List of usage examples for android.webkit WebViewClient WebViewClient
WebViewClient
From source file:com.nxt.yn.app.ui.activity.WebViewUrlActivity.java
private void initData() { refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override//ww w .j av a 2s .c o m public void onRefresh() { handler.sendEmptyMessageDelayed(0, 1000); } }); refreshLayout.setColorSchemeResources(R.color.title_color, R.color.title_color, R.color.title_color, R.color.title_color); newsid = getIntent().getIntExtra("newsid", 0); LogUtils.i("ssss", "newsid---------->" + newsid); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSupportMultipleWindows(false); webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setDatabaseEnabled(true); /* if(Settings.isNightMode) { webView.setBackgroundColor(ContextCompat.getColor(this, R.color.night_primary)); }*/ if (EaseCommonUtils.isWiFi(this) == false) { webView.getSettings() .setBlockNetworkImage(ZPreferenceUtils.getPrefBoolean(Settings.NO_PIC_MODE, false)); } else { // fix issue #13 webView.getSettings().setBlockNetworkImage(false); } webView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { refreshLayout.setRefreshing(false); super.onPageFinished(view, url); } @Override public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { view.loadUrl("file:///android_asset/error.html"); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { view.loadUrl("file:///android_asset/error.html"); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (isfirsarload) { isfirsarload = false; return false; } else { startActivity(new Intent(WebViewUrlActivity.this, WebViewUrlActivity.class) .putExtra("title", getString(R.string.app_name)).putExtra("url", url)); } return true; } }); }
From source file:com.timrae.rikaidroid.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mWebView = (WebView) findViewById(R.id.webview); mWebClient = new WebViewClient() { @Override/* w w w. ja v a 2 s .co m*/ public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri uri = Uri.parse(url); if (uri.getScheme().equals("lookup")) { String query = uri.getHost(); Intent i = new Intent(AEDICT_INTENT); i.putExtra("kanjis", query); i.putExtra("showEntryDetailOnSingleResult", true); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); view.reload(); return true; } else { view.loadUrl(url); } return true; } }; mWebView.setWebViewClient(mWebClient); mEditText = (EditText) findViewById(R.id.search_src_text); mProgressBar = (ProgressBar) findViewById(R.id.progress_bar); if (mProgressBar != null) { mProgressBar.setVisibility(View.VISIBLE); } }
From source file:com.remdo.app.WebViewActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_web_view); // Get the uri from the intent Intent intent = getIntent();/* w w w . j a v a2 s. c o m*/ String uriToDisplay = intent.getStringExtra("DEVICE_URL"); String usr = intent.getStringExtra("DEVICE_USER"); String pwd = intent.getStringExtra("DEVICE_PASSWORD"); Integer odTypeId = intent.getIntExtra("DEVICE_ODTYPEID", -1); if (odTypeId == 1)//ODNetWork { if (!uriToDisplay.contains("cgi-bin/od.cgi")) { uriToDisplay = uriToDisplay.concat("/cgi-bin/od.cgi"); } //initialize WebView webView = (WebView) findViewById(R.id.webView1); //we should define a webview client to get user navigation inside our webview otherwise //defaul behaviour will open a webbrowser on first click webView.setWebViewClient(new WebViewClient()); try { byte[] post = EncodingUtils.getBytes("USERNAME=" + usr + "&PASSWORD=" + pwd, "BASE64"); webView.postUrl(uriToDisplay, post); } catch (Exception e) { String message = e.getMessage(); } } else//ODControl { webView = (WebView) findViewById(R.id.webView1); webView.setHttpAuthUsernamePassword(uriToDisplay, "/", "user@opendomo.com", "opendomo"); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new MyWebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("http://local.opendomo.com"); } }
From source file:io.github.hidroh.materialistic.WebFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { if (mIsHackerNewsUrl) { return createLocalView(container, savedInstanceState); }//from w ww. ja v a 2 s . c o m final View view = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_web, container, false); mScrollView = (NestedScrollView) view.findViewById(R.id.nested_scroll_view); final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progress); mWebView = (WebView) view.findViewById(R.id.web_view); mWebView.setBackgroundColor(Color.TRANSPARENT); mWebView.setWebViewClient(new WebViewClient()); mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(newProgress); if (newProgress == 100) { progressBar.setVisibility(View.GONE); mWebView.setBackgroundColor(Color.WHITE); mWebView.setVisibility(mExternalRequired ? View.GONE : View.VISIBLE); } } }); mWebView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { if (getActivity() == null) { return; } final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (intent.resolveActivity(getActivity().getPackageManager()) == null) { return; } mExternalRequired = true; mWebView.setVisibility(View.GONE); view.findViewById(R.id.empty).setVisibility(View.VISIBLE); view.findViewById(R.id.download_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(intent); } }); } }); mWebView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) { if (mWebView.canGoBack()) { mWebView.goBack(); return true; } } return false; } }); setWebViewSettings(mWebView.getSettings()); return view; }
From source file:com.blogspot.holbohistorier.readonfree.BookView.java
@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override/*w w w . ja v a 2s . c om*/ public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); loadPage(viewedPage); }
From source file:com.tomeokin.lspush.biz.home.CollectionWebViewActivity.java
@Override protected void onPrepareWebView(WebView webView) { super.onPrepareWebView(webView); webView.setWebViewClient(new WebViewClient() { @Override/*from w w w . ja v a 2s . c o m*/ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { return false; // let the web view handle the url } @Override public void onPageFinished(WebView view, String url) { boolean canGoBack = view.canGoBack(); mBottomBar.backButton.setEnabled(canGoBack); mBottomBar.backButton .setImageResource(canGoBack ? R.drawable.ic_action_back_deep : R.drawable.ic_action_back); boolean canGoForward = view.canGoForward(); mBottomBar.forwardButton.setEnabled(canGoForward); mBottomBar.forwardButton.setImageResource( canGoForward ? R.drawable.ic_action_forward_deep : R.drawable.ic_action_forward); } }); }
From source file:com.johnny.gank.ui.activity.WebviewActivity.java
private void setUpWebView() { WebSettings settings = vWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setLoadWithOverviewMode(true); vWebView.setWebViewClient(new WebViewClient() { @Override/*from w w w . jav a 2s .c om*/ public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); vRefreshLayout.setRefreshing(true); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); vRefreshLayout.setRefreshing(false); } @Override public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { super.onReceivedError(view, request, error); vRefreshLayout.setRefreshing(false); } }); vWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress >= 80) { vRefreshLayout.setRefreshing(false); } } }); }
From source file:li.klass.fhem.fragments.AbstractWebViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w w w .java 2s .co m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) return view; view = inflater.inflate(R.layout.webview, container, false); assert view != null; final WebView webView = (WebView) view.findViewById(R.id.webView); WebSettings settings = webView.getSettings(); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); final ProgressDialog progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage(getResources().getString(R.string.loading)); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress < 100) { progressDialog.setProgress(newProgress); progressDialog.show(); } else { progressDialog.hide(); } } }); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedSslError(WebView view, @NotNull SslErrorHandler handler, SslError error) { handler.proceed(); } @SuppressWarnings("ConstantConditions") @Override public void onReceivedHttpAuthRequest(WebView view, @NotNull HttpAuthHandler handler, String host, String realm) { FHEMServerSpec currentServer = connectionService.getCurrentServer(getActivity()); String url = currentServer.getUrl(); String alternativeUrl = trimToNull(currentServer.getAlternateUrl()); try { String fhemUrlHost = new URL(url).getHost(); String alternativeUrlHost = alternativeUrl == null ? null : new URL(alternativeUrl).getHost(); String username = currentServer.getUsername(); String password = currentServer.getPassword(); if (host.startsWith(fhemUrlHost) || (alternativeUrlHost != null && host.startsWith(alternativeUrlHost))) { handler.proceed(username, password); } else { handler.cancel(); Intent intent = new Intent(Actions.SHOW_TOAST); intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_authentication); getActivity().sendBroadcast(intent); } } catch (MalformedURLException e) { Intent intent = new Intent(Actions.SHOW_TOAST); intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_host_connection); getActivity().sendBroadcast(intent); LOG.error("malformed URL: " + url, e); handler.cancel(); } } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if ("about:blank".equalsIgnoreCase(url)) { Optional<String> alternativeUrl = getAlternateLoadUrl(); if (alternativeUrl.isPresent()) { webView.loadUrl(alternativeUrl.get()); } } else { onPageLoadFinishedCallback(view, url); } } }); return view; }
From source file:com.jaspervanriet.huntingthatproduct.Activities.WebActivity.java
private void setupWebView() { mWebView.setWebViewClient(new WebViewClient() { @Override/*from ww w.j ava2s. c o m*/ public void onLoadResource(WebView view, String url) { if (isPlayStoreLink(url)) { redirectToPlayStore(url); view.stopLoading(); } } @Override public void onPageFinished(WebView view, String url) { getSupportActionBar().setTitle(mProductTitle); if (isPlayStoreLink(url)) { redirectToPlayStore(url); } } @Override public void onReceivedSslError(WebView view, @NonNull SslErrorHandler handler, SslError error) { Toast.makeText(WebActivity.this, getString(R.string.error_ssl), Toast.LENGTH_LONG).show(); } }); mWebView.loadUrl(mProductUrl); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setDisplayZoomControls(false); mWebView.getSettings().setJavaScriptEnabled(true); }
From source file:me.philio.disqus.AuthorizeFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { mWebView = (WebView) view.findViewById(R.id.disqus_authorize_webview); // Setup custom client to catch the redirect mWebView.setWebViewClient(new WebViewClient() { @Override/*from ww w. j a va 2s . com*/ public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith(mRedirectUri)) { // Get fragment from url Log.d(TAG, "Processing redirect: " + url); Uri uri = Uri.parse(url); String uriFragment = uri.getFragment(); // Extract data from fragment and pass to callback Uri queryUri = new Uri.Builder().encodedQuery(uriFragment).build(); AccessToken accessToken = new AccessToken(); accessToken.username = queryUri.getQueryParameter(DisqusConstants.PARAM_USERNAME); accessToken.userId = Long.parseLong(queryUri.getQueryParameter(DisqusConstants.PARAM_USER_ID)); accessToken.accessToken = queryUri.getQueryParameter(DisqusConstants.PARAM_ACCESS_TOKEN); accessToken.expiresIn = Long .parseLong(queryUri.getQueryParameter(DisqusConstants.PARAM_EXPIRES_IN)); accessToken.tokenType = queryUri.getQueryParameter(DisqusConstants.PARAM_TOKEN_TYPE); accessToken.state = queryUri.getQueryParameter(DisqusConstants.PARAM_STATE); accessToken.scope = queryUri.getQueryParameter(DisqusConstants.PARAM_SCOPE); mListener.onSuccess(accessToken); return true; } return super.shouldOverrideUrlLoading(view, url); } }); // Load authorize url String scope = AuthorizeUtils.buildScope(mScopes); Uri uri = AuthorizeUtils.buildAuthorizeUri(mApiKey, scope, mRedirectUri); Log.d(TAG, "Loading authorize url: " + uri.toString()); mWebView.loadUrl(uri.toString()); }