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.github.dfa.diaspora_android.util.Helpers.java

public static void getNotificationCount(final WebView wv) {
    wv.loadUrl("javascript: ( function() {" + "if (document.getElementById('notification')) {"
            + "       var count = document.getElementById('notification').innerHTML;"
            + "       AndroidBridge.setNotificationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));"
            + "    } else {" + "       AndroidBridge.setNotificationCount('0');" + "    }"
            + "    if (document.getElementById('conversation')) {"
            + "       var count = document.getElementById('conversation').innerHTML;"
            + "       AndroidBridge.setConversationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));"
            + "    } else {" + "       AndroidBridge.setConversationCount('0');" + "    }" + "})();");
}

From source file:com.github.dfa.diaspora_android.web.WebHelper.java

public static void optimizeMobileSiteLayout(final WebView wv) {
    wv.loadUrl("javascript: ( function() {"
            + "    if (document.documentElement == null || document.documentElement.style == null) { return; }"
            + "    document.documentElement.style.paddingBottom = '50px';"
            + "    document.getElementById('main').style.paddingTop = '5px';"
            + "    if(document.getElementById('main_nav')) {"
            + "        document.getElementById('main_nav').parentNode.removeChild("
            + "        document.getElementById('main_nav'));"
            + "    } else if (document.getElementById('main-nav')) {"
            + "        document.getElementById('main-nav').parentNode.removeChild("
            + "        document.getElementById('main-nav'));" + "    }" + "})();");
}

From source file:Main.java

public static void webViewLoadLocalJs(WebView view, String path) {
    String jsContent = assetFile2Str(view.getContext(), path);
    view.loadUrl("javascript:" + jsContent);
}

From source file:Main.java

/**
 * <p>Runs raw Javascript that's passed in. You are responsible for encoding/escaping the
 * function call.</p>/*from w ww . j a  va  2  s .c o m*/
 *
 * @param context    An activity context.
 * @param webView    The shared webView.
 * @param javascript The raw Javascript to be executed, fully escaped/encoded in advance.
 */
static void runJavascriptRaw(Context context, final WebView webView, final String javascript) {
    runOnMainThread(context, new Runnable() {
        @Override
        public void run() {
            webView.loadUrl("javascript:" + javascript);
        }
    });
}

From source file:com.github.dfa.diaspora_android.web.WebHelper.java

public static void shareTextIntoWebView(final WebView webView, String sharedText) {
    sharedText = sharedText.replace("'", "&apos;").replace("\"", "&quot;");
    webView.loadUrl("javascript:(function() { "
            + "        document.documentElement.style.paddingBottom = '500px';"
            + "    if (typeof window.hasBeenSharedTo !== 'undefined') { AndroidBridge.contentHasBeenShared(); return; }"
            + "    var textbox = document.getElementsByTagName('textarea')[0];" + "    var textToBeShared = '"
            + sharedText + "';" + "    if (textbox) { " + "        textbox.style.height='210px'; "
            + "        textbox.innerHTML = textToBeShared; " + "        window.hasBeenSharedTo = true;"
            + "        window.lastShared = textToBeShared;" + "    }" + "})();");
}

From source file:Main.java

public static void webViewLoadJs(WebView view, String url) {
    String js = "var newscript = document.createElement(\"script\");";
    js += "newscript.src=\"" + url + "\";";
    js += "document.scripts[0].parentNode.insertBefore(newscript,document.scripts[0]);";
    view.loadUrl("javascript:" + js);
}

From source file:com.oneguy.recognize.Util.java

public static void callJsFunction(WebView webview, String function) {
    if (webview == null) {
        Log.w(TAG, "can not call js on null webview");
        return;/*from www  . j  a v  a 2 s .  c  om*/
    }
    webview.loadUrl("javascript:" + function);
}

From source file:com.bourke.kitchentimer.utils.Utils.java

public static View dialogWebView(Context context, String fileName) {
    View view = View.inflate(context, R.layout.dialog_webview, null);
    //      TextView textView = (TextView) view.findViewById(R.id.message);
    //      textView.setMovementMethod(LinkMovementMethod.getInstance());
    //      CharSequence cs =  readTextFile(context, fileName);
    ///*from   w  w w .j av  a 2 s .c  o  m*/
    //      SpannableString s = new SpannableString(Html.fromHtml(cs.toString()));
    //      Linkify.addLinks(s, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
    //      textView.setText(s);
    WebView web = (WebView) view.findViewById(R.id.wv_dialog);
    web.loadUrl("file:///android_asset/" + fileName);
    return view;
}

From source file:com.github.dfa.diaspora_android.util.Helpers.java

public static void getUserProfile(final WebView wv) {
    // aspects":[{"id":124934,"name":"Friends","selected":true},{"id":124937,"name":"Liked me","selected":false},{"id":124938,"name":"Follow","selected":false},{"id":128327,"name":"Nur ich","selected":false}]
    wv.loadUrl("javascript: ( function() {"
            + "    if (typeof gon !== 'undefined' && typeof gon.user !== 'undefined') {"
            + "       var userProfile = JSON.stringify(gon.user);"
            + "       AndroidBridge.setUserProfile(userProfile.toString());" + "    } " + "})();");
}

From source file:com.github.dfa.diaspora_android.web.WebHelper.java

public static void getUserProfile(final WebView wv) {
    // aspects":[{"id":124934,"name":"Friends","selected":true},{"id":124937,"name":"Liked me","selected":false},{"id":124938,"name":"Follow","selected":false},{"id":128327,"name":"Nur ich","selected":false}]
    wv.loadUrl("javascript: ( function() {"
            + "    if (typeof gon !== 'undefined' && typeof gon.user !== 'undefined') {"
            + "        var followed_tags = document.getElementById(\"followed_tags\");"
            + "        if(followed_tags != null) {" + "            try {"
            + "                var links = followed_tags.nextElementSibling.children[0].children;"
            + "                var tags = [];" + "                for(var i = 0; i < links.length - 1; i++) {" + // the last element is "Manage followed tags" link
            "                    tags.push(links[i].innerText.replace('#',''));" + "                }"
            + "                gon.user[\"android_app.followed_tags\"] = tags;" + "            } catch(e) {}"
            + "        }" + "       var userProfile = JSON.stringify(gon.user);"
            + "       AndroidBridge.setUserProfile(userProfile.toString());" + "    } " + "})();");
}