Android Open Source - That-photo-app-for-that-mobile-class Image Adapter






From Project

Back to project page That-photo-app-for-that-mobile-class.

License

The source code is released under:

GNU General Public License

If you think the Android project That-photo-app-for-that-mobile-class 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 edu.gatech.cs4261.wheresdabeef;
/*  w w w.  j  ava 2  s.c o  m*/
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

/**
 * Created by Jonathan on 10/10/13.
 */
public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    private int[] dog;
    public ImageAdapter(Context c) {
        mContext = c;
        int rand = (int) (30 * Math.random());
        dog = new int[rand];
        for(int i = 0; i < rand; i++)
        {
            dog[i] = mThumbIds[(int) (8 * Math.random())];
        }
    }

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

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

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

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        SquareImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new SquareImageView(mContext);
            //imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(4, 4, 4, 4);
        } else {
            imageView = (SquareImageView) convertView;
        }

        imageView.setImageResource(dog[position]);
        return imageView;
    }

    // references to our images
    private Integer[] mThumbIds = {
            R.drawable.sample_0, R.drawable.sample_1,
            R.drawable.sample_2, R.drawable.sample_3,
            R.drawable.sample_4, R.drawable.sample_5,
            R.drawable.sample_6, R.drawable.sample_7
    };

    private class SquareImageView extends ImageView {
        public SquareImageView(Context context) {
            super(context);
        }

        public SquareImageView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); //Snap to width
        }
    }
}




Java Source Code List

edu.gatech.cs4261.wheresdabeef.ImageAdapter.java
edu.gatech.cs4261.wheresdabeef.MainActivity.java
edu.gatech.cs4261.wheresdabeef.SearchResultsActivity.java
edu.gatech.cs4261.wheresdabeef.SettingsActivity.java