Updated deprecated palette methods and fixed a small bug in artist and album detail activity

This commit is contained in:
Karim Abou Zeid 2015-04-22 13:22:40 +02:00
commit 82c7128ea8
7 changed files with 98 additions and 88 deletions

View file

@ -138,19 +138,20 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
}
private void applyPalette(Bitmap bitmap, final TextView title, final TextView artist, final View footer) {
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
if (vibrantSwatch != null) {
title.setTextColor(vibrantSwatch.getTitleTextColor());
artist.setTextColor(vibrantSwatch.getTitleTextColor());
ViewUtil.animateViewColor(footer, DialogUtils.resolveColor(activity, R.attr.default_bar_color), vibrantSwatch.getRgb());
} else {
paletteBlackAndWhite(title, artist, footer);
}
}
});
Palette.from(bitmap)
.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
if (vibrantSwatch != null) {
title.setTextColor(vibrantSwatch.getTitleTextColor());
artist.setTextColor(vibrantSwatch.getTitleTextColor());
ViewUtil.animateViewColor(footer, DialogUtils.resolveColor(activity, R.attr.default_bar_color), vibrantSwatch.getRgb());
} else {
paletteBlackAndWhite(title, artist, footer);
}
}
});
}
private void paletteBlackAndWhite(final TextView title, final TextView artist, final View footer) {

View file

@ -197,23 +197,24 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
}
private void applyPalette(Bitmap bitmap) {
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
Palette.Swatch swatch = palette.getVibrantSwatch();
if (swatch != null) {
toolbarColor = swatch.getRgb();
albumTitleView.setBackgroundColor(toolbarColor);
albumTitleView.setTextColor(swatch.getTitleTextColor());
if (Util.hasLollipopSDK() && PreferenceUtils.getInstance(AlbumDetailActivity.this).coloredNavigationBarAlbumEnabled())
getWindow().setNavigationBarColor(toolbarColor);
notifyTaskColorChange(toolbarColor);
} else {
resetColors();
}
}
});
Palette.from(bitmap)
.generate(new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
if (vibrantSwatch != null) {
toolbarColor = vibrantSwatch.getRgb();
albumTitleView.setBackgroundColor(toolbarColor);
albumTitleView.setTextColor(vibrantSwatch.getTitleTextColor());
if (Util.hasLollipopSDK() && PreferenceUtils.getInstance(AlbumDetailActivity.this).coloredNavigationBarAlbumEnabled())
getWindow().setNavigationBarColor(toolbarColor);
notifyTaskColorChange(toolbarColor);
} else {
resetColors();
}
}
});
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)

View file

@ -292,23 +292,24 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
}
private void applyPalette(Bitmap bitmap) {
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
Palette.Swatch swatch = palette.getVibrantSwatch();
if (swatch != null) {
toolbarColor = swatch.getRgb();
artistNameTv.setBackgroundColor(swatch.getRgb());
artistNameTv.setTextColor(swatch.getTitleTextColor());
if (Util.hasLollipopSDK() && PreferenceUtils.getInstance(ArtistDetailActivity.this).coloredNavigationBarArtistEnabled())
getWindow().setNavigationBarColor(swatch.getRgb());
notifyTaskColorChange(toolbarColor);
} else {
resetColors();
}
}
});
Palette.from(bitmap)
.generate(new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
if (vibrantSwatch != null) {
toolbarColor = vibrantSwatch.getRgb();
artistNameTv.setBackgroundColor(vibrantSwatch.getRgb());
artistNameTv.setTextColor(vibrantSwatch.getTitleTextColor());
if (Util.hasLollipopSDK() && PreferenceUtils.getInstance(ArtistDetailActivity.this).coloredNavigationBarArtistEnabled())
getWindow().setNavigationBarColor(vibrantSwatch.getRgb());
notifyTaskColorChange(toolbarColor);
} else {
resetColors();
}
}
});
}
@Override

View file

