Skip to content

Instantly share code, notes, and snippets.

@zaur
Created May 3, 2014 16:59
Show Gist options
  • Save zaur/02805cad5840863518a6 to your computer and use it in GitHub Desktop.
Save zaur/02805cad5840863518a6 to your computer and use it in GitHub Desktop.
public class WorldPhotoStreamAdapter extends ArrayAdapter<Photo> {
private LayoutInflater mInflater;
private int photoWidth;
private int photoHeight;
private float scale;
public WorldPhotoStreamAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
mInflater = LayoutInflater.from(context);
final int widthPx = context.getResources().getDisplayMetrics().widthPixels;
scale = context.getResources().getDisplayMetrics().density;
photoWidth = (int) (widthPx * 0.90f);
photoHeight = photoWidth * 190 / 285;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
PhotoHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.world_photo_stream_photo, null);
holder = new PhotoHolder(convertView);
convertView.setTag(holder);
} else {
holder = (PhotoHolder) convertView.getTag();
}
// final SmartImageView image = (SmartImageView) convertView.findViewById(R.id.photo);
holder.photo.setImageDrawable(getContext().getResources().getDrawable(R.drawable.empty_drawable));
holder.photo.setLayoutParams(new LinearLayout.LayoutParams(photoWidth, photoHeight));
Picasso.with(getContext())
.load(getItem(position).getLinkW600h450())
.into(holder.photo);
// holder.photo.setImageUrl(getItem(position).getLinkW600h450());
return convertView;
}
class PhotoHolder {
public ImageView photo;
public PhotoHolder(final View convertView) {
photo = (ImageView) convertView.findViewById(R.id.photo);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment