android.widget.PopupMenu.OnMenuItemClickListener Java Examples

The following examples show how to use android.widget.PopupMenu.OnMenuItemClickListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerActivity.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
public void showAudioPopup(View v) {
  PopupMenu popup = new PopupMenu(this, v);
  Menu menu = popup.getMenu();
  menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
  final MenuItem backgroundAudioItem = menu.findItem(0);
  backgroundAudioItem.setCheckable(true);
  backgroundAudioItem.setChecked(enableBackgroundAudio);
  OnMenuItemClickListener clickListener = new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item == backgroundAudioItem) {
        enableBackgroundAudio = !item.isChecked();
        return true;
      }
      return false;
    }
  };
  configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
  popup.show();
}
 
Example #2
Source File: StoryListActivity.java    From scanvine-android with MIT License 6 votes vote down vote up
public void openOpenInPopup() {
       PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_section));
       Menu menu = popupMenu.getMenu();
       menu.add(Menu.NONE, 0, Menu.NONE, openInBrowser ? "Browser✓" : "Browser");
       menu.add(Menu.NONE, 1, Menu.NONE, openInBrowser ? "Scanvine" : "Scanvine✓");
       popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       	@Override
		public boolean onMenuItemClick(MenuItem item) {
       		SharedPreferences preferences = getPreferences(MODE_PRIVATE);
       		SharedPreferences.Editor editor = preferences.edit();
       		editor.putBoolean(OPEN_IN_BROWSER, item.getItemId()==0);
       		editor.commit();
       		openInBrowser = preferences.getBoolean(OPEN_IN_BROWSER, false);
       		return false;
       	}
       });
       popupMenu.show();
}
 
Example #3
Source File: StoryListActivity.java    From scanvine-android with MIT License 6 votes vote down vote up
public void openSectionsPopup() {
       final String[] sections = {"All","World","Tech","Business","Entertainment","Sports","Life"};
       PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_section));
       Menu menu = popupMenu.getMenu();
       for (int i=0; i<sections.length; i++) {
       	boolean addCheck = sections[i].equalsIgnoreCase(currentSection) || currentSection==null && i==0;
       	menu.add(Menu.NONE, i, Menu.NONE, addCheck ? sections[i]+"✓" : sections[i]);
       }
       popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       	@Override
		public boolean onMenuItemClick(MenuItem item) {
       		currentSection = item.getItemId()==0 ? null : (""+item.getTitle()).replace("✓","");
       		StoryListFragment slf = (StoryListFragment) getSupportFragmentManager().findFragmentById(R.id.story_list);
       		slf.refreshList(currentTime, currentSection, getSourceSlug());
       		return false;
       	}
       });
       popupMenu.show();
}
 
Example #4
Source File: StoryListActivity.java    From scanvine-android with MIT License 6 votes vote down vote up
public void openTimePopup() {
	final String[] times = {"Firehose","Latest","Last Day","Last Week","Last Month"};
	final String[] timeKeys = {"Firehose","Latest","Last1","Last7","Last30"};
       PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_time));
       Menu menu = popupMenu.getMenu();
       for (int i=0; i<times.length; i++) {
       	boolean addCheck = currentTime!=null && currentTime.equalsIgnoreCase(timeKeys[i]);
       	menu.add(Menu.NONE, i, Menu.NONE, addCheck ? times[i]+"✓" : times[i]);
       }
       popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       	@Override
		public boolean onMenuItemClick(MenuItem item) {
       		currentTime = timeKeys[item.getItemId()];
       		StoryListFragment slf = (StoryListFragment) getSupportFragmentManager().findFragmentById(R.id.story_list);
       		slf.refreshList(currentTime, currentSection, getSourceSlug());
       		return false;
       	}
       });
       popupMenu.show();
}
 
Example #5
Source File: SourceListActivity.java    From scanvine-android with MIT License 6 votes vote down vote up
public void openSortPopup() {
       PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_section));
       Menu menu = popupMenu.getMenu();
       menu.add(Menu.NONE, 0, Menu.NONE, sortByName ? "Name✓" : "Name");
       menu.add(Menu.NONE, 1, Menu.NONE, sortByName ? "Score" : "Score✓");
       popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       	@Override
		public boolean onMenuItemClick(MenuItem item) {
       		sortByName = item.getItemId()==0;
       		SourceListFragment slf = (SourceListFragment) getSupportFragmentManager().findFragmentById(R.id.source_list);
       		slf.sortList(sortByName);
       		return false;
       	}
       });
       popupMenu.show();
}
 
