FileDocCategorySizeDatePackage
DetailsOverviewRowPresenter.javaAPI DocAndroid 5.1 API22826Thu Mar 12 22:22:56 GMT 2015android.support.v17.leanback.widget

DetailsOverviewRowPresenter

public class DetailsOverviewRowPresenter extends RowPresenter
A DetailsOverviewRowPresenter renders a {@link DetailsOverviewRow} to display an overview of an item. Typically this row will be the first row in a fragment such as the {@link android.support.v17.leanback.app.DetailsFragment DetailsFragment}. View created by DetailsOverviewRowPresenter is made in three parts: ImageView on the left, action list view on the bottom and a customizable detailed description view on the right.

The detailed description is rendered using a {@link Presenter} passed in {@link #DetailsOverviewRowPresenter(Presenter)}. User can access detailed description ViewHolder from {@link ViewHolder#mDetailsDescriptionViewHolder}.

To participate in activity transition, call {@link #setSharedElementEnterTransition(Activity, String)} during Activity's onCreate().

Because transition support and layout are fully controlled by DetailsOverviewRowPresenter, developer can not override DetailsOverviewRowPresenter.ViewHolder for adding/replacing views of DetailsOverviewRowPresenter. If developer wants more customization beyond replacing detailed description , he/she should write a new presenter class for row object.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final int
MORE_ACTIONS_FADE_MS
private static final long
DEFAULT_TIMEOUT
private final Presenter
mDetailsPresenter
private final ActionPresenterSelector
mActionPresenterSelector
private OnActionClickedListener
mActionClickedListener
private int
mBackgroundColor
private boolean
mBackgroundColorSet
private boolean
mIsStyleLarge
private DetailsOverviewSharedElementHelper
mSharedElementHelper
Constructors Summary
public DetailsOverviewRowPresenter(Presenter detailsPresenter)
Constructor for a DetailsOverviewRowPresenter.

param
detailsPresenter The {@link Presenter} used to render the detailed description of the row.


                                  
       
        setHeaderPresenter(null);
        setSelectEffectEnabled(false);
        mDetailsPresenter = detailsPresenter;
        mActionPresenterSelector = new ActionPresenterSelector();
    
Methods Summary
protected RowPresenter.ViewHoldercreateRowViewHolder(android.view.ViewGroup parent)

        View v = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.lb_details_overview, parent, false);
        ViewHolder vh = new ViewHolder(v, mDetailsPresenter);

        initDetailsOverview(vh);

        return vh;
    
public intgetBackgroundColor()
Returns the background color. If no background color was set, transparent is returned.

        return mBackgroundColor;
    
private intgetCardHeight(android.content.Context context)

        int resId = mIsStyleLarge ? R.dimen.lb_details_overview_height_large :
            R.dimen.lb_details_overview_height_small;
        return context.getResources().getDimensionPixelSize(resId);
    
private intgetDefaultBackgroundColor(android.content.Context context)

        TypedValue outValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true);
        return context.getResources().getColor(outValue.resourceId);
    
private static intgetNonNegativeHeight(android.graphics.drawable.Drawable drawable)

        final int height = (drawable == null) ? 0 : drawable.getIntrinsicHeight();
        return (height > 0 ? height : 0);
    
private static intgetNonNegativeWidth(android.graphics.drawable.Drawable drawable)

        final int width = (drawable == null) ? 0 : drawable.getIntrinsicWidth();
        return (width > 0 ? width : 0);
    
public OnActionClickedListenergetOnActionClickedListener()
Gets the listener for Action click events.

        return mActionClickedListener;
    
private voidinitDetailsOverview(android.support.v17.leanback.widget.DetailsOverviewRowPresenter$ViewHolder vh)

        final View overview = vh.mOverviewFrame;
        ViewGroup.LayoutParams lp = overview.getLayoutParams();
        lp.height = getCardHeight(overview.getContext());
        overview.setLayoutParams(lp);

        if (!getSelectEffectEnabled()) {
            vh.mOverviewFrame.setForeground(null);
        }
    
