Search in sources :

Example 31 with WebSettings

use of android.webkit.WebSettings in project android_frameworks_base by AOSPA.

the class CaptivePortalLoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mCm = ConnectivityManager.from(this);
    mNetwork = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
    mCaptivePortal = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL);
    mUserAgent = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT);
    mUrl = getUrl();
    if (mUrl == null) {
        // getUrl() failed to parse the url provided in the intent: bail out in a way that
        // at least provides network access.
        done(Result.WANTED_AS_IS);
        return;
    }
    if (DBG) {
        Log.d(TAG, String.format("onCreate for %s", mUrl.toString()));
    }
    // Also initializes proxy system properties.
    mCm.bindProcessToNetwork(mNetwork);
    // Proxy system properties must be initialized before setContentView is called because
    // setContentView initializes the WebView logic which in turn reads the system properties.
    setContentView(R.layout.activity_captive_portal_login);
    getActionBar().setDisplayShowHomeEnabled(false);
    // Exit app if Network disappears.
    final NetworkCapabilities networkCapabilities = mCm.getNetworkCapabilities(mNetwork);
    if (networkCapabilities == null) {
        finishAndRemoveTask();
        return;
    }
    mNetworkCallback = new NetworkCallback() {

        @Override
        public void onLost(Network lostNetwork) {
            if (mNetwork.equals(lostNetwork))
                done(Result.UNWANTED);
        }
    };
    final NetworkRequest.Builder builder = new NetworkRequest.Builder();
    for (int transportType : networkCapabilities.getTransportTypes()) {
        builder.addTransportType(transportType);
    }
    mCm.registerNetworkCallback(builder.build(), mNetworkCallback);
    final WebView myWebView = (WebView) findViewById(R.id.webview);
    myWebView.clearCache(true);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
    mWebViewClient = new MyWebViewClient();
    myWebView.setWebViewClient(mWebViewClient);
    myWebView.setWebChromeClient(new MyWebChromeClient());
    // Start initial page load so WebView finishes loading proxy settings.
    // Actual load of mUrl is initiated by MyWebViewClient.
    myWebView.loadData("", "text/html", null);
}
Also used : WebSettings(android.webkit.WebSettings) Network(android.net.Network) NetworkRequest(android.net.NetworkRequest) WebView(android.webkit.WebView) NetworkCapabilities(android.net.NetworkCapabilities) NetworkCallback(android.net.ConnectivityManager.NetworkCallback)

Example 32 with WebSettings

use of android.webkit.WebSettings in project AisenWeiBo by wangdan.

the class WeiboClientActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ui_weibo_client);
    if (!Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        finish();
        return;
    }
    askForAuth = savedInstanceState != null ? savedInstanceState.getBoolean("askForAuth") : getIntent().getBooleanExtra("askForAuth", false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setTitle("");
    progressbar.setIndeterminate(true);
    WebSettings setting = mWebView.getSettings();
    setting.setJavaScriptEnabled(true);
    mWebView.setWebChromeClient(new WeiboWebChromeClient());
    mWebView.addJavascriptInterface(new LoginJavaScriptInterface(), "loginjs");
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!TextUtils.isEmpty(url) && isLoginUrl(mUrl) && url.toLowerCase().startsWith("http://m.weibo.cn")) {
                Logger.d(TAG, "登录成功");
                mWebView.loadUrl("javascript:getAccount()");
                String cookie = CookieManager.getInstance().getCookie(DM_URL);
                String accountCookie = AppContext.getAccount().getCookie();
                if (TextUtils.isEmpty(accountCookie) || (!TextUtils.isEmpty(cookie) && !cookie.equalsIgnoreCase(accountCookie))) {
                    saveCookie(AppContext.getAccount().getAccount(), AppContext.getAccount().getPassword());
                    Logger.d(TAG, "手动记录cookie");
                }
            }
            mUrl = url;
            view.loadUrl(url);
            Logger.d(TAG, "overriderUrlLoading = " + url);
            return true;
        }
    });
    setting.setJavaScriptCanOpenWindowsAutomatically(true);
    if (savedInstanceState == null) {
        if (getIntent().getData() != null)
            mUrl = getIntent().getData().toString();
        if (TextUtils.isEmpty(mUrl))
            mUrl = getIntent().getStringExtra("url");
        if (mUrl.startsWith("aisen://"))
            mUrl = mUrl.replace("aisen://", "");
    } else {
        mUrl = savedInstanceState.getString("url");
    }
    if (askForAuth) {
        fillAccount();
    } else {
        mWebView.loadUrl(mUrl);
    }
}
Also used : WebSettings(android.webkit.WebSettings) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 33 with WebSettings

