WIP added album cover view pager
This commit is contained in:
parent
b1b1aa093d
commit
50035ef8e6
7 changed files with 355 additions and 238 deletions
|
|
@ -0,0 +1,196 @@
|
|||
package com.kabouzeid.gramophone.adapter;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.misc.SimpleAnimatorListener;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
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.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
||||
import com.nostra13.universalimageloader.core.process.BitmapProcessor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class AlbumCoverPagerAdapter extends FragmentStatePagerAdapter {
|
||||
public static final String TAG = AlbumCoverPagerAdapter.class.getSimpleName();
|
||||
|
||||
private ArrayList<Song> dataSet;
|
||||
|
||||
public AlbumCoverPagerAdapter(FragmentManager fm, ArrayList<Song> dataSet) {
|
||||
super(fm);
|
||||
this.dataSet = dataSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(final int position) {
|
||||
return AlbumCoverFragment.newInstance(dataSet.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return dataSet.size();
|
||||
}
|
||||
|
||||
public static class AlbumCoverFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final String SONG_ARG = "song";
|
||||
|
||||
@Bind(R.id.player_image)
|
||||
ImageView albumCover;
|
||||
@Bind(R.id.player_favorite_icon)
|
||||
ImageView favoriteIcon;
|
||||
|
||||
private int color;
|
||||
private Song song;
|
||||
|
||||
public static AlbumCoverFragment newInstance(final Song song) {
|
||||
AlbumCoverFragment frag = new AlbumCoverFragment();
|
||||
final Bundle args = new Bundle();
|
||||
args.putSerializable(SONG_ARG, song);
|
||||
frag.setArguments(args);
|
||||
return frag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
song = (Song) getArguments().getSerializable(SONG_ARG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_album_cover, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
forceSquareAlbumCover(PreferenceUtil.getInstance(getContext()).forceSquareAlbumCover());
|
||||
PreferenceUtil.getInstance(getActivity()).registerOnSharedPreferenceChangedListener(this);
|
||||
loadAlbumCover();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
PreferenceUtil.getInstance(getActivity()).unregisterOnSharedPreferenceChangedListener(this);
|
||||
ButterKnife.unbind(this);
|
||||
}
|
||||
|
||||
private void loadAlbumCover() {
|
||||
ImageLoader.getInstance().displayImage(
|
||||
MusicUtil.getSongImageLoaderString(song),
|
||||
albumCover,
|
||||
new DisplayImageOptions.Builder()
|
||||
.cacheInMemory(true)
|
||||
.showImageOnFail(R.drawable.default_album_art)
|
||||
.postProcessor(new BitmapProcessor() {
|
||||
@Override
|
||||
public Bitmap process(Bitmap bitmap) {
|
||||
color = ColorUtil.generateColor(getActivity(), bitmap);
|
||||
return bitmap;
|
||||
}
|
||||
})
|
||||
.build(),
|
||||
new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, @Nullable FailReason failReason) {
|
||||
color = ColorUtil.resolveColor(getActivity(), R.attr.default_bar_color);
|
||||
notifyColorIsReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
||||
if (loadedImage == null) {
|
||||
onLoadingFailed(imageUri, view, null);
|
||||
return;
|
||||
}
|
||||
notifyColorIsReady();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void showHeartAnimation() {
|
||||
favoriteIcon.clearAnimation();
|
||||
|
||||
favoriteIcon.setAlpha(0f);
|
||||
favoriteIcon.setScaleX(0f);
|
||||
favoriteIcon.setScaleY(0f);
|
||||
favoriteIcon.setVisibility(View.VISIBLE);
|
||||
favoriteIcon.setPivotX(favoriteIcon.getWidth() / 2);
|
||||
favoriteIcon.setPivotY(favoriteIcon.getHeight() / 2);
|
||||
|
||||
favoriteIcon.animate()
|
||||
.setDuration(ViewUtil.PHONOGRAPH_ANIM_TIME / 2)
|
||||
.setInterpolator(new DecelerateInterpolator())
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.alpha(1f)
|
||||
.setListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
favoriteIcon.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
})
|
||||
.withEndAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
favoriteIcon.animate()
|
||||
.setDuration(ViewUtil.PHONOGRAPH_ANIM_TIME / 2)
|
||||
.setInterpolator(new AccelerateInterpolator())
|
||||
.scaleX(0f)
|
||||
.scaleY(0f)
|
||||
.alpha(0f)
|
||||
.start();
|
||||
}
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
switch (key) {
|
||||
case PreferenceUtil.FORCE_SQUARE_ALBUM_COVER:
|
||||
forceSquareAlbumCover(PreferenceUtil.getInstance(getActivity()).forceSquareAlbumCover());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void forceSquareAlbumCover(boolean forceSquareAlbumCover) {
|
||||
albumCover.setScaleType(forceSquareAlbumCover ? ImageView.ScaleType.FIT_CENTER : ImageView.ScaleType.CENTER_CROP);
|
||||
}
|
||||
|
||||
private void notifyColorIsReady() {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.View;
|
||||
|
||||
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class AbsMusicServiceFragment 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 void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
activity.addMusicServiceEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
activity.removeMusicServiceEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayingMetaChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRepeatModeChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShuffleModeChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaStoreChanged() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -2,11 +2,8 @@ package com.kabouzeid.gramophone.ui.fragments.player;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
|
|
@ -14,82 +11,36 @@ import com.kabouzeid.gramophone.dialogs.SleepTimerDialog;
|
|||
import com.kabouzeid.gramophone.dialogs.SongDetailDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.SongShareDialog;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
||||
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
|
||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
|
||||
import com.kabouzeid.gramophone.ui.activities.tageditor.AbsTagEditorActivity;
|
||||
import com.kabouzeid.gramophone.ui.activities.tageditor.SongTagEditorActivity;
|
||||
import com.kabouzeid.gramophone.ui.fragments.AbsMusicServiceFragment;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
|
||||
public abstract class AbsPlayerFragment extends Fragment implements MusicServiceEventListener, Toolbar.OnMenuItemClickListener, PaletteColorHolder {
|
||||
public abstract class AbsPlayerFragment extends AbsMusicServiceFragment implements Toolbar.OnMenuItemClickListener, PaletteColorHolder {
|
||||
public static final String TAG = AbsPlayerFragment.class.getSimpleName();
|
||||
|
||||
protected AbsMusicServiceActivity activity;
|
||||
protected Callbacks callbacks;
|
||||
private Callbacks callbacks;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
try {
|
||||
activity = (AbsMusicServiceActivity) context;
|
||||
callbacks = (Callbacks) context;
|
||||
} catch (ClassCastException e) {
|
||||
throw new RuntimeException(context.getClass().getSimpleName() + " must be an instance of " + AbsMusicServiceActivity.class.getSimpleName() + " and implement " + Callbacks.class.getSimpleName());
|
||||
throw new RuntimeException(context.getClass().getSimpleName() + " must implement " + Callbacks.class.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
activity = null;
|
||||
callbacks = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(final View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
activity.addMusicServiceEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
activity.removeMusicServiceEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayingMetaChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRepeatModeChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShuffleModeChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaStoreChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
final Song song = MusicPlayerRemote.getCurrentSong();
|
||||
|
|
@ -98,16 +49,16 @@ public abstract class AbsPlayerFragment extends Fragment implements MusicService
|
|||
new SleepTimerDialog().show(getFragmentManager(), "SET_SLEEP_TIMER");
|
||||
return true;
|
||||
case R.id.action_toggle_favorite:
|
||||
MusicUtil.toggleFavorite(activity, song);
|
||||
MusicUtil.toggleFavorite(getActivity(), song);
|
||||
return true;
|
||||
case R.id.action_share:
|
||||
SongShareDialog.create(song).show(getFragmentManager(), "SHARE_SONG");
|
||||
return true;
|
||||
case R.id.action_equalizer:
|
||||
NavigationUtil.openEqualizer(activity);
|
||||
NavigationUtil.openEqualizer(getActivity());
|
||||
return true;
|
||||
case R.id.action_shuffle_all:
|
||||
MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(activity), true);
|
||||
MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(getActivity()), true);
|
||||
return true;
|
||||
case R.id.action_add_to_playlist:
|
||||
AddToPlaylistDialog.create(song).show(getFragmentManager(), "ADD_PLAYLIST");
|
||||
|
|
@ -115,7 +66,7 @@ public abstract class AbsPlayerFragment extends Fragment implements MusicService
|
|||
// case R.id.action_playing_queue:
|
||||
// return true;
|
||||
case R.id.action_tag_editor:
|
||||
Intent intent = new Intent(activity, SongTagEditorActivity.class);
|
||||
Intent intent = new Intent(getActivity(), SongTagEditorActivity.class);
|
||||
intent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
|
|
@ -123,10 +74,10 @@ public abstract class AbsPlayerFragment extends Fragment implements MusicService
|
|||
SongDetailDialog.create(song).show(getFragmentManager(), "SONG_DETAIL");
|
||||
return true;
|
||||
case R.id.action_go_to_album:
|
||||
NavigationUtil.goToAlbum(activity, song.albumId);
|
||||
NavigationUtil.goToAlbum(getActivity(), song.albumId);
|
||||
return true;
|
||||
case R.id.action_go_to_artist:
|
||||
NavigationUtil.goToArtist(activity, song.artistId);
|
||||
NavigationUtil.goToArtist(getActivity(), song.artistId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -138,6 +89,10 @@ public abstract class AbsPlayerFragment extends Fragment implements MusicService
|
|||
|
||||
public abstract boolean onBackPressed();
|
||||
|
||||
public Callbacks getCallbacks() {
|
||||
return callbacks;
|
||||
}
|
||||
|
||||
public interface Callbacks {
|
||||
void onPaletteColorChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,16 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments.player;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.AlbumCoverPagerAdapter;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
||||
import com.kabouzeid.gramophone.misc.SimpleAnimatorListener;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
|
||||
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.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
||||
import com.nostra13.universalimageloader.core.process.BitmapProcessor;
|
||||
import com.kabouzeid.gramophone.ui.fragments.AbsMusicServiceFragment;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
|
@ -37,180 +18,76 @@ import butterknife.ButterKnife;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements ViewPager.OnPageChangeListener {
|
||||
|
||||
@Bind(R.id.player_image)
|
||||
ImageView albumCover;
|
||||
@Bind(R.id.player_favorite_icon)
|
||||
ImageView favoriteIcon;
|
||||
@Bind(R.id.player_album_cover_viewpager)
|
||||
ViewPager viewPager;
|
||||
|
||||
private AbsMusicServiceActivity activity;
|
||||
private AlbumCoverPagerAdapter pagerAdapter;
|
||||
private OnColorChangedListener onColorChangedListener;
|
||||
|
||||
@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_player_album_cover, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_player_album_cover, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
forceSquareAlbumCover(PreferenceUtil.getInstance(getContext()).forceSquareAlbumCover());
|
||||
|
||||
PreferenceUtil.getInstance(getContext()).registerOnSharedPreferenceChangedListener(this);
|
||||
activity.addMusicServiceEventListener(this);
|
||||
viewPager.setOffscreenPageLimit(2);
|
||||
updatePlayingQueue();
|
||||
viewPager.addOnPageChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
activity.removeMusicServiceEventListener(this);
|
||||
PreferenceUtil.getInstance(activity).unregisterOnSharedPreferenceChangedListener(this);
|
||||
viewPager.removeOnPageChangeListener(this);
|
||||
ButterKnife.unbind(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayingMetaChanged() {
|
||||
loadAlbumCover();
|
||||
viewPager.setCurrentItem(MusicPlayerRemote.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged() {
|
||||
updatePlayingQueue();
|
||||
}
|
||||
|
||||
private void updatePlayingQueue() {
|
||||
viewPager.setAdapter(new AlbumCoverPagerAdapter(getFragmentManager(), MusicPlayerRemote.getPlayingQueue()));
|
||||
viewPager.setCurrentItem(MusicPlayerRemote.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRepeatModeChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShuffleModeChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaStoreChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
switch (key) {
|
||||
case PreferenceUtil.FORCE_SQUARE_ALBUM_COVER:
|
||||
forceSquareAlbumCover(PreferenceUtil.getInstance(activity).forceSquareAlbumCover());
|
||||
break;
|
||||
public void onPageSelected(int position) {
|
||||
if (position != MusicPlayerRemote.getPosition()) {
|
||||
MusicPlayerRemote.playSongAt(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
|
||||
private static class ColorHolder {
|
||||
@ColorInt
|
||||
public int color;
|
||||
}
|
||||
|
||||
private void loadAlbumCover() {
|
||||
final ColorHolder colorHolder = new ColorHolder();
|
||||
ImageLoader.getInstance().displayImage(
|
||||
MusicUtil.getSongImageLoaderString(MusicPlayerRemote.getCurrentSong()),
|
||||
albumCover,
|
||||
new DisplayImageOptions.Builder()
|
||||
.cacheInMemory(true)
|
||||
.showImageOnFail(R.drawable.default_album_art)
|
||||
.postProcessor(new BitmapProcessor() {
|
||||
@Override
|
||||
public Bitmap process(Bitmap bitmap) {
|
||||
colorHolder.color = ColorUtil.generateColor(activity, bitmap);
|
||||
return bitmap;
|
||||
}
|
||||
})
|
||||
.displayer(new FadeInBitmapDisplayer(ViewUtil.PHONOGRAPH_ANIM_TIME))
|
||||
.build(),
|
||||
new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, @Nullable FailReason failReason) {
|
||||
FadeInBitmapDisplayer.animate(view, ViewUtil.PHONOGRAPH_ANIM_TIME);
|
||||
setColor(ColorUtil.resolveColor(activity, R.attr.default_bar_color));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
||||
if (loadedImage == null) {
|
||||
onLoadingFailed(imageUri, view, null);
|
||||
return;
|
||||
}
|
||||
setColor(colorHolder.color);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void showHeartAnimation() {
|
||||
favoriteIcon.clearAnimation();
|
||||
|
||||
favoriteIcon.setAlpha(0f);
|
||||
favoriteIcon.setScaleX(0f);
|
||||
favoriteIcon.setScaleY(0f);
|
||||
favoriteIcon.setVisibility(View.VISIBLE);
|
||||
favoriteIcon.setPivotX(favoriteIcon.getWidth() / 2);
|
||||
favoriteIcon.setPivotY(favoriteIcon.getHeight() / 2);
|
||||
|
||||
favoriteIcon.animate()
|
||||
.setDuration(ViewUtil.PHONOGRAPH_ANIM_TIME / 2)
|
||||
.setInterpolator(new DecelerateInterpolator())
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.alpha(1f)
|
||||
.setListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
favoriteIcon.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
})
|
||||
.withEndAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
favoriteIcon.animate()
|
||||
.setDuration(ViewUtil.PHONOGRAPH_ANIM_TIME / 2)
|
||||
.setInterpolator(new AccelerateInterpolator())
|
||||
.scaleX(0f)
|
||||
.scaleY(0f)
|
||||
.alpha(0f)
|
||||
.start();
|
||||
}
|
||||
})
|
||||
.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);
|
||||
}
|
||||
|
||||
public void setOnColorChangedListener(OnColorChangedListener listener) {
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
public void onPlayingMetaChanged() {
|
||||
updateIsFavorite();
|
||||
updateCurrentSong();
|
||||
updateQueue();
|
||||
updateQueuePosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -139,6 +139,13 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
}
|
||||
}
|
||||
|
||||
private void updateQueuePosition() {
|
||||
playingQueueAdapter.setCurrent(MusicPlayerRemote.getPosition());
|
||||
if (slidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
|
||||
resetToCurrentPosition();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private void updateCurrentSong() {
|
||||
Song song = MusicPlayerRemote.getCurrentSong();
|
||||
|
|
@ -156,7 +163,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
albumCoverContainer.forceSquare(false);
|
||||
}
|
||||
slidingUpPanelLayout.setPanelHeight(Math.max(minPanelHeight, availablePanelHeight));
|
||||
((AbsSlidingMusicPanelActivity) activity).setAntiDragView(slidingUpPanelLayout.findViewById(R.id.player_panel));
|
||||
((AbsSlidingMusicPanelActivity) getActivity()).setAntiDragView(slidingUpPanelLayout.findViewById(R.id.player_panel));
|
||||
}
|
||||
|
||||
private void setUpSubFragments() {
|
||||
|
|
@ -172,7 +179,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
activity.onBackPressed();
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
});
|
||||
toolbar.setOnMenuItemClickListener(this);
|
||||
|
|
@ -185,12 +192,12 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
currentSongViewHolder.separator.setVisibility(View.VISIBLE);
|
||||
currentSongViewHolder.shortSeparator.setVisibility(View.GONE);
|
||||
currentSongViewHolder.image.setScaleType(ImageView.ScaleType.CENTER);
|
||||
currentSongViewHolder.image.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_volume_up_white_24dp, ColorUtil.resolveColor(activity, R.attr.icon_color)));
|
||||
currentSongViewHolder.image.setImageDrawable(Util.getTintedDrawable(getActivity(), R.drawable.ic_volume_up_white_24dp, ColorUtil.resolveColor(getActivity(), R.attr.icon_color)));
|
||||
}
|
||||
|
||||
private void updateIsFavorite() {
|
||||
boolean isFavorite = MusicUtil.isFavorite(activity, MusicPlayerRemote.getCurrentSong());
|
||||
Drawable favoriteIcon = Util.getTintedDrawable(activity, isFavorite ? R.drawable.ic_favorite_white_24dp : R.drawable.ic_favorite_outline_white_24dp, ViewUtil.getToolbarIconColor(activity, false));
|
||||
boolean isFavorite = MusicUtil.isFavorite(getActivity(), MusicPlayerRemote.getCurrentSong());
|
||||
Drawable favoriteIcon = Util.getTintedDrawable(getActivity(), isFavorite ? R.drawable.ic_favorite_white_24dp : R.drawable.ic_favorite_outline_white_24dp, ViewUtil.getToolbarIconColor(getActivity(), false));
|
||||
toolbar.getMenu().findItem(R.id.action_toggle_favorite)
|
||||
.setIcon(favoriteIcon)
|
||||
.setTitle(isFavorite ? getString(R.string.action_remove_from_favorites) : getString(R.string.action_add_to_favorites));
|
||||
|
|
@ -250,7 +257,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
switch (item.getItemId()) {
|
||||
case R.id.action_toggle_favorite:
|
||||
super.onMenuItemClick(item);
|
||||
if (MusicUtil.isFavorite(activity, song)) {
|
||||
if (MusicUtil.isFavorite(getActivity(), song)) {
|
||||
playerAlbumCoverFragment.showHeartAnimation();
|
||||
}
|
||||
updateIsFavorite();
|
||||
|
|
@ -282,7 +289,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
public void onColorChanged(int color) {
|
||||
animateColorChange(color);
|
||||
playbackControlsFragment.setColor(color);
|
||||
callbacks.onPaletteColorChanged();
|
||||
getCallbacks().onPaletteColorChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
26
app/src/main/res/layout/fragment_album_cover.xml
Normal file
26
app/src/main/res/layout/fragment_album_cover.xml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout android:id="@+id/player_album_art_frame"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/transparent">
|
||||
|
||||
<com.kabouzeid.gramophone.views.WidthFitSquareImageView
|
||||
android:id="@+id/player_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
tools:ignore="ContentDescription,UnusedAttribute" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/player_favorite_icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:padding="72dp"
|
||||
android:src="@drawable/ic_favorite_red_a400_96dp"
|
||||
android:visibility="invisible"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
</FrameLayout>
|
||||
|
|
@ -1,28 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/player_album_art_frame"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_above="@id/player_footer_frame"
|
||||
android:background="@android:color/black">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.kabouzeid.gramophone.views.WidthFitSquareImageView
|
||||
android:id="@+id/player_image"
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/player_album_cover_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
tools:ignore="ContentDescription,UnusedAttribute" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/player_favorite_icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:padding="72dp"
|
||||
android:src="@drawable/ic_favorite_red_a400_96dp"
|
||||
android:visibility="invisible"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
android:layout_height="match_parent" />
|
||||
</FrameLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue