List of usage examples for android.webkit WebViewClient WebViewClient
WebViewClient
From source file:com.mummyding.app.leisure.ui.support.BaseWebViewActivity.java
private void initData() { data = getData();/*from w w w . j a v a 2 s .c o m*/ webView = (WebView) findViewById(R.id.webview); progressBar = (ProgressBar) findViewById(R.id.progressbar); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSupportMultipleWindows(false); /* cache web page */ 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 (HttpUtil.isWIFI == false) { webView.getSettings() .setBlockNetworkImage(Settings.getInstance().getBoolean(Settings.NO_PIC_MODE, false)); } else { // fix issue #13 webView.getSettings().setBlockNetworkImage(false); } loadData(); setProgressBarIndeterminateVisibility(true); webView.setWebViewClient(new WebViewClient() { @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) { 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) { return false; } }); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (isLoading) { progressBar.incrementProgressBy(newProgress - progressBar.getProgress()); if (newProgress > 25) { isLoading = false; progressBar.setVisibility(View.GONE); } } } }); }
From source file:com.appnexus.opensdk.MRAIDImplementation.java
WebViewClient getWebViewClient() { return new WebViewClient() { @Override//from w w w. ja v a 2s . com public boolean shouldOverrideUrlLoading(WebView view, String url) { if (!url.startsWith("mraid:") && !url.startsWith("javascript:")) { Intent intent; if (owner.owner.getOpensNativeBrowser()) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); } else { intent = new Intent(owner.getContext(), BrowserActivity.class); intent.putExtra("url", url); } try { owner.getContext().startActivity(intent); } catch (ActivityNotFoundException e) { Clog.w(Clog.mraidLogTag, Clog.getString(R.string.opening_url_failed, url)); } return true; } else if (url.startsWith("mraid://")) { MRAIDImplementation.this.dispatch_mraid_call(url); return true; } // See if any native activities can handle the Url try { owner.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); // If it's an IAV, prevent it from closing if (owner.owner instanceof InterstitialAdView) { ((InterstitialAdView) (owner.owner)).interacted(); } return true; } catch (ActivityNotFoundException e) { return false; } } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { Clog.e(Clog.httpRespLogTag, Clog.getString(R.string.webclient_error, error.getPrimaryError(), error.toString())); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingURL) { Clog.e(Clog.httpRespLogTag, Clog.getString(R.string.webclient_error, errorCode, description)); } @Override public void onPageFinished(WebView view, String url) { // Fire the ready event only once if (!readyFired) { view.loadUrl(String.format("javascript:window.mraid.util.setPlacementType('%s')", owner.owner.isBanner() ? "inline" : "interstitial")); view.loadUrl("javascript:window.mraid.util.setIsViewable(true)"); view.loadUrl("javascript:window.mraid.util.stateChangeEvent('default')"); view.loadUrl("javascript:window.mraid.util.readyEvent();"); // Store width and height for close() default_width = owner.getLayoutParams().width; default_height = owner.getLayoutParams().height; readyFired = true; } } }; }
From source file:com.dubsar_dictionary.Dubsar.FAQActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from www . ja va 2s. c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState, R.layout.faq); mWebView = (WebView) findViewById(R.id.faq_web_view); mWebView.getSettings().setJavaScriptEnabled(true); SharedPreferences preferences = getSharedPreferences(PreferencesActivity.DUBSAR_PREFERENCES, MODE_PRIVATE); String host = preferences.getString(PreferencesActivity.HTTP_PROXY_HOST, null); int port = preferences.getInt(PreferencesActivity.HTTP_PROXY_PORT, 0); if (host != null && port != 0) { mProxyFailed = !setProxy(mWebView, host, port); if (mProxyFailed) { String html = "<html><body style=\"background-color: #e0e0ff;\"><h1 style=\"color: #1c94c4; text-align: center; margin-top: 2ex; font: bold 18pt sans-serif\">" + getString(R.string.proxy_fail) + " " + host + ":" + port + "</h1></body></html>"; mWebView.loadData(html, "text/html", "utf-8"); return; } } if (savedInstanceState != null) { mWebView.restoreState(savedInstanceState); } else { String html = "<html><body style=\"background-color: #e0e0ff;\"><h1 style=\"color: #1c94c4; text-align: center; margin-top: 2ex; font: bold 18pt sans-serif\">" + getString(R.string.loading_faq) + "</h1></body></html>"; mWebView.loadData(html, "text/html", "utf-8"); // Log.i(getString(R.string.app_name), "Initial FAQ HTML: " + html); } mWebView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } public void onPageFinished(WebView view, String url) { String faqUrl = getString(R.string.faq_url); if (!mProxyFailed && (url == null || !url.equals(faqUrl))) { mWebView.loadUrl(faqUrl); } } }); }
From source file:corp.seedling.news.wordy.DetailFragment.java
public void updateContent(String url, String keyword) { Log.e(TAG, "updateContent :"); webUrl = url;//from www. jav a2s. co m searchText = keyword; webView.setWebViewClient(new WebViewClient() { @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onPageFinished(WebView view, String url) { if (searchText != null && !searchText.equals("")) { webView.findAllAsync(searchText); } } }); webView.loadUrl(webUrl); }
From source file:com.rickendirk.rsgwijzigingen.WebFragment.java
@Nullable @Override/*ww w. j ava 2 s . com*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) { View mainView = inflater.inflate(R.layout.fragment_web, container, false); if (savedInstanceState != null) { is1eKeerGenegeerd = true; } progressBar = (ProgressBar) getActivity().findViewById(R.id.progressBar); webView = (NestedWebView) mainView.findViewById(R.id.webView); webView.setNestedScrollingEnabled(true); WebSettings webSettings = webView.getSettings(); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { isLoading = true; isFinished = false; progressBar.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { isFinished = true; isLoading = false; //Ondestaande if voorkomt weergeven "pagina is vernieuwd" bij orintatie-verandering if (is1eKeerGenegeerd) { is1eKeerGenegeerd = false; } else Toast.makeText(getActivity(), "Pagina is vernieuwd", Toast.LENGTH_LONG).show(); progressBar.setVisibility(View.GONE); swipeLayout.setRefreshing(false); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { progressBar.setProgress(newProgress); super.onProgressChanged(view, newProgress); } }); swipeLayout = (SwipeRefreshLayout) mainView.findViewById(R.id.swipeLayout); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(); } }); swipeLayout.setColorSchemeResources(R.color.gmailRood, R.color.orange, R.color.lighter_blue, R.color.green); setRetainInstance(true); return mainView; }
From source file:com.btmura.android.reddit.app.LoginFragment.java
private void setupWebView() { // Clear reddit cookie to present a fresh login form. CookieManager.getInstance().setCookie(".reddit.com", "reddit_session="); WebSettings settings = webView.getSettings(); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setLoadWithOverviewMode(true); settings.setSupportZoom(true);/* www .j a v a 2 s. c om*/ settings.setUseWideViewPort(true); // Don't save usernames entered into the login forms. settings.setSaveFormData(false); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (progressBar != null) { progressBar.setVisibility(View.VISIBLE); } } @Override public void onPageFinished(WebView view, String url) { if (progressBar != null) { progressBar.setVisibility(View.GONE); } } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // WebView will show an unrecognized scheme error unless we intercept // the OAuth callback URL and fire off an intent instead. return url != null && url.startsWith(Urls.OAUTH_REDIRECT_URL) && handleOAuthRedirectUrl(url); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (progressBar != null) { progressBar.setProgress(newProgress); } } }); }
From source file:com.android.browser.GoogleAccountLogin.java
private GoogleAccountLogin(Activity activity, Account account, Runnable runnable) { mActivity = activity;//from w ww .j av a2 s . co m mAccount = account; mWebView = new WebView(mActivity); mRunnable = runnable; mUserAgent = mWebView.getSettings().getUserAgentString(); // XXX: Doing pre-login causes onResume to skip calling // resumeWebViewTimers. So to avoid problems with timers not running, we // duplicate the work here using the off-screen WebView. CookieSyncManager.getInstance().startSync(); WebViewTimersControl.getInstance().onBrowserActivityResume(mWebView); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } @Override public void onPageFinished(WebView view, String url) { done(); } }); }
From source file:com.mediaexplorer.remote.MexRemoteActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from w w w . j av a 2 s . c o m*/ this.setTitle(R.string.app_name); dbg = "MexWebremote"; text_view = (TextView) findViewById(R.id.text); web_view = (WebView) findViewById(R.id.link_view); web_view.getSettings().setJavaScriptEnabled(true);/* /* Future: setOverScrollMode is API level >8 * web_view.setOverScrollMode (OVER_SCROLL_NEVER); */ web_view.setBackgroundColor(0); web_view.setWebViewClient(new WebViewClient() { /* for some reason we only get critical errors so an auth error * is not handled here which is why there is some crack that test * the connection with a special httpclient */ @Override public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler, final String host, final String realm) { String[] userpass = new String[2]; userpass = view.getHttpAuthUsernamePassword(host, realm); HttpResponse response = null; HttpGet httpget; DefaultHttpClient httpclient; String target_host; int target_port; target_host = MexRemoteActivity.this.target_host; target_port = MexRemoteActivity.this.target_port; /* We may get null from getHttpAuthUsernamePassword which will * break the setCredentials so junk used instead to keep * it happy. */ Log.d(dbg, "using the set httpauth, testing auth using client"); try { if (userpass == null) { userpass = new String[2]; userpass[0] = "none"; userpass[1] = "none"; } } catch (Exception e) { userpass = new String[2]; userpass[0] = "none"; userpass[1] = "none"; } /* Log.d ("debug", * "trying: GET http://"+userpass[0]+":"+userpass[1]+"@"+target_host+":"+target_port+"/"); */ /* We're going to test the authentication credentials that we * have before using them so that we can act on the response. */ httpclient = new DefaultHttpClient(); httpget = new HttpGet("http://" + target_host + ":" + target_port + "/"); httpclient.getCredentialsProvider().setCredentials(new AuthScope(target_host, target_port), new UsernamePasswordCredentials(userpass[0], userpass[1])); try { response = httpclient.execute(httpget); } catch (IOException e) { Log.d(dbg, "Problem executing the http get"); e.printStackTrace(); } Log.d(dbg, "HTTP reponse:" + Integer.toString(response.getStatusLine().getStatusCode())); if (response.getStatusLine().getStatusCode() == 401) { /* We got Authentication failed (401) so ask user for u/p */ /* login dialog box */ final AlertDialog.Builder logindialog; final EditText user; final EditText pass; LinearLayout layout; LayoutParams params; TextView label_username; TextView label_password; logindialog = new AlertDialog.Builder(MexRemoteActivity.this); logindialog.setTitle("Mex Webremote login"); user = new EditText(MexRemoteActivity.this); pass = new EditText(MexRemoteActivity.this); layout = new LinearLayout(MexRemoteActivity.this); pass.setTransformationMethod(new PasswordTransformationMethod()); layout.setOrientation(LinearLayout.VERTICAL); params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); layout.setLayoutParams(params); user.setLayoutParams(params); pass.setLayoutParams(params); label_username = new TextView(MexRemoteActivity.this); label_password = new TextView(MexRemoteActivity.this); label_username.setText("Username:"); label_password.setText("Password:"); layout.addView(label_username); layout.addView(user); layout.addView(label_password); layout.addView(pass); logindialog.setView(layout); logindialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); logindialog.setPositiveButton("Login", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String uvalue = user.getText().toString().trim(); String pvalue = pass.getText().toString().trim(); view.setHttpAuthUsernamePassword(host, realm, uvalue, pvalue); handler.proceed(uvalue, pvalue); } }); logindialog.show(); /* End login dialog box */ } else /* We didn't get a 401 */ { handler.proceed(userpass[0], userpass[1]); } } /* End onReceivedHttpAuthRequest */ }); /* End Override */ /* Run mdns to check for service in a "runnable" (async) */ handler.post(new Runnable() { public void run() { startMdns(); } }); dialog = ProgressDialog.show(MexRemoteActivity.this, "", "Searching...", true); /* Let's put something in the webview while we're waiting */ String summary = "<html><head><style>body { background-color: #000000; color: #ffffff; }></style></head><body><p>Searching for the media explorer webservice</p><p>More infomation on <a href=\"http://media-explorer.github.com\" >Media Explorer's home page</a></p></body></html>"; web_view.loadData(summary, "text/html", "utf-8"); }
From source file:com.cnm.cnmrc.fragment.search.SearchNaverSub.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.tvch_semidetail, container, false); preventClickDispatching = (FrameLayout) layout.findViewById(R.id.search_tvch_prevent_click_dispatching); preventClickDispatching.setOnClickListener(this); webview = (WebView) layout.findViewById(R.id.webView); webview.setVisibility(View.INVISIBLE); // listview/*from ww w .ja v a 2 s .co m*/ listView = (ListView) layout.findViewById(R.id.tvch_semidetail); listView.setDivider(null); listView.setDividerHeight(0); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @SuppressLint("SetJavaScriptEnabled") @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //Intent intent = new Intent(Intent.ACTION_VIEW); //Uri uri = Uri.parse(mResult.get(position).getLink()); //intent.setData(uri); //getActivity().startActivity(intent); //webview use to call own site webview.setWebViewClient(new WebViewClient()); WebSettings set = webview.getSettings(); set.setJavaScriptEnabled(true); set.setBuiltInZoomControls(true); webview.loadUrl(mResult.get(position).getLink()); webview.setVisibility(View.VISIBLE); // zoom all webview.getSettings().setLoadWithOverviewMode(true); webview.getSettings().setUseWideViewPort(true); //webview.setVerticalScrollBarEnabled(false); //webview.setHorizontalScrollBarEnabled(false); } }); return layout; }
From source file:com.cjones.taskforcemamba.activity.WebActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle();/*from ww w. j a v a2s .c om*/ //WebView Intent launchingIntent = getIntent(); // String content = launchingIntent.getData().toString(); String home = "http://www.tfmamba.com"; // Log.i(TAG, "Content = " + content + " . Home = " + home); // if(content == home){ // content = content + "&styleid=2"; // Log.i(TAG, "IF Statement - Content = " + content + " . Home = " + home); // } else { // Log.i(TAG, "Else Statement - Content = " + content + " . Home = " + home); // } // Log.i(TAG, "conte = " + content); myWebView = (WebView) findViewById(R.id.webview); // if(content == null){ myWebView.loadUrl(home); // }else { // myWebView.loadUrl(content); // } myWebView.setWebViewClient(new WebViewClient()); myWebView.getSettings().setBuiltInZoomControls(true); myWebView.getSettings().setJavaScriptEnabled(true); myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); final ProgressBar Pbar; Pbar = (ProgressBar) findViewById(R.id.pB1); myWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { if (progress < 100 && Pbar.getVisibility() == ProgressBar.GONE) { Pbar.setVisibility(ProgressBar.VISIBLE); } Pbar.setProgress(progress); if (progress == 100) { Pbar.setVisibility(ProgressBar.GONE); } } }); if (savedInstanceState != null) { myWebView.restoreState(savedInstanceState); } else { // if(content == null && !content.isEmpty()){ // myWebView.loadUrl("http://www.tfmamba.com"); } }