Example usage for android.webkit WebView loadUrl

List of usage examples for android.webkit WebView loadUrl

Introduction

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

Prototype

public void loadUrl(String url) 

Source Link

Document

Loads the given URL.

Usage

From source file:com.sourcey.materiallogindemo.MainActivity.java

private void DialogMap() {
    View dialogBoxView = View.inflate(this, R.layout.activity_map, null);
    final WebView map = (WebView) dialogBoxView.findViewById(R.id.webView);

    String url = getString(R.string.url_map) + "index.php?poinFrom=" + txtStart.getText().toString().trim()
            + "&poinTo=" + txtEnd.getText().toString().trim();

    map.getSettings().setLoadsImagesAutomatically(true);
    map.getSettings().setJavaScriptEnabled(true);
    map.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    map.loadUrl(url);

    AlertDialog.Builder builderInOut = new AlertDialog.Builder(this);
    builderInOut.setTitle("Map");
    builderInOut.setMessage("").setView(dialogBoxView).setCancelable(false)
            .setPositiveButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();//from ww  w  .j  ava 2s  .co m
                }
            }).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  w  w  w.  ja v  a 2s  .  c  o m*/
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                FileChooserParams fileChooserParams) {
            SETools.uploadMessage = filePathCallback;
            pickFile();
            return true;
        }

    });
    webView.loadUrl(url);
}

From source file:com.timrae.rikaidroid.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mWebView = (WebView) findViewById(R.id.webview);
    mWebClient = new WebViewClient() {
        @Override/* w w w  . j a va  2  s.  com*/
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Uri uri = Uri.parse(url);
            if (uri.getScheme().equals("lookup")) {
                String query = uri.getHost();
                Intent i = new Intent(AEDICT_INTENT);
                i.putExtra("kanjis", query);
                i.putExtra("showEntryDetailOnSingleResult", true);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);
                view.reload();
                return true;
            }

            else {
                view.loadUrl(url);
            }
            return true;
        }
    };
    mWebView.setWebViewClient(mWebClient);
    mEditText = (EditText) findViewById(R.id.search_src_text);
    mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
    if (mProgressBar != null) {
        mProgressBar.setVisibility(View.VISIBLE);
    }

}

From source file:ca.rmen.android.networkmonitor.app.log.LogActivity.java

/**
 * Read the data from the DB, export it to an HTML file, and load the HTML file in the WebView.
 *///from  ww w . jav  a 2  s.co m
private void loadHTMLFile() {
    Log.v(TAG, "loadHTMLFile");
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
    progressBar.setVisibility(View.VISIBLE);
    startRefreshIconAnimation();
    AsyncTask<Void, Void, File> asyncTask = new AsyncTask<Void, Void, File>() {

        @Override
        protected File doInBackground(Void... params) {
            Log.v(TAG, "loadHTMLFile:doInBackground");
            // Export the DB to the HTML file.
            HTMLExport htmlExport = new HTMLExport(LogActivity.this, false);
            int recordCount = NetMonPreferences.getInstance(LogActivity.this).getFilterRecordCount();
            return htmlExport.export(recordCount, null);
        }

        @SuppressLint("SetJavaScriptEnabled")
        @Override
        protected void onPostExecute(File result) {
            Log.v(TAG, "loadHTMLFile:onPostExecute, result=" + result);
            if (isFinishing()) {
                Log.v(TAG, "finishing, ignoring loadHTMLFile result");
                return;
            }
            if (result == null) {
                Toast.makeText(LogActivity.this, R.string.error_reading_log, Toast.LENGTH_LONG).show();
                return;
            }
            // Load the exported HTML file into the WebView.
            mWebView = (WebView) findViewById(R.id.web_view);
            // Save our current horizontal scroll position so we can keep our
            // horizontal position after reloading the page.
            final int oldScrollX = mWebView.getScrollX();
            mWebView.getSettings().setUseWideViewPort(true);
            mWebView.getSettings().setBuiltInZoomControls(true);
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.loadUrl("file://" + result.getAbsolutePath());
            mWebView.setWebViewClient(new WebViewClient() {

                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    super.onPageStarted(view, url, favicon);
                    Log.v(TAG, "onPageStarted");
                    // Javascript hack to scroll back to our old X position.
                    // http://stackoverflow.com/questions/6855715/maintain-webview-content-scroll-position-on-orientation-change
                    if (oldScrollX > 0) {
                        String jsScrollX = "javascript:window:scrollTo(" + oldScrollX
                                + " / window.devicePixelRatio,0);";
                        view.loadUrl(jsScrollX);
                    }
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    progressBar.setVisibility(View.GONE);
                    stopRefreshIconAnimation();
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    Log.v(TAG, "url: " + url);
                    // If the user clicked on one of the column names, let's update
                    // the sorting preference (column name, ascending or descending order).
                    if (url.startsWith(HTMLExport.URL_SORT)) {
                        NetMonPreferences prefs = NetMonPreferences.getInstance(LogActivity.this);
                        SortPreferences oldSortPreferences = prefs.getSortPreferences();
                        // The new column used for sorting will be the one the user tapped on.
                        String newSortColumnName = url.substring(HTMLExport.URL_SORT.length());
                        SortOrder newSortOrder = oldSortPreferences.sortOrder;
                        // If the user clicked on the column which is already used for sorting,
                        // toggle the sort order between ascending and descending.
                        if (newSortColumnName.equals(oldSortPreferences.sortColumnName)) {
                            if (oldSortPreferences.sortOrder == SortOrder.DESC)
                                newSortOrder = SortOrder.ASC;
                            else
                                newSortOrder = SortOrder.DESC;
                        }
                        // Update the sorting preferences (our shared preference change listener will be notified
                        // and reload the page).
                        prefs.setSortPreferences(new SortPreferences(newSortColumnName, newSortOrder));
                        return true;
                    }
                    // If the user clicked on the filter icon, start the filter activity for this column.
                    else if (url.startsWith(HTMLExport.URL_FILTER)) {
                        Intent intent = new Intent(LogActivity.this, FilterColumnActivity.class);
                        String columnName = url.substring(HTMLExport.URL_FILTER.length());
                        intent.putExtra(FilterColumnActivity.EXTRA_COLUMN_NAME, columnName);
                        startActivityForResult(intent, REQUEST_CODE_FILTER_COLUMN);
                        return true;
                    } else {
                        return super.shouldOverrideUrlLoading(view, url);
                    }
                }
            });
        }
    };
    asyncTask.execute();
}

