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.almunt.jgcaap.systemupdater.MainActivity.java

public void LicencesDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Open Source Licenses");
    WebView wv = new WebView(this);
    wv.loadUrl("file:///android_asset/open_source_licenses.html");
    wv.setWebViewClient(new WebViewClient() {
        @Override//from ww  w . j  a v  a  2 s  .com
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    alert.setView(wv);
    alert.setPositiveButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    alert.show();
}

From source file:io.github.hidroh.materialistic.SubmitActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppUtils.setStatusBarColor(getWindow(), ContextCompat.getColor(this, R.color.blackT12));
    setContentView(R.layout.activity_submit);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    //noinspection ConstantConditions
    getSupportActionBar().setDisplayOptions(
            ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP);
    mTitleLayout = (TextInputLayout) findViewById(R.id.textinput_title);
    mContentLayout = (TextInputLayout) findViewById(R.id.textinput_content);
    mTitleEditText = (TextView) findViewById(R.id.edittext_title);
    mContentEditText = (TextView) findViewById(R.id.edittext_content);
    String text, subject;/*  ww w  . j ava  2  s  .c o  m*/
    if (savedInstanceState == null) {
        subject = getIntent().getStringExtra(Intent.EXTRA_SUBJECT);
        text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
    } else {
        subject = savedInstanceState.getString(STATE_SUBJECT);
        text = savedInstanceState.getString(STATE_TEXT);
    }
    mTitleEditText.setText(subject);
    mContentEditText.setText(text);
    if (TextUtils.isEmpty(subject)) {
        if (isUrl(text)) {
            WebView webView = new WebView(this);
            webView.setWebChromeClient(new WebChromeClient() {
                @Override
                public void onReceivedTitle(WebView view, String title) {
                    if (mTitleEditText.length() == 0) {
                        mTitleEditText.setText(title);
                    }
                }
            });
            webView.loadUrl(text);
        } else if (!TextUtils.isEmpty(text)) {
            extractUrl(text);
        }
    }
}

From source file:com.agustinprats.myhrv.fragment.MonitorFragment.java

/** Displays help to the user. */
private void showHelp() {

    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    alert.setTitle(getActivity().getString(R.string.Help));

    WebView wv = new WebView(getActivity());

    // loading the html file
    String htmlData = readAsset("help.html");

    // selecting the css based on the activity theme
    //        htmlData = htmlData.replaceFirst("CSS_FILE_NAME", ((MainActivity) getActivity()).isLightTheme() ? "light" : "dark");
    htmlData = htmlData.replaceFirst("CSS_FILE_NAME", "dark");
    // loading html in the webview
    wv.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null);

    wv.setWebViewClient(new WebViewClient() {
        @Override//from   w ww  .j  a v  a  2s.co m
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

    alert.setView(wv);
    alert.setNegativeButton(getActivity().getString(R.string.Close), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    alert.show();
}

From source file:com.amgems.uwschedule.api.uw.LoginAuthenticator.java

private LoginAuthenticator(Context context, Handler handler, HttpClient httpClient, String username,
        String password) {/*from   w  ww.j ava2  s  .c om*/
    mUsername = username;
    mPassword = password;
    mCookiesValue = "";

    mHttpClient = httpClient;
    mLoadingFinished = false;
    mJsWebview = new WebView(context);
    mHandler = handler;
    CookieManager.getInstance().removeAllCookie();
    mJsWebview.getSettings().setJavaScriptEnabled(true);
    mJsWebview.addJavascriptInterface(new CaptureHtmBody(), CaptureHtmBody.INTERFACE_NAME);
    mJsWebview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            // If the page has been loaded before, then the WebView must have
            // returned from a JavaScript redirect required for
            // appropriate login cookies. This is when the html content
            // should be captured and processed
            if (mPageLoadCount >= 1)
                view.loadUrl(CaptureHtmBody.CAPTURE_HTML_SCRIPT);
            mPageLoadCount++;
        }
    });
}

From source file:bolts.WebViewAppLinkResolver.java