Example #6
Source File: SourceListActivity.java    From scanvine-android with MIT License 6 votes vote down vote up
public void openSectionPopup() {
       final String[] sections = {"All","World","Tech","Business","Entertainment","Sports","Life"};
       PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_section));
       Menu menu = popupMenu.getMenu();
       for (int i=0; i<sections.length; i++) {
       	boolean addCheck = currentSection!=null &&
       					   (currentSection.equalsIgnoreCase(sections[i]) ||
       					   currentSection.length()==0 && "All".equalsIgnoreCase(sections[i]));
       	menu.add(Menu.NONE, i, Menu.NONE, addCheck ? sections[i]+"✓" : sections[i]);
       }
       popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       	@Override
		public boolean onMenuItemClick(MenuItem item) {
       		currentSection = item.getItemId()==0 ? null : (""+item.getTitle()).replace("✓","");
       		SourceListFragment slf = (SourceListFragment) getSupportFragmentManager().findFragmentById(R.id.source_list);
       		slf.refreshList(currentSection);
       		return false;
       	}
       });
       popupMenu.show();
}
 
Example #7
Source File: PlayerActivity.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
public void showVerboseLogPopup(View v) {
  PopupMenu popup = new PopupMenu(this, v);
  Menu menu = popup.getMenu();
  menu.add(Menu.NONE, 0, Menu.NONE, R.string.logging_normal);
  menu.add(Menu.NONE, 1, Menu.NONE, R.string.logging_verbose);
  menu.setGroupCheckable(Menu.NONE, true, true);
  menu.findItem((VerboseLogUtil.areAllTagsEnabled()) ? 1 : 0).setChecked(true);
  popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item.getItemId() == 0) {
        VerboseLogUtil.setEnableAllTags(false);
      } else {
        VerboseLogUtil.setEnableAllTags(true);
      }
      return true;
    }
  });
  popup.show();
}
 
Example #8
Source File: VideoGridFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onContextPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu());
    MediaWrapper media = mVideoAdapter.getItem(position);
    if (media == null)
        return;
    setContextMenuItems(popupMenu.getMenu(), media);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example #9
Source File: AudioBrowserFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
    setContextMenuItems(popupMenu.getMenu(), anchor);

    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example #10
Source File: AudioAlbumsSongsFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
    setContextMenuItems(popupMenu.getMenu(), anchor, position);

    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example #11
Source File: PlayerActivity.java    From Android-Example-HLS-ExoPlayer with Apache License 2.0 6 votes vote down vote up
public void showVerboseLogPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();
    menu.add(Menu.NONE, 0, Menu.NONE, R.string.logging_normal);
    menu.add(Menu.NONE, 1, Menu.NONE, R.string.logging_verbose);
    menu.setGroupCheckable(Menu.NONE, true, true);
    menu.findItem((VerboseLogUtil.areAllTagsEnabled()) ? 1 : 0).setChecked(true);
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == 0) {
                VerboseLogUtil.setEnableAllTags(false);
            } else {
                VerboseLogUtil.setEnableAllTags(true);
            }
            return true;
        }
    });
    popup.show();
}
 
Example #12
Source File: PlayerActivity.java    From Android-Example-HLS-ExoPlayer with Apache License 2.0 6 votes vote down vote up
public void showAudioPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();
    menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
    final MenuItem backgroundAudioItem = menu.findItem(0);
    backgroundAudioItem.setCheckable(true);
    backgroundAudioItem.setChecked(enableBackgroundAudio);
    OnMenuItemClickListener clickListener = new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item == backgroundAudioItem) {
                enableBackgroundAudio = !item.isChecked();
                return true;
            }
            return false;
        }
    };
    configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
    popup.show();
}
 
Example #13
Source File: TileOrderActivity.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
void showMenu(final ListView listView, final View anchorView) {
    final PopupMenu menu = new PopupMenu(listView.getContext(), anchorView);
    menu.inflate(R.menu.tile_menu);
    menu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.tile_dual:
                    dual = !dual;
                    break;
                case R.id.tile_locked:
                    locked = !locked;
                    if (locked) {
                        secured = true;
                        lockedOnly = false;
                    }
                    break;
                case R.id.tile_locked_only:
                    lockedOnly = !lockedOnly;
                    break;
                case R.id.tile_secured:
                    secured = !secured;
                    break;
            }
            updateMenu(menu.getMenu());
            listView.invalidateViews();
            return true;
        }
    });
    updateMenu(menu.getMenu());
    menu.show();
}
 