public booleanisStyleLarge()
Returns true if the layout style is large.

        return mIsStyleLarge;
    
public final booleanisUsingDefaultSelectEffect()

        return false;
    
protected voidonBindRowViewHolder(RowPresenter.ViewHolder holder, java.lang.Object item)

        super.onBindRowViewHolder(holder, item);

        DetailsOverviewRow row = (DetailsOverviewRow) item;
        ViewHolder vh = (ViewHolder) holder;

        ViewGroup.MarginLayoutParams layoutParams =
                (ViewGroup.MarginLayoutParams) vh.mImageView.getLayoutParams();
        final int cardHeight = getCardHeight(vh.mImageView.getContext());
        final int verticalMargin = vh.mImageView.getResources().getDimensionPixelSize(
                R.dimen.lb_details_overview_image_margin_vertical);
        final int horizontalMargin = vh.mImageView.getResources().getDimensionPixelSize(
                R.dimen.lb_details_overview_image_margin_horizontal);
        final int drawableWidth = getNonNegativeWidth(row.getImageDrawable());
        final int drawableHeight = getNonNegativeHeight(row.getImageDrawable());

        boolean scaleImage = row.isImageScaleUpAllowed();
        boolean useMargin = false;

        if (row.getImageDrawable() != null) {
            boolean landscape = false;

            // If large style and landscape image we always use margin.
            if (drawableWidth > drawableHeight) {
                landscape = true;
                if (mIsStyleLarge) {
                    useMargin = true;
                }
            }
            // If long dimension bigger than the card height we scale down.
            if ((landscape && drawableWidth > cardHeight) ||
                    (!landscape && drawableHeight > cardHeight)) {
                scaleImage = true;
            }
            // If we're not scaling to fit the card height then we always use margin.
            if (!scaleImage) {
                useMargin = true;
            }
            // If using margin than may need to scale down.
            if (useMargin && !scaleImage) {
                if (landscape && drawableWidth > cardHeight - horizontalMargin) {
                    scaleImage = true;
                } else if (!landscape && drawableHeight > cardHeight - 2 * verticalMargin) {
                    scaleImage = true;
                }
            }
        }

        final int bgColor = mBackgroundColorSet ? mBackgroundColor :
            getDefaultBackgroundColor(vh.mOverviewView.getContext());

        if (useMargin) {
            layoutParams.setMarginStart(horizontalMargin);
            layoutParams.topMargin = layoutParams.bottomMargin = verticalMargin;
            RoundedRectHelper.getInstance().setRoundedRectBackground(vh.mOverviewFrame, bgColor);
            vh.mRightPanel.setBackground(null);
            vh.mImageView.setBackground(null);
        } else {
            layoutParams.leftMargin = layoutParams.topMargin = layoutParams.bottomMargin = 0;
            vh.mRightPanel.setBackgroundColor(bgColor);
            vh.mImageView.setBackgroundColor(bgColor);
            RoundedRectHelper.getInstance().setRoundedRectBackground(vh.mOverviewFrame,
                    Color.TRANSPARENT);
        }
        if (scaleImage) {
            vh.mImageView.setScaleType(ImageView.ScaleType.FIT_START);
            vh.mImageView.setAdjustViewBounds(true);
            vh.mImageView.setMaxWidth(cardHeight);
            layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
            layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        } else {
            vh.mImageView.setScaleType(ImageView.ScaleType.CENTER);
            vh.mImageView.setAdjustViewBounds(false);
            layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            // Limit width to the card height
            layoutParams.width = Math.min(cardHeight, drawableWidth);
        }
        vh.mImageView.setLayoutParams(layoutParams);
        vh.mImageView.setImageDrawable(row.getImageDrawable());

        mDetailsPresenter.onBindViewHolder(vh.mDetailsDescriptionViewHolder, row.getItem());

        ArrayObjectAdapter aoa = new ArrayObjectAdapter(mActionPresenterSelector);
        aoa.addAll(0, (Collection)row.getActions());
        vh.bind(aoa);

        if (row.getImageDrawable() != null && mSharedElementHelper != null) {
            mSharedElementHelper.onBindToDrawable(vh);
        }
    
