Example usage for android.webkit WebView setWebViewClient

List of usage examples for android.webkit WebView setWebViewClient

Introduction

In this page you can find the example usage for android.webkit WebView setWebViewClient.

Prototype

public void setWebViewClient(WebViewClient client) 

Source Link

Document

Sets the WebViewClient that will receive various notifications and requests.

Usage

From source file:com.sparkplatform.ui.WebViewActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from ww  w.j  a  v a2s.  c  o  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);

    this.sparkClient = SparkAPI.getInstance();

    Intent intent = getIntent();
    loginHybrid = intent.getBooleanExtra(UIConstants.EXTRA_LOGIN_HYBRID, true);

    WebView webView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.setWebViewClient(new SparkWebViewClient());

    webView.loadUrl(SparkAPI.sparkOpenIdLogoutURL);
}

From source file:de.nico.asura.activities.WebView1.java

private void openWebView() {
    setContentView(R.layout.webview);//from   w w  w.ja  v  a2s  . co  m
    final WebView webView = (WebView) findViewById(R.id.webView_main);
    WebSettings settings = webView.getSettings();
    settings.setDomStorageEnabled(true);
    webView.setWebViewClient(new MyWebViewClient());
    webView.loadUrl(getString(R.string.menu_Web_1_url));
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setJavaScriptEnabled(getResources().getBoolean(R.bool.menu_Web_1_js));
}

From source file:de.nico.asura.activities.WebView2.java

private void openWebView() {
    setContentView(R.layout.webview);//from  w  w  w .j a va 2 s . c o  m
    final WebView webView = (WebView) findViewById(R.id.webView_main);
    WebSettings settings = webView.getSettings();
    settings.setDomStorageEnabled(true);
    webView.setWebViewClient(new MyWebViewClient());
    webView.loadUrl(getString(R.string.menu_Web_2_url));
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setJavaScriptEnabled(getResources().getBoolean(R.bool.menu_Web_2_js));
}

From source file:de.nico.asura.activities.WebView3.java

private void openWebView() {
    setContentView(R.layout.webview);// ww w  .j a va2 s  .co  m
    final WebView webView = (WebView) findViewById(R.id.webView_main);
    WebSettings settings = webView.getSettings();
    settings.setDomStorageEnabled(true);
    webView.setWebViewClient(new MyWebViewClient());
    webView.loadUrl(getString(R.string.menu_Web_3_url));
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setJavaScriptEnabled(getResources().getBoolean(R.bool.menu_Web_3_js));
}

From source file:de.appplant.cordova.plugin.printer.Printer.java

/**
 * Creates the web view client which sets the print document.
 *
 * @param props/*  w w w  .ja v a 2  s .  co m*/
 *      The JSON object with the containing page properties
 */
private void setWebViewClient(JSONObject props) {
    final String docName = props.optString("name", DEFAULT_DOC_NAME);
    final boolean landscape = props.optBoolean("landscape", false);
    final boolean graystyle = props.optBoolean("graystyle", false);

    view.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }

        @Override
        public void onPageFinished(WebView webView, String url) {
            // Get a PrintManager instance
            PrintManager printManager = (PrintManager) cordova.getActivity()
                    .getSystemService(Context.PRINT_SERVICE);

            // Get a print adapter instance
            PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();

            // Get a print builder instance
            PrintAttributes.Builder builder = new PrintAttributes.Builder();

            // The page does itself set its own margins
            builder.setMinMargins(PrintAttributes.Margins.NO_MARGINS);

            builder.setColorMode(
                    graystyle ? PrintAttributes.COLOR_MODE_MONOCHROME : PrintAttributes.COLOR_MODE_COLOR);

            builder.setMediaSize(landscape ? PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE
                    : PrintAttributes.MediaSize.UNKNOWN_PORTRAIT);

            // Create a print job with name and adapter instance
            PrintJob job = printManager.print(docName, printAdapter, builder.build());

            invokeCallbackOnceCompletedOrCanceled(job);

            view = null;
        }
    });
}

From source file:org.feedhenry.saml.fragments.WebViewFragment.java

