use of android.widget.PopupMenu in project SeriesGuide by UweTrottmann.
the class SeasonsFragment method setCollectedToggleState.
private void setCollectedToggleState(int uncollectedEpisodes) {
collectedAllEpisodes = uncollectedEpisodes == 0;
//noinspection ResourceType
buttonCollectedAll.setImageResource(collectedAllEpisodes ? R.drawable.ic_collected_all : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollectAll));
buttonCollectedAll.setContentDescription(getString(collectedAllEpisodes ? R.string.uncollect_all : R.string.collect_all));
// set onClick listener not before here to avoid unexpected actions
buttonCollectedAll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
if (!collectedAllEpisodes) {
popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_ALL_ID, 0, R.string.collect_all);
}
popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_NONE_ID, 0, R.string.uncollect_all);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case CONTEXT_COLLECTED_SHOW_ALL_ID:
{
onFlagShowCollected(true);
Utils.trackAction(getActivity(), TAG, "Flag all collected (inline)");
return true;
}
case CONTEXT_COLLECTED_SHOW_NONE_ID:
{
onFlagShowCollected(false);
Utils.trackAction(getActivity(), TAG, "Flag all uncollected (inline)");
return true;
}
}
return false;
}
});
popupMenu.show();
}
});
}
use of android.widget.PopupMenu in project NewPipe by TeamNewPipe.
the class MissionAdapter method buildPopup.
private void buildPopup(final ViewHolder h) {
PopupMenu popup = new PopupMenu(mContext, h.menu);
popup.inflate(R.menu.mission);
Menu menu = popup.getMenu();
MenuItem start = menu.findItem(R.id.start);
MenuItem pause = menu.findItem(R.id.pause);
MenuItem view = menu.findItem(R.id.view);
MenuItem delete = menu.findItem(R.id.delete);
MenuItem checksum = menu.findItem(R.id.checksum);
// Set to false first
start.setVisible(false);
pause.setVisible(false);
view.setVisible(false);
delete.setVisible(false);
checksum.setVisible(false);
if (!h.mission.finished) {
if (!h.mission.running) {
if (h.mission.errCode == -1) {
start.setVisible(true);
}
delete.setVisible(true);
} else {
pause.setVisible(true);
}
} else {
view.setVisible(true);
delete.setVisible(true);
checksum.setVisible(true);
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
switch(id) {
case R.id.start:
mManager.resumeMission(h.position);
mBinder.onMissionAdded(mManager.getMission(h.position));
return true;
case R.id.pause:
mManager.pauseMission(h.position);
mBinder.onMissionRemoved(mManager.getMission(h.position));
h.lastTimeStamp = -1;
h.lastDone = -1;
return true;
case R.id.view:
File f = new File(h.mission.location, h.mission.name);
String ext = Utility.getFileExt(h.mission.name);
Log.d(TAG, "Viewing file: " + f.getAbsolutePath() + " ext: " + ext);
if (ext == null) {
Log.w(TAG, "Can't view file because it has no extension: " + h.mission.name);
return false;
}
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext.substring(1));
Log.v(TAG, "Mime: " + mime + " package: " + mContext.getApplicationContext().getPackageName() + ".provider");
if (f.exists()) {
viewFileWithFileProvider(f, mime);
} else {
Log.w(TAG, "File doesn't exist");
}
return true;
case R.id.delete:
mManager.deleteMission(h.position);
notifyDataSetChanged();
return true;
case R.id.md5:
case R.id.sha1:
DownloadMission mission = mManager.getMission(h.position);
new ChecksumTask().execute(mission.location + "/" + mission.name, ALGORITHMS.get(id));
return true;
default:
return false;
}
}
});
popup.show();
}
use of android.widget.PopupMenu in project SeriesGuide by UweTrottmann.
the class ExtensionsAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (getItemViewType(position) == VIEW_TYPE_ADD) {
if (convertView == null) {
convertView = mLayoutInflater.inflate(LAYOUT_ADD, parent, false);
}
// warn non-supporters that they only can add a few extensions
boolean isAtLimit = getCount() - 1 == ExtensionsConfigurationFragment.EXTENSION_LIMIT_FREE && !Utils.hasAccessToX(getContext());
convertView.findViewById(R.id.textViewItemExtensionAddLabel).setVisibility(isAtLimit ? View.GONE : View.VISIBLE);
convertView.findViewById(R.id.textViewItemExtensionAddLimit).setVisibility(isAtLimit ? View.VISIBLE : View.GONE);
return convertView;
}
ViewHolder viewHolder;
if (convertView == null) {
convertView = mLayoutInflater.inflate(LAYOUT_EXTENSION, parent, false);
viewHolder = new ViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final ExtensionManager.Extension extension = getItem(position);
viewHolder.description.setText(extension.description);
// title
viewHolder.title.setText(extension.label);
// icon
if (extension.icon != null) {
viewHolder.icon.setImageDrawable(extension.icon);
} else {
viewHolder.icon.setImageResource(R.drawable.ic_launcher);
}
// overflow menu
viewHolder.settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
popupMenu.getMenuInflater().inflate(R.menu.extension_menu, popupMenu.getMenu());
if (extension.settingsActivity == null) {
MenuItem item = popupMenu.getMenu().findItem(R.id.menu_action_extension_settings);
item.setVisible(false);
item.setEnabled(false);
}
popupMenu.setOnMenuItemClickListener(new OverflowItemClickListener(position));
popupMenu.show();
}
});
return convertView;
}
use of android.widget.PopupMenu in project meatspace-android by RomainPiel.
the class ChatItemView method onViewChanged.
@Override
public void onViewChanged() {
ButterKnife.inject(this);
popupMenu = new PopupMenu(getContext(), menuButton);
popupMenu.inflate(R.menu.card);
menuButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popupMenu.show();
}
});
}
use of android.widget.PopupMenu in project android_frameworks_base by ParanoidAndroid.
the class RecentsPanelView method handleLongPress.
public void handleLongPress(final View selectedView, final View anchorView, final View thumbnailView) {
thumbnailView.setSelected(true);
final PopupMenu popup = new PopupMenu(mContext, anchorView == null ? selectedView : anchorView);
mPopup = popup;
popup.getMenuInflater().inflate(R.menu.recent_popup_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.recent_remove_item) {
mRecentsContainer.removeViewInLayout(selectedView);
} else if (item.getItemId() == R.id.recent_inspect_item) {
ViewHolder viewHolder = (ViewHolder) selectedView.getTag();
if (viewHolder != null) {
final TaskDescription ad = viewHolder.taskDescription;
startApplicationDetailsActivity(ad.packageName);
show(false);
} else {
throw new IllegalStateException("Oops, no tag on view " + selectedView);
}
} else if (item.getItemId() == R.id.recent_launch_floating) {
ViewHolder viewHolder = (ViewHolder) selectedView.getTag();
if (viewHolder != null) {
final TaskDescription ad = viewHolder.taskDescription;
dismissAndGoBack();
Intent intent = ad.intent;
intent.addFlags(Intent.FLAG_FLOATING_WINDOW | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
getContext().startActivity(intent);
}
} else {
return false;
}
return true;
}
});
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
public void onDismiss(PopupMenu menu) {
thumbnailView.setSelected(false);
mPopup = null;
}
});
popup.show();
}
Aggregations