@Override public View getView(int position, View convertView, ViewGroup parent) { final View view = convertView != null ? convertView : inflater.inflate(R.layout.app_grid_item, parent, false); final AbsListView.LayoutParams params = (AbsListView.LayoutParams) view.getLayoutParams(); if (position < mColumnCount) { params.height = mGridViewTopRowHeight; view.setLayoutParams(params); view.setVisibility(View.INVISIBLE); } else { if (position == (getCount() - 1)) { params.height = mGridViewBottomRowHeight; } else { params.height = ViewGroup.LayoutParams.WRAP_CONTENT; } view.setLayoutParams(params); view.setVisibility(View.VISIBLE); final LaunchableActivity launchableActivity = getItem(position - mColumnCount); final CharSequence label = launchableActivity.getActivityLabel(); final TextView appLabelView = (TextView) view.findViewById(R.id.appLabel); final ImageView appIconView = (ImageView) view.findViewById(R.id.appIcon); final View appShareIndicator = view.findViewById(R.id.appShareIndicator); final View appPinToTop = view.findViewById(R.id.appPinToTop); appLabelView.setText(label); appIconView.setTag(launchableActivity); if (!launchableActivity.isIconLoaded()) { appIconView.setImageDrawable(mDefaultAppIcon); if (!mDisableIcons) mImageLoadingConsumersManager.addTask( new ImageLoadingTask(appIconView, launchableActivity, mImageTasksSharedData)); } else { appIconView.setImageDrawable( launchableActivity.getActivityIcon(mPm, mContext, mIconSizePixels)); } appShareIndicator.setVisibility( launchableActivity.isShareable() ? View.VISIBLE : View.GONE); appPinToTop.setVisibility(launchableActivity.getPriority() > 0 ? View.VISIBLE : View.GONE); } return view; }
@Override public View getView(final int position, View convertView, final ViewGroup parent) { int viewType = getItemViewType(position); if (viewType == TYPE_CAMERA) { CameraViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.media_camera_item, parent, false); AbsListView.LayoutParams params = (AbsListView.LayoutParams) convertView.getLayoutParams(); int width = (mWidth - 2 * getPixelSize(R.dimen.media_item_horizontal_spacing)) / 3; params.width = width; params.height = width; convertView.setLayoutParams(params); holder = new CameraViewHolder(convertView); convertView.setTag(holder); } else { holder = (CameraViewHolder) convertView.getTag(); } } else { MediaViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.media_item, parent, false); AbsListView.LayoutParams params = (AbsListView.LayoutParams) convertView.getLayoutParams(); int width = (mWidth - 2 * getPixelSize(R.dimen.media_item_horizontal_spacing)) / 3; params.width = width; params.height = width; convertView.setLayoutParams(params); holder = new MediaViewHolder(convertView); convertView.setTag(holder); } else { holder = (MediaViewHolder) convertView.getTag(); } final Media media = mMedias.get(position); setImage(holder.photoIv, media.getData()); setIndex(holder.indexTv, contains(media)); setText(holder.sizeTv, ByteUtil.format(media.getSize())); setVisibility(holder.indexTv, true); setVisibility(holder.videoLayout, media.getMediaType() == MediaType.MEDIA_TYPE_VIDEO); final View view = convertView; holder.indexTv.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (mOnItemCheckedListener == null) return; mOnItemCheckedListener.onItemChecked(view, position); } }); } return convertView; }