protected voidonRowViewAttachedToWindow(RowPresenter.ViewHolder vh)

        super.onRowViewAttachedToWindow(vh);
        if (mDetailsPresenter != null) {
            mDetailsPresenter.onViewAttachedToWindow(
                    ((ViewHolder) vh).mDetailsDescriptionViewHolder);
        }
    
protected voidonRowViewDetachedFromWindow(RowPresenter.ViewHolder vh)

        super.onRowViewDetachedFromWindow(vh);
        if (mDetailsPresenter != null) {
            mDetailsPresenter.onViewDetachedFromWindow(
                    ((ViewHolder) vh).mDetailsDescriptionViewHolder);
        }
    
protected voidonRowViewSelected(RowPresenter.ViewHolder vh, boolean selected)

        super.onRowViewSelected(vh, selected);
        if (selected) {
            ((ViewHolder) vh).dispatchItemSelection(null);
        }
    
protected voidonSelectLevelChanged(RowPresenter.ViewHolder holder)

        super.onSelectLevelChanged(holder);
        if (getSelectEffectEnabled()) {
            ViewHolder vh = (ViewHolder) holder;
            int dimmedColor = vh.mColorDimmer.getPaint().getColor();
            ((ColorDrawable) vh.mOverviewFrame.getForeground().mutate()).setColor(dimmedColor);
        }
    
protected voidonUnbindRowViewHolder(RowPresenter.ViewHolder holder)

        super.onUnbindRowViewHolder(holder);

        ViewHolder vh = (ViewHolder) holder;
        if (vh.mDetailsDescriptionViewHolder != null) {
            mDetailsPresenter.onUnbindViewHolder(vh.mDetailsDescriptionViewHolder);
        }
    
public voidsetBackgroundColor(int color)
Sets the background color. If not set, a default from the theme will be used.

        mBackgroundColor = color;
        mBackgroundColorSet = true;
    
public voidsetOnActionClickedListener(OnActionClickedListener listener)
Sets the listener for Action click events.

        mActionClickedListener = listener;
    
public final voidsetSharedElementEnterTransition(android.app.Activity activity, java.lang.String sharedElementName, long timeoutMs)
Set enter transition of target activity (typically a DetailActivity) to be transiting into overview row created by this presenter. The transition will be cancelled if overview image is not loaded in the timeout period.

It assumes shared element passed from calling activity is an ImageView; the shared element transits to overview image on the left of detail overview row, while bounds of overview row grows and reveals text and buttons on the right.

The method must be invoked in target Activity's onCreate().

        if (mSharedElementHelper == null) {
            mSharedElementHelper = new DetailsOverviewSharedElementHelper();
        }
        mSharedElementHelper.setSharedElementEnterTransition(activity, sharedElementName,
                timeoutMs);
    
public final voidsetSharedElementEnterTransition(android.app.Activity activity, java.lang.String sharedElementName)
Set enter transition of target activity (typically a DetailActivity) to be transiting into overview row created by this presenter. The transition will be cancelled if overview image is not loaded in a default timeout period.

It assumes shared element passed from calling activity is an ImageView; the shared element transits to overview image on the left of detail overview row, while bounds of overview row grows and reveals text and buttons on the right.

The method must be invoked in target Activity's onCreate().

        setSharedElementEnterTransition(activity, sharedElementName, DEFAULT_TIMEOUT);
    
public voidsetStyleLarge(boolean large)
Sets the layout style to be large or small. This affects the height of the overview, including the text description. The default is large.

        mIsStyleLarge = large;