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.hhs.hfnavigator.slidingtabs.harbinger.LiveStreamFragment.java

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

    progressWheel = (ProgressWheel) root.findViewById(R.id.webViewProgress);

    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe);
    swipeRefreshLayout.setEnabled(false);
    progressWheel.spin();/*from w w w  .j  a  v  a 2s . co m*/

    final WebView webView = (WebView) root.findViewById(R.id.webView);
    if (webView != null) {
        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                progressWheel.stopSpinning();
                webView.setVisibility(View.VISIBLE);
            }
        });
        webView.loadUrl("http://www.harbingernews.net/livestreams");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);

    }
    webView.setVisibility(View.INVISIBLE);
    return root;
}

From source file:com.rizal.lovins.smartkasir.activity.SettingsActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from w w  w  .  j a v a  2s. c om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setTitle("Settings");

    WebView mWebView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.getSettings().setBuiltInZoomControls(false);
    mWebView.getSettings().setDisplayZoomControls(false);
    mWebView.loadUrl("file:///android_asset/license/settings.html");

    CustomGridViewSettingAdapter adapterViewAndroid = new CustomGridViewSettingAdapter(SettingsActivity.this,
            gridViewString, gridViewImageId);
    androidGridView = (GridView) findViewById(R.id.grid_view_image_text);
    androidGridView.setAdapter(adapterViewAndroid);
    androidGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                startActivity(new Intent(SettingsActivity.this, AboutActivity.class));
                break;
            case 1:
                startActivity(new Intent(SettingsActivity.this, DeveloperActivity.class));
                break;
            case 2:
                startActivity(new Intent(SettingsActivity.this, LicenseActivity.class));
                break;
            case 3:
                startActivity(new Intent(SettingsActivity.this, MapsActivity.class));
                break;
            case 4:
                location();
                break;
            }
        }
    });

}

From source file:jp.mydns.sys1yagi.android.printingframeworksample.html.HtmlPrintActivity.java

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

    final WebView webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override// w  w w.  j a v  a  2  s.  c om
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
    webView.loadUrl("http://visible-true.blogspot.jp/");

    findViewById(R.id.print_button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            printHtml(webView.getTitle() + ".pdf", webView);
        }
    });
}

From source file:com.work.nishant.publicchannel.StartHere.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*from ww w .jav  a 2  s.com*/
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_editProfile) {

        Intent it = new Intent(StartHere.this, Profile.class);
        startActivity(it);

    } else if (id == R.id.nav_fb) {

        sp = getApplicationContext().getSharedPreferences("shared", 0);
        ed = sp.edit();

        if (sp.getString("facebook", "no").contentEquals("yes")) {
            Intent it = new Intent(StartHere.this, FbDone.class);
            startActivity(it);
        } else {

            Intent it = new Intent(StartHere.this, FbLogin.class);
            startActivity(it);
        }

    } else if (id == R.id.nav_Skill) {
        Intent it = new Intent(StartHere.this, SkillPost.class);
        startActivity(it);

    } else if (id == R.id.nav_developer) {
        Intent it = new Intent(StartHere.this, AboutMe.class);
        startActivity(it);

    } else if (id == R.id.nav_Attendance) {

        Intent it = new Intent(StartHere.this, Attendance.class);
        startActivity(it);

    } else if (id == R.id.nav_share) {

        try {
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_SUBJECT, "Public Channel");
            String sAux = "\nAn android app for UPES students to check their attendance, timetable and search other students\n\n";
            sAux = sAux + "https://play.google.com/store/apps/details?id=com.work.nishant.publicchannel \n\n";
            i.putExtra(Intent.EXTRA_TEXT, sAux);
            startActivity(Intent.createChooser(i, "choose one"));
        } catch (Exception e) { //e.toString();
        }

    } else if (id == R.id.nav_logout) {
        ed.clear();
        ed.commit();

        eco.clear();
        eco.commit();

        Intent it = new Intent(StartHere.this, MainActivity.class);
        startActivity(it);
        finish();
    } else if (id == R.id.nav_opensource) {

        WebView view = (WebView) LayoutInflater.from(this).inflate(R.layout.license, null);
        view.loadUrl("file:///android_asset/open.html");
        view.getSettings().setUseWideViewPort(true);
        view.getSettings().setBuiltInZoomControls(true);
        AlertDialog.Builder mAlertDialog = new AlertDialog.Builder(this,
                R.style.Theme_AppCompat_Light_Dialog_Alert).setTitle("Open Source License").setView(view)
                        .setPositiveButton(android.R.string.ok, null);
        AlertDialog alert = mAlertDialog.create();
        alert.show();

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.nxt.yn.app.ui.activity.WebViewUrlActivity.java

private void initData() {
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override// w ww  .  j  ava2  s  .co m
        public void onRefresh() {
            handler.sendEmptyMessageDelayed(0, 1000);
        }
    });
    refreshLayout.setColorSchemeResources(R.color.title_color, R.color.title_color, R.color.title_color,
            R.color.title_color);

    newsid = getIntent().getIntExtra("newsid", 0);
    LogUtils.i("ssss", "newsid---------->" + newsid);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setSupportMultipleWindows(false);
    webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setDatabaseEnabled(true);

    /*  if(Settings.isNightMode) {
    webView.setBackgroundColor(ContextCompat.getColor(this, R.color.night_primary));
     }*/
    if (EaseCommonUtils.isWiFi(this) == false) {
        webView.getSettings()
                .setBlockNetworkImage(ZPreferenceUtils.getPrefBoolean(Settings.NO_PIC_MODE, false));
    } else {
        // fix issue #13
        webView.getSettings().setBlockNetworkImage(false);
    }
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            refreshLayout.setRefreshing(false);
            super.onPageFinished(view, url);
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            view.loadUrl("file:///android_asset/error.html");
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            view.loadUrl("file:///android_asset/error.html");
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (isfirsarload) {
                isfirsarload = false;
                return false;
            } else {
                startActivity(new Intent(WebViewUrlActivity.this, WebViewUrlActivity.class)
                        .putExtra("title", getString(R.string.app_name)).putExtra("url", url));
            }
            return true;
        }
    });

}