From source file:io.vit.vitio.Fragments.CampusMapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.campusmap_fragment, container, false);
    setTransitions();/* w w w.  j ava  2s  .  c  om*/
    WebView view = (WebView) rootView.findViewById(R.id.img_map);
    view.setVisibility(View.GONE);

    view.getSettings().setBuiltInZoomControls(true);

    view.getSettings().setDisplayZoomControls(false);

    view.getSettings().setLoadWithOverviewMode(true);

    view.getSettings().setUseWideViewPort(true);

    view.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            try {
                view.setVisibility(View.VISIBLE);
            } catch (Exception ignore) {
            }

        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            try {
            } catch (Exception ignore) {
            }

        }
    });

    view.loadUrl("file:///android_asset/vit_map.jpg");

    return rootView;
}

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

public void onResume() {
    super.onResume();
    String url = null;//from w w  w . ja  v a  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:org.safegees.safegees.gui.view.MainActivity.java

private void start() {
    if (DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)) != null
            && DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)).length() > 0) {
        shareDataWithServer();//from   w ww .j  a v a2  s .  c  o m
    } else {

        /* TEST
        if(DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)) != null && DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)).length()>0){
        launchMainActivity();
        }else{
        //Start the loggin for result
        Intent loginInt = new Intent(this, LoginActivity.class);
        startActivityForResult(loginInt, 1);
        }*/

        if (Connectivity.isNetworkAvaiable(this) || StoredDataQuequesManager.getAppUsersMap(this).size() != 0) {

            final MainActivity mainActivity = this;

            //Download data
            this.adviceUser.setText(getResources().getString(R.string.splash_advice_download_info_hub));

            //Test
            //Not here at final
            final WebView webView = (WebView) this.findViewById(R.id.webview_info_pre_cache);
            final ArrayList<String> infoWebUrls = WebViewInfoWebDownloadController.getInfoUrlsArrayList();
            webView.setWebViewClient(new WebViewClient() {

                @Override
                public void onPageFinished(WebView view, String url) {
                    if (infoWebUrls.size() > 0) {
                        String nextUrl = infoWebUrls.get(0);
                        infoWebUrls.remove(nextUrl);
                        webView.loadUrl(nextUrl);
                    } else {
                        //Only one time
                        DATA_STORAGE.putBoolean(mainActivity.getResources().getString(R.string.KEY_INFO_WEB),
                                true);
                        //Start the loggin for result
                        Intent loginInt = new Intent(mainActivity, LoginActivity.class);
                        startActivityForResult(loginInt, 1);
                    }
                }
            });

            String nextUrl = infoWebUrls.get(0);
            infoWebUrls.remove(nextUrl);
            webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.setWebChromeClient(new WebChromeClient());

            if (StoredDataQuequesManager.getAppUsersMap(mainActivity).size() == 0
                    && !DATA_STORAGE.getBoolean(getResources().getString(R.string.KEY_INFO_WEB))) {
                webView.loadUrl(nextUrl);
            } else {
                if (DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)) != null
                        && DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL))
                                .length() > 0) {
                    launchMainActivity();
                } else {
                    //Start the loggin for result
                    Intent loginInt = new Intent(mainActivity, LoginActivity.class);
                    startActivityForResult(loginInt, 1);
                }
            }

        } else {
            setNoInternetAdvice(this);
        }
    }
}

