package com.longtu.sample;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;

import com.acegameproject.burstshooter.R;
import com.longtu.android.channels.LTAdsAdmob.LTAdmob.LTAdsAdmob;
import com.longtu.android.channels.LTAdsAdmob.LTAdmob.LTAdsAdmobInterstitialListener;
import com.longtu.sdk.base.view.LTToast;

/**
 * 广告相关接口测试。
 * <p>
 *
 * @author ming
 */
public class LTBase_Demo_Ads extends Activity implements View.OnClickListener {


    /**
     * 插页广告
     */
    private Button loadInterstitialad, showInterstitialad, loadshowInterstitialad;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 设置无标题(DEMO代码)
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        // // 设置全屏幕(DEMO代码)
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        int currentApiVersion = Build.VERSION.SDK_INT;
        if (currentApiVersion >= 14) {
            WindowManager.LayoutParams params = getWindow().getAttributes();
            params.systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            getWindow().setAttributes(params);
        }

        // 强制使屏幕一直处于活动状态，不关闭背景光(DEMO代码)
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.longtu_demo_adsample);

        /**
         * UI相关初始化
         */
        uiInit();


        /**
         * 插页广告回调
         */
        LTAdsAdmob.getInstance().setmLTAdsAdmobInterstitialListener(mLTAdsAdmobInterstitialListener);

        /**
         * Admob广告初始化
         */
        LTAdsAdmob.getInstance().initAdmob(this);



    }

    /**
     * 初始化button
     */
    private void uiInit() {

        this.loadInterstitialad = findViewById(R.id.loadInterstitialad);
        this.showInterstitialad = findViewById(R.id.showInterstitialad);
        this.loadshowInterstitialad = findViewById(R.id.loadshowInterstitialad);

        this.loadInterstitialad.setOnClickListener(this);
        this.showInterstitialad.setOnClickListener(this);
        this.loadshowInterstitialad.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
         if (v == this.loadInterstitialad) {
            LTAdsAdmob.getInstance().LTLoadInterstitialAd(this, "ca-app-pub-3940256099942544/5354046379");
        } else if (v == this.showInterstitialad) {
            LTAdsAdmob.getInstance().LTShowInterstitialAd(this, "9527", "BOSS");
        } else if (v == this.loadshowInterstitialad) {
            LTAdsAdmob.getInstance().LTLoadAndShowInterstitialAd(this,
                    "ca-app-pub-3940256099942544/5354046379", "9527",
                    "BOSS");
        }
    }


    /**
     * 插页广告回调
     */
    private LTAdsAdmobInterstitialListener mLTAdsAdmobInterstitialListener = new LTAdsAdmobInterstitialListener() {
        @Override
        public void onInitializationFinished() {
            LTToast.makeText(LTBase_Demo_MainActivity.mMainActivity, "广告初始化成功", Toast.LENGTH_LONG);
        }

        @Override
        public void onAdFailedToShowFullScreenContent(String AdError) {
            LTToast.makeText(LTBase_Demo_MainActivity.mMainActivity, "广告展示失败：" + AdError, Toast.LENGTH_LONG);
        }

        @Override
        public void onAdShowedFullScreenContent() {
            LTToast.makeText(LTBase_Demo_MainActivity.mMainActivity, "广告展示完成", Toast.LENGTH_LONG);
        }

        @Override
        public void onAdDismissedFullScreenContent() {
            LTToast.makeText(LTBase_Demo_MainActivity.mMainActivity, "广告关闭", Toast.LENGTH_LONG);
        }

        @Override
        public void onAdNoLoaded() {
            LTToast.makeText(LTBase_Demo_MainActivity.mMainActivity, "广告未加载", Toast.LENGTH_LONG);
        }

        @Override
        public void onAdFailedToLoad(String loadAdError) {
            LTToast.makeText(LTBase_Demo_MainActivity.mMainActivity, "广告加载失败" + loadAdError, Toast.LENGTH_LONG);
        }

        @Override
        public void onAdLoaded() {
            LTToast.makeText(LTBase_Demo_MainActivity.mMainActivity, "广告加载完成", Toast.LENGTH_LONG);
        }

        @Override
        public void onUserEarnedReward(int amount, String type) {
            LTToast.makeText(LTBase_Demo_MainActivity.mMainActivity, "广告收益" + amount + "#" + type, Toast.LENGTH_LONG);
        }

    };


}