From source file:in.rab.bildkort.ImageFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from   w w  w  .j  a va2 s.  c o m
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mWebView = (WebView) getView().findViewById(R.id.webView);
    final ProgressBar progress = (ProgressBar) getView().findViewById(R.id.image_progress);
    mWebView.setWebChromeClient(new WebChromeClient());
    final WebSettings settings = mWebView.getSettings();

    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setJavaScriptEnabled(true);

    // We replace the src urls in imagepicker.js::init(), so don't load
    // images twice.
    settings.setBlockNetworkImage(true);

    mWebView.setInitialScale(100);

    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            if (Objects.equals(url, GSTATIC_SERVER)) {
                settings.setBlockNetworkImage(false);

                progress.setVisibility(View.GONE);
                mWebView.setVisibility(View.VISIBLE);
            } else {
                view.loadUrl("javascript:" + getImagePickerJs() + "getPickerHtml();");
            }
        }
    });

    mWebView.addJavascriptInterface(new WcmJsObject(), "wcm");
    mWebView.loadUrl("https://www.google.se/search?tbm=isch&q=" + getWord());
}

From source file:it.clipart.swipehtmlpageapp.IntroFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.intro_screen, container, false);

    View controlView = rootView.findViewById(R.id.introFinishControls);

    /*/*from   w w w . jav a 2s  . c o m*/
     If we are on the last page of the intro, we show a special controlView that lets the user
     select if they ever want to see this again, and continue on to the main part of the app.
            
     Se si  nell'ultima pagina dell'intro, verr mostrato uno speciale controlView che lascia l'utente
     se vuole vederlo da capo o proseguire nella parte principale.
     */

    if (item == MyWebActivity.NUM_INTRO_PAGES) {
        /* Se  l'ultima pagina rende visibile il layout contenente il controllo che
        lancia la guida vera e propria
        - Il fatto che sia l'ultima pagina non viene creato un successivo Fragment e quindi
        lo swipe non  pi attivo.
        */
        controlView.setVisibility(View.VISIBLE);
        // Controlla la checkBox "Non mostrare pi"
        rootView.findViewById(R.id.checkBox).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dontShowAgainTapped();
            }
        });

    }
    // Se si torna indietro ( ad esempio ) rende invisibile il controllo di cui sopra
    else {
        controlView.setVisibility(View.INVISIBLE);
    }

    WebView webview = (WebView) rootView.findViewById(R.id.webView);
    android.webkit.WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webview.getSettings().setLoadsImagesAutomatically(true);
    webview.addJavascriptInterface(new WebAppInterface(this.activity), "Android");
    webview.loadUrl("file:///android_asset/intro" + item + ".html");
    Log.d(TAG, "Caricata la pagina intro url: " + webview.getUrl());

    return rootView;
}