Example #14
Source File: PlayerActivity.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
private void configurePopupWithTracks(PopupMenu popup,
    final OnMenuItemClickListener customActionClickListener,
    final int trackType) {
  if (player == null) {
    return;
  }
  String[] tracks = player.getTracks(trackType);
  if (tracks == null) {
    return;
  }
  popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      return (customActionClickListener != null
          && customActionClickListener.onMenuItemClick(item))
          || onTrackItemClick(item, trackType);
    }
  });
  Menu menu = popup.getMenu();
  // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0)
  menu.add(MENU_GROUP_TRACKS, DemoPlayer.DISABLED_TRACK + ID_OFFSET, Menu.NONE, R.string.off);
  if (tracks.length == 1 && TextUtils.isEmpty(tracks[0])) {
    menu.add(MENU_GROUP_TRACKS, DemoPlayer.PRIMARY_TRACK + ID_OFFSET, Menu.NONE, R.string.on);
  } else {
    for (int i = 0; i < tracks.length; i++) {
      menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE, tracks[i]);
    }
  }
  menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true);
  menu.findItem(player.getSelectedTrackIndex(trackType) + ID_OFFSET).setChecked(true);
}
 
Example #15
Source File: DisplayImageFragment.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the popup menu for rotating the image.
 *
 * @param view The view opening the menu.
 */
private void showRotateMenu(final View view) {
	PopupMenu popup = new PopupMenu(getActivity(), view);
	popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
		@Override
		public boolean onMenuItemClick(@NonNull final MenuItem item) {
			int itemId = item.getItemId();
			if (itemId == R.id.action_rotate_right) {
				mImageView.rotateImage((short) ExifInterface.ORIENTATION_ROTATE_90);
				return true;
			}
			else if (itemId == R.id.action_rotate_left) {
				mImageView.rotateImage((short) ExifInterface.ORIENTATION_ROTATE_270);
				return true;
			}
			else if (itemId == R.id.action_rotate_180) {
				mImageView.rotateImage((short) ExifInterface.ORIENTATION_ROTATE_180);
				return true;
			}
			else {
				return true;
			}
		}
	});
	popup.inflate(R.menu.menu_image_rotate);

	popup.show();
}
 
Example #16
Source File: PlayerActivity.java    From Android-Example-HLS-ExoPlayer with Apache License 2.0 5 votes vote down vote up
private void configurePopupWithTracks(PopupMenu popup,
                                      final OnMenuItemClickListener customActionClickListener,
                                      final int trackType) {
    if (player == null) {
        return;
    }
    int trackCount = player.getTrackCount(trackType);
    if (trackCount == 0) {
        return;
    }
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return (customActionClickListener != null
                    && customActionClickListener.onMenuItemClick(item))
                    || onTrackItemClick(item, trackType);
        }
    });
    Menu menu = popup.getMenu();
    // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0).
    menu.add(MENU_GROUP_TRACKS, DemoPlayer.TRACK_DISABLED + ID_OFFSET, Menu.NONE, R.string.off);
    for (int i = 0; i < trackCount; i++) {
        menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE,
                buildTrackName(player.getTrackFormat(trackType, i)));
    }
    menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true);
    menu.findItem(player.getSelectedTrack(trackType) + ID_OFFSET).setChecked(true);
}
 
Example #17
Source File: DisplayImageFragment.java    From Augendiagnose with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create the popup menu for saving metadata.
 *
 * @param view The view opening the menu.
 */
