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.google.android.apps.gutenberg.LicensesFragment.java

@NonNull
@Override// w  w  w.  ja  va 2 s . c o m
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:com.emobc.android.activities.generators.PdfActivityGenerator.java

@Override
protected void loadAppLevelData(final Activity activity, final AppLevelData data) {
    final PdfLevelDataItem item = (PdfLevelDataItem) data.findByNextLevel(nextLevel);
    if (item == null)
        return;// w  ww  .  j  a  v  a 2  s .c  o  m

    //rotateScreen(activity);
    initializeHeader(activity, item);

    //Create Banner
    CreateMenus c = (CreateMenus) activity;
    c.createBanner();
    if (Utils.hasLength(item.getPdfUrl())) {
        WebView webview = (WebView) activity.findViewById(R.id.pdfviewer);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setPluginsEnabled(true);
        webview.setWebViewClient(new InsideWebViewClient(activity));

        webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + item.getPdfUrl());

        //activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(item.getPdfUrl())));

        /*
        File outputDir = activity.getCacheDir(); 
        try {
           File outputFile = File.createTempFile("eMobc", ".tmp", outputDir);
           if(downloadPdfToFile(outputFile, item.getPdfUrl())){
              File file = new File(outputFile.getAbsolutePath());
                
              if (file.exists()) {                      
               Uri path = Uri.fromFile(outputFile);
               Intent intent = new Intent(Intent.ACTION_VIEW);
               intent.setDataAndType(path, "application/pdf");
               intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                
               try {
                  activity.startActivity(intent);
               }catch (ActivityNotFoundException e) {
                   Toast.makeText(activity, 
                       "No Application Available to View PDF", 
                       Toast.LENGTH_SHORT).show();
               }
              }
           }            
        } catch (IOException e1) {
           Log.e("PdfActivityGenerator", "Error: " + e1.getMessage());
        }*/
        /*
                
        String pdfFileUrl = String.format(PDF_WEBVIEW_TPL, item.getPdfUrl());
                
        try {
           URL url = new URL(pdfFileUrl);
           URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
           url = uri.toURL();
                
                   
           WebView webView = (WebView)activity.findViewById(R.id.pdfviewer);
           webView.getSettings().setJavaScriptEnabled(true); 
           webView.loadUrl(url.toString());
                   
           Uri uriPath = Uri.parse(item.getPdfUrl());
                   
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uriPath, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                
        try {
           activity.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(activity, 
                "No Application Available to View PDF", 
                Toast.LENGTH_SHORT).show();
        }
        } catch (MalformedURLException e) {
           Log.e("PdfActivityGenerator", "MalformedURLException: " + e.getMessage());
        } catch (URISyntaxException e) {
           Log.e("PdfActivityGenerator", "URISyntaxException: " + e.getMessage());
        }
        */
    }
}

From source file:com.almalence.opencam.ui.AlmalenceStore.java