From source file:org.digitalcampus.oppia.widgets.PageWidget.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    wv = (WebView) super.getActivity().findViewById(activity.getActId());
    // get the location data
    String url = course.getLocation() + activity
            .getLocation(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()));

    int defaultFontSize = Integer.parseInt(prefs.getString(PrefsActivity.PREF_TEXT_SIZE, "16"));
    wv.getSettings().setDefaultFontSize(defaultFontSize);

    try {/*from w  w w . j  a va 2s . c o m*/
        wv.getSettings().setJavaScriptEnabled(true);
        //We inject the interface to launch intents from the HTML
        wv.addJavascriptInterface(new JSInterfaceForResourceImages(this.getActivity(), course.getLocation()),
                JSInterfaceForResourceImages.InterfaceExposedName);

        wv.loadDataWithBaseURL("file://" + course.getLocation() + File.separator, FileUtils.readFile(url),
                "text/html", "utf-8", null);
    } catch (IOException e) {
        wv.loadUrl("file://" + url);
    }

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            //We execute the necessary JS code to bind click on images with our JavascriptInterface
            view.loadUrl(JSInterfaceForResourceImages.JSInjection);
        }

        // set up the page to intercept videos
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if (url.contains("/video/")) {
                // extract video name from url
                int startPos = url.indexOf("/video/") + 7;
                String mediaFileName = url.substring(startPos, url.length());

                // check video file exists
                boolean exists = FileUtils.mediaFileExists(PageWidget.super.getActivity(), mediaFileName);
                if (!exists) {
                    Log.d(TAG, PageWidget.super.getActivity().getString(R.string.error_media_not_found,
                            mediaFileName));
                    Toast.makeText(PageWidget.super.getActivity(), PageWidget.super.getActivity()
                            .getString(R.string.error_media_not_found, mediaFileName), Toast.LENGTH_LONG)
                            .show();
                    return true;
                } else {
                    Log.d(TAG, "Media found: " + mediaFileName);
                }

                String mimeType = FileUtils
                        .getMimeType(FileUtils.getMediaPath(PageWidget.super.getActivity()) + mediaFileName);

                if (!FileUtils.supportedMediafileType(mimeType)) {
                    Toast.makeText(PageWidget.super.getActivity(), PageWidget.super.getActivity()
                            .getString(R.string.error_media_unsupported, mediaFileName), Toast.LENGTH_LONG)
                            .show();
                    return true;
                }

                Intent intent = new Intent(PageWidget.super.getActivity(), VideoPlayerActivity.class);
                Bundle tb = new Bundle();
                tb.putSerializable(VideoPlayerActivity.MEDIA_TAG, mediaFileName);
                tb.putSerializable(Activity.TAG, activity);
                tb.putSerializable(Course.TAG, course);
                intent.putExtras(tb);
                startActivity(intent);
                return true;

            } else {

                try {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    Uri data = Uri.parse(url);
                    intent.setData(data);
                    PageWidget.super.getActivity().startActivity(intent);
                } catch (ActivityNotFoundException anfe) {
                    // do nothing
                }
                // launch action in mobile browser - not the webview
                // return true so doesn't follow link within webview
                return true;
            }

        }
    });
}

From source file:net.mceoin.cominghome.oauth.OAuthFlowApp.java

@SuppressLint("SetJavaScriptEnabled")
@Override/* ww w  . ja  v a2 s.c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.oauth);
    this.prefs = PreferenceManager.getDefaultSharedPreferences(this);

    EditText editPincode = (EditText) findViewById(R.id.editPincode);
    editPincode.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            Button usePincode = (Button) findViewById(R.id.btn_use_pincode);
            if (s.length() == 8) {
                usePincode.setEnabled(true);
            } else {
                usePincode.setEnabled(false);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    editPincode.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                if (v.length() == 8) {
                    usePincode();
                    return true;
                }
            }
            return false;
        }
    });

    Button usePincode = (Button) findViewById(R.id.btn_use_pincode);
    usePincode.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            usePincode();
        }
    });

    WebView webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(false);

    try {
        webView.loadUrl(Constants.AUTHORIZE_URL);
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(this, "Failed", Toast.LENGTH_LONG).show();
    }

}

From source file:com.emuneee.nctrafficcams.ui.activities.MainActivity.java

/**
 * Displays the end user license agreement at startup
 *//*from www. j  a v  a2s.c o m*/
private void showEula() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.eula_dialog, null);
    final Dialog dialog;
    builder.setCancelable(false);
    builder.setView(view);
    builder.setTitle(R.string.eula_title);

    builder.setPositiveButton(R.string.agree, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
            Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
            editor.putBoolean(Constants.PREF_EULA_ACCEPTED, true);
            editor.commit();

            editor = getPreferences(Context.MODE_PRIVATE).edit();
            editor.putBoolean(Constants.PREF_TRAFFIC_CAMS_INIT, true);
            editor.commit();
            mGetLatestCamerasTask.execute();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
            Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
            editor.putBoolean(Constants.PREF_EULA_ACCEPTED, false);
            editor.commit();
            MainActivity.this.finish();
        }
    });

    dialog = builder.create();
    // load the eula from assets
    WebView wv = (WebView) view.findViewById(R.id.web_view_eula);
    wv.loadUrl("file:///android_asset/eula.htm");
    dialog.show();
}