This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
Copyright (C) 2014 The Android Open Source Project | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MovieDetailsFragment extends DetailsFragment implements Palette.PaletteAsyncListener { | |
... | |
ArrayObjectAdapter mRecommendationsAdapter = new ArrayObjectAdapter(new MoviePresenter()); | |
... | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MovieDetailsFragment extends DetailsFragment implements Palette.PaletteAsyncListener { | |
// Add the adapter and use the newly created Presenter to define how to render the objects | |
ArrayObjectAdapter mCastAdapter = new ArrayObjectAdapter(new PersonPresenter()); | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// Adds the adapter and fetches the data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PersonPresenter extends Presenter { | |
Context mContext; | |
@Override | |
public ViewHolder onCreateViewHolder(ViewGroup parent) { | |
if (mContext == null) { | |
// We do this to avoid creating a new ContextThemeWrapper for each one of the cards | |
// If we look inside the ImageCardView they warn us about the same this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
... | |
<style name="PersonCardTheme" parent="Theme.Leanback"> | |
<item name="imageCardViewImageStyle">@style/PersonCardViewStyle</item> | |
</style> | |
<style name="PersonCardViewStyle" parent="Widget.Leanback.ImageCardView.ImageStyle"> | |
<item name="android:layout_width">180dp</item> | |
<item name="android:layout_height">250dp</item> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void bind(MovieDetails movie) { | |
if (movie != null && movie.getTitle() != null) { | |
... | |
int primaryDarkColor = ContextCompat.getColor(itemView.getContext(), R.color.primary_dark); | |
if (movie.getPaletteColors() != null) { | |
movieTitleTV.setTextColor(movie.getPaletteColors().getTitleColor()); | |
mOverviewLabelTV.setTextColor(movie.getPaletteColors().getTitleColor()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onGenerated(Palette palette) { | |
PaletteColors colors = PaletteUtils.getPaletteColors(palette); | |
mFullWidthMovieDetailsPresenter.setActionsBackgroundColor(colors.getStatusBarColor()); | |
mFullWidthMovieDetailsPresenter.setBackgroundColor(colors.getToolbarBackgroundColor()); | |
if (movieDetails != null) { | |
this.movieDetails.setPaletteColors(colors); | |
} | |
notifyDetailsChanged(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MovieDetailsFragment extends DetailsFragment | |
implements Palette.PaletteAsyncListener // Implement the PaletteAsyncListener { | |
// Change this from FullWidthDetailsOverviewRowPresenter to use our Custom one. | |
private CustomMovieDetailsPresenter mFullWidthMovieDetailsPresenter; | |
/** | |
* Sets up the adapter for this Fragment | |
*/ | |
private void setUpAdapter() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PaletteUtils { | |
public static PaletteColors getPaletteColors(Palette palette) { | |
PaletteColors colors = new PaletteColors(); | |
//figuring out toolbar palette color in order of preference | |
if (palette.getDarkVibrantSwatch() != null) { | |
colors.setToolbarBackgroundColor(palette.getDarkVibrantSwatch().getRgb()); | |
colors.setTextColor(palette.getDarkVibrantSwatch().getBodyTextColor()); | |
colors.setTitleColor(palette.getDarkVibrantSwatch().getTitleTextColor()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) { | |
super.onBindRowViewHolder(holder, item); | |
FullWidthDetailsOverviewRowPresenter.ViewHolder vh = (FullWidthDetailsOverviewRowPresenter.ViewHolder) holder; | |
View v = vh.getOverviewView(); | |
v.setBackgroundColor(getBackgroundColor()); | |
v.findViewById(android.support.v17.leanback.R.id.details_overview_actions_background) | |
.setBackgroundColor(getActionsBackgroundColor()); | |
} |