package com.zswc.creativity.utils;

import android.content.Context;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;

/**
 * Created by xianguangjin on 16/6/30.
 * <p>
 * 我的GitHub: https://github.com/ysnows
 * <p>
 * 加油,做一个真的汉子
 */

public class WebViewUtils {



    /**
     * 获取URL的域名--后面两个
     */
    public static String getDomain(String url) {
        url = url.replace("http://", "").replace("https://", "");
        if (url.contains("/")) {
            url = url.substring(0, url.indexOf('/'));
            String ss[] = url.split("\\.");
            if (ss.length > 2) {
                url = ss[ss.length - 2] + "." + ss[ss.length - 1];

            }

        }
        return url;
    }


    /**
     * @param context 清除cookie
     */
    public static void clearCookie(Context context) {
        try {
            CookieSyncManager.createInstance(context);
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            cookieManager.removeSessionCookie();// 移除
            cookieManager.removeAllCookie();
        } catch (Exception e) {

        }
    }




    /**
     *
     * 没有处理图片
     * @param bodyHTML
     *
     * @return
     */
    public static String getHtmlData2(String bodyHTML) {
        String head = "<head>" +
                "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> " +
                "<style> img{max-width: 100%; width:auto; height:auto;} body{ background-color: #ffffff;font-size:large;}</style>" +
                "</head>";

        return "<!DOCTYPE html>" + head + "<body>" + bodyHTML + "</body>" +
                "<script type=\"text/javascript\">\n" + "\n" +
                "</script>" +
                "</html>";
    }


//    img.src+'?x-oss-process=image/resize,w_200'
//https://cdn.mayinongchang.net/ueditor/9/55b2ce973ca55.jpg





}
