Android Open Source - android_google_image_searcher Google Image Adapter






From Project

Back to project page android_google_image_searcher.

License

The source code is released under:

GNU General Public License

If you think the Android project android_google_image_searcher 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.github.snambi.googleimagesearcher;
//from w ww  .  ja  v  a  2s  . c o  m
import java.util.List;

import android.content.Context;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

public class GoogleImageAdapter extends ArrayAdapter<Image>{

  public GoogleImageAdapter(Context context, List<Image> images) {
    super(context, android.R.layout.simple_list_item_1, images);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    if( convertView == null ){
      convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_grid_photo, parent, false);      
    }
    
    GoogleViewHolder holder = null;
    if( convertView.getTag() == null ){
      holder = new GoogleViewHolder();
      holder.imgGridItem = (SquareImage) convertView.findViewById(R.id.imgGridItem);
      holder.tvGridItem = (TextView) convertView.findViewById(R.id.tvGridItem);
    }else{
      holder = (GoogleViewHolder) convertView.getTag();
    }
    
    holder.imgGridItem.getLayoutParams().width = parent.getWidth();
    //holder.imgGridItem.getLayoutParams().height = (parent.getHeight() - holder.tvGridItem.getLayoutParams().height);
    
    holder.imgGridItem.setImageResource(0);
        
    // get the appropriate image
    Image image = getItem(position);
    holder.imgGridItem.setTag(image);
    
    Log.i("INFO", "Loading Image : " + image.getUrl() );
    
    
    //Picasso.with( getContext() ).load( photo.getImageUrl() ).fit().centerInside().into(holder.imgPhoto);
    Picasso.with(getContext())
        .load( image.getThumbUrl())
        .resize( image.getThumbWidth(), image.getThumbHeight())
//        .fit()
//        .noFade()
//        .centerCrop()
        .into(holder.imgGridItem);
    
    //holder.imgGridItem.setImageResource(R.drawable.ic_launcher);
    holder.tvGridItem.setText( Html.fromHtml(image.getTitle() ) );

    return convertView;
  }
  
  public static class GoogleViewHolder{
    SquareImage imgGridItem;
    TextView tvGridItem;
    int height;
    int weight;
  }
}




Java Source Code List

com.github.snambi.googleimagesearcher.AndroidUtils.java
com.github.snambi.googleimagesearcher.EndlessScrollListener.java
com.github.snambi.googleimagesearcher.FullScreenActivity.java
com.github.snambi.googleimagesearcher.GoogleImageAdapter.java
com.github.snambi.googleimagesearcher.GoogleImageClient.java
com.github.snambi.googleimagesearcher.ImageUtil.java
com.github.snambi.googleimagesearcher.Image.java
com.github.snambi.googleimagesearcher.SearchActivity.java
com.github.snambi.googleimagesearcher.SettingsActivity.java
com.github.snambi.googleimagesearcher.SettingsDialog.java
com.github.snambi.googleimagesearcher.SettingsFragmentActivity.java
com.github.snambi.googleimagesearcher.SquareImage.java