New now playing screen. Work in progress!
This commit is contained in:
parent
479a7d81cd
commit
1cde43af07
27 changed files with 889 additions and 571 deletions
|
|
@ -15,6 +15,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
|
@ -43,7 +44,6 @@ import com.kabouzeid.gramophone.util.ColorUtil;
|
|||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
import com.kabouzeid.gramophone.views.SquareIfPlaceImageView;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
|
|
@ -68,7 +68,7 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
public static final String EXTRA_ARTIST_ID = "extra_artist_id";
|
||||
|
||||
@Bind(R.id.image)
|
||||
SquareIfPlaceImageView artistImage;
|
||||
ImageView artistImage;
|
||||
@Bind(R.id.list_background)
|
||||
View songListBackground;
|
||||
@Bind(R.id.list)
|
||||
|
|
|
|||
|
|
@ -1,40 +1,31 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewAnimationUtils;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialdialogs.internal.ThemeSingleton;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.helper.MusicProgressViewUpdateHelper;
|
||||
import com.kabouzeid.gramophone.helper.PlayPauseButtonOnClickHandler;
|
||||
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
||||
import com.kabouzeid.gramophone.misc.FloatingActionButtonProperties;
|
||||
import com.kabouzeid.gramophone.misc.SimpleAnimatorListener;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.misc.SimpleOnSeekbarChangeListener;
|
||||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
|
||||
import com.kabouzeid.gramophone.util.ColorUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.kabouzeid.gramophone.views.PlayPauseDrawable;
|
||||
|
||||
import butterknife.Bind;
|
||||
|
|
@ -43,20 +34,10 @@ import butterknife.ButterKnife;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class PlaybackControlsFragment extends Fragment implements MusicServiceEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final int FAB_CIRCULAR_REVEAL_ANIMATION_TIME = 1000;
|
||||
public class PlaybackControlsFragment extends Fragment implements MusicServiceEventListener, MusicProgressViewUpdateHelper.Callback {
|
||||
|
||||
@Bind(R.id.player_play_pause_fab)
|
||||
FloatingActionButton playPauseFab;
|
||||
|
||||
@Bind(R.id.player_title)
|
||||
TextView songTitle;
|
||||
@Bind(R.id.player_text)
|
||||
TextView songText;
|
||||
@Bind(R.id.player_footer)
|
||||
LinearLayout footer;
|
||||
@Bind(R.id.player_playback_controller_card)
|
||||
CardView playbackControllerCard;
|
||||
@Bind(R.id.player_prev_button)
|
||||
ImageButton prevButton;
|
||||
@Bind(R.id.player_next_button)
|
||||
|
|
@ -65,20 +46,20 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
ImageButton repeatButton;
|
||||
@Bind(R.id.player_shuffle_button)
|
||||
ImageButton shuffleButton;
|
||||
@Bind(R.id.player_media_controller_container)
|
||||
RelativeLayout mediaControllerContainer;
|
||||
@Bind(R.id.player_media_controller_container_background)
|
||||
View mediaControllerContainerBackground;
|
||||
|
||||
private int lastFooterColor;
|
||||
private int lastPlaybackControlsColor;
|
||||
private int lastTitleTextColor;
|
||||
private int lastCaptionTextColor;
|
||||
@Bind(R.id.player_progress_slider)
|
||||
SeekBar progressSlider;
|
||||
@Bind(R.id.player_song_total_time)
|
||||
TextView songTotalTime;
|
||||
@Bind(R.id.player_song_current_progress)
|
||||
TextView songCurrentProgress;
|
||||
|
||||
private PlayPauseDrawable playerFabPlayPauseDrawable;
|
||||
private AnimatorSet colorTransitionAnimator;
|
||||
|
||||
private AbsMusicServiceActivity activity;
|
||||
private int lastPlaybackControlsColor;
|
||||
|
||||
private MusicProgressViewUpdateHelper progressViewUpdateHelper;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
|
|
@ -96,6 +77,12 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
activity = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
progressViewUpdateHelper = new MusicProgressViewUpdateHelper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
|
@ -106,23 +93,32 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ButterKnife.bind(this, view);
|
||||
PreferenceUtil.getInstance(getContext()).registerOnSharedPreferenceChangedListener(this);
|
||||
activity.addMusicServiceEventListener(this);
|
||||
|
||||
setUpMusicControllers();
|
||||
updateProgressTextColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
activity.removeMusicServiceEventListener(this);
|
||||
PreferenceUtil.getInstance(activity).unregisterOnSharedPreferenceChangedListener(this);
|
||||
ButterKnife.unbind(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
progressViewUpdateHelper.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
progressViewUpdateHelper.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayingMetaChanged() {
|
||||
updateMetaTexts();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -145,31 +141,19 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
switch (key) {
|
||||
case PreferenceUtil.PLAYBACK_CONTROLLER_CARD_NOW_PLAYING:
|
||||
updatePlaybackControllerCardVisibility();
|
||||
break;
|
||||
case PreferenceUtil.COLOR_PLAYBACK_CONTROLS_NOW_PLAYING:
|
||||
updateRepeatState();
|
||||
updateShuffleState();
|
||||
updatePlayPauseFabTint();
|
||||
break;
|
||||
case PreferenceUtil.LARGER_TITLE_BOX_NOW_PLAYING:
|
||||
updateTitleBoxSize();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
animateColorChange(color);
|
||||
lastPlaybackControlsColor = ColorUtil.getOpaqueColor(ColorUtil.getSecondaryTextColorForBackground(getContext(), color));
|
||||
updateRepeatState();
|
||||
updateShuffleState();
|
||||
updatePrevNextColor();
|
||||
updateProgressSliderTint();
|
||||
updateProgressTextColor();
|
||||
}
|
||||
|
||||
private void setUpPlayPauseFab() {
|
||||
updatePlayPauseDrawableState(false);
|
||||
playPauseFab.setImageDrawable(playerFabPlayPauseDrawable);
|
||||
updatePlayPauseFabTint();
|
||||
FloatingActionButtonProperties.COLOR.set(playPauseFab, Color.WHITE);
|
||||
playPauseFab.setOnClickListener(new PlayPauseButtonOnClickHandler());
|
||||
playPauseFab.post(new Runnable() {
|
||||
@Override
|
||||
|
|
@ -180,11 +164,6 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
});
|
||||
}
|
||||
|
||||
private void updatePlayPauseFabTint() {
|
||||
int fabColor = PreferenceUtil.getInstance(activity).colorPlaybackControlsNowPlaying() ? lastPlaybackControlsColor : activity.getThemeColorAccent();
|
||||
FloatingActionButtonProperties.COLOR.set(playPauseFab, fabColor);
|
||||
}
|
||||
|
||||
protected void updatePlayPauseDrawableState(boolean animate) {
|
||||
if (playerFabPlayPauseDrawable == null) {
|
||||
playerFabPlayPauseDrawable = new PlayPauseDrawable(activity);
|
||||
|
|
@ -196,37 +175,16 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
}
|
||||
}
|
||||
|
||||
private void updateTitleBoxSize() {
|
||||
boolean largerTitleBox = PreferenceUtil.getInstance(activity).largerTitleBoxNowPlaying();
|
||||
int paddingTopBottom = largerTitleBox ? getResources().getDimensionPixelSize(R.dimen.title_box_padding_large) : getResources().getDimensionPixelSize(R.dimen.title_box_padding_small);
|
||||
footer.setPadding(footer.getPaddingLeft(), paddingTopBottom, footer.getPaddingRight(), paddingTopBottom);
|
||||
|
||||
songTitle.setPadding(songTitle.getPaddingLeft(), songTitle.getPaddingTop(), songTitle.getPaddingRight(), largerTitleBox ? getResources().getDimensionPixelSize(R.dimen.title_box_text_spacing_large) : getResources().getDimensionPixelSize(R.dimen.title_box_text_spacing_small));
|
||||
songText.setPadding(songText.getPaddingLeft(), largerTitleBox ? getResources().getDimensionPixelSize(R.dimen.title_box_text_spacing_large) : getResources().getDimensionPixelSize(R.dimen.title_box_text_spacing_small), songText.getPaddingRight(), songText.getPaddingBottom());
|
||||
|
||||
songTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, largerTitleBox ? getResources().getDimensionPixelSize(R.dimen.title_box_title_text_size_large) : getResources().getDimensionPixelSize(R.dimen.title_box_title_text_size_small));
|
||||
songText.setTextSize(TypedValue.COMPLEX_UNIT_PX, largerTitleBox ? getResources().getDimensionPixelSize(R.dimen.title_box_caption_text_size_large) : getResources().getDimensionPixelSize(R.dimen.title_box_caption_text_size_small));
|
||||
}
|
||||
|
||||
private void updatePlaybackControllerCardVisibility() {
|
||||
boolean showPlaybackControllerCard = PreferenceUtil.getInstance(activity).playbackControllerCardNowPlaying();
|
||||
playbackControllerCard.setVisibility(showPlaybackControllerCard ? View.VISIBLE : View.GONE);
|
||||
mediaControllerContainerBackground.setVisibility(showPlaybackControllerCard ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
private void setUpMusicControllers() {
|
||||
setUpPlayPauseFab();
|
||||
setUpPrevNext();
|
||||
setUpRepeatButton();
|
||||
setUpShuffleButton();
|
||||
setUpProgressSlider();
|
||||
}
|
||||
|
||||
private void setUpPrevNext() {
|
||||
int themedDrawableColor = ColorUtil.resolveColor(activity, android.R.attr.textColorSecondary);
|
||||
nextButton.setImageDrawable(Util.getTintedDrawable(activity,
|
||||
R.drawable.ic_skip_next_white_36dp, themedDrawableColor));
|
||||
prevButton.setImageDrawable(Util.getTintedDrawable(activity,
|
||||
R.drawable.ic_skip_previous_white_36dp, themedDrawableColor));
|
||||
updatePrevNextColor();
|
||||
nextButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
@ -241,6 +199,19 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
});
|
||||
}
|
||||
|
||||
private void updateProgressTextColor() {
|
||||
int color = ColorUtil.getPrimaryTextColor(getContext(), false);
|
||||
songTotalTime.setTextColor(color);
|
||||
songCurrentProgress.setTextColor(color);
|
||||
}
|
||||
|
||||
private void updatePrevNextColor() {
|
||||
nextButton.setImageDrawable(Util.getTintedDrawable(activity,
|
||||
R.drawable.ic_skip_next_white_36dp, lastPlaybackControlsColor));
|
||||
prevButton.setImageDrawable(Util.getTintedDrawable(activity,
|
||||
R.drawable.ic_skip_previous_white_36dp, lastPlaybackControlsColor));
|
||||
}
|
||||
|
||||
private void setUpShuffleButton() {
|
||||
updateShuffleState();
|
||||
shuffleButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
|
@ -255,11 +226,11 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
switch (MusicPlayerRemote.getShuffleMode()) {
|
||||
case MusicService.SHUFFLE_MODE_SHUFFLE:
|
||||
shuffleButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_shuffle_white_36dp,
|
||||
getActivatedIconColor()));
|
||||
lastPlaybackControlsColor));
|
||||
break;
|
||||
default:
|
||||
shuffleButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_shuffle_white_36dp,
|
||||
getDeactivatedIconColor()));
|
||||
lastPlaybackControlsColor));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -278,84 +249,19 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
switch (MusicPlayerRemote.getRepeatMode()) {
|
||||
case MusicService.REPEAT_MODE_ALL:
|
||||
repeatButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_repeat_white_36dp,
|
||||
getActivatedIconColor()));
|
||||
lastPlaybackControlsColor));
|
||||
break;
|
||||
case MusicService.REPEAT_MODE_THIS:
|
||||
repeatButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_repeat_one_white_36dp,
|
||||
getActivatedIconColor()));
|
||||
lastPlaybackControlsColor));
|
||||
break;
|
||||
default:
|
||||
repeatButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_repeat_white_36dp,
|
||||
getDeactivatedIconColor()));
|
||||
lastPlaybackControlsColor));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private int getActivatedIconColor() {
|
||||
if (PreferenceUtil.getInstance(activity).colorPlaybackControlsNowPlaying()) {
|
||||
return ensureActivatedColorVisibleIfNecessary(lastPlaybackControlsColor);
|
||||
} else {
|
||||
return ThemeSingleton.get().positiveColor.getDefaultColor();
|
||||
}
|
||||
}
|
||||
|
||||
private int getDeactivatedIconColor() {
|
||||
return ColorUtil.resolveColor(activity, android.R.attr.textColorSecondary);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If the activated color wont have enough difference to the deactivated color Color.WHITE / Color.BLACK (depending on the theme),
|
||||
* else the unmodified accentColor.
|
||||
*/
|
||||
private int ensureActivatedColorVisibleIfNecessary(int activatedColor) {
|
||||
// Not optimal, but much easier then computing the opaque deactivated color on the background color every time.
|
||||
int preBlendedDeactivatedIconColor = ThemeSingleton.get().darkTheme ? Color.argb(255, 188, 188, 188) : Color.argb(255, 115, 115, 115);
|
||||
if (ColorUtil.getColorDifference(activatedColor, preBlendedDeactivatedIconColor) <= 30d) {
|
||||
return ThemeSingleton.get().darkTheme ? Color.WHITE : Color.BLACK;
|
||||
}
|
||||
return activatedColor;
|
||||
}
|
||||
|
||||
private void updateMetaTexts() {
|
||||
final Song song = MusicPlayerRemote.getCurrentSong();
|
||||
songTitle.setText(song.title);
|
||||
songText.setText(song.artistName);
|
||||
}
|
||||
|
||||
private void animateColorChange(final int newColor) {
|
||||
if (colorTransitionAnimator != null && colorTransitionAnimator.isStarted()) {
|
||||
colorTransitionAnimator.cancel();
|
||||
}
|
||||
colorTransitionAnimator = new AnimatorSet();
|
||||
AnimatorSet.Builder animatorSetBuilder = colorTransitionAnimator.play(ViewUtil.createBackgroundColorTransition(footer, lastFooterColor, newColor));
|
||||
|
||||
int titleTextColor = ColorUtil.getPrimaryTextColorForBackground(activity, newColor);
|
||||
int captionTextColor = ColorUtil.getSecondaryTextColorForBackground(activity, newColor);
|
||||
|
||||
animatorSetBuilder.with(ViewUtil.createTextColorTransition(songTitle, lastTitleTextColor, titleTextColor));
|
||||
animatorSetBuilder.with(ViewUtil.createTextColorTransition(songText, lastCaptionTextColor, captionTextColor));
|
||||
|
||||
colorTransitionAnimator.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
if (newColor == ColorUtil.resolveColor(activity, R.attr.default_bar_color) && ThemeSingleton.get().darkTheme) {
|
||||
lastPlaybackControlsColor = Color.WHITE;
|
||||
} else {
|
||||
lastPlaybackControlsColor = newColor;
|
||||
}
|
||||
updateRepeatState();
|
||||
updateShuffleState();
|
||||
updatePlayPauseFabTint();
|
||||
}
|
||||
});
|
||||
|
||||
colorTransitionAnimator.start();
|
||||
|
||||
lastFooterColor = newColor;
|
||||
lastTitleTextColor = titleTextColor;
|
||||
lastCaptionTextColor = captionTextColor;
|
||||
}
|
||||
|
||||
public void showControls() {
|
||||
playPauseFab.animate()
|
||||
.scaleX(1f)
|
||||
|
|
@ -363,28 +269,38 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
.rotation(360f)
|
||||
.setInterpolator(new DecelerateInterpolator())
|
||||
.start();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (mediaControllerContainer.getVisibility() == View.INVISIBLE) {
|
||||
int cx = (playPauseFab.getLeft() + playPauseFab.getRight()) / 2;
|
||||
int cy = (playPauseFab.getTop() + playPauseFab.getBottom()) / 2;
|
||||
int finalRadius = Math.max(mediaControllerContainer.getWidth(), mediaControllerContainer.getHeight());
|
||||
|
||||
final Animator animator = ViewAnimationUtils.createCircularReveal(mediaControllerContainer, cx, cy, 0, finalRadius);
|
||||
animator.setInterpolator(new DecelerateInterpolator());
|
||||
animator.setDuration(FAB_CIRCULAR_REVEAL_ANIMATION_TIME);
|
||||
animator.start();
|
||||
mediaControllerContainer.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetShowControlsAnimation() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
mediaControllerContainer.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
playPauseFab.setScaleX(0f);
|
||||
playPauseFab.setScaleY(0f);
|
||||
playPauseFab.setRotation(0f);
|
||||
}
|
||||
|
||||
private void updateProgressSliderTint() {
|
||||
int color = ColorUtil.getPrimaryTextColor(getContext(), false);
|
||||
progressSlider.getThumb().mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
progressSlider.getProgressDrawable().mutate().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
private void setUpProgressSlider() {
|
||||
updateProgressSliderTint();
|
||||
progressSlider.setOnSeekBarChangeListener(new SimpleOnSeekbarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (fromUser) {
|
||||
MusicPlayerRemote.seekTo(progress);
|
||||
onUpdateProgressViews(MusicPlayerRemote.getSongProgressMillis(), MusicPlayerRemote.getSongDurationMillis());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateProgressViews(int progress, int total) {
|
||||
progressSlider.setMax(total);
|
||||
progressSlider.setProgress(progress);
|
||||
songTotalTime.setText(MusicUtil.getReadableDurationString(total));
|
||||
songCurrentProgress.setText(MusicUtil.getReadableDurationString(progress));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
|
@ -25,13 +24,10 @@ import com.kabouzeid.gramophone.util.ColorUtil;
|
|||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.kabouzeid.gramophone.views.SquareIfPlaceImageView;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.assist.LoadedFrom;
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
|
||||
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
||||
import com.nostra13.universalimageloader.core.process.BitmapProcessor;
|
||||
|
||||
|
|
@ -44,13 +40,9 @@ import butterknife.ButterKnife;
|
|||
public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@Bind(R.id.player_image)
|
||||
SquareIfPlaceImageView albumArt;
|
||||
ImageView albumCover;
|
||||
@Bind(R.id.player_favorite_icon)
|
||||
ImageView favoriteIcon;
|
||||
@Bind(R.id.player_album_art_frame)
|
||||
FrameLayout albumArtFrame;
|
||||
|
||||
private boolean forceSquareAlbumArt;
|
||||
|
||||
private AbsMusicServiceActivity activity;
|
||||
private OnColorChangedListener onColorChangedListener;
|
||||
|
|
@ -82,7 +74,7 @@ public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEv
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
albumArt.forceSquare(forceSquareAlbumArt);
|
||||
forceSquareAlbumCover(PreferenceUtil.getInstance(getContext()).forceSquareAlbumCover());
|
||||
|
||||
PreferenceUtil.getInstance(getContext()).registerOnSharedPreferenceChangedListener(this);
|
||||
activity.addMusicServiceEventListener(this);
|
||||
|
|
@ -124,9 +116,8 @@ public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEv
|
|||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
switch (key) {
|
||||
case PreferenceUtil.FORCE_SQUARE_ALBUM_ART:
|
||||
forceSquareAlbumArt = PreferenceUtil.getInstance(activity).forceAlbumArtSquared();
|
||||
albumArt.forceSquare(forceSquareAlbumArt);
|
||||
case PreferenceUtil.FORCE_SQUARE_ALBUM_COVER:
|
||||
forceSquareAlbumCover(PreferenceUtil.getInstance(activity).forceSquareAlbumCover());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -140,7 +131,7 @@ public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEv
|
|||
final ColorHolder colorHolder = new ColorHolder();
|
||||
ImageLoader.getInstance().displayImage(
|
||||
MusicUtil.getSongImageLoaderString(MusicPlayerRemote.getCurrentSong()),
|
||||
albumArt,
|
||||
albumCover,
|
||||
new DisplayImageOptions.Builder()
|
||||
.cacheInMemory(true)
|
||||
.showImageOnFail(R.drawable.default_album_art)
|
||||
|
|
@ -151,13 +142,7 @@ public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEv
|
|||
return bitmap;
|
||||
}
|
||||
})
|
||||
.displayer(new FadeInBitmapDisplayer(ViewUtil.DEFAULT_COLOR_ANIMATION_DURATION) {
|
||||
@Override
|
||||
public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
|
||||
super.display(bitmap, imageAware, loadedFrom);
|
||||
setColor(colorHolder.color);
|
||||
}
|
||||
})
|
||||
.displayer(new FadeInBitmapDisplayer(ViewUtil.DEFAULT_COLOR_ANIMATION_DURATION))
|
||||
.build(),
|
||||
new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
|
|
@ -170,7 +155,9 @@ public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEv
|
|||
public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
||||
if (loadedImage == null) {
|
||||
onLoadingFailed(imageUri, view, null);
|
||||
return;
|
||||
}
|
||||
setColor(colorHolder.color);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -211,6 +198,10 @@ public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEv
|
|||
.start();
|
||||
}
|
||||
|
||||
public void forceSquareAlbumCover(boolean forceSquareAlbumCover) {
|
||||
albumCover.setScaleType(forceSquareAlbumCover ? ImageView.ScaleType.FIT_CENTER : ImageView.ScaleType.CENTER_CROP);
|
||||
}
|
||||
|
||||
private void setColor(int color) {
|
||||
if (onColorChangedListener != null) onColorChangedListener.onColorChanged(color);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,8 +42,6 @@ import butterknife.ButterKnife;
|
|||
public class PlayerFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, MusicServiceEventListener, Toolbar.OnMenuItemClickListener, PaletteColorHolder, MusicProgressViewUpdateHelper.Callback, PlayerAlbumCoverFragment.OnColorChangedListener {
|
||||
public static final String TAG = PlayerFragment.class.getSimpleName();
|
||||
|
||||
@Bind(R.id.player_status_bar)
|
||||
View statusbar;
|
||||
@Bind(R.id.player_toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
|
|
@ -59,6 +57,7 @@ public class PlayerFragment extends Fragment implements SharedPreferences.OnShar
|
|||
private Callbacks callbacks;
|
||||
|
||||
private PlaybackControlsFragment playbackControlsFragment;
|
||||
private PlayingInfoFragment playingInfoFragment;
|
||||
private PlayerAlbumCoverFragment playerAlbumCoverFragment;
|
||||
|
||||
@Override
|
||||
|
|
@ -97,6 +96,7 @@ public class PlayerFragment extends Fragment implements SharedPreferences.OnShar
|
|||
ButterKnife.bind(this, view);
|
||||
|
||||
playbackControlsFragment = (PlaybackControlsFragment) getChildFragmentManager().findFragmentById(R.id.playback_controls_fragment);
|
||||
playingInfoFragment = (PlayingInfoFragment) getChildFragmentManager().findFragmentById(R.id.playing_info_fragment);
|
||||
playerAlbumCoverFragment = (PlayerAlbumCoverFragment) getChildFragmentManager().findFragmentById(R.id.player_album_cover_fragment);
|
||||
playerAlbumCoverFragment.setOnColorChangedListener(this);
|
||||
|
||||
|
|
@ -340,46 +340,7 @@ public class PlayerFragment extends Fragment implements SharedPreferences.OnShar
|
|||
}
|
||||
|
||||
private void animateColorChange(final int newColor) {
|
||||
// if (colorTransitionAnimator != null && colorTransitionAnimator.isStarted()) {
|
||||
// colorTransitionAnimator.cancel();
|
||||
// }
|
||||
// colorTransitionAnimator = new AnimatorSet();
|
||||
// AnimatorSet.Builder animatorSetBuilder = colorTransitionAnimator.play(ViewUtil.createBackgroundColorTransition(footer, lastColor, newColor));
|
||||
//
|
||||
// if (opaqueToolBar) {
|
||||
// animatorSetBuilder.with(ViewUtil.createBackgroundColorTransition(toolbar, lastColor, newColor));
|
||||
// ViewUtil.setToolbarContentColorForBackground(activity, toolbar, newColor);
|
||||
// } else {
|
||||
// toolbar.setBackgroundColor(Color.TRANSPARENT);
|
||||
// ViewUtil.setToolbarContentDark(activity, toolbar, false);
|
||||
// }
|
||||
//
|
||||
// if (opaqueStatusBar) {
|
||||
// int newStatusbarColor = newColor;
|
||||
// int oldStatusbarColor = lastColor;
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
// newStatusbarColor = ColorUtil.shiftColorDown(newStatusbarColor);
|
||||
// oldStatusbarColor = ColorUtil.shiftColorDown(oldStatusbarColor);
|
||||
// }
|
||||
// animatorSetBuilder.with(ViewUtil.createBackgroundColorTransition(statusbar, oldStatusbarColor, newStatusbarColor));
|
||||
// } else {
|
||||
// statusbar.setBackgroundColor(Color.TRANSPARENT);
|
||||
// }
|
||||
//
|
||||
// colorTransitionAnimator.addListener(new SimpleAnimatorListener() {
|
||||
// @Override
|
||||
// public void onAnimationStart(Animator animation) {
|
||||
// if (newColor == ColorUtil.resolveColor(activity, R.attr.default_bar_color) && ThemeSingleton.get().darkTheme) {
|
||||
// lastPlaybackControlsColor = Color.WHITE;
|
||||
// } else {
|
||||
// lastPlaybackControlsColor = newColor;
|
||||
// }
|
||||
// updateProgressSliderTint();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// colorTransitionAnimator.start();
|
||||
|
||||
getView().setBackgroundColor(newColor);
|
||||
lastColor = newColor;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class PlayingInfoFragment extends Fragment implements MusicServiceEventListener {
|
||||
|
||||
|
||||
private AbsMusicServiceActivity activity;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
try {
|
||||
activity = (AbsMusicServiceActivity) context;
|
||||
} catch (ClassCastException e) {
|
||||
throw new RuntimeException(context.getClass().getSimpleName() + " must be an instance of " + AbsMusicServiceActivity.class.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
activity = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_playing_info, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ButterKnife.bind(this, view);
|
||||
activity.addMusicServiceEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
activity.removeMusicServiceEventListener(this);
|
||||
ButterKnife.unbind(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayingMetaChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRepeatModeChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShuffleModeChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaStoreChanged() {
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue