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 AdViewVideoListener,
		OnClickListener {

	private Button nextVideo = null;
	private Button video_back = null;
	private AdViewVideoManager videoManager = null;
	//test case
	public static final String APPID = "SDK201916270406508oj5ykxwe3xrjyx";
	public static final String POSID = "POSID50r4bpi1abbc"; //video
	//public static final String POSID = "POSID9wdm9r7f261a"; //paste video

	public final static String TAG = "AdViewBID";

	private void requestAd() {
		videoManager = new AdViewVideoManager(this,
				MainActivity.test_APPID,
                MainActivity.test_Video_POSID,
				this,
				false);
		// 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);

		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);
	}

	@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 ++++++++++++");
	}

	@Override
	public void onVideoClosed() {
		Log.i(TAG, "++++++++++++[app] onVideoClosed ++++++++++++");
	}

	@Override
	public void onPlayedError(String arg0) {
		Log.i(TAG, "onPlayedError:"+arg0);
	}

	@Override
	public void onReceivedVideo(String arg0) {

		Log.i(TAG, "onRecievedVideo:"+arg0);
	}

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

}
