Ejemplo n.º 1
0
 private void configurePopupWithTracks(
     PopupMenu popup,
     final PopupMenu.OnMenuItemClickListener customActionClickListener,
     final int trackType) {
   if (player == null) {
     return;
   }
   int trackCount = player.getTrackCount(trackType);
   if (trackCount == 0) {
     return;
   }
   popup.setOnMenuItemClickListener(
       new PopupMenu.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 (trackCount == 1 && TextUtils.isEmpty(player.getTrackName(trackType, 0))) {
     menu.add(MENU_GROUP_TRACKS, DemoPlayer.PRIMARY_TRACK + ID_OFFSET, Menu.NONE, R.string.on);
   } else {
     for (int i = 0; i < trackCount; i++) {
       menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE, player.getTrackName(trackType, i));
     }
   }
   menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true);
   menu.findItem(player.getSelectedTrackIndex(trackType) + ID_OFFSET).setChecked(true);
 }
Ejemplo n.º 2
0
 private boolean haveTracks(int type) {
   return player != null && player.getTrackCount(type) > 0;
 }