Example usage for android.webkit WebSettings setLoadsImagesAutomatically

List of usage examples for android.webkit WebSettings setLoadsImagesAutomatically

Introduction

In this page you can find the example usage for android.webkit WebSettings setLoadsImagesAutomatically.

Prototype

public abstract void setLoadsImagesAutomatically(boolean flag);

Source Link

Document

Sets whether the WebView should load image resources.

Usage

From source file:io.github.calvinmikael.anymanga.WebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from  w ww. j  a va  2 s  . co  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_web_view, container, false);
    mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar);
    mProgressBar.setVisibility(View.GONE);

    mWebView = (ObservableWebView) view.findViewById(R.id.webView);
    mWebView.setScrollViewCallbacks(this);
    WebSettings settings = mWebView.getSettings();

    settings.setLoadsImagesAutomatically(true);
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            if (!mProgressBar.isShown()) {
                mProgressBar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (mProgressBar.isShown()) {
                mProgressBar.setVisibility(View.GONE);
            }
        }
    });
    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {
            // if a view already exists then immediately terminate the new one
            if (mCustomView != null) {
                onHideCustomView();
                return;
            }

            // Save the current state
            mCustomView = view;
            mOriginalSystemUiVisibility = getActivity().getWindow().getDecorView().getSystemUiVisibility();

            // Save the custom view callback
            mCustomViewCallback = callback;

            // Add the custom view to the view hierarchy
            FrameLayout decorView = (FrameLayout) getActivity().getWindow().getDecorView();
            decorView.addView(mCustomView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));

            mTabStrip = (PagerSlidingTabStrip) getActivity().findViewById(R.id.tabs);
            mTabStrip.setVisibility(View.GONE);

            // Go fullscreen
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                getActivity().getWindow().getDecorView()
                        .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
            } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT
                    && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getActivity().getWindow().getDecorView()
                        .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
            }
        }

        @Override
        public void onHideCustomView() {
            // Remove the custom view
            FrameLayout decorView = (FrameLayout) getActivity().getWindow().getDecorView();
            decorView.removeView(mCustomView);
            mCustomView = null;

            mTabStrip.setVisibility(View.VISIBLE);
            // Restore the original form
            getActivity().getWindow().getDecorView().setSystemUiVisibility(mOriginalSystemUiVisibility);

            // Call the custom view callback
            mCustomViewCallback.onCustomViewHidden();
            mCustomViewCallback = null;
        }
    });
    // The back button must be handled within the mWebView for the
    // mWebView to have back behavior based on the current mPage
    // if back behavior is not handled with this listener then
    // back behavior will be entirely dependent on the first mPage
    mWebView.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()
                    && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                mWebView.goBack();
                return true;
            }

            return false;
        }
    });

    if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
    } else {
        if (mPage == 1) {
            mWebView.loadUrl(getString(R.string.website_kissmanga));
        } else if (mPage == 2) {
            mWebView.loadUrl(getString(R.string.website_mangapark));
        } else if (mPage == 3) {
            mWebView.loadUrl(getString(R.string.website_line_webtoon));
        }
    }

    return view;
}

From source file:com.gh4a.FileViewerActivity.java

private void fillData(boolean highlight) {
    String data = new String(EncodingUtils.fromBase64(mContent.getContent()));
    WebView webView = (WebView) findViewById(R.id.web_view);

    WebSettings s = webView.getSettings();
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    s.setAllowFileAccess(true);/*from   w  w w .java  2s .co  m*/
    s.setBuiltInZoomControls(true);
    s.setLightTouchEnabled(true);
    s.setLoadsImagesAutomatically(true);
    s.setPluginsEnabled(false);
    s.setSupportZoom(true);
    s.setSupportMultipleWindows(true);
    s.setJavaScriptEnabled(true);
    s.setUseWideViewPort(true);

    webView.setWebViewClient(webViewClient);
    if (FileUtils.isImage(mName)) {
        String htmlImage = StringUtils.highlightImage(
                "https://github.com/" + mRepoOwner + "/" + mRepoName + "/raw/" + mRef + "/" + mPath);
        webView.loadDataWithBaseURL("file:///android_asset/", htmlImage, "text/html", "utf-8", "");
    } else {
        String highlighted = StringUtils.highlightSyntax(data, highlight, mName);
        webView.loadDataWithBaseURL("file:///android_asset/", highlighted, "text/html", "utf-8", "");
    }
}

From source file:com.ap.github.ui.activitys.LoginActivity.java

