package com.adviewbid.demo;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.kuaiyou.loader.AdViewInstlManager;
import com.kuaiyou.loader.loaderInterface.AdViewInstlListener;
import com.kuaiyou.utils.ConstantValues;
import com.adviewbid.demo.R;

/**
 * Instl ad
 * @author YYZ
 *
 */
public class AdInstlActivity extends Activity implements AdViewInstlListener,OnClickListener {

	private Button nextInstl = null;
	private Button insert_back = null;
	private AdViewInstlManager adInstlBIDView = null;

	protected void requestInstlAd() {
		adInstlBIDView = new AdViewInstlManager(this,
							MainActivity.test_APPID,
							true //show close button ：true，no show ：false
							);
		adInstlBIDView.setOnAdViewListener(this);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_insert);
		nextInstl = (Button) findViewById(R.id.instl_change);
		insert_back = (Button) findViewById(R.id.insert_back);
		nextInstl.setOnClickListener(this);
		insert_back.setOnClickListener(this);

		requestInstlAd();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.insert_back:
				this.finish();
				break;
			case R.id.instl_change:
//				adInstlBIDView = new AdViewInstlManager(this, MainActivity.APPID, true);
//				adInstlBIDView.setOnAdViewListener(this);
				requestInstlAd();
				break;
			default:
				break;
		}

	}

	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}

	@Override
	public void onAdClicked() {
		Log.i("AdInstlActivity", "onAdClicked");
	}

	@Override
	public void onAdClosed() {
		Log.i("AdInstlActivity", "onAdClosedAd");
	}

	@Override
	public void onAdReady() {
		Log.i("AdInstlActivity", "onAdReady");
		/**
		 * 1.normal show mode
		 */
		adInstlBIDView.showInstl(this);
		/**
		 * 2.custom show
		 */
		// if want to use custom show, pls use the following references codes
//		if (adInstlBIDView.getDialogView() != null) {
//			new AlertDialog.Builder(AdInstlActivity.this).setView(adInstlBIDView.getDialogView()).setPositiveButton("去看看", new DialogInterface.OnClickListener() {
//				@Override
//				public void onClick(DialogInterface dialog, int which) {
//					adInstlBIDView.reportClick();
//					adInstlBIDView.closeInstl();
//				}
//			}).setNegativeButton("退出应用", new DialogInterface.OnClickListener() {
//				@Override
//				public void onClick(DialogInterface dialog, int which) {
//					adInstlBIDView.closeInstl();
//				}
//			}).show();
//			adInstlBIDView.reportImpression();
//		}

	}

	@Override
	public void onAdDisplayed() {
		Log.i("AdInstlActivity", "onDisplayed");
	}

	@Override
	public void onAdFailedReceived( String arg1) {
		Log.i("AdInstlActivity", "onAdRecieveFailed："+arg1);
	}

	@Override
	public void onAdReceived() {
		Log.i("AdInstlActivity", "onAdRecieved");
	}


	@Override
	public void onPointerCaptureChanged(boolean hasCapture) {

	}

}
