public View getViewMedia(int position, View convertView, ViewGroup parent) { View v = convertView; ViewHolder holder; /* convertView may be a recycled view but we must recreate it * if it does not correspond to a media view. */ boolean b_createView = true; if (v != null) { holder = (ViewHolder) v.getTag(); if (holder.viewType == VIEW_MEDIA) b_createView = false; } if (b_createView) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.audio_browser_item, parent, false); holder = new ViewHolder(); holder.layout = v.findViewById(R.id.layout_item); holder.title = (TextView) v.findViewById(R.id.title); Util.setAlignModeByPref(mAlignMode, holder.title); holder.cover = (ImageView) v.findViewById(R.id.cover); holder.subtitle = (TextView) v.findViewById(R.id.subtitle); holder.footer = v.findViewById(R.id.footer); holder.more = (ImageView) v.findViewById(R.id.item_more); holder.viewType = VIEW_MEDIA; v.setTag(holder); } else holder = (ViewHolder) v.getTag(); ListItem item = getItem(position); holder.title.setText(item.mTitle); RelativeLayout.LayoutParams paramsCover; if (mItemType == ITEM_WITH_COVER) { Media media = mItems.get(position).mMediaList.get(0); Bitmap cover = AudioUtil.getCover(v.getContext(), media, 64); if (cover == null) cover = BitmapCache.GetFromResource(v, R.drawable.icon); holder.cover.setImageBitmap(cover); int size = (int) mContext.getResources().getDimension(R.dimen.audio_browser_item_size); paramsCover = new RelativeLayout.LayoutParams(size, size); } else paramsCover = new RelativeLayout.LayoutParams(0, RelativeLayout.LayoutParams.WRAP_CONTENT); holder.cover.setLayoutParams(paramsCover); holder.subtitle.setVisibility(item.mSubTitle == null ? TextView.GONE : TextView.VISIBLE); holder.subtitle.setText(item.mSubTitle); // Remove the footer if the item is just above a separator. holder.footer.setVisibility(isMediaItemAboveASeparator(position) ? View.GONE : View.VISIBLE); final int pos = position; holder.more.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (mContextPopupMenuListener != null) mContextPopupMenuListener.onPopupMenu(v, pos); } }); return v; }
/** Called when the overall system is running low on memory */ @Override public void onLowMemory() { super.onLowMemory(); Log.w(TAG, "System is running low on memory"); BitmapCache.getInstance().clear(); }