下面列出了android.view.View#setOnCreateContextMenuListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public CommentViewHolder(View v, Context context, ICommentableFragment fragment) {
super(v);
this.fragment = fragment;
this.context = context;
commentAuthor = (TextView) v.findViewById(R.id.user);
commentTime = (TextView) v.findViewById(R.id.time);
commentRole = (TextView) v.findViewById(R.id.role);
commentContent = (TextView) v.findViewById(R.id.content);
commentContent.setMovementMethod(LinkMovementMethod.getInstance());
commentMarker = v.findViewById(R.id.comment_marker);
commentIndent = v.findViewById(R.id.comment_indent);
commentImage = (ImageView) v.findViewById(R.id.author_avatar);
tradeScoreDivider = v.findViewById(R.id.trade_divider);
tradeScorePositive = (TextView) v.findViewById(R.id.trade_score_positive);
tradeScoreNegative = (TextView) v.findViewById(R.id.trade_score_negative);
v.setOnCreateContextMenuListener(this);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
final Room searchResult = getItem(position);
viewHolder.binding.name.setText(searchResult.getName());
final String description = searchResult.getDescription();
final String language = searchResult.getLanguage();
if (TextUtils.isEmpty(description)) {
viewHolder.binding.description.setVisibility(View.GONE);
} else {
viewHolder.binding.description.setText(description);
viewHolder.binding.description.setVisibility(View.VISIBLE);
}
if (language == null || language.length() != 2) {
viewHolder.binding.language.setVisibility(View.GONE);
} else {
viewHolder.binding.language.setText(language.toUpperCase(Locale.ENGLISH));
viewHolder.binding.language.setVisibility(View.VISIBLE);
}
final Jid room = searchResult.getRoom();
viewHolder.binding.room.setText(room != null ? room.asBareJid().toString() : "");
AvatarWorkerTask.loadAvatar(searchResult, viewHolder.binding.avatar, R.dimen.avatar);
final View root = viewHolder.binding.getRoot();
root.setTag(searchResult);
root.setOnClickListener(v -> listener.onChannelSearchResult(searchResult));
root.setOnCreateContextMenuListener(this);
}
LogRowViewHolder(View view) {
super(view);
tv_date = (TextView) view.findViewById(R.id.tv_log_date);
tv_time = (TextView) view.findViewById(R.id.tv_log_time);
tv_glucose = (TextView) view.findViewById(R.id.tv_log_glucose);
iv_unit = (ImageView) view.findViewById(R.id.iv_log_unit);
iv_predictionArrow = (ImageView) view.findViewById(R.id.iv_log_prediction);
view.setOnClickListener(this);
// enable context menu only in developer mode
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(fragment.getContext());
boolean developerMode = settings.getBoolean("pref_developer_mode", false);
if (developerMode) {
view.setOnCreateContextMenuListener(this);
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.view_w_transaction, parent, false);
itemView.setOnCreateContextMenuListener(contextMenuListener);
itemView.setOnClickListener(clickListener);
return new MyViewHolder(itemView);
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.view_w_address, parent, false);
itemView.setOnClickListener(listener);
itemView.setOnCreateContextMenuListener(contextMenuListener);
return new MyViewHolder(itemView);
}
ViewHolder(View itemView, OnItemClickListener listener) {
super(itemView);
this.listener = listener;
title = itemView.findViewById(R.id.title);
url = itemView.findViewById(R.id.url);
favourite = itemView.findViewById(R.id.favourite);
read = itemView.findViewById(R.id.read);
readingTime = itemView.findViewById(R.id.estimatedReadingTime);
itemView.setOnClickListener(this);
itemView.setOnCreateContextMenuListener(this);
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == CONTENT) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.view_w_transaction, parent, false);
itemView.setOnCreateContextMenuListener(contextMenuListener);
itemView.setOnClickListener(clickListener);
return new MyViewHolder(itemView);
} else {
return new AdRecyclerHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.view_w_transaction_ad, parent, false));
}
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.view_w_token, parent, false);
itemView.setOnClickListener(listener);
itemView.setOnCreateContextMenuListener(contextMenuListener);
return new MyViewHolder(itemView);
}
public GroupViewHolder(View view) {
super(view);
mIndicator = (ExpandableIndicatorView) view.findViewById(R.id.group_indicator);
mSymbol = (TextView) view.findViewById(R.id.property_symbol);
mHalfLife = (TextView) view.findViewById(R.id.property_half_life);
mAbundance = (TextView) view.findViewById(R.id.property_abundance);
view.setOnClickListener(this);
view.setOnCreateContextMenuListener(this);
}
public ViewHolder(View itemView) {
super(itemView);
mName = (TextView) itemView.findViewById(R.id.property_name);
mValue = (TextView) itemView.findViewById(R.id.property_value);
if (mValue != null) {
mValue.setTypeface(mTypeface);
itemView.setOnClickListener(this);
itemView.setOnCreateContextMenuListener(this);
}
}
public void initComponent() {
LinearLayout llRoot = (LinearLayout)findViewById(R.id.llRoot);
LinearLayout llHeaderBase = (LinearLayout)findViewById(R.id.llHeaderBase);
ThemeUtil.setRootBackground(llRoot);
ThemeUtil.setSecondaryMicroBlogHeader(llHeaderBase);
//资料头部
LayoutInflater inflater = LayoutInflater.from(this);
View headerView = inflater.inflate(R.layout.include_micro_blog_list_header, null);
LinearLayout llProfileHeader = (LinearLayout)headerView.findViewById(R.id.llProfileHeader);
TextView tvScreenName = (TextView)headerView.findViewById(R.id.tvScreenName);
ImageView ivVerify = (ImageView)headerView.findViewById(R.id.ivVerify);
TextView tvImpress = (TextView)headerView.findViewById(R.id.tvImpress);
ImageView ivMoreDetail = (ImageView)headerView.findViewById(R.id.ivMoreDetail);
ThemeUtil.setHeaderProfile(llProfileHeader);
int highlight = theme.getColor("highlight");
tvScreenName.setTextColor(highlight);
ivVerify.setImageDrawable(theme.getDrawable("icon_verification"));
tvImpress.setTextColor(theme.getColor("content"));
ivMoreDetail.setBackgroundDrawable(theme.getDrawable("icon_more_detail"));
//微博内容
TextView tvText = (TextView)headerView.findViewById(R.id.tvText);
LinearLayout llThumbnailShape = (LinearLayout)headerView.findViewById(R.id.llThumbnailShape);
TextView tvImageInfo = (TextView)headerView.findViewById(R.id.tvImageInfo);
LinearLayout llRetweet = (LinearLayout)headerView.findViewById(R.id.llRetweet);
TextView tvRetweetText = (TextView)headerView.findViewById(R.id.tvRetweetText);
LinearLayout llRetweetThumbnailShape = (LinearLayout)headerView.findViewById(R.id.llRetweetThumbnailShape);
TextView tvRetweetImageInfo = (TextView)headerView.findViewById(R.id.tvRetweetImageInfo);
ImageView ivRetweetLocation = (ImageView)headerView.findViewById(R.id.ivRetweetLocation);
TextView tvRetweetLocation = (TextView)headerView.findViewById(R.id.tvRetweetLocation);
TextView tvRetweetCreatedAt = (TextView)headerView.findViewById(R.id.tvRetweetCreatedAt);
TextView tvRetweetSource = (TextView)headerView.findViewById(R.id.tvRetweetSource);
ImageView ivLocation = (ImageView)headerView.findViewById(R.id.ivLocation);
TextView tvLocation = (TextView)headerView.findViewById(R.id.tvLocation);
TextView tvCreatedAt = (TextView)headerView.findViewById(R.id.tvCreatedAt);
TextView tvSource = (TextView)headerView.findViewById(R.id.tvSource);
TextView tvRetweetCount = (TextView)headerView.findViewById(R.id.tvRetweetCount);
TextView tvCommentCount = (TextView)headerView.findViewById(R.id.tvCommentCount);
ImageView ivLineSeperator = (ImageView)headerView.findViewById(R.id.ivLineSeperator);
tvText.setTextColor(theme.getColor("content"));
ColorStateList selectorTextLink = theme.getColorStateList("selector_text_link");
tvText.setLinkTextColor(selectorTextLink);
Drawable shapeAttachment = theme.getDrawable("shape_attachment");
llThumbnailShape.setBackgroundDrawable(shapeAttachment);
int quote = theme.getColor("quote");
tvImageInfo.setTextColor(quote);
llRetweet.setBackgroundDrawable(theme.getDrawable("bg_retweet_frame"));
int padding10 = theme.dip2px(10);
llRetweet.setPadding(padding10, padding10, padding10, theme.dip2px(6));
tvRetweetText.setTextColor(quote);
tvRetweetText.setLinkTextColor(selectorTextLink);
llRetweetThumbnailShape.setBackgroundDrawable(shapeAttachment);
tvRetweetImageInfo.setTextColor(quote);
Drawable iconLocation = theme.getDrawable("icon_location");
ivRetweetLocation.setImageDrawable(iconLocation);
tvRetweetLocation.setTextColor(quote);
tvRetweetCreatedAt.setTextColor(quote);
tvRetweetSource.setTextColor(quote);
ivLocation.setImageDrawable(iconLocation);
tvLocation.setTextColor(quote);
tvCreatedAt.setTextColor(quote);
tvSource.setTextColor(quote);
int emphasize = theme.getColor("emphasize");
tvRetweetCount.setTextColor(emphasize);
tvCommentCount.setTextColor(emphasize);
ivLineSeperator.setBackgroundDrawable(theme.getDrawable("line_comment_of_status_normal"));
//工具条
LinearLayout llToolbar = (LinearLayout)findViewById(R.id.llToolbar);
Button btnComment = (Button)findViewById(R.id.btnComment);
Button btnRetweet = (Button)findViewById(R.id.btnRetweet);
Button btnFavorite = (Button)findViewById(R.id.btnFavorite);
Button btnShare = (Button)findViewById(R.id.btnShare);
Button btnMore = (Button)findViewById(R.id.btnMore);
llToolbar.setBackgroundDrawable(theme.getDrawable("bg_toolbar"));
btnComment.setBackgroundDrawable(theme.getDrawable("selector_toolbar_comment"));
btnRetweet.setBackgroundDrawable(theme.getDrawable("selector_toolbar_retweet"));
btnFavorite.setBackgroundDrawable(theme.getDrawable("selector_toolbar_favorite_add"));
btnShare.setBackgroundDrawable(theme.getDrawable("selector_toolbar_share"));
btnMore.setBackgroundDrawable(theme.getDrawable("selector_toolbar_more"));
lvCommentsOfStatus = (ListView) this.findViewById(R.id.lvCommentsOfStatus);
ThemeUtil.setListViewStyle(lvCommentsOfStatus);
lvCommentsOfStatus.addHeaderView(headerView);
setBack2Top(lvCommentsOfStatus);
//注册上下文菜单
View statusView = this.findViewById(R.id.llStatus);
statusContextMenuListener = new MicroBlogStatusContextMenuListener(status);
statusView.setOnCreateContextMenuListener(statusContextMenuListener);
autoLoadMoreListener = new AutoLoadMoreListener();
}
/**
* @see Activity#registerForContextMenu(View)
*/
public void registerForContextMenu(@NonNull View view) {
view.setOnCreateContextMenuListener(this);
}
public void registerForContextMenu(View view) {
view.setOnCreateContextMenuListener(this);
}
public void unregisterForContextMenu(View view)
{
view.setOnCreateContextMenuListener(null);
}
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
itemView.setOnCreateContextMenuListener(this);
}
/**
* Registers the object to given view.
*
* @param view
* the view
* @return this
*/
public SearchClickListener registerTo(final View view) {
view.setOnClickListener(this);
new FocusVisual().registerTo(view);
view.setOnCreateContextMenuListener(this);
return this;
}
/**
* Registers a context menu to be shown for the given view (multiple views
* can show the context menu). This method will set the
* {@link OnCreateContextMenuListener} on the view to this fragment, so
* {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
* called when it is time to show the context menu.
*
* @see #unregisterForContextMenu(View)
* @param view The view that should show a context menu.
*/
public void registerForContextMenu(View view) {
view.setOnCreateContextMenuListener(this);
}
/**
* Prevents a context menu to be shown for the given view. This method will
* remove the {@link OnCreateContextMenuListener} on the view.
*
* @see #registerForContextMenu(View)
* @param view The view that should stop showing a context menu.
*/
public void unregisterForContextMenu(View view) {
view.setOnCreateContextMenuListener(null);
}
/**
* Registers a context menu to be shown for the given view (multiple views
* can show the context menu). This method will set the
* {@link OnCreateContextMenuListener} on the view to this fragment, so
* {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
* called when it is time to show the context menu.
*
* @see #unregisterForContextMenu(View)
* @param view The view that should show a context menu.
*/
public void registerForContextMenu(View view) {
view.setOnCreateContextMenuListener(this);
}
/**
* Registers a context menu to be shown for the given view (multiple views
* can show the context menu). This method will set the
* {@link OnCreateContextMenuListener} on the view to this fragment, so
* {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
* called when it is time to show the context menu.
*
* @see #unregisterForContextMenu(View)
* @param view The view that should show a context menu.
*/
public void registerForContextMenu(View view) {
view.setOnCreateContextMenuListener(this);
}