Files
assistant-android/app/src/main/java/com/gh/gamecenter/adapter/ImagePagerAdapter.java
huangzhuanghua 3cbc850d12 项目整理
2016-12-12 16:34:19 +08:00

146 lines
5.0 KiB
Java

/*
* 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.GameUtils;
import com.gh.common.util.ImageUtils;
import com.gh.common.util.NewsUtils;
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 <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2014-2-23
*/
public class ImagePagerAdapter extends RecyclingPagerAdapter {
private Context context;
// private List<Integer> imageIdList;
private List<SlideEntity> slideList = null;
private int size;
private boolean isInfiniteLoop;
// private ImageIndicator indicator;
public ImagePagerAdapter(Context context, List<SlideEntity> slideList,
boolean isInfiniteLoop) {
this.context = context;
this.slideList = slideList;
this.size = getSize(slideList);
this.isInfiniteLoop = isInfiniteLoop;
}
@Override
public int getCount() {
// Infinite loop
return isInfiniteLoop ? Integer.MAX_VALUE : getSize(slideList);
}
public int getSize(List<SlideEntity> sourceList) {
return sourceList == null ? 0 : sourceList.size();
}
/**
* get really position
*
* @param position
* @return
*/
private int getPosition(int position) {
return isInfiniteLoop ? position % size : position;
}
@Override
public View getView(final int position, View view, ViewGroup container) {
if (view == null) {
view = new SimpleDraweeView(context);
}
final SlideEntity slideEntity = slideList.get(getPosition(position));
ImageUtils.getInstance().display(context.getResources(), (SimpleDraweeView) view,
slideEntity.getImage(), R.drawable.preload);
// indicator.setPosition(slideList.size(), getPosition(position));
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Map<String, Object> kv = new HashMap<>();
kv.put("名字", slideEntity.getName());
kv.put("位置", getPosition(position) + 1);
DataUtils.onEvent(context, "点击", "游戏-插件-滚动图", kv);
// 首页轮播图数据统计
DataLogUtils.uploadLunbotuLog(context, slideEntity.getType(),
slideEntity.getName(), String.valueOf(getPosition(position) + 1));
if ("game".equals(slideEntity.getType())) {
String entrance = "(游戏-插件:滚动图["
+ slideEntity.getName()
+ "=" + slideEntity.getType()
+ "=" + (getPosition(position) + 1)
+ "])";
GameUtils.startGameDetailActivity(context, slideEntity.getLink(), entrance);
} else if ("news".equals(slideEntity.getType())) {
// 统计阅读量
NewsUtils.statNewsViews(slideEntity.getLink());
Intent intent = new Intent(context, NewsDetailActivity.class);
intent.putExtra("newsId", slideEntity.getLink());
intent.putExtra("entrance", "(游戏-插件:滚动图["
+ slideEntity.getName()
+ "=" + slideEntity.getType()
+ "=" + (getPosition(position) + 1)
+ "])");
context.startActivity(intent);
} else if ("column".equals(slideEntity.getType())) {
Intent intent = new Intent(context, SubjectActivity.class);
intent.putExtra("id", slideEntity.getLink());
intent.putExtra("name", slideEntity.getName());
context.startActivity(intent);
}
}
});
return view;
}
/**
* @return the isInfiniteLoop
*/
public boolean isInfiniteLoop() {
return isInfiniteLoop;
}
/**
* @param isInfiniteLoop
* the isInfiniteLoop to set
*/
public ImagePagerAdapter setInfiniteLoop(boolean isInfiniteLoop) {
this.isInfiniteLoop = isInfiniteLoop;
return this;
}
}