package com.wasu.cs.widget;

import android.content.Context;
import android.graphics.Rect;
import android.os.Handler;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.RelativeLayout;

import com.wasu.cs.adapter.ContAdapter;
import com.wasu.cs.model.HomeColumnModel;
import com.wasu.cs.protocol.HomeColumnProtocol;
import com.wasu.cs.protocol.HomeColumnProtocol.HomeColumnFetchCallback;
import com.wasu.cs.ui.ActivityMain;
import com.wasu.module.log.WLog;
import com.wasu.statistics.WasuStatistics;
import com.wasu.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

import cn.com.wasu.main.AppUtil;
import cn.com.wasu.main.R;

/**
 * 
 * @ClassName: MainHPageView
 * @Description: 内容区的Page
 * @author 海迪
 * @date 2015年6月16日 下午1:16:26
 * 
 */
public class MainHPageView extends HorizontalScrollView {

	private Context context;
	private int mMarginTop = 0;
	private int mMarginLeft = 0;
	private int space = 0;
	private String jsonUrl;

	private int rightPadding = 0;
	private int leftPadding = 0;
	/**首页第几排**/
	private int position = 0;
	/**首页最多支持的屏数**/
	private int maxPosition = 0;
	private int itemTotal = 0;
	private boolean isFocusFirstItem = false;
	private boolean defaultFirstItemFocus = false;

	public ContAdapter mAdapter;

	public PageRelativeLayout pageBox;
	private HomeColumnModel scModel;
	private ActivityMain activityMain;
	private String layout;
	private String parentTitle;
	private int loadDataCount = 0;
	public MainHPageItemBase leftView1, leftView2, rightView1, rightView2;

	public MainHPageView(Context context, ActivityMain activityMain) {
		super(context);
		this.activityMain = activityMain;
		init(context);

	}

