Android Open Source - droidling Image Adapter






From Project

Back to project page droidling.

License

The source code is released under:

Copyright (c) 2012 Keith Trnka Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwa...

If you think the Android project droidling 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.ktrnka.droidling;
// w w  w.j av a 2 s.c  o m
import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.github.ktrnka.droidling.helpers.AsyncDrawable;
import com.github.ktrnka.droidling.helpers.BitmapLoaderTask;

public class ImageAdapter extends BaseAdapter {
    private ExtendedApplication application;
    private String[] imageUris;
    private int imageSizePixels;

    public ImageAdapter(ExtendedApplication application, String[] imageUris, int imageSizePixels) {
        this.application = application;
        this.imageUris = imageUris;
        this.imageSizePixels = imageSizePixels;
    }

    public int getCount() {
        return imageUris.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = (ImageView) convertView;

        // inflate a view if we can't recycle
        if (imageView == null) {
            LayoutInflater inflater = (LayoutInflater) application
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            imageView = (ImageView) inflater.inflate(R.layout.grid_image, null);
            imageView.setScaleType(ScaleType.CENTER_CROP);
        }

        Resources res = application.getResources();

        // set the image
        Uri imageUri = Uri.parse(imageUris[position]);
        // Log.v("ImageAdapter", "Setting " + imageUri + ", want " +
        // imageSizePixels + " px");
        if (!BitmapLoaderTask.cancelPotentialWork(imageView, imageUri)) {
            BitmapLoaderTask task = new BitmapLoaderTask(imageView, imageSizePixels,
                    imageSizePixels, application);
            AsyncDrawable placeholder = new AsyncDrawable(res, null, task);
            imageView.setImageDrawable(placeholder);
            task.execute(imageUri);
        }

        return imageView;
    }

}




Java Source Code List

com.github.ktrnka.droidling.AboutActivity.java
com.github.ktrnka.droidling.AboutInterpersonalActivity.java
com.github.ktrnka.droidling.AboutLangIDActivity.java
com.github.ktrnka.droidling.AboutPersonalActivity.java
com.github.ktrnka.droidling.CorpusStats.java
com.github.ktrnka.droidling.DateDistribution.java
com.github.ktrnka.droidling.DiagnosticActivity.java
com.github.ktrnka.droidling.ExtendedApplication.java
com.github.ktrnka.droidling.GraphCard.java
com.github.ktrnka.droidling.ImageAdapter.java
com.github.ktrnka.droidling.InterpersonalActivity.java
com.github.ktrnka.droidling.InterpersonalCard.java
com.github.ktrnka.droidling.InterpersonalSingleStats.java
com.github.ktrnka.droidling.InterpersonalStats.java
com.github.ktrnka.droidling.LIDStats.java
com.github.ktrnka.droidling.LanguageIdentificationActivity.java
com.github.ktrnka.droidling.LanguageIdentifier.java
com.github.ktrnka.droidling.MainActivity.java
com.github.ktrnka.droidling.PersonalActivity.java
com.github.ktrnka.droidling.PersonalStats.java
com.github.ktrnka.droidling.RefreshableActivity.java
com.github.ktrnka.droidling.ShareableCard.java
com.github.ktrnka.droidling.Sms.java
com.github.ktrnka.droidling.Tokenizer.java
com.github.ktrnka.droidling.WordDistribution.java
com.github.ktrnka.droidling.helpers.AsyncDrawable.java
com.github.ktrnka.droidling.helpers.BitmapLoaderTask.java
com.github.ktrnka.droidling.helpers.Util.java