// Path: chh/src/main/java/com/fei_ke/chiphellclient/ui/commen/AnimateFirstDisplayListener.java
// public class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
// 
//     private final List<String> displayedImages = Collections
//             .synchronizedList(new LinkedList<String>());
// 
//     @Override
//     public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
//         if (loadedImage != null) {
//             ImageView imageView = (ImageView) view;
//             boolean firstDisplay = !displayedImages.contains(imageUri);
//             if (firstDisplay) {
//                 FadeInBitmapDisplayer.animate(imageView, 500);
//                 displayedImages.add(imageUri);
//             }
//         }
//     }
// }
// 
// Path: chh/src/main/java/com/fei_ke/chiphellclient/ui/customviews/SquareImageView.java
// public 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) {
//         int widthMode = MeasureSpec.getMode(widthMeasureSpec);
//         int heightMode = MeasureSpec.getMode(heightMeasureSpec);
//         if (widthMode == MeasureSpec.EXACTLY && heightMode != MeasureSpec.EXACTLY) {
//             int width = MeasureSpec.getSize(widthMeasureSpec);
//             int height = width;
//             if (heightMode == MeasureSpec.AT_MOST) {
//                 height = Math.min(height, MeasureSpec.getSize(heightMeasureSpec));
//             }
//             setMeasuredDimension(width, height);
//         } else {
//             super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//         }
//     }
// }


import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.fei_ke.chiphellclient.R;
import com.fei_ke.chiphellclient.ui.commen.AnimateFirstDisplayListener;
import com.fei_ke.chiphellclient.ui.customviews.SquareImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;
import java.util.ArrayList;
import java.util.List;
package com.fei_ke.chiphellclient.ui.fragment;





/**
 * 图片列表
 * Created by fei-ke on 2016/2/17.
 */
@EFragment(R.layout.fragment_grid_pic)
public class GridPicFragment extends BaseFragment {
    @ViewById(R.id.gridView)
    GridView gridView;
    private GridAdapter mAdapter;

    @Override
    protected void onAfterViews() {
        mAdapter = new GridAdapter();
        gridView.setAdapter(mAdapter);

    }

    public void update(List<String> pics) {
        mAdapter.update(pics);
        mAdapter.notifyDataSetChanged();
    }

    public void setSelection(int position) {
        gridView.setSelection(position);
    }

    public void setOnItemClickListener(@Nullable AdapterView.OnItemClickListener listener) {
        gridView.setOnItemClickListener(listener);
    }

    static class GridAdapter extends BaseAdapter {
        private static DisplayImageOptions imageOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true).cacheOnDisk(true)
                .showImageForEmptyUri(R.drawable.default_img)
                .showImageOnFail(R.drawable.default_img)
                .showImageOnLoading(R.drawable.default_img)
                .build();
        private List<String> pics = new ArrayList<>();
// Path: chh/src/main/java/com/fei_ke/chiphellclient/ui/commen/AnimateFirstDisplayListener.java
// public class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
// 
//     private final List<String> displayedImages = Collections
//             .synchronizedList(new LinkedList<String>());
// 
//     @Override
//     public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
//         if (loadedImage != null) {
//             ImageView imageView = (ImageView) view;
//             boolean firstDisplay = !displayedImages.contains(imageUri);
//             if (firstDisplay) {
//                 FadeInBitmapDisplayer.animate(imageView, 500);
//                 displayedImages.add(imageUri);
//             }
//         }
//     }
// }
// 
// Path: chh/src/main/java/com/fei_ke/chiphellclient/ui/customviews/SquareImageView.java
// public 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) {
//         int widthMode = MeasureSpec.getMode(widthMeasureSpec);
//         int heightMode = MeasureSpec.getMode(heightMeasureSpec);
//         if (widthMode == MeasureSpec.EXACTLY && heightMode != MeasureSpec.EXACTLY) {
//             int width = MeasureSpec.getSize(widthMeasureSpec);
//             int height = width;
//             if (heightMode == MeasureSpec.AT_MOST) {
//                 height = Math.min(height, MeasureSpec.getSize(heightMeasureSpec));
//             }
//             setMeasuredDimension(width, height);
//         } else {
//             super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//         }
//     }
// }


// Path: chh/src/main/java/com/fei_ke/chiphellclient/ui/fragment/GridPicFragment.java
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.fei_ke.chiphellclient.R;
import com.fei_ke.chiphellclient.ui.commen.AnimateFirstDisplayListener;
import com.fei_ke.chiphellclient.ui.customviews.SquareImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;
import java.util.ArrayList;
import java.util.List;

package com.fei_ke.chiphellclient.ui.fragment;





/**
 * 图片列表
 * Created by fei-ke on 2016/2/17.
 */
@EFragment(R.layout.fragment_grid_pic)
public class GridPicFragment extends BaseFragment {
    @ViewById(R.id.gridView)
    GridView gridView;
    private GridAdapter mAdapter;

    @Override
    protected void onAfterViews() {
        mAdapter = new GridAdapter();
        gridView.setAdapter(mAdapter);

    }

    public void update(List<String> pics) {
        mAdapter.update(pics);
        mAdapter.notifyDataSetChanged();
    }

    public void setSelection(int position) {
        gridView.setSelection(position);
    }

    public void setOnItemClickListener(@Nullable AdapterView.OnItemClickListener listener) {
        gridView.setOnItemClickListener(listener);
    }

    static class GridAdapter extends BaseAdapter {
        private static DisplayImageOptions imageOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true).cacheOnDisk(true)
                .showImageForEmptyUri(R.drawable.default_img)
                .showImageOnFail(R.drawable.default_img)
                .showImageOnLoading(R.drawable.default_img)
                .build();
        private List<String> pics = new ArrayList<>();
        private AnimateFirstDisplayListener firstDisplayListener = new AnimateFirstDisplayListener();