package com.navinfo.outdoor.fragment;

import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.base.BaseFragment;

/**
 * 联系我们的Fragment
 */
public class ContactFragment extends BaseFragment implements View.OnClickListener{

    private ImageView ivContact;
    private String content = "<div>\n" +
            "<h2>定义和用法</h2>\n" +
            "\n" +
            "<p>\n" +
            "\t<img  src=\"https://exp-picture.cdn.bcebos.com/560be432939c2cf72dff4caa452c5b1b1fde12e1.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_jpg%2Fquality%2Cq_80\">\n" +
            "</p>\n" +
            "\n" +
            "<p style=\"color: red; margin-left: 20px\">&lt;style&gt; 标签用于为 HTML 文档定义样式信息。</p>\n" +
            "\n" +
            "<p style=\"background-color: lightblue; margin-left: 20px\">在 style 中，您可以规定在浏览器中如何呈现 HTML 文档。</p>\n" +
            "\n" +
            "<p style=\"font-family: verdana; margin-left: 20px\">type 属性是必需的，定义 style 元素的内容。唯一可能的值是 \"text/css\"。</p>\n" +
            "\n" +
            "<p style=\"font-size: 20px; margin-left: 20px\">style 元素位于 head 部分中。</p>\n" +
            "</div>";
    private WebView nWebView;

    public static ContactFragment newInstance(Bundle bundle) {
        ContactFragment fragment = new ContactFragment();
        fragment.setArguments(bundle);
        return fragment;
    }
    @Override
    protected int getLayout() {
        return R.layout.contact_fragment;
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    protected void initView() {
        super.initView();
        ivContact = findViewById(R.id.iv_contact);
        ivContact.setOnClickListener(this);
        nWebView = findViewById(R.id.news_webView);
        nWebView.getSettings().setBlockNetworkImage(false);
        WebSettings settings = nWebView.getSettings();
        settings.setJavaScriptEnabled(true);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
            nWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        settings.setBuiltInZoomControls(false);
        content = content.replace("<img", "<img style='max-width: 100%'");
        nWebView.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_contact:
                getActivity().finish();
                break;
        }
    }
}
