Example usage for android.webkit WebViewClient WebViewClient

List of usage examples for android.webkit WebViewClient WebViewClient

Introduction

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

Prototype

WebViewClient

Source Link

Usage

From source file:com.elkriefy.android.apps.chubbytabby.activity.WebViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);
    mWebView = (WebView) findViewById(R.id.web_view);
    String url = getIntent().getStringExtra(EXTRA_URL);
    mWebView.setWebViewClient(new WebViewClient());
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.loadUrl(url);//from www .  ja  va 2 s .co  m
    setupActionBar(url);
}

From source file:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WebView webview = new WebView(this);
    setContentView(webview);/*  w ww  . j  a v a 2 s.  c  o m*/
    webview.loadUrl("https://www.java2s.com/");
    webview.setWebViewClient(new WebViewClient());

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
}

From source file:com.nobr.android.questr.controllers.other.LicensesDialogFragment.java

@NonNull
@Override/*from   w  ww  . jav a 2  s  .c  om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_licenses, null);
    ButterKnife.inject(this, view);

    mWebView.loadUrl(BaseConstants.FILE_ANDROID_ASSET_OPEN_SOURCE_LICENSES_HTML);
    mWebView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            mImageView.setVisibility(View.VISIBLE);
        }
    });

    return new AlertDialog.Builder(getActivity(), R.style.BaseDialog).setView(view).create();
}

From source file:com.ambergleam.android.governmentsalaries.dialog.LicensesDialogFragment.java

@NonNull
@Override/*from   w  ww.  j a  v a  2 s. co  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_licenses, null);
    ButterKnife.bind(this, view);

    mWebView.loadUrl(BaseConstants.FILE_ANDROID_ASSET_OPEN_SOURCE_LICENSES_HTML);
    mWebView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            mImageView.setVisibility(View.VISIBLE);
        }
    });

    return new AlertDialog.Builder(getActivity(), R.style.BaseDialog).setView(view).create();
}

From source file:com.salesforce.marketingcloud.android.demoapp.ui.OriginalDocsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView markdownView = (WebView) findViewById(R.id.markdownView);
    markdownView.getSettings().setJavaScriptEnabled(true);
    markdownView.loadUrl(getResources().getString(R.string.official_remote_url));
    markdownView.setWebViewClient(new WebViewClient() {
        @Override/*from  w ww.  jav  a2s.c  o m*/
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return false;
        }
    });

    MarketingCloudSdk.requestSdk(new MarketingCloudSdk.WhenReadyListener() {
        @Override
        public void ready(MarketingCloudSdk marketingCloudSdk) {
            marketingCloudSdk.getAnalyticsManager().trackPageView("data://OriginalDocsActivity",
                    getResources().getString(R.string.official_remote_url), null, null);
        }
    });
}

From source file:com.microsoft.azure.engagement.fragment.AboutFragment.java

@Nullable
@Override//  ww w  . j  a  va2 s  . c om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_about, container, false);

    final WebView webView = (WebView) view.findViewById(R.id.webView);
    webView.loadUrl("file:///android_asset/html/about.html");
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            final String eventName;

            switch (url) {
            case "file:///android_asset/html/smartnsoft":
                eventName = null;
                url = getString(R.string.smartnsoft_url);
                break;
            case "file:///android_asset/html/github":
                eventName = "click_source_link";
                url = getString(R.string.github_url);
                break;
            case "file:///android_asset/html/application_license":
                eventName = "click_application_license_link";
                url = getString(R.string.application_license_url);
                break;
            case "file:///android_asset/html/third_party_notices":
                eventName = "click_3rd_party_notices_link";
                url = getString(R.string.third_party_notices_url);
                break;
            default:
                eventName = null;
                break;
            }

            Log.d(AboutFragment.TAG, "String url clicked on: " + url);

            CustomTabActivityHelper.openCustomTab(getActivity(), Uri.parse(url), eventName, null, null);

            return true;
        }
    });

    AzmeTracker.startActivity(getActivity(), "about");

    return view;
}

From source file:com.google.android.apps.gutenberg.LicensesFragment.java

@NonNull
@Override//from  w  w w . j  av a  2s .  com
public Dialog onCreateDialog(Bundle savedInstanceState) {
    WebView webView = new WebView(getActivity());
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!TextUtils.isEmpty(url) && Patterns.WEB_URL.matcher(url).matches()) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            } else {
                return false;
            }
        }
    });
    webView.loadUrl("file:///android_asset/licenses.html");
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.licenses).setView(webView)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                }
            }).create();
}

From source file:org.h4des.alertrmobilemanager.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this.webView = (WebView) findViewById(R.id.webView);

    // clear cache
    this.webView.clearCache(true);

    // enable JavaScript
    this.webView.getSettings().setJavaScriptEnabled(true);

    this.webView.setWebChromeClient(new WebChromeClient());

    // create own WebViewClient
    this.webView.setWebViewClient(new WebViewClient() {

        // for debugging in the emulator only
        // install your own certificate on the android device via copying your cert.cer
        // on the sd card and add it in the security options
        //@Override
        //public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {            
        //    handler.proceed();
        //}//from  w w  w .  j ava 2s . c  o m

        // when using basic http authentication
        // enter your own credentials
        @Override
        public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host,
                String realm) {

            // get username and password from the settings
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            String username = preferences.getString("username", "None");
            String password = preferences.getString("password", "None");

            // use credentials from the settings
            handler.proceed(username, password);
        }
    });

    // get URL from the settings
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
    String url = preferences.getString("url", "None");

    this.webView.loadUrl(url);

    // focus webView
    this.webView.requestFocus(View.FOCUS_DOWN);
}

From source file:local.maciejkrysztofiak.stackviewer.WebViewFragment.java

/**
 * Called to instantiate the view. Creates and returns the WebView.
 *///from  w  ww.  jav  a  2  s  .com
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mWebView != null) {
        mWebView.destroy();
    }
    mWebView = new WebView(getActivity());
    mIsWebViewAvailable = true;
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
    mWebView.loadUrl(getArguments().getString(ResultsActivity.EXTRA_URL));
    return mWebView;
}

From source file:com.hhs.hfnavigator.slidingtabs.harbinger.SportsFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_webview, null);

    WebView webView = (WebView) root.findViewById(R.id.webView);
    if (webView != null) {
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("http://www.harbingernews.net/sports");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setBuiltInZoomControls(true);
    }//  www .j a  v  a  2  s  . co  m
    return root;
}