@Nullable
@Override/*from ww w  .j  av  a2s . c  o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    String ssoStringURL = getArguments().getString(URL);

    View view = View.inflate(getActivity(), R.layout.fragment_webview, null);

    WebView webView = (WebView) view.findViewById(R.id.ssoWebView);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // It' logged
            if (url.endsWith("login/ok")) {
                SAMLActivity activity = (SAMLActivity) getActivity();
                activity.retrieveUserData();
            }
        }
    });
    webView.loadUrl(ssoStringURL);

    return view;
}

From source file:com.hyperkode.friendshare.fragment.TwitterWebViewFragment.java

public void onResume() {
    super.onResume();
    String url = null;//ww  w .  j a  va 2 s . c om
    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:com.appnexus.opensdkapp.DebugFragment.java

private void createDebugAuctionDialog() {
    // hacked to be fullscreen with minHeight. see xml
    RelativeLayout frame = (RelativeLayout) getActivity().getLayoutInflater().inflate(R.layout.dialog_debug,
            null, false);/*from   www  .  j a  v a 2  s .  c o m*/
    View placeholderView = frame.findViewById(R.id.debug_auction_view);

    pullToRefreshView = new PullToRefreshWebView(getActivity().getApplicationContext());
    WebView webView = pullToRefreshView.getRefreshableView();
    webViewClient = new DebugAuctionWebViewClient(webView);
    webView.setWebViewClient(webViewClient);

    pullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<WebView>() {
        @Override
        public void onRefresh(PullToRefreshBase<WebView> refreshView) {
            webViewClient.runAuction();
        }
    });

    pullToRefreshView.setLayoutParams(placeholderView.getLayoutParams());
    // make sure the close button is on top of the webView
    frame.addView(pullToRefreshView, 1);

    debugDialog = new AlertDialog.Builder(getActivity()).setView(frame).create();

    ImageButton close = (ImageButton) frame.findViewById(R.id.debug_btn_close);
    close.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (debugDialog != null)
                debugDialog.dismiss();
        }
    });

    Button email = (Button) frame.findViewById(R.id.debug_btn_email);
    email.setOnClickListener(emailDebugAuctionOnClickListener);
}

From source file:felixwiemuth.lincal.ui.HtmlDialogFragment.java

@NonNull
@SuppressLint("InflateParams")
@Override//from  w w  w.j  av a  2  s  . c  o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View content = LayoutInflater.from(getActivity()).inflate(R.layout.html_dialog_fragment, null);
    webView = (WebView) content.findViewById(R.id.html_dialog_fragment_web_view);
    // Set the WebViewClient (in API <24 have to parse URI manually)
    if (Build.VERSION.SDK_INT >= 24) {
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
                Uri uri = webResourceRequest.getUrl(); // @TargetApi(Build.VERSION_CODES.N_MR1)
                return HtmlDialogFragment.this.loadUrl(webView, uri);
            }
        });
    } else { //TODO test on an API < 24 device
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView webView, String url) {
                Uri uri = Uri.parse(url);
                return HtmlDialogFragment.this.loadUrl(webView, uri);
            }
        });
    }

    indeterminateProgress = (ProgressBar) content
            .findViewById(R.id.html_dialog_fragment_indeterminate_progress);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    Bundle arguments = getArguments();
    // if argument for title is given (string or int referencing a string resource) set the title
    if (arguments.getString(ARG_TITLE) != null) {
        builder.setTitle(arguments.getString(ARG_TITLE));
    } else {
        builder.setTitle(getArguments().getInt(ARG_TITLE)); //TODO error handling
    }
    builder.setView(content);
    return builder.create();
}

From source file:com.todoroo.astrid.taskrabbit.TaskRabbitOAuthLoginActivity.java

@SuppressWarnings("nls")
@Override//from   ww  w  .ja v a2  s . c  o m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    DependencyInjectionService.getInstance().inject(this);

    setContentView(R.layout.oauth_login_activity);
    getSupportActionBar().setTitle(R.string.actfm_OLA_prompt);

    final String urlParam = getIntent().getStringExtra(URL_TOKEN);

    final WebView webView = (WebView) findViewById(R.id.browser);

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setSavePassword(false);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setSupportZoom(true);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            System.err.println("hey error. " + errorCode + ": " + description);
        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.contains("?client_id=") && (url.lastIndexOf("?client_id=") != url.indexOf("?client_id="))) {
                String redirectUrl = url.substring(0, url.lastIndexOf("?client_id="));
                webView.loadUrl(redirectUrl);
                return true;
            }
            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public void onLoadResource(WebView view, String url) {
            super.onLoadResource(view, url);
        }

        @Override
        public void onPageFinished(WebView view, final String url) {
            super.onPageFinished(view, url);
            pd.dismiss();
            if (url.contains("access_token=")) {
                String token = url.substring(url.indexOf("access_token="), url.length());
                Intent intent = new Intent();
                intent.putExtra(DATA_RESPONSE, token);
                setResult(RESULT_OK, intent);
                finish();
            }
        }
    });

    pd = DialogUtilities.progressDialog(this, getString(R.string.DLG_wait));
    webView.loadUrl(urlParam);
}