use of android.webkit.WebSettings in project Diaspora-Webclient by voidcode.

the class ShareActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isNetworkAvailable()) {
        if (!this.main_domain.equals("")) {
            WebSettings settings = mWeb.getSettings();
            // set Javascript
            settings.setJavaScriptEnabled(true);
            // settings.setRenderPriority(RenderPriority.HIGH);
            settings.setCacheMode(WebSettings.LOAD_NORMAL);
            //set cache size to 8mb by default.
            //settings.setAppCacheMaxSize(1024*1024*8);
            //settings.setDomStorageEnabled(true);
            //settings.setAppCachePath("/data/data/com.voidcode.diasporawebclient/cache");
            //settings.setAllowFileAccess(true);
            //settings.setAppCacheEnabled(true);
            //settings.setBuiltInZoomControls(true);
            // load: open new messages
            mWeb.loadUrl("https://" + main_domain + "/status_messages/new");
            //when you are on eg your default browser and choose 'share with', 
            //and then choose 'Diaspora-Webclient' it goto here 
            Intent intent = getIntent();
            final Bundle extras = intent.getExtras();
            String action = intent.getAction();
            if (//if user has 
            Intent.ACTION_SEND.equals(action)) {
                mWeb.setWebViewClient(new WebViewClient() {

                    public void onPageFinished(WebView view, String url) {
                        if (mProgress.isShowing()) {
                            mProgress.dismiss();
                        }
                        //this have to be intent
                        if (extras.containsKey(Intent.EXTRA_TEXT) && extras.containsKey(Intent.EXTRA_SUBJECT)) {
                            //get url on the site user will share
                            final String extraText = (String) extras.get(Intent.EXTRA_TEXT);
                            //get the url�s title
                            final String extraSubject = (String) extras.get(Intent.EXTRA_SUBJECT);
                            //inject share pageurl into 'textarea' via javascript
                            mWeb.loadUrl("javascript:(function() { " + //make more space to user-message
                            "document.getElementsByTagName('textarea')[0].style.height='110px'; " + //inject formate bookmark
                            "document.getElementsByTagName('textarea')[0].innerHTML = '[" + extraSubject + "](" + extraText + ") #bookmark '; " + "})()");
                        }
                    }
                });
            }
        } else {
            this.finish();
            startActivity(new Intent(this, SetupInternetActivity.class));
        }
    }
}
Also used : WebSettings(android.webkit.WebSettings) Bundle(android.os.Bundle) Intent(android.content.Intent) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 34 with WebSettings