public void showStore() {
    LayoutInflater inflater = LayoutInflater.from(MainScreen.getInstance());
    List<RelativeLayout> pages = new ArrayList<RelativeLayout>();

    // <!-- -+-
    final boolean unlocked = false;
    //-+- -->//from  w  ww  . j  a v  a 2  s. c o m
    /* <!-- +++
    final boolean unlocked = true; 
     +++ --> */

    // page 1
    RelativeLayout page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    initStoreList();

    RelativeLayout store = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_store, null);
    final ImageView imgStoreNext = (ImageView) store.findViewById(R.id.storeWhatsNew);
    GridView gridview = (GridView) store.findViewById(R.id.storeGrid);
    gridview.setAdapter(storeAdapter);

    if (!unlocked) {
        page.addView(store);
        pages.add(page);
    }

    // page 2
    page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    RelativeLayout features = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_features, null);
    final ImageView imgFeaturesPrev = (ImageView) features.findViewById(R.id.storeWhatsNew);
    imgFeaturesPrev.setVisibility(View.INVISIBLE);
    WebView wv = (WebView) features.findViewById(R.id.text_features);
    wv.loadUrl("file:///android_asset/www/features.html");

    page.addView(features);
    pages.add(page);

    SamplePagerAdapter pagerAdapter = new SamplePagerAdapter(pages);
    final ViewPager viewPager = new ViewPager(MainScreen.getInstance());
    viewPager.setAdapter(pagerAdapter);
    if (!unlocked)
        viewPager.setCurrentItem(0);
    else
        viewPager.setCurrentItem(1);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            switch (position) {
            case 0:
                // 0
                imgStoreNext.setVisibility(View.VISIBLE);
                // 1
                imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            case 1:
                // 0
                imgStoreNext.setVisibility(View.INVISIBLE);
                // 1
                if (!unlocked)
                    imgFeaturesPrev.setVisibility(View.VISIBLE);
                else
                    imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            default:
                break;
            }
        }
    });

    imgStoreNext.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(1);
        }
    });

    imgFeaturesPrev.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(0);
        }
    });

    guiView.findViewById(R.id.buttonGallery).setEnabled(false);
    guiView.findViewById(R.id.buttonShutter).setEnabled(false);
    guiView.findViewById(R.id.buttonSelectMode).setEnabled(false);

    PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
            ApplicationInterface.MSG_CONTROL_LOCKED);

    MainScreen.getGUIManager().lockControls = true;

    // <!-- -+-
    if (MainScreen.getInstance().showPromoRedeemed) {
        Toast.makeText(MainScreen.getInstance(),
                "The promo code has been successfully redeemed. All PRO-Features are unlocked",
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemed = false;
    }
    if (MainScreen.getInstance().showPromoRedeemedJulius) {
        Toast.makeText(MainScreen.getInstance(),
                MainScreen.getInstance().getResources().getString(R.string.promoRedeemedJulius),
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemedJulius = false;
    }
    //-+- -->

    final RelativeLayout pagerLayout = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayout));
    pagerLayout.addView(viewPager);

    final RelativeLayout pagerLayoutMain = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayoutMain));
    pagerLayoutMain.setVisibility(View.VISIBLE);
    pagerLayoutMain.bringToFront();

    // We need this timer, to show store on top, after we return from google
    // play.
    // In MainScreen there is timer, which brings main buttons on top,
    // after MainScreen activity resumed.
    // So this timer "blocks" timer from MainScreen if we want to show
    // store.
    new CountDownTimer(600, 10) {
        public void onTick(long millisUntilFinished) {
            pagerLayoutMain.bringToFront();
        }

        public void onFinish() {
            pagerLayoutMain.bringToFront();
        }
    }.start();
}

From source file:com.phonegap.plugins.slaveBrowser.SlaveBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url       The url to load.//  www.  ja  va 2 s. com
 * @param jsonObject 
 */
public String showWebPage(final String url, JSONObject options, String myNewTitle) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }
    zeTitle = myNewTitle;

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(ctx.getContext());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);
                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);
            LinearLayout main = new LinearLayout(ctx.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(ctx.getContext());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            edittext = new TextView(ctx.getContext());
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(zeTitle);
            edittext.setTextSize(TypedValue.COMPLEX_UNIT_PX, 24);
            edittext.setGravity(Gravity.CENTER);
            edittext.setTextColor(Color.DKGRAY);
            edittext.setTypeface(Typeface.DEFAULT_BOLD);
            edittext.setLayoutParams(editParams);

            webview = new WebView(ctx.getContext());
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setBuiltInZoomControls(true);

            // dda: intercept calls to console.log
            webview.setWebChromeClient(new WebChromeClient() {
                public boolean onConsoleMessage(ConsoleMessage cmsg) {
                    // check secret prefix
                    if (cmsg.message().startsWith("MAGICHTML")) {
                        String msg = cmsg.message().substring(9); // strip off prefix
                        /* process HTML */
                        try {
                            JSONObject obj = new JSONObject();
                            obj.put("type", PAGE_LOADED);
                            obj.put("html", msg);
                            sendUpdate(obj, true);
                        } catch (JSONException e) {
                            Log.d(LOG_TAG, "This should never happen");
                        }
                        return true;
                    }
                    return false;
                }
            });

            // dda: inject the JavaScript on page load
            webview.setWebViewClient(new SlaveBrowserClient(edittext) {
                public void onPageFinished(WebView view, String address) {
                    // have the page spill its guts, with a secret prefix
                    view.loadUrl(
                            "javascript:console.log('MAGICHTML'+document.getElementsByTagName('html')[0].innerHTML);");
                }
            });

            webview.loadUrl(url);
            webview.setId(5);
            webview.setInitialScale(0);
            webview.setLayoutParams(wvParams);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            toolbar.addView(edittext);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}

