package com.adviewbid.demo;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
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.AdViewVideoManager;
import com.kuaiyou.loader.loaderInterface.AdViewVideoListener;
import com.adviewbid.demo.R;

import java.io.Serializable;

/**
 * video
 * @author YYZ
 *
 */
public class AdVideoActivity extends Activity implements OnClickListener {

	private Button nextVideo = null;
	private Button video_back = null;
	private AdViewVideoManager videoManager = null;
	private AdViewVideoListener advListener;

	public final static String TAG = "AdViewVideoBID";

	private void requestAd() {
		videoManager = new AdViewVideoManager(this,
				MainActivity.offical_APPID,
                MainActivity.offical_Video_POSID,
				advListener,
				false);
		//videoManager.setTestMode(true);
		videoManager.setGDPR2(1,
				MainActivity.Gdpr);


		// screen orientation , pls refer to ActivityInfo.SCREEN_XXXXXX definition
		videoManager.setVideoOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_video);
		nextVideo = (Button) findViewById(R.id.video_change);
		video_back = (Button) findViewById(R.id.video_back);
		nextVideo.setOnClickListener(this);
		video_back.setOnClickListener(this);
		advListener = new com.kuaiyou.loader.loaderInterface.AdViewVideoListener() {
			@Override
			public void onFailedReceivedVideo(String error) {
				Log.i(TAG, "onFailedRecievedVideo:"+error);
//		nextVideo.setEnabled(true);
			}
			@Override
			public void onVideoStartPlayed() {

				Log.i(TAG, "++++++++++++ [app]onVideoStartPlayed ++++++++++");
			}
			@Override
			public void onVideoFinished() {
				Log.i(TAG, "++++++++++++[app] onVideoFinished ++++++++++++");
//		nextVideo.setEnabled(true);
			}
			@Override
			public void onVideoClosed() {
				Log.i(TAG, "++++++++++++[app] onVideoClosed ++++++++++++");
//		nextVideo.setEnabled(true);
			}
			@Override
			public void onPlayedError(String arg0) {
				Log.i(TAG, "onPlayedError:"+arg0);
//		nextVideo.setEnabled(true);
			}
			@Override
			public void onReceivedVideo(String arg0) {

				Log.i(TAG, "onRecievedVideo:"+arg0);
			}
			@Override
			public void onVideoReady() {
				Log.i(TAG, "onVideoReady");
				//videoManager.playVideo(this);
			}
		};


		requestAd();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.video_back:
			this.finish();
			break;
		case R.id.video_change:
			Log.i(TAG, "clickButton");
			requestAd();
			break;
		}

	}

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



}
