package com.siteshot.siteshot.adapters;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.siteshot.siteshot.utils.PhotoUtils;

/**
 * Adapts PhotoUtils' List of UserPhotos.
 */
public class ImageAdapter extends BaseAdapter {

    private final String TAG = getClass().getName();
    private final int width = 90, height = 90;

    private Context mContext;

    public ImageAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return PhotoUtils.getInstance().getUserPhotos().size();
    }

    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
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(width, height));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        } else {
            imageView = (ImageView) convertView;
        }

        // Retrieve the photo data from the UserPhoto instance.
        ParseObject object = PhotoUtils.getInstance().getUserPhotos().get(position);
        ParseFile file = object.getParseFile("photo");
        byte[] data = new byte[0];
        try {
            data = file.getData();
        } catch (ParseException e) {
            Log.e(TAG, "could not get data from ParseFile:");
            e.printStackTrace();
        }
        Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

        imageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, width, height, false));

        imageView.setImageBitmap(bitmap);

        return imageView;
    }

}
@@ -627,44 +627,77 @@
 ate 
-final 
 int 
-w
+mW
 idth
- = 90, height
+, mHeight;%0A    private static final float SIZE_DP
  = 90
+.0f
 ;%0A
-%0A
     
@@ -782,16 +782,242 @@
 xt = c;%0A
+        final float scale = c.getResources().getDisplayMetrics().density;%0A%0A        // Adjust the width and height %22constants%22 based on screen density.%0A        mWidth = (int) (SIZE_DP * scale + 0.5f);%0A        mHeight = mWidth;%0A
     %7D%0A%0A 
@@ -1588,24 +1588,26 @@
 tParams(
-w
+mW
 idth, 
-h
+mH
 eight));
@@ -2332,16 +2332,18 @@
 ap, 
-w
+mW
 idth, 
-h
+mH
 eigh

Use density-independent pixels on the profile grid