提交项目
This commit is contained in:
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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 java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.tendcloud.tenddata.TCAgent;
|
||||
|
||||
/**
|
||||
* 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<GameEntity> slideList = null;
|
||||
|
||||
private int size;
|
||||
private boolean isInfiniteLoop;
|
||||
|
||||
// private ImageIndicator indicator;
|
||||
|
||||
public ImagePagerAdapter(Context context, List<GameEntity> 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<GameEntity> 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(int position, View view, ViewGroup container) {
|
||||
ViewHolder holder;
|
||||
if (view == null) {
|
||||
holder = new ViewHolder();
|
||||
view = holder.imageView = new ImageView(context);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) view.getTag();
|
||||
}
|
||||
|
||||
final GameEntity gameEntity = slideList.get(getPosition(position));
|
||||
|
||||
ImageUtils.getInstance(context).display(gameEntity.getSlide(),
|
||||
holder.imageView, R.drawable.preload);
|
||||
// indicator.setPosition(slideList.size(), getPosition(position));
|
||||
|
||||
holder.imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("入口", "插件-精品-滚动图");
|
||||
TCAgent.onEvent(context, "游戏详情", gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "精品-滚动图");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("page", "插件");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "插件-精品滚动图");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
ImageView imageView;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isInfiniteLoop
|
||||
*/
|
||||
public boolean isInfiniteLoop() {
|
||||
return isInfiniteLoop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isInfiniteLoop
|
||||
* the isInfiniteLoop to set
|
||||
*/
|
||||
public ImagePagerAdapter setInfiniteLoop(boolean isInfiniteLoop) {
|
||||
this.isInfiniteLoop = isInfiniteLoop;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user