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

PlaybackControlsRowPresenter

public class PlaybackControlsRowPresenter extends RowPresenter
A PlaybackControlsRowPresenter renders a {@link PlaybackControlsRow} to display a series of playback control buttons. Typically this row will be the first row in a fragment such as the {@link android.support.v17.leanback.app.PlaybackOverlayFragment PlaybackControlsFragment}.

Fields Summary
private int
mBackgroundColor
private boolean
mBackgroundColorSet
private int
mProgressColor
private boolean
mProgressColorSet
private boolean
mSecondaryActionsHidden
private Presenter
mDescriptionPresenter
private PlaybackControlsPresenter
mPlaybackControlsPresenter
private ControlBarPresenter
mSecondaryControlsPresenter
private OnActionClickedListener
mOnActionClickedListener
private static float
sShadowZ
private final android.support.v17.leanback.widget.ControlBarPresenter.OnControlSelectedListener
mOnControlSelectedListener
private final android.support.v17.leanback.widget.ControlBarPresenter.OnControlClickedListener
mOnControlClickedListener
Constructors Summary
public PlaybackControlsRowPresenter(Presenter descriptionPresenter)
Constructor for a PlaybackControlsRowPresenter.

param
descriptionPresenter Presenter for displaying item details.


                    
       
        setHeaderPresenter(null);
        setSelectEffectEnabled(false);

        mDescriptionPresenter = descriptionPresenter;
        mPlaybackControlsPresenter = new PlaybackControlsPresenter(R.layout.lb_playback_controls);
        mSecondaryControlsPresenter = new ControlBarPresenter(R.layout.lb_control_bar);

        mPlaybackControlsPresenter.setOnControlSelectedListener(mOnControlSelectedListener);
        mSecondaryControlsPresenter.setOnControlSelectedListener(mOnControlSelectedListener);
        mPlaybackControlsPresenter.setOnControlClickedListener(mOnControlClickedListener);
        mSecondaryControlsPresenter.setOnControlClickedListener(mOnControlClickedListener);
    
public PlaybackControlsRowPresenter()
Constructor for a PlaybackControlsRowPresenter.

        this(null);
    
Methods Summary
public booleanareSecondaryActionsHidden()
Returns true if secondary actions are hidden.

        return mSecondaryActionsHidden;
    
protected RowPresenter.ViewHoldercreateRowViewHolder(android.view.ViewGroup parent)

        View v = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.lb_playback_controls_row, parent, false);
        ViewHolder vh = new ViewHolder(v, mDescriptionPresenter);
        initRow(vh);
        return vh;
    
public intgetBackgroundColor()
Returns the background color. If no background color was set, transparent is returned.

        return mBackgroundColor;
    
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 intgetDefaultProgressColor(android.content.Context context)

        TypedValue outValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.playbackProgressPrimaryColor, outValue, true);
        return context.getResources().getColor(outValue.resourceId);
    
public OnActionClickedListenergetOnActionClickedListener()
Gets the listener for {@link Action} click events.

        return mOnActionClickedListener;
    
public intgetProgressColor()
Returns the primary color for the progress bar. If no color was set, transparent is returned.

        return mProgressColor;
    
private voidinitRow(android.support.v17.leanback.widget.PlaybackControlsRowPresenter$ViewHolder vh)

        vh.mCardHeight = vh.mCard.getLayoutParams().height;

        MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams();
        vh.mControlsDockMarginStart = lp.getMarginStart();
        vh.mControlsDockMarginEnd = lp.getMarginEnd();

        vh.mControlsVh = (PlaybackControlsPresenter.ViewHolder)
                mPlaybackControlsPresenter.onCreateViewHolder(vh.mControlsDock);
        mPlaybackControlsPresenter.setProgressColor(vh.mControlsVh,
                mProgressColorSet ? mProgressColor :
                        getDefaultProgressColor(vh.mControlsDock.getContext()));
        vh.mControlsDock.addView(vh.mControlsVh.view);

        vh.mSecondaryControlsVh =
                mSecondaryControlsPresenter.onCreateViewHolder(vh.mSecondaryControlsDock);
        if (!mSecondaryActionsHidden) {
            vh.mSecondaryControlsDock.addView(vh.mSecondaryControlsVh.view);
        }
    