From source file:org.schabi.newpipe.ReCaptchaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recaptcha);

    // Set return to Cancel by default
    setResult(RESULT_CANCELED);/*from  ww w .  j av  a 2  s .c om*/

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.reCaptcha_title);
        actionBar.setDisplayShowTitleEnabled(true);
    }

    WebView myWebView = (WebView) findViewById(R.id.reCaptchaWebView);

    // Enable Javascript
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    ReCaptchaWebViewClient webClient = new ReCaptchaWebViewClient(this);
    myWebView.setWebViewClient(webClient);

    // Cleaning cache, history and cookies from webView
    myWebView.clearCache(true);
    myWebView.clearHistory();
    android.webkit.CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.removeAllCookies(new ValueCallback<Boolean>() {
            @Override
            public void onReceiveValue(Boolean aBoolean) {
            }
        });
    } else {
        cookieManager.removeAllCookie();
    }

    myWebView.loadUrl(YT_URL);
}

From source file:com.facebook.internal.FacebookWebFallbackDialog.java

@Override
public void dismiss() {
    WebView webView = getWebView();

    if (isListenerCalled() || webView == null || !webView.isShown()) {
        // If the listener has been called, or if the WebView isn't visible, we cannot give the dialog a chance
        // to respond. So defer to the parent implementation.
        super.dismiss();
        return;// w  ww.j ava 2 s  .  com
    }

    // If we have already notified the dialog to close, then ignore this request to dismiss. The timer will
    // honor the request.
    if (waitingForDialogToClose) {
        return;
    }
    waitingForDialogToClose = true;

    // Now fire off the event that will tell the dialog to wind down.
    String eventJS = "(function() {" + "  var event = document.createEvent('Event');"
            + "  event.initEvent('fbPlatformDialogMustClose',true,true);" + "  document.dispatchEvent(event);"
            + "})();";
    webView.loadUrl("javascript:" + eventJS);

    // Set up a timeout for the dialog to respond. If the timer expires, we need to honor the user's desire to
    // dismiss the dialog.
    Handler handler = new Handler(Looper.getMainLooper());
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (!isListenerCalled()) {
                // If we get here, then the dialog did not close quickly enough. So we need to honor the user's
                // wish to cancel.
                sendCancelToListener();
            }
        }
    }, OS_BACK_BUTTON_RESPONSE_TIMEOUT_MILLISECONDS);
}

From source file:net.sarangnamu.scroll_capture.MainActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from   w w  w. j  a v a2 s .  c om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        WebView.enableSlowWholeDocumentDraw();
    }

    setContentView(R.layout.activity_main);

    ButterKnife.bind(this);

    mWeb.loadUrl("http://aucd29.tistory.com/m");
    BkCfg.hideKeyboard(mWeb);

    mWeb.getSettings().setJavaScriptEnabled(true);
    mWeb.getSettings().setDomStorageEnabled(true);
    mWeb.getSettings().setLoadWithOverviewMode(true);
    mWeb.getSettings().setUseWideViewPort(true);
    mWeb.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (mLog.isDebugEnabled()) {
                String log = "";
                log += "===================================================================\n";
                log += "WEBPAGE LOADED\n";
                log += "===================================================================\n";
                mLog.debug(log);
            }

            if (url.equals("http://aucd29.tistory.com/")) {
                mProgress.setVisibility(View.GONE);
                //                    mFab.animate().alpha(1);
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);

            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

            if (url.equals("http://aucd29.tistory.com/")) {
                mProgress.setVisibility(View.VISIBLE);
                //                    mFab.animate().alpha(0);
            }
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            if (mLog.isErrorEnabled()) {
                String log = "";
                log += "===================================================================\n";
                log += "ERROR: \n";
                log += "===================================================================\n";
                mLog.error(log);
            }
            super.onReceivedError(view, request, error);
        }
    });

}