use of android.webkit.WebSettings in project Diaspora-Webclient by voidcode.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isNetworkAvailable()) {
        // load main domain�s rooturl
        SharedPreferences preferences = getSharedPreferences(SETTINGS_FILENAME, MODE_PRIVATE);
        this.main_domain = preferences.getString("currentpod", "");
        // set the home screen
        setContentView(R.layout.main);
        mWeb = (WebView) findViewById(R.id.webView_main);
        //--------------------------------------------------------------------------//
        //start up the webbrowser------------------------------------------------START
        //--------------------------------------------------------------------------//
        WebSettings settings = mWeb.getSettings();
        // set Javascript
        settings.setJavaScriptEnabled(true);
        //settings.setRenderPriority(RenderPriority.HIGH);
        settings.setCacheMode(WebSettings.LOAD_NORMAL);
        // adds JSInterface class to webview
        if (userHasEnableTranslate()) {
            mWeb.addJavascriptInterface(new JSInterface(), "jsinterface");
        }
        //fix to bug 2: cannot reshare
        //see: https://github.com/voidcode/Diaspora-Webclient/issues/2
        mWeb.setWebChromeClient(new WebChromeClient() {

            public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
                return super.onJsAlert(view, url, message, result);
            }
        });
        mWeb.setWebViewClient(new WebViewClient() {

            private String googleapikey;

            private String defaultlanguage;

            private Matcher matcher;

            private Pattern pattern = Pattern.compile("^(https?)://" + main_domain + "[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");

            // load url
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //this see if the user is trying to open a internel or externel link
                if (//if internel(on main_domain) eks: joindiaspora.com
                pattern.matcher(url).matches()) {
                    view.loadUrl(url);
                    return true;
                } else // if user try to open a externel link, then open it in the default webbrowser.
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url));
                    startActivity(i);
                    return true;
                }
            }

            public void onPageFinished(WebView view, String url) {
                // when finish loading page
                if (mProgress.isShowing()) {
                    mProgress.dismiss();
                } else {
                    if (//adds translate link to all post
                    userHasEnableTranslate()) {
                        SharedPreferences preferences = getSharedPreferences(TRANSLATE_FILENAME, MODE_PRIVATE);
                        this.googleapikey = preferences.getString("googleapikey", "microsoft-translator");
                        //default-language=english
                        this.defaultlanguage = preferences.getString("defaultlanguage", "en");
                        //Inject google translate link via javascript into all posts
                        mWeb.loadUrl("javascript:(function() { " + //get variables			        	    			"var i=0; "+
                        "var ltrs=document.getElementsByClassName('ltr'); " + //loop: adds translate buttons to all 'ltr' tags
                        "for(i=0;i<ltrs.length;i++) " + "{" + //makes new div
                        "var btn = document.createElement('div'); " + //retrive select post
                        "var selectpost = encodeURIComponent(ltrs.item(i).innerHTML); " + //"var selectpost = 'google is a search '; "+
                        "btn.setAttribute('onclick','alert(window.jsinterface.Translate( \"" + main_domain + "\",  \"" + this.googleapikey + "\", \"" + this.defaultlanguage + //adds onclick-handler
                        "\", \"'+selectpost+'\" ));'); " + //adds style
                        "btn.setAttribute('style','margin:15px 0px 15px 0px;'); " + //adds id
                        "btn.id='btn_translate_id_'+i; " + //title on link.
                        "btn.innerHTML='Translate this post'; " + //append new button to post '.ltr'
                        "ltrs.item(i).appendChild(btn); " + "} " + "})()");
                    }
                }
            }
        });
        //then open SettingsActivity
        if (this.main_domain.equals("")) {
            startActivity(new Intent(this, PodSettingsActivity.class));
        } else {
            mProgress = ProgressDialog.show(this, "Stream", "Please wait a moment...");
            //goto start or logon pages
            this.mWeb.loadUrl("https://" + main_domain + "/stream");
            // goto users stream
            Toast.makeText(this, "Pod: " + main_domain, Toast.LENGTH_SHORT).show();
        }
    } else {
        // if user don�t have internet
        this.finish();
        startActivity(new Intent(this, SetupInternetActivity.class));
    }
}
Also used : Pattern(java.util.regex.Pattern) SharedPreferences(android.content.SharedPreferences) Matcher(java.util.regex.Matcher) Intent(android.content.Intent) JsResult(android.webkit.JsResult) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 35 with WebSettings

use of android.webkit.WebSettings in project WordPress-Android by wordpress-mobile.

the class LearnMorePreference method loadSupportWebView.

@SuppressLint("SetJavaScriptEnabled")
private WebView loadSupportWebView() {
    WebView webView = new WebView(getContext());
    WebSettings webSettings = webView.getSettings();
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setJavaScriptEnabled(true);
    webView.setWebViewClient(new LearnMoreClient());
    webView.loadUrl(WP_SUPPORT_URL);
    return webView;
}
Also used : WebSettings(android.webkit.WebSettings) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint)

Aggregations

WebSettings (android.webkit.WebSettings)92 WebView (android.webkit.WebView)49 WebViewClient (android.webkit.WebViewClient)29 SuppressLint (android.annotation.SuppressLint)23 View (android.view.View)17 WebChromeClient (android.webkit.WebChromeClient)17 Intent (android.content.Intent)10 JsResult (android.webkit.JsResult)7 Bitmap (android.graphics.Bitmap)6 KeyEvent (android.view.KeyEvent)6 WebResourceRequest (android.webkit.WebResourceRequest)6 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)5 Network (android.net.Network)5 NetworkCapabilities (android.net.NetworkCapabilities)5 NetworkRequest (android.net.NetworkRequest)5 Bundle (android.os.Bundle)5 RelativeLayout (android.widget.RelativeLayout)5 TextView (android.widget.TextView)5 WebResourceError (android.webkit.WebResourceError)4 Activity (android.app.Activity)3