@Override
public Task<AppLink> getAppLinkFromUrlInBackground(final Uri url) {
    final Capture<String> content = new Capture<String>();
    final Capture<String> contentType = new Capture<String>();
    return Task.callInBackground(new Callable<Void>() {
        @Override/*  ww w .  ja  v a2 s  .c om*/
        public Void call() throws Exception {
            URL currentURL = new URL(url.toString());
            URLConnection connection = null;
            while (currentURL != null) {
                // Fetch the content at the given URL.
                connection = currentURL.openConnection();
                if (connection instanceof HttpURLConnection) {
                    // Unfortunately, this doesn't actually follow redirects if they go from http->https,
                    // so we have to do that manually.
                    ((HttpURLConnection) connection).setInstanceFollowRedirects(true);
                }
                connection.setRequestProperty(PREFER_HEADER, META_TAG_PREFIX);
                connection.connect();

                if (connection instanceof HttpURLConnection) {
                    HttpURLConnection httpConnection = (HttpURLConnection) connection;
                    if (httpConnection.getResponseCode() >= 300 && httpConnection.getResponseCode() < 400) {
                        currentURL = new URL(httpConnection.getHeaderField("Location"));
                        httpConnection.disconnect();
                    } else {
                        currentURL = null;
                    }
                } else {
                    currentURL = null;
                }
            }

            try {
                content.set(readFromConnection(connection));
                contentType.set(connection.getContentType());
            } finally {
                if (connection instanceof HttpURLConnection) {
                    ((HttpURLConnection) connection).disconnect();
                }
            }
            return null;
        }
    }).onSuccessTask(new Continuation<Void, Task<JSONArray>>() {
        @Override
        public Task<JSONArray> then(Task<Void> task) throws Exception {
            // Load the content in a WebView and use JavaScript to extract the meta tags.
            final TaskCompletionSource<JSONArray> tcs = new TaskCompletionSource<>();
            final WebView webView = new WebView(context);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.setNetworkAvailable(false);
            webView.setWebViewClient(new WebViewClient() {
                private boolean loaded = false;

                private void runJavaScript(WebView view) {
                    if (!loaded) {
                        // After the first resource has been loaded (which will be the pre-populated data)
                        // run the JavaScript meta tag extraction script
                        loaded = true;
                        view.loadUrl(TAG_EXTRACTION_JAVASCRIPT);
                    }
                }

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

                @Override
                public void onLoadResource(WebView view, String url) {
                    super.onLoadResource(view, url);
                    runJavaScript(view);
                }
            });
            // Inject an object that will receive the JSON for the extracted JavaScript tags
            webView.addJavascriptInterface(new Object() {
                @JavascriptInterface
                public void setValue(String value) {
                    try {
                        tcs.trySetResult(new JSONArray(value));
                    } catch (JSONException e) {
                        tcs.trySetError(e);
                    }
                }
            }, "boltsWebViewAppLinkResolverResult");
            String inferredContentType = null;
            if (contentType.get() != null) {
                inferredContentType = contentType.get().split(";")[0];
            }
            webView.loadDataWithBaseURL(url.toString(), content.get(), inferredContentType, null, null);
            return tcs.getTask();
        }
    }, Task.UI_THREAD_EXECUTOR).onSuccess(new Continuation<JSONArray, AppLink>() {
        @Override
        public AppLink then(Task<JSONArray> task) throws Exception {
            Map<String, Object> alData = parseAlData(task.getResult());
            AppLink appLink = makeAppLinkFromAlData(alData, url);
            return appLink;
        }
    });
}