	public MainHPageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public MainHPageView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init(context);
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: init
	 * @Description: 初始化PageView
	 * @param @param context
	 * @return void
	 * @throws
	 * 
	 * @param context
	 */
	private void init(Context context) {
		this.context = context;
		setHorizontalScrollBarEnabled(false);
		setChildrenDrawingOrderEnabled(true);
		setClipChildren(false);
		// LayoutInflater.from(context).inflate(R.layout.main_hpage_view, this);
		// item容器
		// pageBox = (PageRelativeLayout) findViewById(R.id.page_box);
		pageBox = new PageRelativeLayout(context);
		pageBox.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
		this.addView(pageBox);
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: initData
	 * @Description: 初始化内容区数据，并展现UI
	 * @param @param model
	 * @return void
	 * @throws
	 * @param model
	 * 初始化内容区数据，并展现UI
	 */
	public void initData(HomeColumnModel model) {
		scModel = model;
		jsonUrl = model.getJsonUrl();
		layout = model.getLayout();
		parentTitle = model.getTitle();
		if (!StringUtils.isBlank(jsonUrl))
			reqColumnData();
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: reqColumnData
	 * @Description: 向服务器发起请求，获取内容区数据
	 * @param
	 * @return void
	 * @throws
	 * 
	 */
	private void reqColumnData() {
		if (activityMain != null) {
			activityMain.showLoading();
		}
		// http://120.26.137.228/?s=2002&p=sntCat&k=1&v=1&catId=220195&debug=1
		loadDataCount++;
		HomeColumnProtocol.fetch(jsonUrl, new HomeColumnFetchCallback() {

			@Override
			public void onResult(boolean successed, HomeColumnProtocol homeColumnProtocol) {
				activityMain.hideLoading();
				WLog.e("test", "reqColumnData jsonUrl = "+jsonUrl);
				WLog.e("test", "reqColumnData successed = "+successed);
				if (successed) {
					homeColumnProtocol.initChildrenTimeAndCorner(scModel.getCarouselTime(), scModel.getCornerIconMap());
					// 拿到所有的数据，传给activity
					// 点播数据，推荐数据
					ArrayList<HomeColumnModel> list = (ArrayList<HomeColumnModel>) homeColumnProtocol.getColumnList();
					if (list == null || list.size() < 1) {// 如果数据为空，重新加载
						if (loadDataCount < 3) {
							reqColumnData();
							return;
						}
					}
					for (int i = 0; i < homeColumnProtocol.getColumnList().size(); i++) {
						if (!TextUtils.isEmpty(layout)) {
							if (layout.equals("Home_Rec")) {
								// 传给activity
								activityMain.setRecList(list);
							} else {
								activityMain.setVodList(list);
							}
						} else {
							if (loadDataCount < 3) {
								reqColumnData();
								return;
							}
						}
					}
					initAdapter(homeColumnProtocol.getColumnList());
					/**当UI展现完成后马上请求一下焦点，防止在apk第一安转后焦点丢失**/
					requestFirstItemFocus();
					loadDataCount = 0;
				} else {
					if (loadDataCount < 3) {
						reqColumnData();
						return;
					}
					/*
					 * if(homeColumnProtocol != null) {
					 * activityMain.showErrorExitDlg(ErrorMap.mapError(context,
					 * homeColumnProtocol.getCode(),
					 * homeColumnProtocol.getMessage())); } else {
					 * activityMain.showErrorExitDlg
					 * (getResources().getString(R.string.error_unknown)); }
					 */
				}
			}
		});
	}

	public interface OnHomeItemClickListener {

		void onHomeItemClick(int index);
	}

	// MainHPageItemBase videoItem;
	/**
	 * 
	 * @author 海迪
	 * @Title: initAdapter
	 * @Description: 初始化Adapter，向服务器请求数据成功后，被调用
	 * @param @param cList
	 * @return void
	 * @throws
	 * 
	 * @param cList
	 */
	public void initAdapter(final List<HomeColumnModel> cList) {
		if (cList == null || cList.size() <= 0) {
			return;
		}
		ContAdapter adapter = new ContAdapter(cList);
		adapter.setViewInterface(new ContAdapter.ViewInterface() {

			@Override
			public View getView(final int item_position, Object dataObject, View convertView, ViewGroup parent) {

				final HomeColumnModel cm = (HomeColumnModel) dataObject;
				if (cm == null) {
					return null;
				}

				MainHPageItemBase pageItem = null;
				if (convertView == null) {
					pageItem = createItem(cm);
				} else {
					pageItem = (MainHPageItemBase) convertView;

				}
				if (pageItem.isVideoItem()) {

//					activityMain.videoItem = pageItem;
				}

				pageItem.setOnHomeItemClickListener(new OnHomeItemClickListener() {

					@Override
					public void onHomeItemClick(int index) {
						sendItemClickStatistical(cList, index);

					}
				});
				cm.setParentLayout(layout);
				cm.setParentTitle(parentTitle);
				pageItem.initData(cm);

				pageItem.setContentDescription(cm.getName());

				return pageItem;
			}
		});

		this.setAdapter(adapter);
	}

	private void sendItemClickStatistical(List<HomeColumnModel> list, int item_position) {
		// 首页点击统计

		int pagenum;
		// 当下被点击的item
		HomeColumnModel cur_hcm = list.get(item_position);

		if (maxPosition >= 1) {
			pagenum = position;
		} else {
			pagenum = 1;
		}

		if (layout.equals("Home_Rec")) {// 如果是
			// 统计展示

			if (list != null && list.size() > 0) {
				int len = list.size();
				String[] items = new String[len];

				String[] items_traceid = new String[len];

				for (int index = 0; index < list.size(); index++) {
					HomeColumnModel hcm = list.get(index);
					if (hcm == null)
						continue;

					items[index] = hcm.getEid() + "";
					items_traceid[index] = hcm.getTraceid();

				}
				if (item_position < items_traceid.length && TextUtils.isEmpty(items_traceid[item_position])) {
					WasuStatistics.getInstance().click(items[item_position]);
				} else {

					// 此处的点击需要设置
//					WasuStatistics.getInstance().BigDataRecommendListView(items, items_traceid);
//					WasuStatistics.getInstance().recommendItemClick("", "", items, items_traceid, (position + 1) + "");
				}

			}
		}
		// homeItemClick点击事件统计
		int num = item_position - firstDataList.size();
		String position = "";
		if (num < 0) {
			position = 1 + "_" + (item_position + 1);
		} else {
			position = 2 + "_" + (item_position + 1 - firstDataList.size());
		}
		WasuStatistics.getInstance().homeItemClick(pagenum, parentTitle, position, cur_hcm.getEid() + "", cur_hcm.getName());
		// 播放路径入口统计
		AppUtil.playEnter = parentTitle + "_" + position;
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: createItem
	 * @Description: 根据数据生成内容区Item
	 * @param @param cm
	 * @param @return
	 * @return MainHPageItemBase
	 * @throws
	 * 
	 * @param cm
	 * @return
	 */
	private MainHPageItemBase createItem(HomeColumnModel cm) {
		MainHPageItemBase item = null;

		if (context == null || cm == null)
			return item;
		int rowspan = cm.getRowspan();
		int colspan = cm.getColspan();
		String frontImgUrl = null;
		if (cm.getPicUrlList().size() > 0) {
			frontImgUrl = cm.getPicUrlList().get(0).getTopPic();
		}

		 if (cm.getLinkType() == 8 || cm.getLinkType() == 7) { // 直播频道
		 item = new MainHPageItemVideoLive(activityMain);
			 final MainHPageItemBase finalItem = item;
			 getHandler().postDelayed(new Runnable() {
				 @Override
				 public void run() {
					 WLog.d("danxx", "延迟请求焦点");
					finalItem.requestFocus();
				 }
			 }, 200);
		 } else if (cm.getLinkType() == 20) { // 点击小屏转大屏，
		 item = new MainHPageItemVideoVOD(activityMain);
		 } else if (cm.getLinkType() == 21) { // 点击进详情
		 item = new MainHPageItemVideoVOD(activityMain);
		 } else if (cm.getLinkType() == 22) { // 点击进栏目
		 item = new MainHPageItemVideoVOD(activityMain);
		 } else
		if (rowspan == 2 && colspan == 1) { // 2*1Item
			item = new MainHPageItem21(context);
		} else if (rowspan == 1 && colspan == 1) { // 1*1Item
			item = new MainHPageItem11(context);
		} else if (rowspan == 2 && colspan == 2) {
			if (!StringUtils.isBlank(frontImgUrl)) { // 2*2 异形图Item
				item = new MainHPageItemFront(context);
			} else { // 2*2 普通Item
				item = new MainHPageItem22(context);
			}
		}else{
			item = new MainHPageItem21(context);
		}

		return item;
	}

	public void setAdapter(ContAdapter adapter) {
		this.mAdapter = adapter;
		initChildrenView();
	}

	private List<MainHPageItemBase> firstItemList = new ArrayList<MainHPageItemBase>();
	private List<HomeColumnModel> firstDataList = new ArrayList<HomeColumnModel>();
	private List<HomeColumnModel> secondDataList = new ArrayList<HomeColumnModel>();

	/**
	 * 
	 * @author 海迪
	 * @Title: initChildrenView
	 * @Description: 根据数据生成内容区Item, 并布局显示
	 * @param
	 * @return void
	 * @throws
	 * 
	 */
	private void initChildrenView() {
		if (mAdapter == null)
			return;

		firstDataList.clear();
		secondDataList.clear();

		MainHPageItemBase child = null;
		List<MainHPageItemBase> firstList = new ArrayList<MainHPageItemBase>(); // 第一行的数据集
		List<MainHPageItemBase> secondList = new ArrayList<MainHPageItemBase>(); // 第二行的数据集
		int firstColspantoTotal = 0;
		int secondColspantoTotal = 0;
		for (int i = 0, len = mAdapter.getCount(); i < len; i++) {

			child = (MainHPageItemBase) mAdapter.getView(i, null, null);

			if (child == null)
				continue;

			child.setId(AppUtil.createId()); // 给item创建id
			child.setPageRelativeLayout(pageBox); // 设置承载item的容器
			if (child.getRowspan() == 2) {
				firstList.add(child); // 加入第一行数据集
				firstColspantoTotal += child.getColspan();
				firstDataList.add(child.getData());
			} else if (child.getRowspan() == 1) {
				secondList.add(child); // 加入第二行数据集
				secondColspantoTotal += child.getColspan();
				secondDataList.add(child.getData());
			}

		}

		MainHPageItemBase tempItem = null;
		MainHPageItemBase firstItem = null;
		RelativeLayout.LayoutParams lp = null;
		int index = 0;
		itemTotal = firstList.size();
		// int mSpace =
		// getResources().getInteger(R.integer.i_main_page_item_mtop);
		int mSpace = getResources().getDimensionPixelSize(R.dimen.d_45dp);
		for (MainHPageItemBase item : firstList) { // 添加第一行数据
			// lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
			// LayoutParams.WRAP_CONTENT);
			lp = (android.widget.RelativeLayout.LayoutParams) item.getLayoutParams();

			if (tempItem == null) {

				if (item.isFrontItem()) {
					lp.topMargin = mMarginTop;
					lp.leftMargin = mMarginLeft - mSpace;
				} else {
					lp.topMargin = mMarginTop + mSpace;
					lp.leftMargin = mMarginLeft;
				}

				firstItem = item;
			} else {

				lp.leftMargin = space;

				if (tempItem.isFrontItem() && item.isFrontItem()) {
					lp.leftMargin = space - 2 * mSpace;
				} else if (item.isFrontItem() != tempItem.isFrontItem()) {
					lp.leftMargin = space - mSpace;
//					lp.topMargin = tempItem.isFrontItem() ? mSpace : -mSpace;
				}
				// 设置显示位置
				lp.addRule(RelativeLayout.ALIGN_TOP, tempItem.getId());
				lp.addRule(RelativeLayout.RIGHT_OF, tempItem.getId());
			}

			tempItem = item;

			item.setLayoutParams(lp);
			item.setIndex(index++);

			// 向容器添加item
			pageBox.addView(item);
			firstItemList.add(item);
		}
		leftView1 = firstItemList.get(0);
		rightView1 = firstItemList.get(firstItemList.size() - 1);

		tempItem = null;
		if (secondColspantoTotal > firstColspantoTotal) {
			itemTotal += secondList.size();
		}

		for (MainHPageItemBase item : secondList) { // 添加第二行数据
			// lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
			// LayoutParams.WRAP_CONTENT);
			lp = (android.widget.RelativeLayout.LayoutParams) item.getLayoutParams();

			if (tempItem == null) {
				if (firstItem != null) {
					lp.topMargin = space;

					if (item.isFrontItem() && firstItem.isFrontItem()) {
						lp.topMargin = space - 2 * mSpace;
					} else if (item.isFrontItem() != firstItem.isFrontItem()) {
						lp.topMargin = space - mSpace;
//						lp.leftMargin = firstItem.isFrontItem() ? mSpace : -mSpace;
					}

					lp.addRule(RelativeLayout.ALIGN_LEFT, firstItem.getId());
					lp.addRule(RelativeLayout.BELOW, firstItem.getId());
				} else {
					if (item.isFrontItem()) {
						lp.topMargin = mMarginTop;
						lp.leftMargin = mMarginLeft - mSpace;
					} else {
						lp.topMargin = mMarginTop + mSpace;
						lp.leftMargin = mMarginLeft;
					}
				}
			} else {
				lp.leftMargin = space;

				if (tempItem.isFrontItem() && item.isFrontItem()) {
					lp.leftMargin = space - 2 * mSpace;
				} else if (item.isFrontItem() != tempItem.isFrontItem()) {
					lp.leftMargin = space - mSpace;
//					lp.topMargin = tempItem.isFrontItem() ? mSpace : -mSpace;
				}

				lp.addRule(RelativeLayout.ALIGN_TOP, tempItem.getId());
				lp.addRule(RelativeLayout.RIGHT_OF, tempItem.getId());
			}

			tempItem = item;

			item.setLayoutParams(lp);
			item.setIndex(index++);
			// 添加第二行的item
			pageBox.addView(item);
		}
		leftView2 = secondList.get(0);
		rightView2 = secondList.get(secondList.size() - 1);
		if (isFocusFirstItem && AppUtil.MAIN_PAGERVIEW_POSITION == position && pageBox.getChildCount() > 0) {
			requestFirstItemFocus();
		}

		if (defaultFirstItemFocus) {
			/**默认屏请求焦点**/
			activityMain.firstRequestFocus();
//			requestFirstItemFocus();
		}
	}

	/*
	 * (非 Javadoc) <p>Title: computeScrollDeltaToGetChildRectOnScreen</p>
	 * <p>Description: PageView翻页时，某个Item没有显示完整，则进行滚动</p>
	 * 
	 * @param rect
	 * 
	 * @return 返回滚动距离
	 * 
	 * @see
	 * android.widget.HorizontalScrollView#computeScrollDeltaToGetChildRectOnScreen
	 * (android.graphics.Rect)
	 */
	@Override
	protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {

		int scrollXDelta = 0;

		int itemLeft = rect.left;
		int itemRight = rect.right;
		int scrollX = getScrollX();
		int width = getWidth();
		if ((itemLeft - scrollX) < leftPadding) {// 如果左边越界

			/*
			 * int x = itemRight - width + rightPadding; if(x < 0) { x = 0; }
			 * smoothScrollTo(x, 0);
			 */

			int x = itemRight - width + rightPadding;// 右边的所有控件
			scrollXDelta = x - scrollX;// 把右边控件以及滚动差值滚动出来
			if (x < 0) {// 如果右边部分不超出屏幕
				scrollXDelta = -scrollX;
			}

		}

		if ((itemRight + rightPadding) > (scrollX + width)) {// 如果右边越界
			/*
			 * int pWidth = pageBox.getWidth(); int x = itemLeft - leftPadding;
			 * if((x+width) > pWidth) { x = pWidth-width; } smoothScrollTo(x,
			 * 0);
			 */

			int pWidth = pageBox.getWidth();
			int x = itemLeft - leftPadding;
			scrollXDelta = x - scrollX;
			if ((x + width) > pWidth) {// 如果往右把超出屏幕的部分全部滚动过来以后该view左边也不超出屏幕
				scrollXDelta = pWidth - scrollX - width;// 滚动超出屏幕的部分
			}
			// 否则滚动左边展示出来的所有控件的距离
		}

		if (scrollXDelta != 0 && activityMain != null) {
			sendStatistical(activityMain.getStatisticalList(), scrollXDelta);
		}
		return scrollXDelta;
	}

	public void sendStatistical(List<MainHPageItemBase> statisticalList, int scrollX) {

		int x = scrollX + getScrollX();
		List<MainHPageItemBase> tempList = new ArrayList<MainHPageItemBase>();
		for (MainHPageItemBase item : firstItemList) {
			if (item.isShow(x)) {
				tempList.add(item);

				if (!statisticalList.contains(item)) {
					WasuStatistics.getInstance().BigDataRecommendListView("" + item.getData().getEid(), "");
//					WasuStatistics.getInstance().view("" + item.getData().getEid());
				}
			}
		}

		statisticalList.clear();
		statisticalList.addAll(tempList);
	}

	/*
	 * (非 Javadoc) <p>Title: onRequestFocusInDescendants</p> <p>Description:
	 * 修改PageView之间在进行翻页后，指定相应的Item获取焦点</p>
	 * 
	 * @param direction
	 * 
	 * @param previouslyFocusedRect
	 * 
	 * @return
	 * 
	 * @see android.widget.HorizontalScrollView#onRequestFocusInDescendants(int,
	 * android.graphics.Rect)
	 */
	@Override
	protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {

		int index = -1;
		if (previouslyFocusedRect == null && position > 0 && position < maxPosition) {// 如果当前屏不是第一屏也不是最后一屏
			if (direction == View.FOCUS_LEFT) {
				index = itemTotal - 1;
				if (AppUtil.MAIN_PAGERVIEW_POSITION == maxPosition) {// 如果是最后一屏
					index = 0;
				}
			} else if (direction == View.FOCUS_RIGHT) {// 如果是从按右键获得的焦点，第一个获焦
				index = 0;
				if (AppUtil.MAIN_PAGERVIEW_POSITION == 0) {// 如果当前是第一屏
					index = itemTotal - 1;
				}
			}

			if (pageBox.getChildCount() == 0) {
				isFocusFirstItem = true;
			}

			if (index != -1 && pageBox.getChildCount() > index) {
				View child = pageBox.getChildAt(index);
				if (child.getVisibility() == View.VISIBLE) {
					if (child.requestFocus(direction, previouslyFocusedRect)) {
						AppUtil.MAIN_PAGERVIEW_POSITION = position;

						return true;
					}
				}
			}

		}

		AppUtil.MAIN_PAGERVIEW_POSITION = position;

		return super.onRequestFocusInDescendants(direction, previouslyFocusedRect);
	}

	public void setmMarginTop(int mMarginTop) {
		this.mMarginTop = mMarginTop;
	}

	public void setmMarginLeft(int mMarginLeft) {
		this.mMarginLeft = mMarginLeft;
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: setSpace
	 * @Description: 设置Item之间的间隔
	 * @param @param space
	 * @return void
	 * @throws
	 * 
	 * @param space
	 */
	public void setSpace(int space) {
		this.space = space;
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: setRightPadding
	 * @Description: 设定最右边的Item与PageView右边的边距
	 * @param @param rightPadding
	 * @return void
	 * @throws
	 * 
	 * @param rightPadding
	 */
	public void setRightPadding(int rightPadding) {
		this.rightPadding = rightPadding;

		if (pageBox != null) {
			pageBox.setPadding(leftPadding, 0, rightPadding, 0);
		}
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: setLeftPadding
	 * @Description: 设定最左边的Item与PageView左边的边距
	 * @param @param leftPadding
	 * @return void
	 * @throws
	 * 
	 * @param leftPadding
	 */
	public void setLeftPadding(int leftPadding) {
		this.leftPadding = leftPadding;
		if (pageBox != null) {
			pageBox.setPadding(leftPadding, 0, rightPadding, 0);
		}
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: setItemTotal
	 * @Description: 设置最大列数
	 * @param @param itemTotal
	 * @return void
	 * @throws
	 * 
	 * @param itemTotal
	 */
	public void setItemTotal(int itemTotal) {
		this.itemTotal = itemTotal;
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: setPosition
	 * @Description: 指定当前View在PagerView的Index;
	 * @param @param position
	 * @return void
	 * @throws
	 * 
	 * @param position
	 */
	public void setPosition(int position) {
		this.position = position;
	}

	/**
	 * 取得当前PageView的Index
	 * 
	 * @return
	 */
	public int getPosition() {
		return this.position;
	}

	/**
	 * 
	 * @author 海迪
	 * @Title: setMaxPosition
	 * @Description: 设置PagerView中最大的position
	 * @param @param maxPosition
	 * @return void
	 * @throws
	 * 
	 * @param maxPosition
	 */
	public void setMaxPosition(int maxPosition) {
		this.maxPosition = maxPosition;
	}

	/**
	 * 初始化焦点
	 */
	public void requestFirstItemFocus() {
		if (pageBox == null) {
			return;
		}

		int childCount = pageBox.getChildCount();
		if (childCount <= 0) {
			return;
		}

		View child = null;
		for (int i = 0; i < childCount; i++) {
			child = pageBox.getChildAt(i);
			if (child != null && ((child instanceof MainHPageItemVideoLive) || (child instanceof MainHPageItemVideoVOD))) {
				child.requestFocus();
				return;
			}
		}
		pageBox.getChildAt(0).requestFocus();
	}

	public void setDefaultFirstItemFocus(boolean defaultFirstItemFocus) {
		this.defaultFirstItemFocus = defaultFirstItemFocus;
	}

	/**
	 * 通知子View当前被选中
	 * 
	 * @param isSelect
	 */
	public void notifySelect(boolean isSelect) {
		if (pageBox != null) {
			View child = null;
			int count = pageBox.getChildCount();
			for (int i = 0; i < count; i++) {
				child = pageBox.getChildAt(i);
				if (child != null) {
					if (child instanceof MainHPageItemVideoLive) {
						MainHPageItemVideoLive itemVideo = (MainHPageItemVideoLive) child;
						itemVideo.changeStatus(isSelect);
					} else if (child instanceof MainHPageItemVideoVOD) {
						MainHPageItemVideoVOD itemVideo1 = (MainHPageItemVideoVOD) child;
						itemVideo1.changeStatus(isSelect);
					}

				}
			}
		}
	}

	Handler handler = new Handler();
	Runnable runnable = new Runnable() {

		@Override
		public void run() {
			if (pageBox != null) {
				View child = null;
				int count = pageBox.getChildCount();
				for (int i = 0; i < count; i++) {
					child = pageBox.getChildAt(i);
					if (child != null) {
						if (child instanceof MainHPageItemVideoLive) {
							MainHPageItemVideoLive itemVideo = (MainHPageItemVideoLive) child;
							itemVideo.detect();
						} else if (child instanceof MainHPageItemVideoVOD) {
							MainHPageItemVideoVOD itemVideo1 = (MainHPageItemVideoVOD) child;

							itemVideo1.detect();
						}
						// MainHPageItemBase itemVideo = (MainHPageItemBase)
						// child;
						// itemVideo.detect();
					}
				}
			}
		}
	};

	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {

		super.onScrollChanged(l, t, oldl, oldt);
		handler.removeCallbacks(runnable);
		handler.postDelayed(runnable, 200);

	}

	public List<HomeColumnModel> getFirstDataList() {
		return firstDataList;
	}

	public List<HomeColumnModel> getSecondDataList() {
		return secondDataList;
	}

}
