Android Open Source - photos Photo Gallery Item List Adapter






From Project

Back to project page photos.

License

The source code is released under:

MIT License

If you think the Android project photos listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ericfarraro.photos.adapters;
/* w  ww. j  av  a  2 s.  com*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.ericfarraro.photos.R;
import com.ericfarraro.photos.singletons.PhotoCache;
import com.ericfarraro.photos.core.ImageDownloader;
import com.ericfarraro.sdk.models.Photo;

import java.util.List;

/**
 * Created by Eric on 10/7/2014.
 */
public class PhotoGalleryItemListAdapter extends ArrayAdapter<Photo> {

    protected ImageDownloader mImageDownloadHandler;

    public PhotoGalleryItemListAdapter(
            Context context, List<Photo> objects, ImageDownloader downloader) {
        super(context, 0, objects);

        mImageDownloadHandler = downloader;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null) {
            LayoutInflater inflater =
                    (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = inflater.inflate(R.layout.grid_item_photo, parent, false);
        }

        ImageView image = (ImageView)convertView.findViewById(R.id.grid_item_photo_root);
        Photo photo = getItem(position);

        // set a default placeholder
        image.setImageResource(R.drawable.image_placeholder);

        // store a reference to the image's URL so that we can retrieve it later
        image.setTag(photo.getUrl());

        if(PhotoCache.getInstance().get(photo.getUrl()) != null) {
            image.setImageBitmap(PhotoCache.getInstance().get(photo.getUrl()));
        } else {
            mImageDownloadHandler.queueImageUrl(image, photo.getUrl());
        }

        return convertView;
    }
}




Java Source Code List

com.ericfarraro.photos.ApplicationTest.java
com.ericfarraro.photos.activities.MainActivity.java
com.ericfarraro.photos.activities.PhotoDetailActivity.java
com.ericfarraro.photos.adapters.PhotoGalleryItemListAdapter.java
com.ericfarraro.photos.core.EndlessScrollListener.java
com.ericfarraro.photos.core.ImageDownloader.java
com.ericfarraro.photos.fragments.MainFragment.java
com.ericfarraro.photos.fragments.PhotoDetailFragment.java
com.ericfarraro.photos.singletons.PhotoCache.java
com.ericfarraro.sdk.core.ImageDownloader.java
com.ericfarraro.sdk.data.FlickrPhotoSource.java
com.ericfarraro.sdk.data.PhotoSource.java
com.ericfarraro.sdk.interfaces.ImageDownloadCompleted.java
com.ericfarraro.sdk.interfaces.PhotoListRequestCompleted.java
com.ericfarraro.sdk.interfaces.UrlContentRetrieved.java
com.ericfarraro.sdk.models.Photo.java
com.ericfarraro.sdk.util.UrlFetchTask.java
com.ericfarraro.sdk.util.Utility.java