List of usage examples for android.webkit WebChromeClient WebChromeClient
WebChromeClient
From source file:cn.zhangls.android.weibo.ui.web.WebActivity.java
/** * ?//from w ww . ja v a2 s .c om */ private void initialize() { // Appbar setSupportActionBar(mBinding.acWebToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // ? Title getSupportActionBar().setTitle(""); mWeiboUrl = getIntent().getStringExtra(WEIBO_URL); //SwipeRefreshLayout mBinding.acWebSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mBinding.acWebWebView.reload(); } }); mBinding.acWebSwipeRefresh.setColorSchemeColors(ContextCompat.getColor(this, R.color.colorAccent)); mBinding.acWebWebView.loadUrl(mWeiboUrl); mBinding.acWebWebView.setWebChromeClient(new WebChromeClient() { /** * Tell the host application the current progress of loading a page. * * @param view The WebView that initiated the callback. * @param newProgress Current page loading progress, represented by */ @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { mBinding.acWebSwipeRefresh.setRefreshing(false); } } /** * Notify the host application of a change in the document title. * * @param view The WebView that initiated the callback. * @param title A String containing the new title of the document. */ @Override public void onReceivedTitle(WebView view, String title) { getSupportActionBar().setTitle(title); } }); mBinding.acWebWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { mBinding.acWebWebView.loadUrl(mWeiboUrl); return true; } }); // ??javascript mBinding.acWebWebView.getSettings().setJavaScriptEnabled(true); // mBinding.acWebWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); }
From source file:net.olejon.mdapp.MedicationFelleskatalogenFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w w w . j a va2s.c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_medication_felleskatalogen, container, false); // Activity final Activity activity = getActivity(); // Context final Context context = activity.getApplicationContext(); // Tools final MyTools mTools = new MyTools(context); // Arguments Bundle bundle = getArguments(); final String pageUri = bundle.getString("uri"); // Progress bar final ProgressBar progressBar = (ProgressBar) activity .findViewById(R.id.medication_toolbar_progressbar_horizontal); // Toolbar final LinearLayout toolbarSearchLayout = (LinearLayout) activity .findViewById(R.id.medication_toolbar_search_layout); final EditText toolbarSearchEditText = (EditText) activity.findViewById(R.id.medication_toolbar_search); // Web view WEBVIEW = (WebView) viewGroup.findViewById(R.id.medication_felleskatalogen_content); WebSettings webSettings = WEBVIEW.getSettings(); webSettings.setJavaScriptEnabled(true); WEBVIEW.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (!mTools.isDeviceConnected()) { mTools.showToast(getString(R.string.device_not_connected), 0); return true; } else if (url.matches("^https?://.*?\\.pdf$")) { mTools.downloadFile(view.getTitle(), url); return true; } return false; } }); WEBVIEW.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { progressBar.setVisibility(View.INVISIBLE); } else { progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(newProgress); toolbarSearchLayout.setVisibility(View.GONE); toolbarSearchEditText.setText(""); } } }); if (savedInstanceState == null) { WEBVIEW.loadUrl(pageUri); } else { WEBVIEW.restoreState(savedInstanceState); } return viewGroup; }
From source file:li.klass.fhem.fragments.AbstractWebViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override/* w ww . ja v a2s . c o 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:it.redturtle.mobile.apparpav.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.showbulletin, container, false); // Set button in order to start the bulletin fragmnet final Button mv = (Button) view.findViewById(R.id.mv); mv.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent newintent = new Intent(); newintent.setClass(activity, BulletinActivity.class); newintent.putExtra("bulletinid", "MV"); startActivity(newintent);/* w w w .j av a2 s . c o m*/ } }); // Set button in order to start the bulletin fragmnet final Button dm = (Button) view.findViewById(R.id.dm); dm.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent newintent = new Intent(); newintent.setClass(activity, BulletinActivity.class); newintent.putExtra("bulletinid", "DM"); startActivity(newintent); } }); // Set button in order to start the bulletin fragmnet final Button pm = (Button) view.findViewById(R.id.pm); pm.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent newintent = new Intent(); newintent.setClass(activity, BulletinActivity.class); newintent.putExtra("bulletinid", "MP"); startActivity(newintent); } }); WebView webview = (WebView) view.findViewById(R.id.datail_content); webview.setWebChromeClient(new WebChromeClient() { }); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); String html = "<!doctype html>"; html += "<html>"; html += "<head>"; html += "<meta name=\"author\" content=\"RedTurtle.it\" />"; html += "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />"; html += "</head>"; html += "<body style=\"font-family:Helvetica;font-size:small;\">"; html += "<div style=\"text-align:center;\"><b>" + forecast.getName() + "</b></div>"; if (forecast.getType() == 1) { html += "<div style=\"text-align:center;\">"; html += "<p>" + forecast.getCaptionAt(0) + "</p>"; html += "<img src=\"" + forecast.getPathAt(0) + "\" width=\"140\" style=\"padding:2px;\"/>"; html += "</div>"; } if (forecast.getType() == 2) { html += "<div style=\"text-align:center;\">"; html += "<div style=\"display:inline-block;\">"; html += "<div style=\"float:left;\">"; html += "<p>" + forecast.getCaptionAt(0) + "</p>"; html += "<img src=\"" + forecast.getPathAt(0) + "\" width=\"140\" style=\"padding:2px;\"/>"; html += "</div>"; html += "<div style=\"float:left;\">"; html += "<p>" + forecast.getCaptionAt(1) + "</p>"; html += "<img src=\"" + forecast.getPathAt(1) + "\" width=\"140\" style=\"padding:2px;\"/>"; html += "</div>"; html += "</div>"; html += "</div>"; } html += forecast.getBody(); html += "</body>"; html += "</html>"; webview.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null); return view; }
From source file:com.github.snowdream.android.app.books.BookFragment.java
private void initUI(View rootview) { webView = (WebView) rootview.findViewById(R.id.webView); // progressbar = (SmoothProgressBar) rootview.findViewById(R.id.progressbar); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setSupportZoom(true);/*w ww. j a v a 2s .c om*/ webSettings.setBuiltInZoomControls(true); webSettings.setUseWideViewPort(true); String appCachePath = getActivity().getApplicationContext().getCacheDir().getAbsolutePath(); webSettings.setAppCachePath(appCachePath); webSettings.setAppCacheEnabled(true); 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 void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // progressbar.setVisibility(View.INVISIBLE); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); // progressbar.setVisibility(View.INVISIBLE); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); // The "loadAdOnCreate" and "testDevices" XML attributes no longer available. AdView adView = (AdView) rootview.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice(TEST_DEVICE_ID).build(); adView.loadAd(adRequest); getView().setFocusableInTouchMode(true); getView().setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (webView.canGoBack() && keyCode == KeyEvent.KEYCODE_BACK) { webView.goBack(); return true; } return false; } }); }
From source file:in.rab.bildkort.ImageFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override// w w w. jav a 2 s . c o m public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mWebView = (WebView) getView().findViewById(R.id.webView); final ProgressBar progress = (ProgressBar) getView().findViewById(R.id.image_progress); mWebView.setWebChromeClient(new WebChromeClient()); final WebSettings settings = mWebView.getSettings(); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setJavaScriptEnabled(true); // We replace the src urls in imagepicker.js::init(), so don't load // images twice. settings.setBlockNetworkImage(true); mWebView.setInitialScale(100); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { if (Objects.equals(url, GSTATIC_SERVER)) { settings.setBlockNetworkImage(false); progress.setVisibility(View.GONE); mWebView.setVisibility(View.VISIBLE); } else { view.loadUrl("javascript:" + getImagePickerJs() + "getPickerHtml();"); } } }); mWebView.addJavascriptInterface(new WcmJsObject(), "wcm"); mWebView.loadUrl("https://www.google.se/search?tbm=isch&q=" + getWord()); }
From source file:com.springsource.greenhouse.WebOAuthActivity.java
@AfterViews void initWebView() { webView.setWebViewClient(new OAuthWebViewClient()); webView.getSettings().setSaveFormData(false); webView.getSettings().setSavePassword(false); webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { setTitle("Loading..."); setProgress(progress * 100); if (progress == 100) { setTitle(R.string.app_name); }/*from w ww . j a v a2 s . c o m*/ } }); }
From source file:com.smoothsync.smoothsetup.microfragments.appspecificpassword.AppSpecificWebviewFragment.java
@SuppressLint("SetJavaScriptEnabled") @Nullable//from ww w . ja va 2 s. c om @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.smoothsetup_microfragment_webview, container, false); mWebView = (WebView) root.findViewById(R.id.smoothsetup_webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setDomStorageEnabled(true); mWebView.setOnKeyListener(this); mWebView.setWebChromeClient(new WebChromeClient()); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); mProgress.animate().alpha(0).start(); } }); mWebView.addJavascriptInterface(new AppSpecificPasswordCallback() { @JavascriptInterface @Override public void onAppSpecificPassword(final String appSpecificPassword) { if (!TextUtils.isEmpty(appSpecificPassword) && !TextUtils.equals(mAppSpecificPassword, appSpecificPassword)) { mAppSpecificPassword = appSpecificPassword; mSnackbar = Snackbar .make(mWebView, getString(R.string.smoothsetup_snackbar_found_app_specific_password, appSpecificPassword), Snackbar.LENGTH_INDEFINITE) .setAction(R.string.smoothsetup_button_copy_app_specific_password, mOnCopyPasswordListener); mSnackbar.show(); } } }, "SmoothSetup"); String url = new FragmentEnvironment<Params>(this).microFragment().parameter().uri().toASCIIString(); if (savedInstanceState == null) { mWebView.loadUrl(url); } else { mWebView.restoreState(savedInstanceState); } mPasswordProbe = new DefaultPasswordProbeFactory().forUrl(URI.create(url)); mProgress = (ProgressBar) root.findViewById(android.R.id.progress); // start probing for the password mHandler.postDelayed(mPasswordProbeRunnable, PASSWORD_PROBE_PERIOD); return root; }
From source file:com.btmura.android.reddit.app.LinkFragment.java
@SuppressLint("SetJavaScriptEnabled") private void setupWebView(WebView webView) { WebSettings settings = webView.getSettings(); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setDomStorageEnabled(true); settings.setJavaScriptEnabled(true); settings.setLoadWithOverviewMode(true); settings.setSupportZoom(true);//w w w .j a v a2s. co m settings.setPluginState(PluginState.ON_DEMAND); settings.setUseWideViewPort(true); webView.setOnLongClickListener(this); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (progress != null) { progress.setVisibility(View.VISIBLE); } } @Override public void onPageFinished(WebView view, String url) { if (progress != null) { progress.setVisibility(View.GONE); } } }); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (progress != null) { progress.setProgress(newProgress); } } }); }
From source file:com.akingyin.librarys.widgets.BrowserLayout.java
private void init(Context context) { mContext = context;/*from w w w . ja v a2 s . com*/ setOrientation(VERTICAL); mProgressBar = (ProgressBar) LayoutInflater.from(context).inflate(R.layout.progress_horizontal, null); mProgressBar.setMax(100); mProgressBar.setProgress(0); addView(mProgressBar, LayoutParams.MATCH_PARENT, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mBarHeight, getResources().getDisplayMetrics())); mWebView = new WebView(context); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); mWebView.getSettings().setDefaultTextEncodingName("UTF-8"); mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); mWebView.getSettings().setBuiltInZoomControls(false); mWebView.getSettings().setSupportMultipleWindows(true); mWebView.getSettings().setUseWideViewPort(true); mWebView.getSettings().setLoadWithOverviewMode(true); mWebView.getSettings().setSupportZoom(false); mWebView.getSettings().setPluginState(WebSettings.PluginState.ON); mWebView.getSettings().setDomStorageEnabled(true); mWebView.getSettings().setLoadsImagesAutomatically(true); LayoutParams lps = new LayoutParams(LayoutParams.MATCH_PARENT, 0, 1); addView(mWebView, lps); mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress == 100) { mProgressBar.setVisibility(View.GONE); } else { mProgressBar.setVisibility(View.VISIBLE); mProgressBar.setProgress(newProgress); } } }); mWebView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); mLoadUrl = url; } }); mBrowserControllerView = LayoutInflater.from(context).inflate(R.layout.browser_controller, null); mGoBackBtn = (ImageButton) mBrowserControllerView.findViewById(R.id.browser_controller_back); mGoForwardBtn = (ImageButton) mBrowserControllerView.findViewById(R.id.browser_controller_forward); mGoBrowserBtn = (ImageButton) mBrowserControllerView.findViewById(R.id.browser_controller_go); mRefreshBtn = (ImageButton) mBrowserControllerView.findViewById(R.id.browser_controller_refresh); mGoBackBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (canGoBack()) { goBack(); } } }); mGoForwardBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (canGoForward()) { goForward(); } } }); mRefreshBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { loadUrl(mLoadUrl); } }); mGoBrowserBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!TextUtils.isEmpty(mLoadUrl)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(mLoadUrl)); mContext.startActivity(intent); } } }); addView(mBrowserControllerView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); }