@SuppressLint("SetJavaScriptEnabled")
private void initLoginWebView() {
    mLoginWebView.setVerticalScrollBarEnabled(false);
    mLoginWebView.setHorizontalScrollBarEnabled(false);
    mLoginWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    mLoginWebView.getSettings().setJavaScriptEnabled(true);
    mLoginWebView.setWebViewClient(new LoginWebViewClient(this));

    WebSettings webSettings = mLoginWebView.getSettings();
    webSettings.setUseWideViewPort(true);
    webSettings.setSupportZoom(false);//w w w  .  j  a  v a 2 s  .  c  om
    webSettings.setBuiltInZoomControls(false);
    webSettings.setAllowFileAccess(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setLoadsImagesAutomatically(true);
}

From source file:com.acrutiapps.browser.ui.components.CustomWebView.java

@SuppressLint("SetJavaScriptEnabled")
public void loadSettings() {
    WebSettings settings = getSettings();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    settings.setJavaScriptEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_JAVASCRIPT, true));
    settings.setLoadsImagesAutomatically(prefs.getBoolean(Constants.PREFERENCE_ENABLE_IMAGES, true));
    settings.setUseWideViewPort(prefs.getBoolean(Constants.PREFERENCE_USE_WIDE_VIEWPORT, true));
    settings.setLoadWithOverviewMode(prefs.getBoolean(Constants.PREFERENCE_LOAD_WITH_OVERVIEW, false));

    settings.setGeolocationEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_GEOLOCATION, true));
    settings.setSaveFormData(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_FORM_DATA, true));
    settings.setSavePassword(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_PASSWORDS, true));

    settings.setTextZoom(prefs.getInt(Constants.PREFERENCE_TEXT_SCALING, 100));

    int minimumFontSize = prefs.getInt(Constants.PREFERENCE_MINIMUM_FONT_SIZE, 1);
    settings.setMinimumFontSize(minimumFontSize);
    settings.setMinimumLogicalFontSize(minimumFontSize);

    boolean useInvertedDisplay = prefs.getBoolean(Constants.PREFERENCE_INVERTED_DISPLAY, false);
    setWebSettingsProperty(settings, "inverted", useInvertedDisplay ? "true" : "false");

    if (useInvertedDisplay) {
        setWebSettingsProperty(settings, "inverted_contrast",
                Float.toString(prefs.getInt(Constants.PREFERENCE_INVERTED_DISPLAY_CONTRAST, 100) / 100f));
    }//w ww.ja v a 2s .  c om

    settings.setUserAgentString(prefs.getString(Constants.PREFERENCE_USER_AGENT, Constants.USER_AGENT_ANDROID));
    settings.setPluginState(PluginState
            .valueOf(prefs.getString(Constants.PREFERENCE_PLUGINS, PluginState.ON_DEMAND.toString())));

    CookieManager.getInstance().setAcceptCookie(prefs.getBoolean(Constants.PREFERENCE_ACCEPT_COOKIES, true));

    settings.setSupportZoom(true);
    settings.setDisplayZoomControls(false);
    settings.setBuiltInZoomControls(true);
    settings.setSupportMultipleWindows(true);
    settings.setEnableSmoothTransition(true);

    if (mPrivateBrowsing) {
        settings.setGeolocationEnabled(false);
        settings.setSaveFormData(false);
        settings.setSavePassword(false);

        settings.setAppCacheEnabled(false);
        settings.setDatabaseEnabled(false);
        settings.setDomStorageEnabled(false);
    } else {
        // HTML5 API flags
        settings.setAppCacheEnabled(true);
        settings.setDatabaseEnabled(true);
        settings.setDomStorageEnabled(true);

        // HTML5 configuration settings.
        settings.setAppCacheMaxSize(3 * 1024 * 1024);
        settings.setAppCachePath(mContext.getDir("appcache", 0).getPath());
        settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
        settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
    }

    setLongClickable(true);
    setDownloadListener(this);
}

From source file:ch.gianulli.flashcards.ui.Flashcard.java

/**
 * @param view Instance of flashcard.xml
 *///from   ww  w  . j a  v a2  s.  com
