public class CardAdapter extends RecyclerView.Adapter<CardAdapter.ViewHolder> {
// List<MenuItem> mItems;
OnItemClickListener mItemClickListener;
Context context;
List<CategoryBean> catItems;
int defaultImgId;
ImageLoaderListner imageLoaderListner;
public CardAdapter(Context context, List<CategoryBean> catItems, int defaultImgId) {
this.context = context;
this.catItems = catItems;
this.defaultImgId=defaultImgId;
imageLoaderListner = (ImageLoaderListner)context;
}
class ViewHolder extends RecyclerView.ViewHolder implements
View.OnClickListener {
public LinearLayout placeHolder;
public LinearLayout placeNameHolder;
public ImageView img_categories;
public TextView txt_categories;
public ViewHolder(View itemView) {
super(itemView);
placeHolder = (LinearLayout) itemView.findViewById(R.id.mainHolder);
placeNameHolder = (LinearLayout) itemView
.findViewById(R.id.placeNameHolder);
// lin_categories =
// (RelativeLayout)itemView.findViewById(R.id.lin_categories);
img_categories = (ImageView) itemView
.findViewById(R.id.img_categories);
txt_categories = (TextView) itemView
.findViewById(R.id.txt_categories);
placeHolder.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (mItemClickListener != null) {
mItemClickListener.onItemClick(itemView, getAdapterPosition());
}
}
}
public interface OnItemClickListener {
void onItemClick(View view, int position);
}
public void setOnItemClickListener(
final OnItemClickListener mItemClickListener) {
this.mItemClickListener = mItemClickListener;
}
@Override
public int getItemCount() {
// TODO Auto-generated method stub
return catItems.size();
}
@SuppressWarnings("deprecation")
@Override
public void onBindViewHolder(final ViewHolder holder, final int i) {
CategoryBean mItem = catItems.get(i);
Log.e("OnBind..", ""+i);
imageLoaderListner.onImageLoad(mItem.getCatImgNameResourceId(context), holder.img_categories, defaultImgId);
//holder.img_categories.setImageResource(mItem.getCatImgNameResourceId(context));
holder.txt_categories.setText(mItem.getCatName());
holder.placeNameHolder.setBackgroundColor(mItem.getmColor());
/*Bitmap myPhoto = BitmapFactory.decodeResource(context.getResources(),
mItem.getCatImgNameResourceId(context));
Palette.generateAsync(myPhoto, new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
int bgColor = palette.getVibrantColor(context
.getResources().getColor(android.R.color.black));
Log.e("color code"+i, bgColor+"");
holder.placeNameHolder.setBackgroundColor(bgColor);
}
});*/
holder.placeNameHolder.setAlpha(0.8f);
}
//private ViewHolder viewHolder;
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
// TODO Auto-generated method stub
View v = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.recycler_view_card_item, viewGroup, false);
Log.e("onCreateViewHolder..", ""+i);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
}
// List<MenuItem> mItems;
OnItemClickListener mItemClickListener;
Context context;
List<CategoryBean> catItems;
int defaultImgId;
ImageLoaderListner imageLoaderListner;
public CardAdapter(Context context, List<CategoryBean> catItems, int defaultImgId) {
this.context = context;
this.catItems = catItems;
this.defaultImgId=defaultImgId;
imageLoaderListner = (ImageLoaderListner)context;
}
class ViewHolder extends RecyclerView.ViewHolder implements
View.OnClickListener {
public LinearLayout placeHolder;
public LinearLayout placeNameHolder;
public ImageView img_categories;
public TextView txt_categories;
public ViewHolder(View itemView) {
super(itemView);
placeHolder = (LinearLayout) itemView.findViewById(R.id.mainHolder);
placeNameHolder = (LinearLayout) itemView
.findViewById(R.id.placeNameHolder);
// lin_categories =
// (RelativeLayout)itemView.findViewById(R.id.lin_categories);
img_categories = (ImageView) itemView
.findViewById(R.id.img_categories);
txt_categories = (TextView) itemView
.findViewById(R.id.txt_categories);
placeHolder.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (mItemClickListener != null) {
mItemClickListener.onItemClick(itemView, getAdapterPosition());
}
}
}
public interface OnItemClickListener {
void onItemClick(View view, int position);
}
public void setOnItemClickListener(
final OnItemClickListener mItemClickListener) {
this.mItemClickListener = mItemClickListener;
}
@Override
public int getItemCount() {
// TODO Auto-generated method stub
return catItems.size();
}
@SuppressWarnings("deprecation")
@Override
public void onBindViewHolder(final ViewHolder holder, final int i) {
CategoryBean mItem = catItems.get(i);
Log.e("OnBind..", ""+i);
imageLoaderListner.onImageLoad(mItem.getCatImgNameResourceId(context), holder.img_categories, defaultImgId);
//holder.img_categories.setImageResource(mItem.getCatImgNameResourceId(context));
holder.txt_categories.setText(mItem.getCatName());
holder.placeNameHolder.setBackgroundColor(mItem.getmColor());
/*Bitmap myPhoto = BitmapFactory.decodeResource(context.getResources(),
mItem.getCatImgNameResourceId(context));
Palette.generateAsync(myPhoto, new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
int bgColor = palette.getVibrantColor(context
.getResources().getColor(android.R.color.black));
Log.e("color code"+i, bgColor+"");
holder.placeNameHolder.setBackgroundColor(bgColor);
}
});*/
holder.placeNameHolder.setAlpha(0.8f);
}
//private ViewHolder viewHolder;
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
// TODO Auto-generated method stub
View v = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.recycler_view_card_item, viewGroup, false);
Log.e("onCreateViewHolder..", ""+i);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
}
No comments:
Post a Comment