Android Open Source - collage-lwp Image Adapter






From Project

Back to project page collage-lwp.

License

The source code is released under:

Apache License

If you think the Android project collage-lwp 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 pohkahkong.livewallpaper.collage;
//from   w  ww.  ja  v a2s.  c o  m
import java.io.File;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * @author Poh Kah Kong
 *
 */
public class ImageAdapter extends BaseAdapter {
  private ImageItem[] items;
  private LayoutInflater inflater;
    
  public ImageAdapter(Context context, ImageItem[] items) {
    this.items = items;    
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }  

  public int getCount() {
    // TODO Auto-generated method stub
    return items.length;    
  }

  public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
  }

  public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
  }

  public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub      
    if (convertView == null)
      convertView = inflater.inflate(R.layout.item, null);           
    ImageView imageView = (ImageView) convertView.findViewById(R.id.imageIV);
    TextView labelTV = (TextView) convertView.findViewById(R.id.labelTV);
    Bitmap image = items[position].getThumbnail();
    String path = items[position].getPath();
    imageView.setImageBitmap(image);
    String folderName = path.substring(path.lastIndexOf("/")+1, path.length());
    if (folderName.length()>9)
      folderName = folderName.substring(0, 7) + "..";    
    labelTV.setText(folderName + " (" + getImageCount(path) + ")");
    return convertView;
  }  
  
  private int getImageCount(String path) {
    int imageCount = 0;
    File directory = new File(path);
    File[] files = directory.listFiles();
    for (int i=0; i<files.length; i++) {
        if ((files[i].getName().length()>4 && files[i].getName().substring(files[i].getName().length()-4).equalsIgnoreCase(".jpg")) ||
          (files[i].getName().length()>5 && files[i].getName().substring(files[i].getName().length()-5).equalsIgnoreCase(".jpeg")))
          imageCount++;                
    }    
    return imageCount;
  }
}




Java Source Code List

pohkahkong.livewallpaper.collage.CollageWallpaperService.java
pohkahkong.livewallpaper.collage.Collage.java
pohkahkong.livewallpaper.collage.EightImagesCollage.java
pohkahkong.livewallpaper.collage.FiveImagesCollage.java
pohkahkong.livewallpaper.collage.FourImagesCollage.java
pohkahkong.livewallpaper.collage.ImageAdapter.java
pohkahkong.livewallpaper.collage.ImageDevice.java
pohkahkong.livewallpaper.collage.ImageItem.java
pohkahkong.livewallpaper.collage.ImageNumberDialog.java
pohkahkong.livewallpaper.collage.OneImageCollage.java
pohkahkong.livewallpaper.collage.PathDialog.java
pohkahkong.livewallpaper.collage.Preferences.java
pohkahkong.livewallpaper.collage.SevenImagesCollage.java
pohkahkong.livewallpaper.collage.SixImagesCollage.java
pohkahkong.livewallpaper.collage.StartDialog.java
pohkahkong.livewallpaper.collage.StartPageCollage.java
pohkahkong.livewallpaper.collage.ThreeImagesCollage.java
pohkahkong.livewallpaper.collage.TwoImagesCollage.java