use of android.support.v7.widget.PopupMenu in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testSaveItem.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSaveItem() {
ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
itemListener.getValue().onResponse(item);
adapter.getViewHolder(0).itemView.performLongClick();
PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
assertNotNull(popupMenu);
assertThat(popupMenu.getMenu().findItem(R.id.menu_contextual_save).isVisible()).isFalse();
shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_save));
verify(favoriteManager).add(any(Context.class), eq(item));
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
assertTrue(item.isFavorite());
View snackbarView = ShadowSnackbar.getLatestView();
assertThat((TextView) snackbarView.findViewById(R.id.snackbar_text)).isNotNull().containsText(R.string.toast_saved);
snackbarView.findViewById(R.id.snackbar_action).performClick();
verify(favoriteManager).remove(any(Context.class), eq("1"));
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
assertFalse(item.isFavorite());
}
use of android.support.v7.widget.PopupMenu in project remusic by aa112901.
the class MainFragmentAdapter method setOnPlaylistListener.
private void setOnPlaylistListener(ItemHolder itemHolder, final int position, final long playlistid, final String albumArt, final String playlistname) {
itemHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(mContext, PlaylistActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.putExtra("islocal", true);
intent.putExtra("playlistid", playlistid + "");
intent.putExtra("albumart", albumArt);
intent.putExtra("playlistname", playlistname);
mContext.startActivity(intent);
}
}, 60);
}
});
itemHolder.menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(mContext, v);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (position == 5) {
Toast.makeText(mContext, "此歌单不应删除", Toast.LENGTH_SHORT).show();
} else {
new AlertDialog.Builder(mContext).setTitle(mContext.getString(R.string.sure_to_delete_music)).setPositiveButton(mContext.getString(R.string.sure), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PlaylistInfo.getInstance(mContext).deletePlaylist(playlistid);
PlaylistsManager.getInstance(mContext).delete(playlistid);
Intent intent = new Intent();
intent.setAction(IConstants.PLAYLIST_COUNT_CHANGED);
mContext.sendBroadcast(intent);
dialog.dismiss();
}
}).setNegativeButton(mContext.getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
return true;
}
});
popupMenu.inflate(R.menu.popmenu);
popupMenu.show();
}
});
}
use of android.support.v7.widget.PopupMenu in project Tusky by Vavassor.
the class SFragment method more.
protected void more(final Status status, View view, final AdapterItemRemover adapter, final int position) {
final String id = status.getActionableId();
final String accountId = status.getActionableStatus().account.id;
final String accountUsename = status.getActionableStatus().account.username;
final Spanned content = status.getActionableStatus().content;
final String statusUrl = status.getActionableStatus().url;
PopupMenu popup = new PopupMenu(getContext(), view);
// Give a different menu depending on whether this is the user's own toot or not.
if (loggedInAccountId == null || !loggedInAccountId.equals(accountId)) {
popup.inflate(R.menu.status_more);
} else {
popup.inflate(R.menu.status_more_for_user);
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.status_share_content:
{
StringBuilder sb = new StringBuilder();
sb.append(status.account.username);
sb.append(" - ");
sb.append(status.content.toString());
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, sb.toString());
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_content_to)));
return true;
}
case R.id.status_share_link:
{
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, statusUrl);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_link_to)));
return true;
}
case R.id.status_mute:
{
mute(accountId);
return true;
}
case R.id.status_block:
{
block(accountId);
return true;
}
case R.id.status_report:
{
openReportPage(accountId, accountUsename, id, content);
return true;
}
case R.id.status_delete:
{
delete(id);
adapter.removeItem(position);
return true;
}
}
return false;
}
});
popup.show();
}
use of android.support.v7.widget.PopupMenu in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DashboardAdapter method showRemoveOption.
private void showRemoveOption(View v, final Tile suggestion) {
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(mContext, R.style.Theme_AppCompat_DayNight), v);
popup.getMenu().add(R.string.suggestion_remove).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MetricsLogger.action(mContext, MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION, DashboardAdapter.getSuggestionIdentifier(mContext, suggestion));
disableSuggestion(suggestion);
mSuggestions.remove(suggestion);
recountItems();
return true;
}
});
popup.show();
}
use of android.support.v7.widget.PopupMenu in project RxBinding by JakeWharton.
the class RxPopupMenuTestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View anchor = new View(this);
setContentView(anchor);
popupMenu = new PopupMenu(this, anchor);
}
Aggregations