From source file:com.zuluindia.watchpresenter.MainActivity.java

public void showTroubleShooting() {
    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.html_dialog, null);
    WebView mainWebView = (WebView) dialogLayout.findViewById(R.id.mainWebView);
    mainWebView.loadUrl("file:///android_asset/troubleshooting.html");
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(dialogLayout);/*from   w w w  .  j av a  2  s.  co m*/
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    builder.setTitle(getString(R.string.troubleshooting));
    builder.show();
}

From source file:com.zuluindia.watchpresenter.MainActivity.java

private void showUpdates() {
    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.html_dialog, null);
    WebView mainWebView = (WebView) dialogLayout.findViewById(R.id.mainWebView);
    mainWebView.loadUrl("file:///android_asset/updates.html");
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(dialogLayout);/*ww w.  j a v a  2 s  .co m*/
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    builder.setTitle(getString(R.string.newFeaturesTitle));
    builder.show();
}

From source file:com.devspark.sidenavigation.meiriyiwen.MainActivity.java

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

    setContentView(R.layout.activity_main);
    icon = (ImageView) findViewById(android.R.id.icon);
    sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view);
    sideNavigationView.setMenuItems(R.menu.side_navigation_menu);
    sideNavigationView.setMenuClickCallback(this);

    if (getIntent().hasExtra(EXTRA_TITLE)) {
        String title = getIntent().getStringExtra(EXTRA_TITLE);
        int resId = getIntent().getIntExtra(EXTRA_RESOURCE_ID, 0);
        setTitle(title);/*  www.  j  a v a  2s . com*/
        icon.setImageResource(resId);
        sideNavigationView.setMode(getIntent().getIntExtra(EXTRA_MODE, 0) == 0 ? Mode.LEFT : Mode.RIGHT);
    }

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    {
        String title = "http://meiriyiwen.com/index/mobile";
        //setTitle(title);
        WebView uiwebview = (WebView) findViewById(R.id.meiriyiwenWeb);
        uiwebview.setBackgroundColor(Color.BLACK);
        uiwebview.setWebViewClient(new Callback());
        uiwebview.getSettings().setBuiltInZoomControls(true);
        uiwebview.getSettings().setJavaScriptEnabled(true);
        uiwebview.loadUrl(title);

    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

}

From source file:org.noise_planet.noisecapture.MapActivity.java

public void loadWebView() {
    WebView leaflet = (WebView) findViewById(R.id.webmapview);
    WebSettings webSettings = leaflet.getSettings();
    webSettings.setJavaScriptEnabled(true);
    leaflet.clearCache(true);/* ww w  .  j a  v a2 s  . c o m*/
    leaflet.setInitialScale(200);
    String location = "";
    if (builder != null && validBoundingBox) {
        LatLng latLng = builder.build().getCenter();
        location = "/#18/" + latLng.latitude + "/" + latLng.longitude;
    }
    leaflet.loadUrl("http://onomap.noise-planet.org" + location);
}

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

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // show description if any
    String desc = activity// www  .j a  va  2s  .  com
            .getDescription(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()));

    TextView descTV = (TextView) getView().findViewById(R.id.widget_url_description);
    if (desc.length() > 0) {
        descTV.setText(desc);
    } else {
        descTV.setVisibility(View.GONE);
    }

    WebView wv = (WebView) getView().findViewById(R.id.widget_url_webview);
    int defaultFontSize = Integer.parseInt(prefs.getString(PrefsActivity.PREF_TEXT_SIZE, "16"));
    wv.getSettings().setDefaultFontSize(defaultFontSize);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
    wv.loadUrl(activity
            .getLocation(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())));

}

From source file:com.zuluindia.watchpresenter.MainActivity.java

public void showGestureExperimental() {
    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.html_dialog, null);
    WebView mainWebView = (WebView) dialogLayout.findViewById(R.id.mainWebView);
    mainWebView.setWebViewClient(new MailtoWebView(this));
    mainWebView.loadUrl("file:///android_asset/gestures_experimental.html");
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(dialogLayout);/*from   www  . j  a v  a  2 s. c o m*/
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    builder.setTitle(getString(R.string.experimentalFeature));
    builder.show();
}