List of usage examples for android.webkit WebViewClient WebViewClient
WebViewClient
From source file:com.taobao.luaview.view.LVWebView.java
@TargetApi(Build.VERSION_CODES.M) private void setupDefaultWebViewClient() { if (mWebView != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mWebView.setWebViewClient(new WebViewClient() { @Override/*from ww w. j a v a 2 s . c o m*/ public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; // ???? } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); mIsLoading = true; if (LuaUtil.isTable(mLuaUserdata.getCallback())) { LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onPageStarted")); } } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); mIsLoading = false; if (LuaUtil.isTable(mLuaUserdata.getCallback())) { LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onPageFinished")); } if (LVWebView.this.isRefreshing()) { LVWebView.this.setRefreshing(false); } } @Override public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { super.onReceivedError(view, request, error); mIsLoading = false; if (LuaUtil.isTable(mLuaUserdata.getCallback())) { LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onReceivedError"), valueOf(error.getErrorCode()), valueOf(String.valueOf(error.getDescription())), valueOf(String.valueOf(request.getUrl()))); } if (LVWebView.this.isRefreshing()) { LVWebView.this.setRefreshing(false); } } }); } else { mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; // ???? } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); mIsLoading = true; if (LuaUtil.isTable(mLuaUserdata.getCallback())) { LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onPageStarted")); } } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); mIsLoading = false; if (LuaUtil.isTable(mLuaUserdata.getCallback())) { LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onPageFinished")); } if (LVWebView.this.isRefreshing()) { LVWebView.this.setRefreshing(false); } } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); mIsLoading = false; if (LuaUtil.isTable(mLuaUserdata.getCallback())) { LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onReceivedError"), errorCode, description, failingUrl); } if (LVWebView.this.isRefreshing()) { LVWebView.this.setRefreshing(false); } } }); } } }
From source file:org.catnut.fragment.OAuthFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // set actionbar mActionBar = getActivity().getActionBar(); setHasOptionsMenu(true);//from w w w . ja v a 2 s . c o m // set the auth webview mWebView = new WebView(getActivity()); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mWebView.setLayoutParams(params); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (!url.startsWith(Manifest.AUTH_REDIRECT_URI)) { return false; } String code = Uri.parse(url).getQueryParameter("code"); Log.d(TAG, "the auth code is " + code); String accessTokenUri = Manifest.getAccessTokenUri(code); mProgressDialog = ProgressDialog.show(getActivity(), null, getString(R.string.authing_hint), true, false); mRequestQueue.add(new JsonObjectRequest(Request.Method.POST, accessTokenUri, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.i(TAG, "auth success with result: " + response.toString()); mApp.saveAccessToken(response); Toast.makeText(getActivity(), getString(R.string.auth_success), Toast.LENGTH_SHORT) .show(); // fetch user' s profile mRequestQueue.add( new CatnutRequest(getActivity(), UserAPI.profile(mApp.getAccessToken().uid), new UserProcessor.UserProfileProcessor(), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { mProgressDialog.dismiss(); mApp.getPreferences().edit() .putString(User.screen_name, response.optString(User.screen_name)) .commit(); Intent intent = new Intent(getActivity(), MainActivity.class); startActivity(intent); } }, null // should not happen! )); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.wtf(TAG, "auth fail!", error); WeiboAPIError e = WeiboAPIError.fromVolleyError(error); new AlertDialog.Builder(getActivity()) .setMessage(getString(R.string.auth_fail_with_reason, e.error)) .setNegativeButton(android.R.string.ok, null).show(); } })).setTag(TAG); return true; } }); }
From source file:com.zion.htf.ui.InfoDetailsActivity.java
@Override public void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); this.context = this; String resourceName = this.getIntent().getStringExtra(InfoDetailsActivity.name); if (null == resourceName) { throw new RuntimeException("This requires a 'name' parameter in its starting intent."); }//w w w . j av a 2 s . c o m this.setTitle(this.getString(this.getResources().getIdentifier(resourceName, "string", "com.zion.htf"))); this.webView = new WebView(this); this.webView.loadDataWithBaseURL("file:///android_res/raw/", this.readTextFromResource(resourceName), "text/html", "utf-8", null); this.webView.setBackgroundColor(0x00000000); if ("info_about".equals(resourceName) || "info_open_source".equals(resourceName)) this.webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.v(InfoDetailsActivity.TAG, url); boolean ret = false; if (url.contains("github.com/nstCactus")) { InfoDetailsActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nstCactus/Hadra-Trance-Festival"))); ret = true; } else if (url.contains("donate.me")) { InfoDetailsActivity.this .startActivity(new Intent(InfoDetailsActivity.this, DonateActivity.class)); ret = true; } else if (url.contains("mailto:")) { Log.v(url, url); InfoDetailsActivity.this.startActivity(new Intent(Intent.ACTION_SENDTO, Uri.parse(url))); ret = true; } return ret; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { Log.v(InfoDetailsActivity.TAG, "onPageStarted called"); if (shouldOverrideUrlLoading(view, url)) { view.stopLoading(); } } }); this.setContentView(this.webView); }
From source file:org.ciasaboark.tacere.activity.fragment.AboutLicenseFragment.java
private void initViews() { // Show the Up button in the action bar. // setupActionBar(); WebView wv = (WebView) rootView.findViewById(R.id.webView1); String htmlData = ""; try {//from w w w .ja v a 2 s . c o m BufferedReader br = new BufferedReader(new InputStreamReader(context.getAssets().open("license.html"))); String line; while ((line = br.readLine()) != null) { htmlData += line; } } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } int colorInt = getResources().getColor(R.color.link_color); String hexColor = String.format("#%06X", (0xFFFFFF & colorInt)); while (htmlData.contains("LINKCOLOR")) { htmlData = htmlData.replace("LINKCOLOR", hexColor); } wv.loadData(htmlData, "text/html", "UTF8"); // All links should open in the default browser, not this WebView wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } }); wv.setBackgroundColor(0x00000000); wv.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); }
From source file:corp.seedling.news.wordy.DetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.e(TAG, "oncreateview of detail frag ENTER"); Bundle arguments = getArguments();/* w w w . jav a2 s .c o m*/ View rootView = inflater.inflate(R.layout.fragment_detail, container, false); webView = (WebView) rootView.findViewById(R.id.webview); if (arguments != null) { //when detailact Launched on click through intent when in portrait webUrl = arguments.getString("url"); searchText = arguments.getString("keyword"); Log.e(TAG, "oncreateview of detail frag : arguments != null..url = " + webUrl + "\n keyword =" + searchText); } else if (savedInstanceState != null) { //when frag added on orientation change webUrl = savedInstanceState.getString("url"); searchText = savedInstanceState.getString("keyword"); Log.e(TAG, "oncreateview of detail frag : savedInstanceState != null..url = " + webUrl + "\n keyword =" + searchText); } 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); } } }); Log.e(TAG, "detail frag : LOAD URL :"); webView.loadUrl(webUrl); return rootView; }
From source file:jp.co.conit.sss.sp.ex1.fragment.BookViewerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mWeb = (WebView) inflater.inflate(R.layout.fragment_bookviewer, null); mWeb.setWebViewClient(new WebViewClient() { @Override/*from w w w . j a v a 2s .c o m*/ public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); removeDialogFragment(); } }); mSelf = this; return mWeb; }
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 . j a v a 2s. c o 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.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);//from w ww. j av a 2 s .co m 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:org.geometerplus.android.fbreader.network.auth.WebAuthorisationScreen.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_PROGRESS); SQLiteCookieDatabase.init(this); CookieSyncManager.createInstance(getApplicationContext()); CookieManager.getInstance().removeAllCookie(); final Intent intent = getIntent(); final Uri data = intent.getData(); if (data == null || data.getHost() == null) { finish();// ww w . j a va2s.c o m return; } final String completeUrl = intent.getStringExtra(COMPLETE_URL_KEY); OrientationUtil.setOrientation(this, intent); final WebView view = new WebView(this); view.getSettings().setJavaScriptEnabled(true); view.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { setProgress(progress * 100); } }); view.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { setTitle(url); if (url != null && url.startsWith(completeUrl)) { final HashMap<String, String> cookies = new HashMap<String, String>(); final String cookieString = CookieManager.getInstance().getCookie(url); if (cookieString != null) { // cookieString is a string like NAME=VALUE [; NAME=VALUE] for (String pair : cookieString.split(";")) { final String[] parts = pair.split("=", 2); if (parts.length != 2) { continue; } cookies.put(parts[0].trim(), parts[1].trim()); } } storeCookies(data.getHost(), cookies); WebAuthorisationScreen.this.setResult(RESULT_OK); finish(); } } public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ECLAIR_MR1) { // hack for auth problem in android 2.1 handler.proceed(); } else { super.onReceivedSslError(view, handler, error); } } }); setContentView(view); view.loadUrl(intent.getDataString()); }
From source file:com.analysedesgeeks.android.WebFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final View v = inflater.inflate(R.layout.fragment_webview, container, false); webview = (WebView) v.findViewById(R.id.webview); final WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setDefaultZoom(WebSettings.ZoomDensity.FAR); settings.setSupportZoom(true);//from w w w . ja v a 2 s . c o m settings.setBuiltInZoomControls(true); //load a custom user agent //see http://stackoverflow.com/questions/6856814/problems-loading-mobile-twitter-in-webview settings.setUserAgentString( "Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17"); final View loading = v.findViewById(R.id.loading); webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(final WebView view, final String url) { loading.setVisibility(View.GONE); } }); webview.loadUrl(url); return v; }