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.example.nq.journalism_master.innerbrowser.InnerBrowserFragment.java

private void initWebViewSettings(WebView webView) {
    //js/*from   ww w  . j a va2 s . c  o  m*/
    webView.getSettings().setJavaScriptEnabled(true);
    //,????
    webView.getSettings().setBuiltInZoomControls(false);
    //
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    //?DOM storage API
    webView.getSettings().setDomStorageEnabled(true);
    //?application Cache
    webView.getSettings().setAppCacheEnabled(false);
}

From source file:com.yang.bruce.mumuxi.util.WebDialog.java

private void setWebView(WebView webView, Context context) {
    WebSettings settings = webView.getSettings();
    settings.setDefaultTextEncodingName(KEY_UTF_8);
    settings.setJavaScriptEnabled(true);
    webView.addJavascriptInterface(new WebAppInterface(context), "Android");
}

From source file:MainActivity.java

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

    WebView webview = new WebView(this);
    setContentView(webview);/*  w ww  .j  av  a2 s .  co  m*/
    webview.loadUrl("https://www.java2s.com/");
    webview.setWebViewClient(new WebViewClient());

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
}

From source file:com.chatwingsdk.fragments.EnterpriseAuthenticateFragment.java

private void setup(WebView mWebView) {
    mWebView.setWebViewClient(mWebviewClient);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override/*from  w  ww.  j a v  a2s  .  co  m*/
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            mProgressView.setProgress(newProgress);
            if (newProgress == 100) {
                mProgressView.setVisibility(View.GONE);
            }
        }
    });
}

From source file:com.prasanna.android.stacknetwork.FullscreenTextActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from  www. j a  v a 2s  .co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.code_full_screen);

    getActionBar().hide();

    CharSequence text = getIntent().getCharSequenceExtra(StringConstants.TEXT);

    WebView webView = (WebView) findViewById(R.id.fullScreenText);
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadDataWithBaseURL(BASE_URL,
            CODE_HTML_PREFIX + MarkdownFormatter.escapeHtml(text) + CODE_HTML_SUFFIX,
            HttpContentTypes.TEXT_HTML, HTTP.UTF_8, null);
}

From source file:it.clipart.swipehtmlpageapp.IntroFragment.java

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

    View controlView = rootView.findViewById(R.id.introFinishControls);

    /*//w  w w. j  a v a2  s.  c  o  m
     If we are on the last page of the intro, we show a special controlView that lets the user
     select if they ever want to see this again, and continue on to the main part of the app.
            
     Se si  nell'ultima pagina dell'intro, verr mostrato uno speciale controlView che lascia l'utente
     se vuole vederlo da capo o proseguire nella parte principale.
     */

    if (item == MyWebActivity.NUM_INTRO_PAGES) {
        /* Se  l'ultima pagina rende visibile il layout contenente il controllo che
        lancia la guida vera e propria
        - Il fatto che sia l'ultima pagina non viene creato un successivo Fragment e quindi
        lo swipe non  pi attivo.
        */
        controlView.setVisibility(View.VISIBLE);
        // Controlla la checkBox "Non mostrare pi"
        rootView.findViewById(R.id.checkBox).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dontShowAgainTapped();
            }
        });

    }
    // Se si torna indietro ( ad esempio ) rende invisibile il controllo di cui sopra
    else {
        controlView.setVisibility(View.INVISIBLE);
    }

    WebView webview = (WebView) rootView.findViewById(R.id.webView);
    android.webkit.WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webview.getSettings().setLoadsImagesAutomatically(true);
    webview.addJavascriptInterface(new WebAppInterface(this.activity), "Android");
    webview.loadUrl("file:///android_asset/intro" + item + ".html");
    Log.d(TAG, "Caricata la pagina intro url: " + webview.getUrl());

    return rootView;
}

From source file:name.gudong.translate.widget.WebDialog.java

