/* * Copyright 2014 trinea.cn All right reserved. This software is the confidential and proprietary information of * trinea.cn ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into with trinea.cn. */ package com.gh.gamecenter.adapter; import android.content.Context; import android.content.Intent; import android.view.View; import android.view.ViewGroup; import com.facebook.drawee.view.SimpleDraweeView; import com.gh.common.util.DataLogUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.ImageUtils; import com.gh.common.util.NewsUtils; import com.gh.common.util.StringUtils; import com.gh.gamecenter.GameDetailActivity; import com.gh.gamecenter.NewsDetailActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.SubjectActivity; import com.gh.gamecenter.entity.SlideEntity; import java.util.HashMap; import java.util.List; import java.util.Map; /** * ImagePagerAdapter * * @author Trinea 2014-2-23 */ public class ImagePagerAdapter extends RecyclingPagerAdapter { private Context mContext; // private List imageIdList; private List mSlideEntityList; private int mSize; private boolean mIsInfiniteLoop; // private ImageIndicator indicator; public ImagePagerAdapter(Context context, List slideEntityList, boolean isInfiniteLoop) { mContext = context; mSlideEntityList = slideEntityList; mSize = getSize(slideEntityList); mIsInfiniteLoop = isInfiniteLoop; } public int getSize(List sourceList) { return sourceList == null ? 0 : sourceList.size(); } @Override public int getCount() { // Infinite loop return mIsInfiniteLoop ? Integer.MAX_VALUE : getSize(mSlideEntityList); } @Override public View getView(final int position, View view, ViewGroup container) { if (view == null) { view = new SimpleDraweeView(mContext); } final SlideEntity slideEntity = mSlideEntityList.get(getPosition(position)); ImageUtils.Companion.getInstance().display(mContext.getResources(), (SimpleDraweeView) view, slideEntity.getImage(), R.drawable.preload); // indicator.setPosition(mSlideEntityList.mSize(), getPosition(position)); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map kv = new HashMap<>(); kv.put("名字", slideEntity.getName()); kv.put("位置", getPosition(position) + 1); DataUtils.onEvent(mContext, "点击", "游戏-专题-滚动图", kv); // 首页轮播图数据统计 DataLogUtils.uploadLunbotuLog(mContext, slideEntity.getType(), slideEntity.getName(), String.valueOf(getPosition(position) + 1)); String entrance = StringUtils.buildString("(游戏-专题:滚动图[" , slideEntity.getName() , "=", slideEntity.getType() , "=", String.valueOf(getPosition(position) + 1) , "])"); switch (slideEntity.getType()) { case "game": GameDetailActivity.startGameDetailActivity(mContext, slideEntity.getLink(), entrance); break; case "news": // 统计阅读量 NewsUtils.statNewsViews(mContext, slideEntity.getLink()); Intent intent = NewsDetailActivity.getIntentById(mContext, slideEntity.getLink(), entrance); mContext.startActivity(intent); break; case "column": SubjectActivity.startSubjectActivity(mContext, slideEntity.getLink(), slideEntity.getName(), false, entrance); break; } } }); return view; } /** * get really position * * @param position * @return */ private int getPosition(int position) { return mIsInfiniteLoop ? position % mSize : position; } /** * @return the mIsInfiniteLoop */ public boolean isInfiniteLoop() { return mIsInfiniteLoop; } /** * @param isInfiniteLoop the mIsInfiniteLoop to set */ public ImagePagerAdapter setInfiniteLoop(boolean isInfiniteLoop) { this.mIsInfiniteLoop = isInfiniteLoop; return this; } }