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:com.money.manager.ex.about.AboutCreditsFragment.java

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

    WebView webView = (WebView) getActivity().findViewById(R.id.about_thirdsparty_credits);

    //        webView.loadData(MmxFileUtils.getRawAsString(getActivity(), R.raw.credits_thirdparty), "text/html", "UTF-8");

    // Display Unicode characters.
    WebSettings settings = webView.getSettings();
    settings.setDefaultTextEncodingName("utf-8");

    webView.loadData(//from   w  w  w  .j  av  a2 s  .co m
            MmxFileUtils.getRawAsString(getActivity().getApplicationContext(), R.raw.credits_thirdparty),
            "text/html; charset=utf-8", null);
}

From source file:it.redturtle.mobile.apparpav.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.showbulletin, container, false);

    // Set button in order to start the bulletin fragmnet
    final Button mv = (Button) view.findViewById(R.id.mv);
    mv.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent newintent = new Intent();
            newintent.setClass(activity, BulletinActivity.class);
            newintent.putExtra("bulletinid", "MV");
            startActivity(newintent);/*from  w w w.  ja v a 2s .  com*/
        }
    });

    // Set button in order to start the bulletin fragmnet
    final Button dm = (Button) view.findViewById(R.id.dm);
    dm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent newintent = new Intent();
            newintent.setClass(activity, BulletinActivity.class);
            newintent.putExtra("bulletinid", "DM");
            startActivity(newintent);
        }
    });

    // Set button in order to start the bulletin fragmnet
    final Button pm = (Button) view.findViewById(R.id.pm);
    pm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent newintent = new Intent();
            newintent.setClass(activity, BulletinActivity.class);
            newintent.putExtra("bulletinid", "MP");
            startActivity(newintent);
        }
    });

    WebView webview = (WebView) view.findViewById(R.id.datail_content);
    webview.setWebChromeClient(new WebChromeClient() {
    });
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setBuiltInZoomControls(true);
    webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

    String html = "<!doctype html>";
    html += "<html>";
    html += "<head>";
    html += "<meta name=\"author\" content=\"RedTurtle.it\" />";
    html += "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />";
    html += "</head>";
    html += "<body style=\"font-family:Helvetica;font-size:small;\">";
    html += "<div style=\"text-align:center;\"><b>" + forecast.getName() + "</b></div>";

    if (forecast.getType() == 1) {
        html += "<div style=\"text-align:center;\">";
        html += "<p>" + forecast.getCaptionAt(0) + "</p>";
        html += "<img src=\"" + forecast.getPathAt(0) + "\" width=\"140\" style=\"padding:2px;\"/>";
        html += "</div>";
    }
    if (forecast.getType() == 2) {

        html += "<div style=\"text-align:center;\">";
        html += "<div style=\"display:inline-block;\">";
        html += "<div style=\"float:left;\">";
        html += "<p>" + forecast.getCaptionAt(0) + "</p>";
        html += "<img src=\"" + forecast.getPathAt(0) + "\" width=\"140\" style=\"padding:2px;\"/>";
        html += "</div>";
        html += "<div style=\"float:left;\">";
        html += "<p>" + forecast.getCaptionAt(1) + "</p>";
        html += "<img  src=\"" + forecast.getPathAt(1) + "\" width=\"140\" style=\"padding:2px;\"/>";
        html += "</div>";
        html += "</div>";
        html += "</div>";
    }

    html += forecast.getBody();
    html += "</body>";
    html += "</html>";

    webview.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
    return view;
}

From source file:jp.mixi.android.sdk.MixiDialog.java

private WebView setUpWebView(WebView webView) {
    Log.v(TAG, "setwebview");
    webView.getSettings().setUserAgentString(Constants.USER_AGENT);
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new MixiWebviewClient());

    webView.getSettings().setJavaScriptEnabled(true);
    webView.addJavascriptInterface(new JsHandler(), "mixi");

    String token = mParams.get("oauth_token");
    int sdkInt = Integer.valueOf(Build.VERSION.SDK);
    // android2.1
    if (sdkInt < Constants.SUPPORTED_SDK_VERSION) {
        Uri uri = Uri.parse(mUrl);//w w  w . j av a2  s.  c o m
        if (token != null) {
            Builder builder = uri.buildUpon();
            builder.appendQueryParameter("oauth_token", token);
            uri = builder.build();
        }
        webView.loadUrl(uri.toString());
    } else {
        HashMap<String, String> extraHeaders = new HashMap<String, String>();
        if (token != null) {
            extraHeaders.put("Authorization", "OAuth " + token);
        }
        webView.loadUrl(mUrl, extraHeaders);
    }

    return webView;
}

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/* w w w  . j  a  va 2 s. c om*/
            .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.android.erowser.DownloadTouchIcon.java

public DownloadTouchIcon(ErowserActivity activity, ContentResolver cr, Cursor c, WebView view) {
    mActivity = activity;/* www  .  j  av  a2s  .c om*/
    mContentResolver = cr;
    mCursor = c;
    // Store these in case they change.
    mOriginalUrl = view.getOriginalUrl();
    mUrl = view.getUrl();
    mUserAgent = view.getSettings().getUserAgentString();
}

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

public DownloadTouchIcon(BrowserActivity activity, ContentResolver cr, Cursor c, WebView view) {
    mActivity = activity;/*  ww w. ja  v a 2  s. com*/
    mContentResolver = cr;
    mCursor = c;
    // Store these in case they change.
    mOriginalUrl = view.getOriginalUrl();
    mUrl = view.getUrl();
    mUserAgent = view.getSettings().getUserAgentString();
}

From source file:com.sonymobile.androidapp.gridcomputing.fragments.WebviewFragment.java

@Override
public final void onViewCreated(final View view, final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final WebView webView = (WebView) view.findViewById(R.id.webview);
    final View progress = view.findViewById(R.id.webview_progress);

    final String researchUrl = getArguments().getString(URL_KEY);

    progress.setVisibility(View.VISIBLE);

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.setWebViewClient(new WebViewClient() {

        @Override/*from  ww  w  .  ja va 2  s.c o  m*/
        public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
            if (TextUtils.isEmpty(researchUrl) || researchUrl.equals(url)) {
                return false;
            } else {
                view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            }
        }

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

    webView.loadUrl(researchUrl);
}

From source file:li.klass.fhem.fragments.AbstractWebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from   w  w w .j  a v a  2  s.co m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    if (view != null)
        return view;

    view = inflater.inflate(R.layout.webview, container, false);
    assert view != null;

    final WebView webView = (WebView) view.findViewById(R.id.webView);

    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);

    final ProgressDialog progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage(getResources().getString(R.string.loading));

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress < 100) {
                progressDialog.setProgress(newProgress);
                progressDialog.show();
            } else {
                progressDialog.hide();
            }
        }
    });

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, @NotNull SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @SuppressWarnings("ConstantConditions")
        @Override
        public void onReceivedHttpAuthRequest(WebView view, @NotNull HttpAuthHandler handler, String host,
                String realm) {
            FHEMServerSpec currentServer = connectionService.getCurrentServer(getActivity());
            String url = currentServer.getUrl();
            String alternativeUrl = trimToNull(currentServer.getAlternateUrl());
            try {

                String fhemUrlHost = new URL(url).getHost();
                String alternativeUrlHost = alternativeUrl == null ? null : new URL(alternativeUrl).getHost();
                String username = currentServer.getUsername();
                String password = currentServer.getPassword();

                if (host.startsWith(fhemUrlHost)
                        || (alternativeUrlHost != null && host.startsWith(alternativeUrlHost))) {
                    handler.proceed(username, password);
                } else {
                    handler.cancel();

                    Intent intent = new Intent(Actions.SHOW_TOAST);
                    intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_authentication);
                    getActivity().sendBroadcast(intent);
                }

            } catch (MalformedURLException e) {
                Intent intent = new Intent(Actions.SHOW_TOAST);
                intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_host_connection);
                getActivity().sendBroadcast(intent);
                LOG.error("malformed URL: " + url, e);

                handler.cancel();
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if ("about:blank".equalsIgnoreCase(url)) {
                Optional<String> alternativeUrl = getAlternateLoadUrl();
                if (alternativeUrl.isPresent()) {
                    webView.loadUrl(alternativeUrl.get());
                }
            } else {
                onPageLoadFinishedCallback(view, url);
            }
        }
    });

    return view;
}

From source file:com.yoavst.quickapps.news.LoginActivity.java

@SuppressLint("SetJavaScriptEnabled")
private WebView createWebView(final Context context) {
    WebView webView = new WebView(context);
    webView.setWebViewClient(createWebViewClient());
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setVisibility(View.VISIBLE);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setBuiltInZoomControls(false);
    return webView;
}

From source file:it.rignanese.leo.slimtwitter.MainActivity.java

private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);/*from w w w.ja va 2 s .  c om*/
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }

    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
}