List of usage examples for android.webkit WebChromeClient WebChromeClient
WebChromeClient
From source file:com.google.blockly.android.codegen.CodeGeneratorService.java
@Override public void onCreate() { mHandler = new Handler(); mWebview = new WebView(this); mWebview.getSettings().setJavaScriptEnabled(true); mWebview.setWebChromeClient(new WebChromeClient()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); }/*from w w w .j av a 2 s. com*/ mWebview.addJavascriptInterface(new BlocklyJavascriptInterface(), "BlocklyJavascriptInterface"); mWebview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { synchronized (this) { mReady = true; } handleRequest(); } }); mWebview.loadUrl(BLOCKLY_COMPILER_PAGE); }
From source file:com.example.nq.journalism_master.innerbrowser.InnerBrowserFragment.java
@Nullable @Override/*from w ww. j a v a 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_inner_browser, container, false); initViews(view); initWebViewSettings(webView); // if not set this, click the back arrow will call nothing setHasOptionsMenu(true); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { changeToolbarAndProgressBar(newProgress); } }); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view1, WebResourceRequest request, WebResourceError error) { webView.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); textView.setVisibility(View.VISIBLE); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (NetworkState.networkConnected(getContext())) { webView.loadUrl(url); webView.setVisibility(View.VISIBLE); imageView.setVisibility(View.GONE); textView.setVisibility(View.GONE); } } }); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); progressBar.setVisibility(View.GONE); } }); // WebView?html? webView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { webView.goBack(); return true; } } return false; } }); webView.loadUrl(url); return view; }
From source file:com.liato.bankdroid.WebViewActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview);/* www .jav a2 s . c o m*/ this.addTitleButton(R.drawable.title_icon_back, "back", this); this.addTitleButton(R.drawable.title_icon_forward, "forward", this); this.addTitleButton(R.drawable.title_icon_refresh, "refresh", this); this.setTitleButtonEnabled("forward", false); this.setTitleButtonEnabled("back", false); this.setTitleButtonEnabled("refresh", false); final CookieSyncManager csm = CookieSyncManager.createInstance(this); mWebView = (WebView) findViewById(R.id.wvBank); mWebView.setBackgroundColor(0); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setUserAgentString(Urllib.DEFAULT_USER_AGENT); mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setProgressBar(progress); if (progress == 100) { Handler handler = new Handler(); Runnable runnable = new Runnable() { public void run() { activity.hideProgressBar(); } }; // Let the progress bar hit 100% before we hide it. handler.postDelayed(runnable, 100); } else if (mFirstPageLoaded) { activity.showProgressBar(); } } }); mWebView.setWebViewClient(new BankWebViewClient()); String preloader = "Error..."; try { preloader = IOUtils.toString(getResources().openRawResource(R.raw.loading)); preloader = String.format(preloader, "", // Javascript function "" // HTML ); } catch (NotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } mWebView.loadDataWithBaseURL("what://is/this/i/dont/even", preloader, "text/html", "utf-8", null); Bundle extras = getIntent().getExtras(); final long bankId = extras.getLong("bankid", -1); //final long bankId = -1; if (bankId >= 0) { Runnable generateLoginPage = new Runnable() { public void run() { Bank bank = BankFactory.bankFromDb(bankId, WebViewActivity.this, false); SessionPackage loginPackage = bank.getSessionPackage(WebViewActivity.this); CookieStore cookieStore = loginPackage.getCookiestore(); if ((cookieStore != null) && !cookieStore.getCookies().isEmpty()) { CookieManager cookieManager = CookieManager.getInstance(); String cookieString; for (Cookie cookie : cookieStore.getCookies()) { cookieString = String.format("%s=%s;%spath=%s; domain=%s;", cookie.getName(), cookie.getValue(), cookie.getExpiryDate() == null ? "" : "expires=" + cookie.getExpiryDate() + "; ", cookie.getPath() == null ? "/" : cookie.getPath(), cookie.getDomain()); cookieManager.setCookie(cookie.getDomain(), cookieString); } csm.sync(); } mWebView.loadDataWithBaseURL("what://is/this/i/dont/even", loginPackage.getHtml(), "text/html", "utf-8", null); } }; new Thread(generateLoginPage).start(); } }
From source file:com.scm.reader.resultPage.ui.ItemViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override// www .j a v a 2 s. c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.fragment_result, container, false); mWebView = (WebView) v.findViewById(R.id.webView); // set WebViewClient mWebViewClient = createWebViewClient(getActivity()); mWebView.setWebViewClient(mWebViewClient); final ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.progressBar); mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { if (progress == 100) { progressBar.setVisibility(View.GONE); } else { progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(progress); } } }); initializeWebView(mWebView); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } mWebView.loadUrl(mUrl); return v; }
From source file:it.evilsocket.dsploit.plugins.mitm.hijacker.HijackerWebView.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_PROGRESS); setTitle(System.getCurrentTarget() + " > MITM > Session Hijacker"); setContentView(R.layout.plugin_mitm_hijacker_webview); getSupportActionBar().setDisplayHomeAsUpEnabled(true); setSupportProgressBarIndeterminateVisibility(false); mWebView = (WebView) findViewById(R.id.webView); mSettings = mWebView.getSettings();/*from w w w .ja v a 2s . co m*/ mSettings.setJavaScriptEnabled(true); mSettings.setBuiltInZoomControls(true); mSettings.setAppCacheEnabled(false); mSettings.setUserAgentString(DEFAULT_USER_AGENT); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { if (mWebView != null) getSupportActionBar().setSubtitle(mWebView.getUrl()); setSupportProgressBarIndeterminateVisibility(true); // Normalize our progress along the progress bar's scale int mmprogress = (Window.PROGRESS_END - Window.PROGRESS_START) / 100 * progress; setSupportProgress(mmprogress); if (progress == 100) setSupportProgressBarIndeterminateVisibility(false); } }); CookieSyncManager.createInstance(this); CookieManager.getInstance().removeAllCookie(); Session session = (Session) System.getCustomData(); if (session != null) { String domain = null, rawcookie = null; for (BasicClientCookie cookie : session.mCookies.values()) { domain = cookie.getDomain(); rawcookie = cookie.getName() + "=" + cookie.getValue() + "; domain=" + domain + "; path=/" + (session.mHTTPS ? ";secure" : ""); CookieManager.getInstance().setCookie(domain, rawcookie); } CookieSyncManager.getInstance().sync(); if (session.mUserAgent != null && session.mUserAgent.isEmpty() == false) mSettings.setUserAgentString(session.mUserAgent); mWebView.loadUrl((session.mHTTPS ? "https" : "http") + "://www." + domain); } }
From source file:com.wms.ezyoukuuploader.sdk.activity.GetRefreshTokenActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.youku_login); progressBarLoading = (ProgressBar) findViewById(R.id.progressBarLoading); webviewYouku = (WebView) findViewById(R.id.webViewYouku); webviewYouku.setWebViewClient(new WebViewClient() { @Override/* w w w. j ava 2 s . c o m*/ public boolean shouldOverrideUrlLoading(WebView view, String url) { String[] str = url.split("=")[1].split("&"); authorizationCode = str[0]; String refreshToken = getRefreshToken(); if (refreshToken != null) { Toast.makeText(getApplicationContext(), getString(R.string.loginSuccessful), Toast.LENGTH_LONG) .show(); finish(); } return false; } }); webviewYouku.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { if (progress == 100) { progressBarLoading.setVisibility(View.INVISIBLE); } } }); String url = YoukuConstants.YOUKU_AUTHORIZE_URL + "?" + YoukuConstants.PARAM_CLIENT_ID + "=" + getString(R.string.YOUKU_APP_CLIENT_ID) + "&" + YoukuConstants.PARAM_RESPONSE_TYPE + "=" + YoukuConstants.PARAM_AUTHORIZATION_CODE + "&" + YoukuConstants.PARAM_REDIRECT_URI + "=" + getString(R.string.YOUKU_APP_REDIRECT_URI); webviewYouku.loadUrl(url); Toast.makeText(this, getString(R.string.pleaseLogin), Toast.LENGTH_LONG).show(); }
From source file:com.saltedge.sdk.webview.SEWebViewTools.java
public void initializeWithUrl(Activity activity, final WebView webView, final String url, WebViewRedirectListener listener) { this.activity = activity; this.webViewRedirectListener = listener; progressDialog = UITools.createProgressDialog(this.activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setAllowFileAccess(true); webView.setWebViewClient(new CustomWebViewClient()); webView.setWebChromeClient(new WebChromeClient() { @Override//from www . j a v a 2 s . c om public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { SETools.uploadMessage = filePathCallback; pickFile(); return true; } }); webView.loadUrl(url); }
From source file:com.anxpp.blog.fragment.AboutFragment.java
@SuppressLint("SetJavaScriptEnabled") private void initView() { webView = (WebView) getView().findViewById(R.id.webView); // webView.setVisibility(View.GONE); webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { Activity activity = getActivity(); /**//w w w . ja v a 2s.c om * ?Fragment??? * I am not sure why are you getting this error, * i think it should be something like NullPointerException. * Try next: * Evert time you calling getActivity() on Fragment instance you should be sure, * that fragment is actually have this Activity. * Because when your webview is loading you are calling this function: * */ if (activity == null) return; activity.setTitle("Loading..." + progress + "%"); activity.setProgress(progress * 100); if (progress == 100) { activity.setTitle(R.string.app_name); webView.setVisibility(View.VISIBLE); } } }); webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Toast("shouldOverrideUrlLoading"); view.loadUrl(url); return true; } }); //?? WebSettings webSettings = webView.getSettings(); //? //webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //?js webSettings.setJavaScriptEnabled(true); //? ? webSettings.setUseWideViewPort(false); //?? webSettings.setLoadWithOverviewMode(true); // ?? webView.loadUrl("http://anxpp.com"); // webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //trueWebViewfalse?? view.loadUrl(url); return true; //false? } }); webView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { // ? webView.goBack(); //? return true; //? } } return false; } }); }
From source file:org.projecthdata.hhub.ui.HDataWebOauthActivity2.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_PROGRESS); getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); webView = new WebView(this); setContentView(webView);/*from w ww . jav a 2 s. c om*/ activity = this; this.hDataConnectionFactory = new HDataConnectionFactory(clientId, clientSecret, "server here"); webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setTitle("Loading..."); activity.setProgress(progress * 100); if (progress == 100) { activity.setTitle(R.string.app_name); } } }); webView.setWebViewClient(new MyWebViewClient()); }