Back to project page MediaPicker.
The source code is released under:
Apache License
If you think the Android project MediaPicker 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.urza.mediapicker; // ww w . j ava 2s.c o m import android.content.Context; import android.graphics.Bitmap; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; /** * Created by urza on 17.7.2014. */ public class MediaFolderAdapter extends BaseAdapter { static final String TAG = "MediaFolderAdapter"; private Context mContext; private LayoutInflater mLayoutInflater; private List<MediaFolder> mFolderList; private ImageLoader imageLoader = ImageLoader.getInstance(); private DisplayImageOptions displayImageOptions; private HashMap<Long, Integer> idToPositionMap; private HashMap<String, List<MediaEntityWrapper>> selection; public MediaFolderAdapter(Context context) { mContext = context; mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mFolderList = new ArrayList<MediaFolder>(); idToPositionMap = new HashMap<Long, Integer>(); displayImageOptions = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.empty_photo) .cacheInMemory(true) .cacheOnDisk(true) .considerExifParams(true) .bitmapConfig(Bitmap.Config.RGB_565) .build(); } public void setData(List<MediaFolder> data) { mFolderList = data; if (mFolderList != null) { for (int i = 0; i <= mFolderList.size() - 1; i++) { idToPositionMap.put(Long.parseLong(mFolderList.get(i).getIndex()), i); } } notifyDataSetChanged(); } public int getCount() { if (mFolderList == null) { return 0; } else { return mFolderList.size(); } } //Adapter has stable Ids but overriding this method causes error on //AbsListView.confirmCheckedPositionsById() /*public boolean hasStableIds() { return true; }*/ public Object getItem(int pos) { return mFolderList.get(pos); } public long getItemId(int pos) { return Long.parseLong(mFolderList.get(pos).getIndex()); } public View getView(int position, View convertView, ViewGroup parent) { final MediaFolderHolder viewHolder; if (convertView == null) { convertView = mLayoutInflater.inflate(R.layout.item_media_folder, parent, false); viewHolder = new MediaFolderHolder(); viewHolder.mIndex = (TextView) convertView.findViewById(R.id.mediaFolderIndex); viewHolder.mCount = (TextView) convertView.findViewById(R.id.mediaFolderCount); viewHolder.mName = (TextView) convertView.findViewById(R.id.mediaFolderName); viewHolder.mNumOfSelected = (TextView) convertView.findViewById(R.id.mediaFolderNumOfSelected); viewHolder.mFolderThumb = (ImageView) convertView.findViewById(R.id.folderThumb); convertView.setTag(viewHolder); } else { viewHolder = (MediaFolderHolder) convertView.getTag(); } viewHolder.mIndex.setText("Dir Index: " + mFolderList.get(position).getIndex()); viewHolder.mCount.setText("Count: " + mFolderList.get(position).getCountOfContents()); viewHolder.mName.setText("Dir Name: " + mFolderList.get(position).getDirName()); if (selection.get(mFolderList.get(position).getIndex()) != null) { int numOfSelectedEntities = selection.get(mFolderList.get(position).getIndex()).size(); viewHolder.mNumOfSelected.setText("#selected entities: " + numOfSelectedEntities); } else { viewHolder.mNumOfSelected.setText("#selected entities: " + 0); } imageLoader.displayImage( mFolderList.get(position).thumbnailUri.toString(), viewHolder.mFolderThumb, displayImageOptions); return convertView; } public HashMap<String, List<MediaEntityWrapper>> getSelection() { return selection; } public void setSelection(HashMap<String, List<MediaEntityWrapper>> selection) { this.selection = selection; Log.d(TAG, "selection: " + selection); } public void updateSelection(HashMap<String, List<MediaEntityWrapper>> selection, String parentIndex, AdapterView adapterView) { this.selection = selection; Log.d(TAG, "selection: " + selection); Log.d(TAG, "Update folderView for index: " + parentIndex); int visiblePosition = adapterView.getFirstVisiblePosition(); View view = adapterView.getChildAt(idToPositionMap.get(Long.parseLong(parentIndex)) - visiblePosition); getView(idToPositionMap.get(Long.parseLong(parentIndex)), view, adapterView); } public class MediaFolderHolder { TextView mIndex; TextView mCount; TextView mName; TextView mNumOfSelected; ImageView mFolderThumb; } }