package com.ym.zxhcsdkaar;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.content.FileProvider;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.ym.zxhcsdk.HttpClientUtils;
import com.ym.zxhcsdk.PhoneUtils;
import com.ym.zxhcsdk.ZXHCConstant;
import com.ym.zxhcsdk.listener.FeedAdListener;
import com.ym.zxhcsdk.listener.SplashAdListener;
import com.ym.zxhcsdk.manager.ZXHCADManager;
import com.ym.zxhcsdk.manager.ZXHCAdViewManager;
import com.ym.zxhcsdk.view.ZXHCFeedAD;
import com.ym.zxhcsdk.view.ZXHCSplashAD;

import java.io.File;

public class MainActivity extends Activity {
    ZXHCFeedAD feedAD1;
    ViewGroup vp;
    ZXHCSplashAD zxhcSplashAD;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ZXHCADManager.getInstance().InitAd(this, "1000127", true);
//        ZXHCADManager.getInstance().InitAd(this, "1000298", true);
        String url = "http://sspv2test.zhangxinhuichuan.com/ssp/v1/ads?pid=2100154&type=api&ad_type=3&ad_w=480&ad_h=720&app_package=com.popcap.pvz2cthd&app_id=1000127&app_name=com.popcap.pvz2cthd&app_versionid=1005&device_geo_lat=&device_geo_lon=&device_imei=X6GNU17524105082&device_adid=d0cf1c3d5280f16b&device_mac=F0:C8:50:A1:4E:8E&device_width=1920&device_height=1132&device_imsi=460000501365163&device_carrier=&device_network=1&device_os=Android&device_os_version=24&device_density=2.0&device_ppi=2.0&device_ip=183.211.87.156&device_ua=Dalvik%2F2.1.0+%28Linux%3B+U%3B+Android+9%3B+Redmi+Note+8+Pro+MIUI%2FV10.4.9.0.PGGCNXM%29&device_type=0&is_mobile=1&device_model=FLA-AL10&device_brand=HUAWEI";
        String BaseUrl = "http://sspv2test.zhangxinhuichuan.com/ssp/v1/ads";
        new OaidUtils().GetOaid(MainActivity.this, new IOaidListener() {
            @Override
            public void getOaid(String oaid) {
                Log.d("wxw", "oaid" + oaid);
                ZXHCConstant.device_oaid = oaid;
            }
        });
        findViewById(R.id.test_DownLoad).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                feedAD1.destroyFeedAd(vp);
            }
        });

        findViewById(R.id.test_Feed).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                feedAD1 = new ZXHCFeedAD(MainActivity.this, "2100154", 1080, 720, new FeedAdListener() {
                    @Override
                    public void OnAdLoaded() {
                        vp = ZXHCAdViewManager.getInstance().newFrameLayout(MainActivity.this);
                        ZXHCAdViewManager.getInstance().showAdView(MainActivity.this, vp, true);
                        feedAD1.showAd(vp);
                    }

                    @Override
                    public void OnError(String error) {
                        Log.d("wxw", "OnError"+error);
                    }

                    @Override
                    public void OnAdClicked() {
                        Log.d("wxw", "OnAdClicked");
                    }

                    @Override
                    public void OnAdShow() {
                        Log.d("wxw", "OnAdShow");
                    }

                    @Override
                    public void OnAdClosed() {
                        Log.d("wxw", "OnAdClosed");
                    }
                });
                feedAD1.loadAD();
            }
        });
        findViewById(R.id.test_splsh).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //2100154 落地页
                //2100155 下载
                //2100156 跳转链接
                zxhcSplashAD = new ZXHCSplashAD(MainActivity.this, "2100154", new SplashAdListener() {
                    @Override
                    public void OnAdLoaded() {
                        ViewGroup vp = ZXHCAdViewManager.getInstance().newFrameLayout(MainActivity.this);
                        ZXHCAdViewManager.getInstance().showAdView(MainActivity.this, vp, false);
                        zxhcSplashAD.showAd(vp);
                    }

                    @Override
                    public void OnError(String error) {
                        Log.d("wxw", "OnError");
                    }

                    @Override
                    public void OnAdClicked() {
                        Log.d("wxw", "OnAdClicked");
                    }

                    @Override
                    public void OnAdShow() {
                        Log.d("wxw", "OnAdShow");
                    }

                    @Override
                    public void OnAdClosed() {
                        Log.d("wxw", "OnAdClosed");
                    }
                }, 3);
                zxhcSplashAD.fetchAdOnly();
            }
        });

    }
}