/** * Called when the shuffle button is clicked. */ public void onShuffleClicked() { if (getMediaController() == null) { Log.e(TAG, "onShuffleClicked failed because getMediaController() is null"); return; } Bundle playbackStateExtras = getMediaController().getPlaybackState().getExtras(); if (playbackStateExtras != null) { int shuffleMode = playbackStateExtras.getInt(PlaybackService.EXTRAS_KEY_SHUFFLE_MODE); int newShuffleMode = shuffleMode == PlaybackManager.SHUFFLED ? PlaybackManager.NOT_SHUFFLED : PlaybackManager.SHUFFLED; Bundle extras = new Bundle(); extras.putInt(PlaybackService.EXTRAS_KEY_SHUFFLE_MODE, newShuffleMode); getMediaController().getTransportControls() .sendCustomAction(PlaybackService.ACTION_SET_SHUFFLE_MODE, extras); } }
/** * Update the {@link Playlist} of the {@link AlbumArtSwipeAdapter} with the current one in * {@link org.tomahawk.tomahawk_android.services.PlaybackService} */ public void updatePlaylist() { if (mPageScrollState != ViewPager.SCROLL_STATE_IDLE) { mUpdateWhenIdle = true; return; } if (mMediaController != null && mPlaybackManager != null) { if (mMediaController.getPlaybackState().getExtras() != null) { mRepeatMode = mMediaController.getPlaybackState().getExtras() .getInt(PlaybackService.EXTRAS_KEY_REPEAT_MODE); } else { mRepeatMode = PlaybackManager.NOT_REPEATING; } mSize = mPlaybackManager.getPlaybackListSize(); notifyDataSetChanged(); if (mSize > 0) { mFakeInfinityOffset = mSize * ((FAKE_INFINITY_COUNT / 2) / mSize); setCurrentItem(mPlaybackManager.getCurrentEntry(), false); } } } }
/** * Called when the repeat button is clicked. */ public void onRepeatClicked() { if (getMediaController() == null) { Log.e(TAG, "onRepeatClicked failed because getMediaController() is null"); return; } Bundle playbackStateExtras = getMediaController().getPlaybackState().getExtras(); if (playbackStateExtras != null) { int repeatMode = playbackStateExtras.getInt(PlaybackService.EXTRAS_KEY_REPEAT_MODE); int newRepeatMode = PlaybackManager.NOT_REPEATING; if (repeatMode == PlaybackManager.NOT_REPEATING) { newRepeatMode = PlaybackManager.REPEAT_ALL; } else if (repeatMode == PlaybackManager.REPEAT_ALL) { newRepeatMode = PlaybackManager.REPEAT_ONE; } else if (repeatMode == PlaybackManager.REPEAT_ONE) { newRepeatMode = PlaybackManager.NOT_REPEATING; } Bundle extras = new Bundle(); extras.putInt(PlaybackService.EXTRAS_KEY_REPEAT_MODE, newRepeatMode); getMediaController().getTransportControls() .sendCustomAction(PlaybackService.ACTION_SET_REPEAT_MODE, extras); } }
/** * Refresh the information in this fragment to reflect that of the current shuffleButton state. */ protected void refreshShuffleButtonState(PlaybackStateCompat playbackState) { if (getView() != null) { ImageButton imageButton = (ImageButton) getView().findViewById(R.id.imageButton_shuffle); if (imageButton != null) { if (playbackState.getExtras() != null && !(getPlaybackManager().getPlaylist() instanceof StationPlaylist) && getPlaybackManager().getCurrentEntry() != null) { imageButton.setAlpha(1f); imageButton.setClickable(true); int repeatMode = playbackState.getExtras() .getInt(PlaybackService.EXTRAS_KEY_SHUFFLE_MODE); if (repeatMode == PlaybackManager.SHUFFLED) { ImageUtils.setTint(imageButton.getDrawable(), R.color.tomahawk_red); } else if (repeatMode == PlaybackManager.NOT_SHUFFLED) { ImageUtils.clearTint(imageButton.getDrawable()); } } else { imageButton.setAlpha(0.2f); imageButton.setClickable(false); } } } }
ImageButton imageButton = (ImageButton) getView().findViewById(R.id.imageButton_repeat); if (imageButton != null) { if (playbackState.getExtras() != null && !(getPlaybackManager().getPlaylist() instanceof StationPlaylist) && getPlaybackManager().getCurrentEntry() != null) { imageButton.setAlpha(1f); imageButton.setClickable(true); int repeatMode = playbackState.getExtras() .getInt(PlaybackService.EXTRAS_KEY_REPEAT_MODE); if (repeatMode == PlaybackManager.REPEAT_ALL) {