예제 #1
0
 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);
 }
예제 #2
0
 private boolean haveTracks(int type) {
   return player != null && player.getTrackCount(type) > 0;
 }