public Flashcard(View view, OnCardAnsweredListener listener) {
    mListener = listener;

    mView = view;
    mQuestion = (StyledMarkdownView) view.findViewById(R.id.question);
    mAnswer = (StyledMarkdownView) view.findViewById(R.id.answer);
    mCardView = (CardView) view.findViewById(R.id.card);
    mButtonBar = view.findViewById(R.id.button_bar);
    mCorrectButton = (Button) view.findViewById(R.id.correct_button);
    mWrongButton = (Button) view.findViewById(R.id.wrong_button);

    mContext = mView.getContext();

    // Load colors
    int[] attrs = { android.R.attr.textColorSecondary, android.R.attr.textColorPrimary };
    TypedArray ta = mView.getContext().obtainStyledAttributes(R.style.AppTheme, attrs);
    sDeactivatedTextColor = colorToCSSString(ta.getColor(0, 0));
    sDefaultTextColor = colorToCSSString(ta.getColor(1, 0));
    ta.recycle();

    sGreenTextColor = colorToCSSString(ContextCompat.getColor(mContext, R.color.green));

    mQuestionColor = sDefaultTextColor;
    mAnswerColor = sGreenTextColor;

    // Make question visible
    mQuestion.setAlpha(1.0f);
    mAnswer.setAlpha(0.0f);

    // Setup WebViews
    WebSettings settings = mQuestion.getSettings();
    settings.setDefaultFontSize(mFontSize);
    settings.setLoadsImagesAutomatically(true);
    settings.setGeolocationEnabled(false);
    settings.setAllowFileAccess(false);
    settings.setDisplayZoomControls(false);
    settings.setNeedInitialFocus(false);
    settings.setSupportZoom(false);
    settings.setSaveFormData(false);
    settings.setJavaScriptEnabled(true);
    mQuestion.setHorizontalScrollBarEnabled(false);
    mQuestion.setVerticalScrollBarEnabled(false);

    settings = mAnswer.getSettings();
    settings.setDefaultFontSize(mFontSize);
    settings.setLoadsImagesAutomatically(true);
    settings.setGeolocationEnabled(false);
    settings.setAllowFileAccess(false);
    settings.setDisplayZoomControls(false);
    settings.setNeedInitialFocus(false);
    settings.setSupportZoom(false);
    settings.setSaveFormData(false);
    settings.setJavaScriptEnabled(true);
    mAnswer.setHorizontalScrollBarEnabled(false);
    mAnswer.setVerticalScrollBarEnabled(false);

    // Hack to disable text selection in WebViews
    mQuestion.setOnLongClickListener(new View.OnLongClickListener() {

        public boolean onLongClick(View v) {
            return true;
        }
    });
    mAnswer.setOnLongClickListener(new View.OnLongClickListener() {

        public boolean onLongClick(View v) {
            return true;
        }
    });

    // Card should "turn" on click
    final FrameLayout questionLayout = (FrameLayout) view.findViewById(R.id.question_layout);
    questionLayout.setClickable(true);
    questionLayout.setOnTouchListener(mTurnCardListener);

    mQuestion.setOnTouchListener(mTurnCardListener);
    mAnswer.setOnTouchListener(mTurnCardListener);

    // Deactivate card when user answers it
    mCorrectButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            deactivateCard(true);
            mListener.onCardAnswered(mCard, true);
        }
    });
    mWrongButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            deactivateCard(false);
            mListener.onCardAnswered(mCard, false);
        }
    });

    // Limit card width to 400dp
    ViewTreeObserver observer = mCardView.getViewTreeObserver();
    final int width480dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 400,
            view.getContext().getResources().getDisplayMetrics());
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (mCardView.getWidth() > width480dp) {
                ViewGroup.LayoutParams layoutParams = mCardView.getLayoutParams();
                layoutParams.width = width480dp;
                mCardView.setLayoutParams(layoutParams);
                mCardView.requestLayout();

                return false;
            }
            return true;
        }
    });
}

From source file:net.bluecarrot.lite.MainActivity.java

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

    //allow Geolocation
    settings.setGeolocationEnabled(savedPreferences.getBoolean("pref_allowGeolocation", true));

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    //to make the webview faster
    //settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);//from w ww .  j a  v a  2  s  .c o  m
    settings.setLoadWithOverviewMode(true);
    // better image sizing support
    settings.setSupportZoom(true);
    settings.setDisplayZoomControls(false);
    settings.setBuiltInZoomControls(true);

    settings.setGeolocationDatabasePath(getBaseContext().getFilesDir().getPath());

    settings.setLoadsImagesAutomatically(!savedPreferences.getBoolean("pref_doNotDownloadImages", false));//to save data
    //todo setLoadsImagesAutomatically without restart the app

    // 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);
    }
}