use of android.widget.PopupMenu in project KISS by Neamar.
the class AppResult method buildPopupMenu.
@Override
protected PopupMenu buildPopupMenu(Context context, final RecordAdapter parent, View parentView) {
PopupMenu menu = inflatePopupMenu(R.menu.menu_item_app, context, parentView);
if ((context instanceof MainActivity) && (!((MainActivity) context).isOnSearchView())) {
menu.getMenu().removeItem(R.id.item_remove);
}
try {
// app installed under /system can't be uninstalled
boolean isSameProfile = true;
ApplicationInfo ai;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
LauncherActivityInfo info = launcher.getActivityList(this.appPojo.packageName, this.appPojo.userHandle.getRealHandle()).get(0);
ai = info.getApplicationInfo();
isSameProfile = this.appPojo.userHandle.isCurrentUser();
} else {
ai = context.getPackageManager().getApplicationInfo(this.appPojo.packageName, 0);
}
// Need to AND the flags with SYSTEM:
if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && isSameProfile) {
menu.getMenuInflater().inflate(R.menu.menu_item_app_uninstall, menu.getMenu());
}
} catch (NameNotFoundException | IndexOutOfBoundsException e) {
// should not happen
}
//append root menu if available
if (KissApplication.getRootHandler(context).isRootActivated() && KissApplication.getRootHandler(context).isRootAvailable()) {
menu.getMenuInflater().inflate(R.menu.menu_item_app_root, menu.getMenu());
}
return menu;
}
use of android.widget.PopupMenu in project KISS by Neamar.
the class Result method getPopupMenu.
/**
* How to display the popup menu
*
* @return a PopupMenu object
*/
public PopupMenu getPopupMenu(final Context context, final RecordAdapter parent, View parentView) {
PopupMenu menu = buildPopupMenu(context, parent, parentView);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
return popupMenuClickHandler(context, parent, item);
}
});
return menu;
}
use of android.widget.PopupMenu in project xabber-android by redsolution.
the class LogFilesAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
FileViewHolder fileHolder = (FileViewHolder) holder;
final File file = files[position];
fileHolder.fileName.setText(file.getName());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(holder.itemView.getContext(), holder.itemView);
popup.inflate(R.menu.item_log_file);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_log_file_open:
viewFile(file, holder.itemView.getContext());
return true;
case R.id.action_log_file_send:
sendFile(file, holder.itemView.getContext());
return true;
}
return false;
}
});
popup.show();
}
});
}
use of android.widget.PopupMenu in project cardslib by gabrielemariotti.
the class CardHeaderView method _buildPopupMenu.
/**
* Build the menu
* @return
*/
private PopupMenu _buildPopupMenu() {
PopupMenu popup = new PopupMenu(getContext(), mImageButtonOverflow);
if (mCardHeader.getPopupMenu() > CardHeader.NO_POPUP_MENU) {
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(mCardHeader.getPopupMenu(), popup.getMenu());
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (mCardHeader.getPopupMenuListener() != null) {
// This individual card has it unique menu
mCardHeader.getPopupMenuListener().onMenuItemClick(mCardHeader.getParentCard(), item);
}
return false;
}
});
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu menu) {
if (mImageButtonOverflow != null)
mImageButtonOverflow.setSelected(false);
}
});
return popup;
}
use of android.widget.PopupMenu in project cardslib by gabrielemariotti.
the class HeaderFragment method init_standard_header_with_overflow_button_dynamic_menu.
/**
* This method builds a standard header with overflow button with a dynamic menu
*/
private void init_standard_header_with_overflow_button_dynamic_menu() {
//Create a Card
Card card = new Card(getActivity());
//Create a CardHeader
CardHeader header = new CardHeader(getActivity());
//Set the header title
header.setTitle(getString(R.string.demo_header_basetitle));
//Add a popup menu. This method set OverFlow button to visible
header.setPopupMenu(R.menu.popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() {
@Override
public void onMenuItemClick(BaseCard card, MenuItem item) {
Toast.makeText(getActivity(), "Click on " + item.getTitle(), Toast.LENGTH_SHORT).show();
}
});
//Add a PopupMenuPrepareListener to add dynamically a menu entry
//it is optional.
header.setPopupMenuPrepareListener(new CardHeader.OnPrepareCardHeaderPopupMenuListener() {
@Override
public boolean onPreparePopupMenu(BaseCard card, PopupMenu popupMenu) {
popupMenu.getMenu().add("Dynamic item");
return true;
}
});
card.addCardHeader(header);
//Set card in the CardView
CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo_header_overflow_dynamic);
cardView.setCard(card);
}
Aggregations