private void showSaveMenu(final View view) {
	PopupMenu popup = new PopupMenu(getActivity(), view);
	popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
		@Override
		public boolean onMenuItemClick(@NonNull final MenuItem item) {
			int itemId = item.getItemId();
			if (itemId == R.id.action_store_color_settings) {
				mImageView.storeColorSettings(false);
				return true;
			}
			else if (itemId == R.id.action_reset_color_settings) {
				mImageView.storeColorSettings(true);
				return true;
			}
			else if (itemId == R.id.action_store_position) {
				mImageView.storePositionZoom(false);
				return true;
			}
			else if (itemId == R.id.action_reset_position) {
				mImageView.storePositionZoom(true);
				return true;
			}
			else if (itemId == R.id.action_store_overlay_color) {
				mImageView.storeOverlayColor(false);
				return true;
			}
			else if (itemId == R.id.action_reset_overlay_color) {
				mImageView.storeOverlayColor(true);
				return true;
			}
			else if (itemId == R.id.action_delete_overlay_position) {
				mImageView.resetOverlayPosition(true);
				return true;
			}
			else {
				return true;
			}
		}
	});
	popup.inflate(R.menu.menu_image_save);

	if (mShowUtilities == UtilitiyStatus.SHOW_NOTHING) {
		popup.getMenu().removeGroup(R.id.group_overlay);
	}
	else {
		try {
			JpegMetadata metadata = mImageView.getEyePhoto().getImageMetadata();

			if (!metadata.hasOverlayPosition()) {
				popup.getMenu().removeGroup(R.id.group_overlay);
			}
			else if (metadata.hasFlag(JpegMetadata.FLAG_OVERLAY_SET_BY_CAMERA_ACTIVITY)
					|| metadata.hasFlag(JpegMetadata.FLAG_OVERLAY_POSITION_DETERMINED_AUTOMATICALLY)) {
				popup.getMenu().removeItem(R.id.action_store_overlay_color);
				popup.getMenu().removeItem(R.id.action_reset_overlay_color);
			}
		}
		catch (NullPointerException e) {
			// ignore
		}
	}

	if (mShowUtilities == UtilitiyStatus.SHOW_NOTHING || mShowUtilities == UtilitiyStatus.ONLY_OVERLAY) {
		popup.getMenu().removeGroup(R.id.group_color_settings);
	}

	popup.show();
}
 
Example #18
Source File: MainActivity4.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	tv =(TextView) findViewById(R.id.tv);
	
	// ����ı���ļ����¼�-->�����˵�
	tv.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			
			//����PopupMenu(����ʽ�˵�)
			//1.new PopupMenu
			PopupMenu menu = new PopupMenu(MainActivity4.this, v);
			//2.getMenuInflater.inflat(R.menu.xxx,menu)
			getMenuInflater().inflate(R.menu.main, menu.getMenu());
			//menu.getMenuInflater().inflate(R.menu.main, menu.getMenu());
			//MainActivity4.this.getMenuInflater().inflate(R.menu.main, menu.getMenu());������һ��Ч��
			//3.show
			menu.show();
			//4.����popupmenu����¼�
			menu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
				
				@Override
				public boolean onMenuItemClick(MenuItem item) {
					
					switch (item.getItemId()) {
					case R.id.add:{
						tv.setText("12321321312321312313123");
					}
						
						break;
					case R.id.red:{
						tv.setTextColor(Color.RED);
					}
					
					break;
					case R.id.green:{
						tv.setTextColor(Color.GREEN);
					}
					
					break;
					case R.id.bule:{
						tv.setTextColor(Color.BLUE);
					}
					
					break;

					default:
						break;
					}
				
					return false;
				}
			});
		}
	});
}
 
Example #19
Source File: StillImageActivity.java    From quickstart-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  binding = ActivityStillImageBinding.inflate(getLayoutInflater());
  setContentView(binding.getRoot());

  binding.getImageButton.setOnClickListener(
      new OnClickListener() {
        @Override
        public void onClick(View view) {
          // Menu for selecting either: a) take new photo b) select from existing
          PopupMenu popup = new PopupMenu(StillImageActivity.this, view);
          popup.setOnMenuItemClickListener(
              new OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                  switch (menuItem.getItemId()) {
                    case R.id.select_images_from_local:
                      startChooseImageIntentForResult();
                      return true;
                    case R.id.take_photo_using_camera:
                      startCameraIntentForResult();
                      return true;
                    default:
                      return false;
                  }
                }
              });

          MenuInflater inflater = popup.getMenuInflater();
          inflater.inflate(R.menu.camera_button_menu, popup.getMenu());
          popup.show();
        }
      });

  populateFeatureSelector();
  populateSizeSelector();

  createImageProcessor();

  isLandScape =
      (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);

  if (savedInstanceState != null) {
    imageUri = savedInstanceState.getParcelable(KEY_IMAGE_URI);
    imageMaxWidth = savedInstanceState.getInt(KEY_IMAGE_MAX_WIDTH);
    imageMaxHeight = savedInstanceState.getInt(KEY_IMAGE_MAX_HEIGHT);
    selectedSize = savedInstanceState.getString(KEY_SELECTED_SIZE);

    if (imageUri != null) {
      tryReloadAndDetectInImage();
    }
  }
}