protected voidonBindRowViewHolder(RowPresenter.ViewHolder holder, java.lang.Object item)

        super.onBindRowViewHolder(holder, item);

        ViewHolder vh = (ViewHolder) holder;
        PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow();

        mPlaybackControlsPresenter.enableSecondaryActions(mSecondaryActionsHidden);

        if (row.getItem() == null) {
            LayoutParams lp = vh.mCard.getLayoutParams();
            lp.height = LayoutParams.WRAP_CONTENT;
            vh.mCard.setLayoutParams(lp);
            vh.mDescriptionDock.setVisibility(View.GONE);
            vh.mSpacer.setVisibility(View.GONE);
        } else {
            LayoutParams lp = vh.mCard.getLayoutParams();
            lp.height = vh.mCardHeight;
            vh.mCard.setLayoutParams(lp);
            vh.mDescriptionDock.setVisibility(View.VISIBLE);
            if (vh.mDescriptionViewHolder != null) {
                mDescriptionPresenter.onBindViewHolder(vh.mDescriptionViewHolder, row.getItem());
            }
            vh.mSpacer.setVisibility(View.VISIBLE);
        }

        MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams();
        if (row.getImageDrawable() == null || row.getItem() == null) {
            vh.mImageView.setImageDrawable(null);
            vh.setBackground(vh.mControlsDock);
            lp.setMarginStart(0);
            lp.setMarginEnd(0);
            mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, true);
        } else {
            vh.mImageView.setImageDrawable(row.getImageDrawable());
            vh.setBackground(vh.mCard);
            lp.setMarginStart(vh.mControlsDockMarginStart);
            lp.setMarginEnd(vh.mControlsDockMarginEnd);
            mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, false);
        }
        vh.mControlsDock.setLayoutParams(lp);

        vh.mControlsBoundData.adapter = row.getPrimaryActionsAdapter();
        vh.mControlsBoundData.secondaryActionsAdapter = row.getSecondaryActionsAdapter();
        vh.mControlsBoundData.presenter = vh.getPresenter(true);
        vh.mControlsBoundData.mRowViewHolder = vh;
        mPlaybackControlsPresenter.onBindViewHolder(vh.mControlsVh, vh.mControlsBoundData);

        vh.mSecondaryBoundData.adapter = row.getSecondaryActionsAdapter();
        vh.mSecondaryBoundData.presenter = vh.getPresenter(false);
        vh.mSecondaryBoundData.mRowViewHolder = vh;
        mSecondaryControlsPresenter.onBindViewHolder(vh.mSecondaryControlsVh,
                vh.mSecondaryBoundData);

        mPlaybackControlsPresenter.setTotalTime(vh.mControlsVh, row.getTotalTime());
        mPlaybackControlsPresenter.setCurrentTime(vh.mControlsVh, row.getCurrentTime());
        mPlaybackControlsPresenter.setSecondaryProgress(vh.mControlsVh, row.getBufferedProgress());
        row.setOnPlaybackStateChangedListener(vh.mListener);
    
protected voidonRowViewAttachedToWindow(RowPresenter.ViewHolder vh)

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

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

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

        ViewHolder vh = (ViewHolder) holder;
        PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow();

        if (vh.mDescriptionViewHolder != null) {
            mDescriptionPresenter.onUnbindViewHolder(vh.mDescriptionViewHolder);
        }
        mPlaybackControlsPresenter.onUnbindViewHolder(vh.mControlsVh);
        mSecondaryControlsPresenter.onUnbindViewHolder(vh.mSecondaryControlsVh);
        row.setOnPlaybackStateChangedListener(null);

        super.onUnbindRowViewHolder(holder);
    
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 {@link Action} click events.

        mOnActionClickedListener = listener;
    
public voidsetProgressColor(int color)
Sets the primary color for the progress bar. If not set, a default from the theme will be used.

        mProgressColor = color;
        mProgressColorSet = true;
    
public voidsetSecondaryActionsHidden(boolean hidden)
Sets the secondary actions to be hidden behind a "more actions" button. When "more actions" is selected, the primary actions are replaced with the secondary actions.

        mSecondaryActionsHidden = hidden;
    
public voidshowBottomSpace(android.support.v17.leanback.widget.PlaybackControlsRowPresenter$ViewHolder vh, boolean show)
Shows or hides space at the bottom of the playback controls row. This allows the row to hug the bottom of the display when no other rows are present.

        vh.mBottomSpacer.setVisibility(show ? View.VISIBLE : View.GONE);
    
public voidshowPrimaryActions(android.support.v17.leanback.widget.PlaybackControlsRowPresenter$ViewHolder vh)
Display the primary actions.

        mPlaybackControlsPresenter.showPrimaryActions(vh.mControlsVh);