Java Code Examples for android.webkit.WebView#setSaveEnabled()

The following examples show how to use android.webkit.WebView#setSaveEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebViewUtils.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * webview 显示本地图片,自适应布局大小,图片可缩放
 */
public static void showNetImage(Context mContext, final WebView webview,
                                final String imageLocalUrl, int width, int height) {
    final String fileName = "image.png";

    String data = "<HTML><IMG src=\"" + imageLocalUrl + "\"" + "width=" + width + "height=" + height + "/>";
    webview.loadDataWithBaseURL(imageLocalUrl, data, "text/html", "utf-8", null);

    //webview.loadUrl(imageUrl);//直接显示网上图片
    webview.getSettings().setBuiltInZoomControls(true); //显示放大缩小 controler
    webview.getSettings().setSupportZoom(true); //可以缩放
    webview.setSaveEnabled(true);


}
 
Example 2
Source File: LightningView.java    From Xndroid with GNU General Public License v3.0 4 votes vote down vote up
public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) {
    BrowserApp.getAppComponent().inject(this);
    mActivity = activity;
    mUIController = (UIController) activity;
    mWebView = new WebView(activity);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        mWebView.setId(View.generateViewId());
    }
    mIsIncognitoTab = isIncognito;
    mTitle = new LightningViewTitle(activity);

    sMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();

    mWebView.setDrawingCacheBackgroundColor(Color.WHITE);
    mWebView.setFocusableInTouchMode(true);
    mWebView.setFocusable(true);
    mWebView.setDrawingCacheEnabled(false);
    mWebView.setWillNotCacheDrawing(true);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        //noinspection deprecation
        mWebView.setAnimationCacheEnabled(false);
        //noinspection deprecation
        mWebView.setAlwaysDrawnWithCacheEnabled(false);
    }
    mWebView.setBackgroundColor(Color.WHITE);

    mWebView.setScrollbarFadingEnabled(true);
    mWebView.setSaveEnabled(true);
    mWebView.setNetworkAvailable(true);
    mWebView.setWebChromeClient(new LightningChromeClient(activity, this));
    mWebView.setWebViewClient(new LightningWebClient(activity, this));
    mWebView.setDownloadListener(new LightningDownloadListener(activity));
    mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
    mWebView.setOnTouchListener(new TouchListener());
    sDefaultUserAgent = mWebView.getSettings().getUserAgentString();
    initializeSettings();
    initializePreferences(activity);

    if (url != null) {
        if (!url.trim().isEmpty()) {
            mWebView.loadUrl(url, mRequestHeaders);
        } else {
            // don't load anything, the user is looking for a blank tab
        }
    } else {
        loadHomepage();
    }
}
 
Example 3
Source File: WebViewUtils.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
/**
     * webview 显示本地图片,自适应布局大小,图片可缩放
     *
     * @param mContext
     * @param webview
     * @param imageLocalUrl
     * @param isAdapterScreenWidth 是否自适应屏幕宽度
     * @param color                0-255
     */
    public static void showLocalImage(Context mContext, final WebView webview,
                                      final String imageLocalUrl, int color, boolean isAdapterScreenWidth, boolean doubleClickEabled) {

        boolean fileExist = FileUtils.isExists(imageLocalUrl);

        if (fileExist) {
            String bgcolor = ColorUtils.toBrowserColor(color);

            ZogUtils.printLog(WebViewUtils.class, "bgcolor:" + bgcolor);

            String adapterScreenWidth = "";
            if (isAdapterScreenWidth) {
                adapterScreenWidth = " width:99.9%;";
            }


            String style =
                    "<style>" +
                            "* { margin:0; padding:0; background-color:" +
                            bgcolor +
                            ";  }" +

                            "img { " + adapterScreenWidth + " margin:0; padding:0; }" +

                            "div{" +
                            adapterScreenWidth +
//                            "     border: thin solid #F00;" +
                            "    margin:0; padding:0;" +
                            " }/*这里的width height 大于图片的宽高*/" +

                            "table{ height:100%; width:100%; text-align:center;}" +

                            " </style>";


            String body = "    <body>" +
                    "        <div>" +
                    "            <table>" +
                    "                <tr>" +
                    "                    <td>" +
                    "                       <img src=\"file://" + imageLocalUrl + "\"" +
//                            "                                width=" + width +
                    "                               margin=" + 0 +
                    "                               padding=" + 0 +
//                    "                               height="+height+
                    "                           />" +
                    "                    </td>" +
                    "                </tr>" +
                    "            </table>" +
                    "        </div>" +
                    "    </body>" +
                    "";

            String data = style + body;

            webview.loadDataWithBaseURL("file://" + imageLocalUrl, data, "text/html", "utf-8", null);

            //webview.loadUrl(imageUrl);//直接显示网上图片

            webview.setVerticalScrollBarEnabled(false); // 取消Vertical ScrollBar显示
            webview.setHorizontalScrollBarEnabled(false); //取消Horizontal ScrollBar显示
            webview.getSettings().setBuiltInZoomControls(true); //显示放大缩小 controler
            webview.getSettings().setSupportZoom(true); //可以缩放
            setZoomControlGone(webview);//去掉zoom按钮

            if (doubleClickEabled) {//双击缩放
                webview.getSettings().setUseWideViewPort(true);
                webview.getSettings().setLoadWithOverviewMode(true);
            }
            webview.setSaveEnabled(true);


        }
    }
 
Example 4
Source File: LightningView.java    From JumpGo with Mozilla Public License 2.0 4 votes vote down vote up
public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) {
    BrowserApp.getAppComponent().inject(this);
    mActivity = activity;
    mUIController = (UIController) activity;
    mWebView = new WebView(activity);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        mWebView.setId(View.generateViewId());
    }
    mIsIncognitoTab = isIncognito;
    mTitle = new LightningViewTitle(activity);

    sMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();

    mWebView.setDrawingCacheBackgroundColor(Color.WHITE);
    mWebView.setFocusableInTouchMode(true);
    mWebView.setFocusable(true);
    mWebView.setDrawingCacheEnabled(false);
    mWebView.setWillNotCacheDrawing(true);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        //noinspection deprecation
        mWebView.setAnimationCacheEnabled(false);
        //noinspection deprecation
        mWebView.setAlwaysDrawnWithCacheEnabled(false);
    }
    mWebView.setBackgroundColor(Color.WHITE);

    mWebView.setScrollbarFadingEnabled(true);
    mWebView.setSaveEnabled(true);
    mWebView.setNetworkAvailable(true);
    mWebView.setWebChromeClient(new LightningChromeClient(activity, this));
    mLightningWebClient = new LightningWebClient(activity, this);
    mWebView.setWebViewClient(mLightningWebClient);
    mWebView.setDownloadListener(new LightningDownloadListener(activity));
    mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
    mWebView.setOnTouchListener(new TouchListener());
    sDefaultUserAgent = mWebView.getSettings().getUserAgentString();
    initializeSettings();
    initializePreferences(activity);

    if (url != null) {
        if (!url.trim().isEmpty()) {
            mWebView.loadUrl(url, mRequestHeaders);
        } else {
            // don't load anything, the user is looking for a blank tab
        }
    } else {
        loadHomepage();
    }
}