Example usage for android.webkit WebView getSettings

List of usage examples for android.webkit WebView getSettings

Introduction

In this page you can find the example usage for android.webkit WebView getSettings.

Prototype

public WebSettings getSettings() 

Source Link

Document

Gets the WebSettings object used to control the settings for this WebView.

Usage

From source file:me.robertoestrada.rssreader.fragments.ItemDetailFragment.java

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

    ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(mItemTitle);

    // Show the dummy content as text in a TextView.
    if (mItemContent != null) {
        WebView webView = (WebView) rootView.findViewById(R.id.item_detail);
        webView.loadDataWithBaseURL("", mItemContent, "text/html", "UTF-8", "");
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    }//from   w  ww.ja  v a 2s .  c o m

    return rootView;
}

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);/*  www  .  j  ava  2  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.schabi.newpipe.ReCaptchaActivity.java

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

    // Set return to Cancel by default
    setResult(RESULT_CANCELED);/*  w  w w. java  2s. c om*/

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.reCaptcha_title);
        actionBar.setDisplayShowTitleEnabled(true);
    }

    WebView myWebView = (WebView) findViewById(R.id.reCaptchaWebView);

    // Enable Javascript
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    ReCaptchaWebViewClient webClient = new ReCaptchaWebViewClient(this);
    myWebView.setWebViewClient(webClient);

    // Cleaning cache, history and cookies from webView
    myWebView.clearCache(true);
    myWebView.clearHistory();
    android.webkit.CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.removeAllCookies(new ValueCallback<Boolean>() {
            @Override
            public void onReceiveValue(Boolean aBoolean) {
            }
        });
    } else {
        cookieManager.removeAllCookie();
    }

    myWebView.loadUrl(YT_URL);
}

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

@SuppressLint("SetJavaScriptEnabled")
@Override//from w ww  .  j ava 2  s.co  m
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.owncloud.android.ui.activity.ExternalSiteWebView.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log_OC.v(TAG, "onCreate() start");

    Bundle extras = getIntent().getExtras();
    String title = extras.getString(EXTRA_TITLE);
    String url = extras.getString(EXTRA_URL);
    menuItemId = extras.getInt(EXTRA_MENU_ITEM_ID);
    showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR);

    // show progress
    getWindow().requestFeature(Window.FEATURE_PROGRESS);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.externalsite_webview);

    WebView webview = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = webview.getSettings();

    webview.setFocusable(true);/*from   ww  w .  j a  v  a 2s .c o m*/
    webview.setFocusableInTouchMode(true);
    webview.setClickable(true);

    // setup toolbar
    setupToolbar();

    // setup drawer
    setupDrawer(menuItemId);

    if (!showSidebar) {
        setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }

    getSupportActionBar().setTitle(title);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // enable zoom
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    // Non-responsive webs are zoomed out when loaded
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);

    // user agent
    webSettings.setUserAgentString(MainApp.getUserAgent());

    // no private data storing
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);

    // disable local file access
    webSettings.setAllowFileAccess(false);

    // enable javascript
    webview.getSettings().setJavaScriptEnabled(true);

    final Activity activity = this;
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);

    webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            progressBar.setProgress(progress * 1000);
        }
    });

    webview.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, getString(R.string.webview_error) + ": " + description, Toast.LENGTH_SHORT)
                    .show();
        }
    });

    webview.loadUrl(url);
}

From source file:com.btmura.android.reddit.app.LinkFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void setupWebView(WebView webView) {
    WebSettings settings = webView.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setSupportZoom(true);/*  www .  j  a v  a 2  s. c om*/
    settings.setPluginState(PluginState.ON_DEMAND);
    settings.setUseWideViewPort(true);

    webView.setOnLongClickListener(this);

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (progress != null) {
                progress.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (progress != null) {
                progress.setVisibility(View.GONE);
            }
        }
    });

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (progress != null) {
                progress.setProgress(newProgress);
            }
        }
    });
}

From source file:com.android.browser.DownloadTouchIcon.java

public DownloadTouchIcon(Tab tab, ContentResolver cr, WebView view) {
    mTab = tab;/*from   w  w w  .  j a  v a2 s  . c  om*/
    mContentResolver = cr;
    // Store these in case they change.
    mOriginalUrl = view.getOriginalUrl();
    mUrl = view.getUrl();
    mUserAgent = view.getSettings().getUserAgentString();
}

From source file:se.eliga.aves.AboutFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    WebView webView = (WebView) getView().findViewById(R.id.about_text);
    webView.loadUrl("file:///android_asset/about.html");
    webView.setBackgroundColor(0x00FFFFFF);
    webView.setVisibility(View.VISIBLE);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webView.addJavascriptInterface(/*from  w w  w .  jav  a2s . com*/
            new AboutJSObject(getVersion(), BuildConfig.BUILDTIME, BuildConfig.BUILDTYPE), "AboutData");
}

From source file:de.nico.asura.activities.AuthWebView1.java

private void openWebView() {
    setContentView(R.layout.webview);/*from w  w  w. ja v a  2  s  .co m*/
    WebView webView = (WebView) findViewById(R.id.webView_main);
    webView.setWebViewClient(new MyWebViewClient());
    webView.loadUrl(getString(R.string.menu_AuthWeb_1_url));
    webView.getSettings().setBuiltInZoomControls(true);
}

From source file:com.dwdesign.tweetings.fragment.WebMapFragment.java

/** Sets up the WebView object and loads the URL of the page **/
private void setupWebView() {

    final WebView webview = getWebView();
    webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    setWebViewClient(new MapWebViewClient(getActivity()));
    loadUrl(mUri.toString());/*from   w  ww.j  av a  2  s.c o m*/

    final WebSettings settings = webview.getSettings();
    settings.setBuiltInZoomControls(false);

    /** Allows JavaScript calls to access application resources **/
    webview.addJavascriptInterface(new JavaScriptInterface(), "android");

}