@ -320,21 +320,22 @@ public class MusicControllerActivity extends AbsFabActivity {
}
private void applyPalette(Bitmap bitmap) {
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
Palette.Swatch swatch = palette.getVibrantSwatch();
if (swatch != null) {
final int swatchRgb = swatch.getRgb();
animateColorChange(swatchRgb);
songTitle.setTextColor(swatch.getTitleTextColor());
songArtist.setTextColor(swatch.getBodyTextColor());
notifyTaskColorChange(swatchRgb);
} else {
resetColors();
}
}
});
Palette.from(bitmap)
.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
if (vibrantSwatch != null) {
final int swatchRgb = vibrantSwatch.getRgb();
animateColorChange(swatchRgb);
songTitle.setTextColor(vibrantSwatch.getTitleTextColor());
songArtist.setTextColor(vibrantSwatch.getBodyTextColor());
notifyTaskColorChange(swatchRgb);
} else {
resetColors();
}
}
});
}
private void resetColors() {

View file

@ -132,7 +132,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
}
private void setUpViews() {
restoreStandardColors();
resetColors();
setUpScrollView();
setUpFab();
setUpImageView();
@ -208,7 +208,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
protected abstract void save();
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void restoreStandardColors() {
private void resetColors() {
final int primaryColor = PreferenceUtils.getInstance(this).getThemeColorPrimary();
paletteColorPrimary = primaryColor;
observableScrollViewCallbacks.onScrollChanged(scrollView.getCurrentScrollY(), false, false);
@ -293,27 +293,31 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
if (bitmap != null) {
image.setImageBitmap(bitmap);
applyPalette(bitmap);
} else {
resetColors();
}
}
private void applyPalette(final Bitmap bitmap) {
if (bitmap != null) {
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
final int vibrantColor = palette.getVibrantColor(DialogUtils.resolveColor(AbsTagEditorActivity.this, R.attr.default_bar_color));
paletteColorPrimary = vibrantColor;
observableScrollViewCallbacks.onScrollChanged(scrollView.getCurrentScrollY(), false, false);
setStatusBarColor(ColorChooserDialog.shiftColorDown(vibrantColor), false);
if (Util.hasLollipopSDK() && PreferenceUtils.getInstance(AbsTagEditorActivity.this).coloredNavigationBarTagEditorEnabled())
getWindow().setNavigationBarColor(vibrantColor);
notifyTaskColorChange(vibrantColor);
}
});
} else {
restoreStandardColors();
}
Palette.from(bitmap)
.generate(new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
if (vibrantSwatch != null) {
final int vibrantColor = palette.getVibrantColor(DialogUtils.resolveColor(AbsTagEditorActivity.this, R.attr.default_bar_color));
paletteColorPrimary = vibrantColor;
observableScrollViewCallbacks.onScrollChanged(scrollView.getCurrentScrollY(), false, false);
setStatusBarColor(ColorChooserDialog.shiftColorDown(vibrantColor), false);
if (Util.hasLollipopSDK() && PreferenceUtils.getInstance(AbsTagEditorActivity.this).coloredNavigationBarTagEditorEnabled())
getWindow().setNavigationBarColor(vibrantColor);
notifyTaskColorChange(vibrantColor);
} else {
resetColors();
}
}
});
}
@Override

View file

@ -1,7 +1,7 @@
<FrameLayout 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">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/album_art"
@ -38,6 +38,8 @@
android:layout_height="@dimen/title_view_height"
android:height="@dimen/title_view_height"
android:background="?default_bar_color"
android:clickable="true"
android:elevation="@dimen/toolbar_elevation"
android:fontFamily="sans-serif-medium"
android:gravity="center_vertical"
android:paddingLeft="72dp"
@ -45,7 +47,6 @@
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="?attr/title_text_color"
android:elevation="@dimen/toolbar_elevation"
tools:ignore="UnusedAttribute" />
<View

View file

@ -1,7 +1,7 @@
<FrameLayout 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">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/artist_image"
@ -38,6 +38,7 @@
android:layout_height="@dimen/title_view_height"
android:height="@dimen/title_view_height"
android:background="?default_bar_color"
android:clickable="true"
android:elevation="@dimen/toolbar_elevation"
android:fontFamily="sans-serif-medium"
android:gravity="center_vertical"