use of android.support.v7.widget.RecyclerView.ViewHolder in project baseAdapter by hongyangAndroid.
the class ViewHolder method setOnClickListener.
/**
* 关于事件的
*/
public ViewHolder setOnClickListener(int viewId, View.OnClickListener listener) {
View view = getView(viewId);
view.setOnClickListener(listener);
return this;
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project nmid-headline by miao1007.
the class ImagesFeedAdapter method disPatchOnClick.
private void disPatchOnClick(final StreamViewHolder viewHolder, final int position, final ImageInfo imageInfo) {
viewHolder.mBtn_like.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
RetrofitUtils.getCachedAdapter(HeadlineService.END_POINT).create(ImageService.class).likeImage(knoImageList.get(position).getIdmember(), imageInfo.isHaveClickLike() ? 0 : 1).enqueue(new Callback<ImageLikeResult>() {
@Override
public void onResponse(Response<ImageLikeResult> response) {
if (response.body().status == 1) {
RetrofitUtils.disMsg(v.getContext(), !imageInfo.isHaveClickLike() ? "Success!" : "取消成功");
int currentLike = imageInfo.getCount_like() + (imageInfo.isHaveClickLike() ? (0) : (1));
viewHolder.likesCount.setText(currentLike + "人 觉得赞");
updateHeartButton(viewHolder, true, !imageInfo.isHaveClickLike());
imageInfo.setIsLike(!imageInfo.isHaveClickLike());
}
}
@Override
public void onFailure(Throwable t) {
}
});
}
});
viewHolder.mIv_stream_previous.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), PhotoViewActivity.class);
intent.putExtra(PhotoViewActivity.IMAGE_SIEZ_FULL, imageInfo.getImageurl());
intent.putExtra(PhotoViewActivity.IMAGE_SIEZ_PREVIOUS, imageInfo.getPrevirousurl());
v.getContext().startActivity(intent);
}
});
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project nmid-headline by miao1007.
the class NewsFeedAdapter method onCreateViewHolder.
@Override
public ContentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_content, parent, false);
ContentViewHolder viewHolder = new ContentViewHolder(view);
viewHolder.mCardView.setCardBackgroundColor(parent.getContext().getResources().getColor(ThemePref.getItemBackgroundResColor(parent.getContext())));
return viewHolder;
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project Android-Iconics by mikepenz.
the class IconsFragment method configAdapter.
private void configAdapter() {
//our popup on touch
mAdapter.withOnTouchListener(new FastAdapter.OnTouchListener<IconItem>() {
@Override
public boolean onTouch(View v, MotionEvent motionEvent, IAdapter<IconItem> adapter, IconItem item, int position) {
int a = motionEvent.getAction();
if (a == MotionEvent.ACTION_DOWN) {
if (popup != null && popup.isShowing()) {
popup.dismiss();
}
IconicsDrawable icon = new IconicsDrawable(v.getContext()).icon(item.getIcon()).sizeDp(144).paddingDp(8).backgroundColor(Color.parseColor("#DDFFFFFF")).roundedCornersDp(12);
ImageView imageView = new ImageView(v.getContext());
imageView.setImageDrawable(icon);
int size = (int) UIUtils.convertDpToPixel(144, v.getContext());
popup = new PopupWindow(imageView, size, size);
popup.showAsDropDown(v);
//copy to clipboard
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(icon.getIcon().getFormattedName());
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Android-Iconics icon", icon.getIcon().getFormattedName());
clipboard.setPrimaryClip(clip);
}
} else if (a == MotionEvent.ACTION_UP || a == MotionEvent.ACTION_CANCEL || a == MotionEvent.ACTION_OUTSIDE) {
if (popup != null && popup.isShowing()) {
popup.dismiss();
}
}
return false;
}
});
mAdapter.withOnBindViewHolderListener(new FastAdapter.OnBindViewHolderListener() {
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position, List payloads) {
IconItem.ViewHolder holder = (IconItem.ViewHolder) viewHolder;
//as we overwrite the default listener
mAdapter.getItem(position).bindView(holder, payloads);
if (randomize) {
holder.image.setColorRes(getRandomColor(position));
holder.image.setPaddingDp(random.nextInt(12));
holder.image.setContourWidthDp(random.nextInt(2));
holder.image.setContourColor(getRandomColor(position - 2));
int y = random.nextInt(10);
if (y % 4 == 0) {
holder.image.setBackgroundColorRes(getRandomColor(position - 4));
holder.image.setRoundedCornersDp(2 + random.nextInt(10));
}
}
}
@Override
public void unBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
IconItem item = mAdapter.getItem(position);
if (item != null) {
item.unbindView((IconItem.ViewHolder) viewHolder);
}
}
});
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project AboutLibraries by mikepenz.
the class HeaderItem method bindView.
/**
* binds the data of this item onto the viewHolder
*
* @param holder the viewHolder of this item
*/
@Override
public void bindView(final ViewHolder holder, List<Object> payloads) {
super.bindView(holder, payloads);
//ctx
final Context ctx = holder.itemView.getContext();
//Set the Icon or hide it
if (libsBuilder.aboutShowIcon != null && libsBuilder.aboutShowIcon && aboutIcon != null) {
holder.aboutIcon.setImageDrawable(aboutIcon);
holder.aboutIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (LibsConfiguration.getInstance().getListener() != null) {
LibsConfiguration.getInstance().getListener().onIconClicked(v);
}
}
});
holder.aboutIcon.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return LibsConfiguration.getInstance().getListener() != null && LibsConfiguration.getInstance().getListener().onIconLongClicked(v);
}
});
} else {
holder.aboutIcon.setVisibility(View.GONE);
}
//Set the description or hide it
if (!TextUtils.isEmpty(libsBuilder.aboutAppName)) {
holder.aboutAppName.setText(libsBuilder.aboutAppName);
} else {
holder.aboutAppName.setVisibility(View.GONE);
}
// Reset aboutSpecial fields
holder.aboutSpecialContainer.setVisibility(View.GONE);
holder.aboutSpecial1.setVisibility(View.GONE);
holder.aboutSpecial2.setVisibility(View.GONE);
holder.aboutSpecial3.setVisibility(View.GONE);
// set the values for the special fields
if (!TextUtils.isEmpty(libsBuilder.aboutAppSpecial1) && (!TextUtils.isEmpty(libsBuilder.aboutAppSpecial1Description) || LibsConfiguration.getInstance().getListener() != null)) {
holder.aboutSpecial1.setText(libsBuilder.aboutAppSpecial1);
new Iconics.IconicsBuilder().ctx(ctx).on(holder.aboutSpecial1).build();
holder.aboutSpecial1.setVisibility(View.VISIBLE);
holder.aboutSpecial1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean consumed = false;
if (LibsConfiguration.getInstance().getListener() != null) {
consumed = LibsConfiguration.getInstance().getListener().onExtraClicked(v, Libs.SpecialButton.SPECIAL1);
}
if (!consumed && !TextUtils.isEmpty(libsBuilder.aboutAppSpecial1Description)) {
try {
AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
alert.setMessage(Html.fromHtml(libsBuilder.aboutAppSpecial1Description));
alert.create().show();
} catch (Exception ex) {
}
}
}
});
holder.aboutSpecialContainer.setVisibility(View.VISIBLE);
}
if (!TextUtils.isEmpty(libsBuilder.aboutAppSpecial2) && (!TextUtils.isEmpty(libsBuilder.aboutAppSpecial2Description) || LibsConfiguration.getInstance().getListener() != null)) {
holder.aboutSpecial2.setText(libsBuilder.aboutAppSpecial2);
new Iconics.IconicsBuilder().ctx(ctx).on(holder.aboutSpecial2).build();
holder.aboutSpecial2.setVisibility(View.VISIBLE);
holder.aboutSpecial2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean consumed = false;
if (LibsConfiguration.getInstance().getListener() != null) {
consumed = LibsConfiguration.getInstance().getListener().onExtraClicked(v, Libs.SpecialButton.SPECIAL2);
}
if (!consumed && !TextUtils.isEmpty(libsBuilder.aboutAppSpecial2Description)) {
try {
AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
alert.setMessage(Html.fromHtml(libsBuilder.aboutAppSpecial2Description));
alert.create().show();
} catch (Exception ex) {
}
}
}
});
holder.aboutSpecialContainer.setVisibility(View.VISIBLE);
}
if (!TextUtils.isEmpty(libsBuilder.aboutAppSpecial3) && (!TextUtils.isEmpty(libsBuilder.aboutAppSpecial3Description) || LibsConfiguration.getInstance().getListener() != null)) {
holder.aboutSpecial3.setText(libsBuilder.aboutAppSpecial3);
new Iconics.IconicsBuilder().ctx(ctx).on(holder.aboutSpecial3).build();
holder.aboutSpecial3.setVisibility(View.VISIBLE);
holder.aboutSpecial3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean consumed = false;
if (LibsConfiguration.getInstance().getListener() != null) {
consumed = LibsConfiguration.getInstance().getListener().onExtraClicked(v, Libs.SpecialButton.SPECIAL3);
}
if (!consumed && !TextUtils.isEmpty(libsBuilder.aboutAppSpecial3Description)) {
try {
AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
alert.setMessage(Html.fromHtml(libsBuilder.aboutAppSpecial3Description));
alert.create().show();
} catch (Exception ex) {
}
}
}
});
holder.aboutSpecialContainer.setVisibility(View.VISIBLE);
}
//set the Version or hide it
if (libsBuilder.aboutVersionString != null)
holder.aboutVersion.setText(libsBuilder.aboutVersionString);
else {
if (libsBuilder.aboutShowVersion != null && libsBuilder.aboutShowVersion) {
holder.aboutVersion.setText(ctx.getString(R.string.version) + " " + aboutVersionName + " (" + aboutVersionCode + ")");
} else {
if (libsBuilder.aboutShowVersionName != null && libsBuilder.aboutShowVersionName) {
holder.aboutVersion.setText(ctx.getString(R.string.version) + " " + aboutVersionName);
} else if (libsBuilder.aboutShowVersionCode != null && libsBuilder.aboutShowVersionCode) {
holder.aboutVersion.setText(ctx.getString(R.string.version) + " " + aboutVersionCode);
} else {
holder.aboutVersion.setVisibility(View.GONE);
}
}
}
//Set the description or hide it
if (!TextUtils.isEmpty(libsBuilder.aboutDescription)) {
holder.aboutAppDescription.setText(Html.fromHtml(libsBuilder.aboutDescription));
new Iconics.IconicsBuilder().ctx(ctx).on(holder.aboutAppDescription).build();
holder.aboutAppDescription.setMovementMethod(MovementCheck.getInstance());
} else {
holder.aboutAppDescription.setVisibility(View.GONE);
}
//if there is no description or no icon and version number hide the divider
if (!libsBuilder.aboutShowIcon && !libsBuilder.aboutShowVersion || TextUtils.isEmpty(libsBuilder.aboutDescription)) {
holder.aboutDivider.setVisibility(View.GONE);
}
//notify the libsRecyclerViewListener to allow modifications
if (LibsConfiguration.getInstance().getLibsRecyclerViewListener() != null) {
LibsConfiguration.getInstance().getLibsRecyclerViewListener().onBindViewHolder(holder);
}
}
Aggregations