Improve toolbar scrim

This commit is contained in:
Eugene Cheung 2017-09-09 16:50:59 -04:00
commit 0f6aab7f2c
No known key found for this signature in database
GPG key ID: E1FD745328866B0A
12 changed files with 96 additions and 28 deletions

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent;
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;
@ -24,10 +25,12 @@ public abstract class AbsPlayerFragment extends AbsMusicServiceFragment implemen
public static final String TAG = AbsPlayerFragment.class.getSimpleName();
private Callbacks callbacks;
private boolean isToolbarVisible;
@Override
public void onAttach(Context context) {
super.onAttach(context);
isToolbarVisible = true;
try {
callbacks = (Callbacks) context;
} catch (ClassCastException e) {
@ -88,6 +91,23 @@ public abstract class AbsPlayerFragment extends AbsMusicServiceFragment implemen
MusicUtil.toggleFavorite(getActivity(), song);
}
protected void toggleToolbar(final View toolbar) {
if (toolbar == null) return;
isToolbarVisible = !isToolbarVisible;
if (isToolbarVisible) {
toolbar.setVisibility(View.VISIBLE);
toolbar.animate().alpha(1f).setDuration(PlayerAlbumCoverFragment.VISIBILITY_ANIM_DURATION);
} else {
toolbar.animate().alpha(0f).setDuration(PlayerAlbumCoverFragment.VISIBILITY_ANIM_DURATION).withEndAction(new Runnable() {
@Override
public void run() {
toolbar.setVisibility(View.GONE);
}
});
}
}
protected String getUpNextAndQueueTime() {
return getResources().getString(R.string.up_next) + "" + MusicUtil.getReadableDurationString(MusicPlayerRemote.getQueueDurationMillis(MusicPlayerRemote.getPosition()));
}

View file

@ -35,7 +35,7 @@ import butterknife.Unbinder;
public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements ViewPager.OnPageChangeListener, MusicProgressViewUpdateHelper.Callback {
public static final String TAG = PlayerAlbumCoverFragment.class.getSimpleName();
public static final int LYRICS_ANIM_DURATION = 300;
public static final int VISIBILITY_ANIM_DURATION = 300;
private Unbinder unbinder;
@ -71,6 +71,15 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
viewPager.addOnPageChangeListener(this);
viewPager.setOnTouchListener(new View.OnTouchListener() {
GestureDetector gestureDetector = new GestureDetector(getActivity(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if (callbacks != null) {
callbacks.onToolbarToggled();
return true;
}
return super.onSingleTapConfirmed(e);
}
@Override
public boolean onDoubleTap(MotionEvent e) {
if (callbacks != null) {
@ -121,7 +130,6 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
@ -144,7 +152,6 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
@Override
public void onPageScrollStateChanged(int state) {
}
public void showHeartAnimation() {
@ -193,7 +200,7 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
}
private void hideLyricsLayout() {
lyricsLayout.animate().alpha(0f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION).withEndAction(new Runnable() {
lyricsLayout.animate().alpha(0f).setDuration(PlayerAlbumCoverFragment.VISIBILITY_ANIM_DURATION).withEndAction(new Runnable() {
@Override
public void run() {
if (!isLyricsLayoutBound()) return;
@ -218,7 +225,7 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
lyricsLine2.setText(null);
lyricsLayout.setVisibility(View.VISIBLE);
lyricsLayout.animate().alpha(1f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION);
lyricsLayout.animate().alpha(1f).setDuration(PlayerAlbumCoverFragment.VISIBILITY_ANIM_DURATION);
}
private void notifyColorChange(int color) {
@ -259,11 +266,11 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
lyricsLine1.setAlpha(1f);
lyricsLine1.setTranslationY(0f);
lyricsLine1.animate().alpha(0f).translationY(-h).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION);
lyricsLine1.animate().alpha(0f).translationY(-h).setDuration(PlayerAlbumCoverFragment.VISIBILITY_ANIM_DURATION);
lyricsLine2.setAlpha(0f);
lyricsLine2.setTranslationY(h);
lyricsLine2.animate().alpha(1f).translationY(0f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION);
lyricsLine2.animate().alpha(1f).translationY(0f).setDuration(PlayerAlbumCoverFragment.VISIBILITY_ANIM_DURATION);
}
}
@ -271,5 +278,7 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
void onColorChanged(int color);
void onFavoriteToggled();
void onToolbarToggled();
}
}

View file

@ -10,6 +10,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
@ -23,6 +24,7 @@ import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@ -61,6 +63,9 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
private Unbinder unbinder;
@Nullable
@BindView(R.id.toolbar_container)
FrameLayout toolbarContainer;
@BindView(R.id.player_toolbar)
Toolbar toolbar;
@BindView(R.id.player_sliding_layout)
@ -267,7 +272,6 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
layoutManager.scrollToPositionWithOffset(MusicPlayerRemote.getPosition() + 1, 0);
}
private void updateIsFavorite() {
if (updateIsFavoriteTask != null) updateIsFavoriteTask.cancel(false);
updateIsFavoriteTask = new AsyncTask<Song, Void, Boolean>() {
@ -403,6 +407,11 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
toggleFavorite(MusicPlayerRemote.getCurrentSong());
}
@Override
public void onToolbarToggled() {
toggleToolbar(toolbarContainer);
}
@Override
public void onPanelSlide(View view, float slide) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

View file

@ -21,6 +21,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@ -61,6 +62,9 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
@BindView(R.id.player_status_bar)
View playerStatusBar;
@Nullable
@BindView(R.id.toolbar_container)
FrameLayout toolbarContainer;
@BindView(R.id.player_toolbar)
Toolbar toolbar;
@Nullable
@ -263,7 +267,6 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
layoutManager.scrollToPositionWithOffset(MusicPlayerRemote.getPosition() + 1, 0);
}
private void updateIsFavorite() {
if (updateIsFavoriteTask != null) updateIsFavoriteTask.cancel(false);
updateIsFavoriteTask = new AsyncTask<Song, Void, Boolean>() {
@ -399,6 +402,11 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
toggleFavorite(MusicPlayerRemote.getCurrentSong());
}
@Override
public void onToolbarToggled() {
toggleToolbar(toolbarContainer);
}
@Override
public void onPanelSlide(View view, float slide) {
}