@NonNull
@Override/* w  ww . j a va2  s.c  om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final View customView;
    try {
        customView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_about_dialog, null);
    } catch (InflateException e) {
        throw new IllegalStateException("This device does not support Web Views.");
    }

    String dialogTitle = getArguments().getString("dialogTitle");
    String neutralText = getArguments().getString("neutralText");
    String positiveText = getArguments().getString("positiveText");
    neutralText = TextUtils.isEmpty(neutralText) ? "" : neutralText;
    positiveText = TextUtils.isEmpty(neutralText) ? getString(android.R.string.ok) : positiveText;
    AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(dialogTitle).setView(customView)
            .setNeutralButton(neutralText, mNeutralClickCallback)
            .setPositiveButton(positiveText, mPositiveClickCallback).show();

    final WebView webView = (WebView) customView.findViewById(R.id.webview);
    webView.getSettings().setDefaultTextEncodingName("utf-8");
    try {
        String htmlFileName = getArguments().getString("htmlFileName");
        StringBuilder buf = new StringBuilder();
        InputStream json = getActivity().getAssets().open(htmlFileName);
        BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8"));
        String str;
        while ((str = in.readLine()) != null)
            buf.append(str);
        in.close();

        final int accentColor = getArguments().getInt("accentColor");
        String formatLodString = buf.toString()
                .replace("{style-placeholder}", "body { background-color: #ffffff; color: #000; }")
                .replace("{link-color}", colorToHex(shiftColor(accentColor, true)))
                .replace("{link-color-active}", colorToHex(accentColor));
        webView.loadDataWithBaseURL(null, formatLodString, "text/html", "UTF-8", null);
    } catch (Throwable e) {
        webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
    }
    return dialog;
}

From source file:com.sparkplatform.ui.WebViewActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from  w ww  .j a  va  2  s  . com
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);

    this.sparkClient = SparkAPI.getInstance();

    Intent intent = getIntent();
    loginHybrid = intent.getBooleanExtra(UIConstants.EXTRA_LOGIN_HYBRID, true);

    WebView webView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.setWebViewClient(new SparkWebViewClient());

    webView.loadUrl(SparkAPI.sparkOpenIdLogoutURL);
}

From source file:com.gudong.appkit.ui.fragment.CustomWebViewDialog.java

@NonNull
@Override// w  w  w  . ja va2  s.c o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final View customView;
    try {
        customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_webview, null);
    } catch (InflateException e) {
        throw new IllegalStateException("This device does not support Web Views.");
    }

    String dialogTitle = getArguments().getString("dialogTitle");
    String neutralText = getArguments().getString("neutralText");
    String positiveText = getArguments().getString("positiveText");
    neutralText = TextUtils.isEmpty(neutralText) ? "" : neutralText;
    positiveText = TextUtils.isEmpty(neutralText) ? getString(android.R.string.ok) : positiveText;
    AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(dialogTitle).setView(customView)
            .setNeutralButton(neutralText, mNeutralClickCallback)
            .setPositiveButton(positiveText, mPositiveClickCallback).show();

    final WebView webView = (WebView) customView.findViewById(R.id.webview);
    webView.getSettings().setDefaultTextEncodingName("utf-8");
    try {
        String htmlFileName = getArguments().getString("htmlFileName");
        StringBuilder buf = new StringBuilder();
        InputStream json = getActivity().getAssets().open(htmlFileName);
        BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8"));
        String str;
        while ((str = in.readLine()) != null)
            buf.append(str);
        in.close();

        final int accentColor = getArguments().getInt("accentColor");
        String formatLodString = buf.toString()
                .replace("{style-placeholder}", "body { background-color: #ffffff; color: #000; }")
                .replace("{link-color}", colorToHex(shiftColor(accentColor, true)))
                .replace("{link-color-active}", colorToHex(accentColor));
        webView.loadDataWithBaseURL(null, formatLodString, "text/html", "UTF-8", null);
    } catch (Throwable e) {
        webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
    }
    return dialog;
}

From source file:com.rizal.lovins.smartkasir.activity.SettingsActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from   w  ww .  j a v  a 2s.c o m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setTitle("Settings");

    WebView mWebView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.getSettings().setBuiltInZoomControls(false);
    mWebView.getSettings().setDisplayZoomControls(false);
    mWebView.loadUrl("file:///android_asset/license/settings.html");

    CustomGridViewSettingAdapter adapterViewAndroid = new CustomGridViewSettingAdapter(SettingsActivity.this,
            gridViewString, gridViewImageId);
    androidGridView = (GridView) findViewById(R.id.grid_view_image_text);
    androidGridView.setAdapter(adapterViewAndroid);
    androidGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                startActivity(new Intent(SettingsActivity.this, AboutActivity.class));
                break;
            case 1:
                startActivity(new Intent(SettingsActivity.this, DeveloperActivity.class));
                break;
            case 2:
                startActivity(new Intent(SettingsActivity.this, LicenseActivity.class));
                break;
            case 3:
                startActivity(new Intent(SettingsActivity.this, MapsActivity.class));
                break;
            case 4:
                location();
                break;
            }
        }
    });

}