From source file:system.info.reader.java

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

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    resolutions = Properties.resolution(dm);
    Properties.resolution = resolutions[0] + "*" + resolutions[1];
    int tabHeight = 30, tabWidth = 80;
    if (dm.widthPixels >= 480) {
        tabHeight = 40;/* ww  w  .j  av  a  2  s .  co m*/
        tabWidth = 120;
    }

    tabHost = getTabHost();
    LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true);
    tabHost.addTab(
            tabHost.newTabSpec("tab1").setIndicator(getString(R.string.brief)).setContent(R.id.PropertyList));
    tabHost.addTab(
            tabHost.newTabSpec("tab2").setIndicator(getString(R.string.online)).setContent(R.id.ViewServer));
    tabHost.addTab(
            tabHost.newTabSpec("tab3").setIndicator(getString(R.string.apps)).setContent(R.id.sViewApps));
    tabHost.addTab(
            tabHost.newTabSpec("tab4").setIndicator(getString(R.string.process)).setContent(R.id.sViewProcess));
    tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("Services").setContent(R.id.sViewCpu));
    tabHost.addTab(tabHost.newTabSpec("tab6").setIndicator("Tasks").setContent(R.id.sViewMem));
    //tabHost.addTab(tabHost.newTabSpec("tab7")
    //        .setIndicator("Vending")
    //        .setContent(R.id.sViewDisk));
    AppsText = (TextView) findViewById(R.id.TextViewApps);
    ProcessText = (TextView) findViewById(R.id.TextViewProcess);
    ServiceText = (TextView) findViewById(R.id.TextViewCpu);
    TaskText = (TextView) findViewById(R.id.TextViewMem);

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(tabWidth, tabHeight);
    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++)
        tabHost.getTabWidget().getChildAt(i).setLayoutParams(lp);

    properList = (ListView) findViewById(R.id.PropertyList);
    Properties.properListItem = new ArrayList<HashMap<String, Object>>();
    properListItemAdapter = new SimpleAdapter(this, Properties.properListItem, R.layout.property_list,
            new String[] { "ItemTitle", "ItemText" }, new int[] { R.id.ItemTitle, R.id.ItemText });
    properList.setAdapter(properListItemAdapter);
    properList.setOnItemClickListener(mpropertyCL);

    //will support app list later
    //appList = (ListView)findViewById(R.id.AppList);
    //Properties.appListItem = new ArrayList<HashMap<String, Object>>();  
    //SimpleAdapter appListItemAdapter = new SimpleAdapter(this, Properties.appListItem,   
    //             R.layout.app_list,  
    //             new String[] {"ItemTitle", "ItemText"},   
    //             new int[] {R.id.ItemTitle, R.id.ItemText}  
    //         );  
    //appList.setAdapter(appListItemAdapter);

    serverWeb = (WebView) findViewById(R.id.ViewServer);
    WebSettings webSettings = serverWeb.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUserAgentString("sys.info.trial" + versionCode);
    webSettings.setTextSize(WebSettings.TextSize.SMALLER);
    serverWeb.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return false;//this will not launch browser when redirect.
        }

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

    PackageManager pm = getPackageManager();
    try {
        PackageInfo pi = pm.getPackageInfo("sys.info.trial", 0);
        version = "v" + pi.versionName;
        versionCode = pi.versionCode;

        List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
        nApk = Integer.toString(apps.size());
        apklist = "";
        for (PackageInfo app : apps) {
            apklist += app.packageName + "\t(" + app.versionName + ")\n";
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    showDialog(0);
    initPropList();
    //refresh();
    PageTask task = new PageTask();
    task.execute("");
}

From source file:com.sourcey.materiallogindemo.PostItemActivity.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=" + strStart + "&poinTo=" + strEnd;

    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("?");
    builderInOut.setMessage("").setView(dialogBoxView).setCancelable(false)
            .setPositiveButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();//from w w  w. j  a v  a  2s  .  co  m
                }
            }).show();
}

From source file:com.robandjen.comicsapp.FullscreenActivity.java

void showCurrentComic(String url) {
    if (url == null || url.isEmpty()) {
        url = mComicList.get(mCurComic).getURL();
    }/*w ww  .ja v a 2s  .c  om*/

    final WebView contentView = (WebView) findViewById(R.id.fullscreen_content);
    contentView.stopLoading();

    //Load about:blank to clear any extra data and have a well defined URL in history
    contentView.loadUrl("about:blank");
    contentView.loadUrl(url);
    contentView.clearHistory();
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setTitle(mComicList.get(mCurComic).getName());
    }
    updateShare(url);

    ExpandableListView elv = (ExpandableListView) findViewById(R.id.comic_drawer);
    long packedPos = mAdapter.comicsPosToPackedPos(mCurComic);

    //Selection doesn't work if expandGroup isn't called or group already expanded. ?????
    elv.expandGroup(ExpandableListView.getPackedPositionGroup(packedPos));
    elv.setSelectedChild(ExpandableListView.getPackedPositionGroup(packedPos),
            ExpandableListView.getPackedPositionChild(packedPos), true);
    elv.setItemChecked(elv.getFlatListPosition(packedPos), true);
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * GuideLines Dialog//from  www  . j  a  v  a2  s . c  o  m
 *
 * @param context
 */
public static void GuidLines(Context context) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title("GuideLines");
    WebView webView = new WebView(context);
    webView.loadUrl("file:///android_asset/Guidlines.html");
    builder.positiveText(android.R.string.ok);
    builder.typeface(getFont(context), getFont(context));
    builder.onPositive(new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            dialog.dismiss();
        }
    });
    builder.customView(webView, false);
    builder.build();
    builder.show();
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * GuideLines Dialog/*from  www. j  a v  a 2  s . c o m*/
 *
 * @param context
 */
public static void LyricsApi(Context context) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title("Lyrics Api");
    WebView webView = new WebView(context);
    webView.loadUrl("file:///android_asset/Lyrics_api.html");
    builder.positiveText(android.R.string.ok);
    builder.typeface(getFont(context), getFont(context));
    builder.onPositive(new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            dialog.dismiss();
        }
    });
    builder.customView(webView, false);
    builder.build();
    builder.show();
}