package com.android.chmo.ui.activity.me;

import android.content.Context;
import android.os.Build;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.android.chmo.R;
import com.android.chmo.base.BaseActivity;
import com.android.chmo.ui.view.TopBar;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/8/20.
 */
public class ProtocolActivity extends BaseActivity {

    @BindView(R.id.topBar)
    TopBar topBar;

    @BindView(R.id.webview)
    WebView webView;


    @Override
    protected int getContentResId() {
        return R.layout.activity_protocol;
    }

    @Override
    public void initView() {
        initWebView();

        String title = getIntent().getStringExtra("title");
        String url = getIntent().getStringExtra("url");

        topBar.setTitle(title);
        webView.loadUrl(url);
    }

    private void initWebView() {
        WebSettings webSettings = webView.getSettings();
        // 设置编码
        webSettings.setDefaultTextEncodingName("utf-8");
        webSettings.setTextZoom(100);
        //添加缓存
        webSettings.setAppCachePath(getCacheDir().getAbsolutePath());
        webSettings.setAllowFileAccess(true);
        webSettings.setAppCacheEnabled(true);
        webSettings.setDatabaseEnabled(true);
        String dir = this.getApplicationContext()
                .getDir("database", Context.MODE_PRIVATE).getPath();
        webSettings.setGeolocationEnabled(true);
        webSettings.setGeolocationDatabasePath(dir);
        webSettings.setDomStorageEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        //自适应屏幕
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setLoadWithOverviewMode(true);

        //支持Https
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        // 支持js
        webSettings.setJavaScriptEnabled(true);
    }
}
