List of usage examples for android.webkit WebViewClient WebViewClient
WebViewClient
From source file:shreckye.scu.youth.HomepageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_homepage, container, false); final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) view .findViewById(R.id.swipe_refresh_layout); AppUtil.setupSwipeRefreshLayoutColors(swipeRefreshLayout); homepageWebView = (WebView) view.findViewById(R.id.homepage_web_view); WebSettings webSettings = homepageWebView.getSettings(); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); webSettings.setJavaScriptEnabled(true); homepageWebView.loadUrl(HOMEPAGE_URL); homepageWebView.setWebViewClient(new WebViewClient() { @Override// ww w.j a v a 2s .c o m public void onPageStarted(WebView view, String url, Bitmap favicon) { swipeRefreshLayout.setRefreshing(true); } @Override public void onPageFinished(WebView view, String url) { swipeRefreshLayout.setRefreshing(false); } }); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refreshAsync(); } }); FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AppUtil.openWebPageAndShowSnackbarIfFail(HomepageFragment.this, HOMEPAGE_URL, getView()); } }); return view; }
From source file:com.hyperkode.friendshare.fragment.TwitterWebViewFragment.java
public void onResume() { super.onResume(); String url = null;/*w ww .j ava 2 s . c o m*/ FragmentManager fragmentManager = TwitterWebViewFragment.this.getActivity().getSupportFragmentManager(); Bundle args = this.getArguments(); if (args != null) { url = args.getString("URL"); loginFragment = (LoginFragment) fragmentManager.getFragment(args, "LoginFragment"); } WebView webView = (WebView) mThisActivity.findViewById(R.id.twitter_webview); WebSettings webSettings = webView.getSettings(); webSettings.setSavePassword(false); webSettings.setSaveFormData(false); webSettings.setJavaScriptEnabled(true); webSettings.setSupportZoom(false); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.contains(getString(R.string.TWITTER_CALLBACK_URL))) { Uri uri = Uri.parse(url); String oauthVerifier = uri.getQueryParameter("oauth_verifier"); if (loginFragment != null) { loginFragment.setOAuthVerifierResult(oauthVerifier); } return true; } return false; } }); webView.loadUrl(url); }
From source file:ph.com.globe.connect.AuthenticationActivity.java
/** * On activity create process./*w w w.j a v a 2 s. c om*/ * * @param savedInstanceState instance state */ @Override public void onCreate(Bundle savedInstanceState) { // call base create super.onCreate(savedInstanceState); // initialize web view final WebView webview = new WebView(this); // set content view of the activity setContentView(webview); // get the app id from intent final String appId = getIntent().getStringExtra("app_id"); // get the app secret from intent final String appSecret = getIntent().getStringExtra("app_secret"); // set web view client webview.setWebViewClient(new WebViewClient() { /** * Let's catch all url changes. * * @param view current view * @param url current url * @return boolean */ @SuppressWarnings("deprecation") @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // parse the uri final Uri uri = Uri.parse(url); // are we still on globe labs? if (uri.toString().indexOf(ROOT_URL) != 0) { // get the code String code = uri.getQueryParameter("code"); // get access token request try { getAccessToken(appId, appSecret, code); } catch (ApiException | HttpRequestException e) { e.printStackTrace(); } return false; } // load uri view.loadUrl(uri.toString()); return false; } /** * Let's catch all url changes. * * @param view current view * @param request web resource request * @return boolean */ @TargetApi(Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { // parse the uri final Uri uri = Uri.parse(request.getUrl().toString()); // are we still on globe labs? if (uri.toString().indexOf(ROOT_URL) != 0) { // get the code String code = uri.getQueryParameter("code"); // get access token request try { getAccessToken(appId, appSecret, code); } catch (ApiException | HttpRequestException e) { e.printStackTrace(); } return false; } // load uri view.loadUrl(uri.toString()); return false; } }); try { // set dialog url String DIALOG_URL = this.buildUrl(this.DIALOG_URL, appId); // load the url webview.loadUrl(DIALOG_URL); } catch (ApiException e) { e.printStackTrace(); } }
From source file:at.alladin.rmbt.android.help.RMBTHelpFragment.java
/** * *///from w ww . j av a 2s. c om @SuppressLint("SetJavaScriptEnabled") @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final Bundle args = getArguments(); String url = args.getString(ARG_URL); if (url == null || url.length() == 0) url = this.getString(R.string.url_help); final Activity activity = getActivity(); final WebView webview = new WebView(activity) { @Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && canGoBack()) { goBack(); return true; } return super.onKeyDown(keyCode, event); } }; final WebSettings webSettings = webview.getSettings(); final String userAgent = AppConstants.getUserAgentString(getActivity()); if (userAgent != null) { webSettings.setUserAgentString(userAgent); } webSettings.setJavaScriptEnabled(true); webview.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl) { Log.w(getTag(), "error code:" + errorCode); Log.d(getTag(), "error desc:" + description); Log.d(getTag(), "error url:" + failingUrl); webview.loadUrl("file:///android_res/raw/error.html"); super.onReceivedError(view, errorCode, description, failingUrl); } }); if (!url.matches("^https?://.*")) { final String protocol = ConfigHelper.isControlSeverSSL(activity) ? "https" : "http"; url = protocol + "://" + url; } webview.loadUrl(url); return webview; }
From source file:justforcommunity.radiocom.fragments.HomePageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_home, container, false); mActivity = (Home) getActivity();/*from ww w. ja v a 2s .com*/ mContext = getContext(); try { station.getHistory().replace("<body", "<body style=\'text-align:justify;color:gray;background-color:black;\'"); station.getHistory().replaceAll("style=\".+?\"", ""); } catch (Exception e) { } WebView wb = (WebView) v.findViewById(R.id.history_frame); wb.setBackgroundColor(Color.WHITE); // String fontscript = "<style>@font-face {font-family : 'HelveticaNeue-Light';src:url('file:///android_asset/fonts/"+VariablesGlobalesActivity.GENERICFONT+"');}</style>"; String fontscript = ""; String script = "<style type='text/css' >p{width:100%;}img{width:100%;height:auto;-webkit-transform: translate3d(0px,0px,0px);}a,h1,h2,h3,h4,h5,h6{color:" + GlobalValues.colorHTML + ";}div,p,span,a {max-width: 100%;}iframe{width:100%;height:auto;}</style>"; wb.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } }); wb.loadDataWithBaseURL("", "<html><head>" + fontscript + script + "</head><body style=\"font-family:HelveticaNeue-Light; \">" + station.getHistory() + "</body></html>", "text/html", "utf-8", ""); wb.getSettings().setDomStorageEnabled(true); wb.getSettings().setJavaScriptEnabled(true); App application = (App) getActivity().getApplication(); Tracker mTracker = application.getDefaultTracker(); mTracker.setScreenName(getString(R.string.home_view)); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); return v; }
From source file:com.centurylink.mdw.mobile.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* w ww . j av a 2 s. c om*/ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); settings = new Settings(getApplicationContext()); webView = (WebView) findViewById(R.id.webview); webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowUniversalAccessFromFileURLs(true); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setSupportZoom(true); // webView.getSettings().setBuiltInZoomControls(true); // allow debugging with chrome dev tools WebView.setWebContentsDebuggingEnabled(true); // do not cache in debug webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); webView.getSettings().setAppCacheEnabled(false); webView.clearCache(true); }
From source file:net.olejon.mdapp.MedicationFelleskatalogenFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override/*www .j a va2 s. 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:com.mario22gmail.license.nfc_project.FragmentBrowser.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_browser, container, false); mWebview = (WebView) v.findViewById(R.id.webViewFb); Intent myIntent = new Intent("fragment.setTitle"); myIntent.putExtra("Title", "Browser"); NavigationDrawerActivity.getAppContext().sendBroadcast(myIntent); urlEditText = (EditText) v.findViewById(R.id.searchForGoogle); EditTextFocusChangeListner textLisner = new EditTextFocusChangeListner(getContext(), R.id.searchForGoogle); urlEditText.setOnFocusChangeListener(textLisner); urlEditText.setSingleLine();/*from w w w .j a v a 2s . com*/ urlEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); String query = urlEditText.getText().toString(); if (!query.isEmpty()) { String url = "https://www.google.com/search?q=" + query; mWebview.loadUrl(url); mWebview.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); } } return true; } }); final Button searchButton = (Button) v.findViewById(R.id.searchOnGoogleButton); searchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); String query = urlEditText.getText().toString(); if (!query.isEmpty()) { String url = "https://www.google.com/search?q=" + query; mWebview.loadUrl(url); mWebview.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); } } }); if (!js.equals("") && !url.equals("")) { OpenWebSite(url, js); Log.i("nfc_debug", "A trecut"); } return v; // inflater.inflate(R.layout.fragment_browser, container, false); }
From source file:de.dreier.mytargets.features.scoreboard.ScoreboardActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.activity_scoreboard); Intent intent = getIntent();/* ww w . j ava 2 s . c om*/ mTraining = intent.getLongExtra(TRAINING_ID, -1); mRound = intent.getLongExtra(ROUND_ID, -1); binding.webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } @Override public void onPageFinished(WebView view, String url) { pageLoaded = true; supportInvalidateOptionsMenu(); } }); ToolbarUtils.showHomeAsUp(this); }
From source file:yet.another.hackernews.reader.ViewFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); menuBrowser = (WebView) getSherlockActivity().findViewById(R.id.view_webview); final ProgressBar progressBar = (ProgressBar) getSherlockActivity().findViewById(R.id.view_progress); webviewSettings();/*from w ww .j av a 2 s .c om*/ menuBrowser.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { // Hide dialog on finished if (progress >= 100) { progressBar.setVisibility(View.GONE); } else { progressBar.setProgress(progress); } } }); menuBrowser.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { progressBar.setVisibility(View.GONE); Toast.makeText(getActivity().getApplicationContext(), R.string.error, Toast.LENGTH_SHORT).show(); } }); final Bundle recieveArgs = this.getSherlockActivity().getIntent().getExtras(); if (recieveArgs != null) { try { news = new News(new JSONObject(recieveArgs.getString("NewsObject"))); } catch (JSONException e) { } update(progressBar); } }