Android Open Source - lastfm-android-music-discovery Image Grid Adapter






From Project

Back to project page lastfm-android-music-discovery.

License

The source code is released under:

Apache License

If you think the Android project lastfm-android-music-discovery 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.mikeladze.musicdiscovery.view.gridview;
/*from  w  w  w.  j  av a 2s. c om*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.mikeladze.musicdiscovery.R;
import com.mikeladze.musicdiscovery.http.LastFMResult;
import com.mikeladze.musicdiscovery.view.gridview.loader.ImageLoader;

/**
 * The ImageGridAdapter. A custom adapter to display last.fm image results in a staggered grid
 * view.
 * 
 * @author Tim Mikeladze
 */
public class ImageGridAdapter extends ArrayAdapter<LastFMResult> {
  
  private Context context;
  
  private ImageLoader imageLoader;
  
  /**
   * Instantiates a new image grid adapter.
   * 
   * @param context the context
   * @param resource the resource
   */
  public ImageGridAdapter(Context context, int resource) {
    super(context, resource);
    this.context = context;
    imageLoader = new ImageLoader(context);
    
  }
  
  @Override
  /**
   * Get the view at given position.
   */
  public View getView(int position, View convertView, ViewGroup parent) {
    
    ViewHolder holder;
    
    if (convertView == null) {
      LayoutInflater layoutInflator = LayoutInflater.from(context);
      convertView = layoutInflator.inflate(R.layout.view_image_grid_item, null);
      holder = new ViewHolder();
      holder.image = (DynamicImageView) convertView.findViewById(R.id.imageview);
      holder.title = (TextView) convertView.findViewById(R.id.textview_title);
      
      convertView.setTag(holder);
    }
    
    holder = (ViewHolder) convertView.getTag();
    
    if (getCount() > 0) {
      LastFMResult gi = getItem(position);
      imageLoader.displayImage(gi.getImage(), holder.image);
      holder.title.setText(gi.getTitle());
      
    }
    
    return convertView;
  }
  
  /**
   * This class is used as a container to hold data for smooth scrolling.
   * 
   * @author Tim Mikeladze
   */
  private static class ViewHolder {
    
    private DynamicImageView image;
    private TextView title;
  }
}




Java Source Code List

com.mikeladze.musicdiscovery.album.activity.AlbumActivity.java
com.mikeladze.musicdiscovery.album.adapter.LastFMTrack.java
com.mikeladze.musicdiscovery.album.adapter.OnTrackClickListener.java
com.mikeladze.musicdiscovery.album.adapter.TrackListAdapter.java
com.mikeladze.musicdiscovery.album.fragment.AlbumInfoFragment.java
com.mikeladze.musicdiscovery.album.fragment.AlbumTracksFragment.java
com.mikeladze.musicdiscovery.artist.activity.ArtistActivity.java
com.mikeladze.musicdiscovery.artist.fragment.ArtistAlbumsFragment.java
com.mikeladze.musicdiscovery.artist.fragment.ArtistInfoFragment.java
com.mikeladze.musicdiscovery.artist.fragment.SimilarArtistsFragment.java
com.mikeladze.musicdiscovery.base.activity.BaseFragmentActivity.java
com.mikeladze.musicdiscovery.base.adapter.SectionsPagerAdapter.java
com.mikeladze.musicdiscovery.base.fragment.BaseTabFragment.java
com.mikeladze.musicdiscovery.base.fragment.ImageGridViewFragment.java
com.mikeladze.musicdiscovery.http.LastFMResult.java
com.mikeladze.musicdiscovery.http.RestClient.java
com.mikeladze.musicdiscovery.main.activity.MainActivity.java
com.mikeladze.musicdiscovery.main.fragment.HypedArtistsFragment.java
com.mikeladze.musicdiscovery.main.fragment.TopArtistsFragment.java
com.mikeladze.musicdiscovery.search.activity.SearchResultsActivity.java
com.mikeladze.musicdiscovery.search.adapter.SearchResultsAdapter.java
com.mikeladze.musicdiscovery.util.IntentUtils.java
com.mikeladze.musicdiscovery.view.gridview.DynamicImageView.java
com.mikeladze.musicdiscovery.view.gridview.ImageGridAdapter.java
com.mikeladze.musicdiscovery.view.gridview.loader.FileCache.java
com.mikeladze.musicdiscovery.view.gridview.loader.ImageLoader.java
com.mikeladze.musicdiscovery.view.gridview.loader.MemoryCache.java
com.mikeladze.musicdiscovery.view.gridview.loader.Utils.java