Back to project page Avatar.
The source code is released under:
GNU General Public License
If you think the Android project Avatar listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.syw.avatar; //w ww . j a va2 s . co m import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.GridView; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.listener.PauseOnScrollListener; public class PhotoPickerFragment extends Fragment { @SuppressWarnings("unused") private static final String TAG = PhotoPickerFragment.class.getSimpleName(); public interface OnPhotoSelectClickListener { public void onOKClickListener(PhotoInfo selectedPhoto); } private OnPhotoSelectClickListener onPhotoSelectClickListener; protected ImageLoader imageLoader = ImageLoader.getInstance(); protected boolean pauseOnScroll = true; // ??????????????; protected boolean pauseOnFling = true; // ??????????????; private GridView gridView; private List<PhotoInfo> dataList; private PhotoPickerAdapter gridImageAdapter; @Override public void onAttach(Activity activity) { super.onAttach(activity); if(onPhotoSelectClickListener==null){ onPhotoSelectClickListener = (OnPhotoSelectClickListener)activity; } } @Override public void onStop(){ super.onStop(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_photo_picker, container, false); View unusedView = view.findViewById(R.id.bottom_layout); unusedView.setVisibility(View.GONE); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Bundle args = getArguments(); // ???????; PhotoSerializable photoSerializable = (PhotoSerializable) args.getSerializable("list"); dataList = new ArrayList<PhotoInfo>(); dataList.addAll(photoSerializable.getList()); init(); } public void updateDataList(List<PhotoInfo> newList){ if (dataList == newList){ return; } dataList.clear(); dataList.addAll(newList); gridImageAdapter.notifyDataSetChanged(); } private void init() { View v = getView(); gridView = (GridView)v.findViewById(R.id.myGrid); gridImageAdapter = new PhotoPickerAdapter(getActivity(), dataList); initListener(); gridView.setAdapter(gridImageAdapter); gridView.setOnScrollListener(new PauseOnScrollListener(imageLoader, pauseOnScroll, pauseOnFling)); } private void initListener() { gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (onPhotoSelectClickListener != null){ onPhotoSelectClickListener.onOKClickListener(dataList.get(position)); } } }); } }