PlaybackControlsRowPresenter.java revision e5b67be786d519377ae275ef76f3ad72187183d5
17ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout/*
27ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Copyright (C) 2014 The Android Open Source Project
37ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
47ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
57ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * in compliance with the License. You may obtain a copy of the License at
67ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
77ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * http://www.apache.org/licenses/LICENSE-2.0
87ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
97ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Unless required by applicable law or agreed to in writing, software distributed under the License
107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * or implied. See the License for the specific language governing permissions and limitations under
127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * the License.
137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */
147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutpackage android.support.v17.leanback.widget;
157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.support.v17.leanback.R;
177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.content.Context;
187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.Color;
197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.util.TypedValue;
207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.LayoutInflater;
217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.View;
227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup;
237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup.LayoutParams;
247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup.MarginLayoutParams;
257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.widget.ImageView;
267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout/**
287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * A PlaybackControlsRowPresenter renders a {@link PlaybackControlsRow} to display a
297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * series of playback control buttons. Typically this row will be the first row in a fragment
307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * such as the {@link android.support.v17.leanback.app.PlaybackOverlayFragment
317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * PlaybackControlsFragment}.
327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */
337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutpublic class PlaybackControlsRowPresenter extends RowPresenter {
347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * A ViewHolder for the PlaybackControlsRow.
377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
386dca725412977bb56b933bdec120e31909233cdbCraig Stout    public class ViewHolder extends RowPresenter.ViewHolder {
397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ViewGroup mCard;
407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ImageView mImageView;
417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ViewGroup mDescriptionDock;
427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ViewGroup mControlsDock;
437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ViewGroup mSecondaryControlsDock;
447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final View mSpacer;
457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        int mCardHeight;
467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        int mControlsDockMarginStart;
477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        int mControlsDockMarginEnd;
487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        Presenter.ViewHolder mDescriptionVh;
496dca725412977bb56b933bdec120e31909233cdbCraig Stout        PlaybackControlsPresenter.ViewHolder mControlsVh;
507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        Presenter.ViewHolder mSecondaryControlsVh;
517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        PlaybackControlsPresenter.BoundData mControlsBoundData =
527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                new PlaybackControlsPresenter.BoundData();
537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ControlBarPresenter.BoundData mSecondaryBoundData = new ControlBarPresenter.BoundData();
546dca725412977bb56b933bdec120e31909233cdbCraig Stout        PlaybackControlsRow.OnPlaybackStateChangedListener mListener =
556dca725412977bb56b933bdec120e31909233cdbCraig Stout                new PlaybackControlsRow.OnPlaybackStateChangedListener() {
566dca725412977bb56b933bdec120e31909233cdbCraig Stout                    @Override
576dca725412977bb56b933bdec120e31909233cdbCraig Stout                    public void onCurrentTimeChanged(int ms) {
586dca725412977bb56b933bdec120e31909233cdbCraig Stout                        mPlaybackControlsPresenter.setCurrentTime(mControlsVh, ms);
596dca725412977bb56b933bdec120e31909233cdbCraig Stout                    }
606dca725412977bb56b933bdec120e31909233cdbCraig Stout                    @Override
616dca725412977bb56b933bdec120e31909233cdbCraig Stout                    public void onBufferedProgressChanged(int ms) {
626dca725412977bb56b933bdec120e31909233cdbCraig Stout                        mPlaybackControlsPresenter.setSecondaryProgress(mControlsVh, ms);
636dca725412977bb56b933bdec120e31909233cdbCraig Stout                    }
646dca725412977bb56b933bdec120e31909233cdbCraig Stout        };
657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ViewHolder(View rootView) {
677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            super(rootView);
687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mCard = (ViewGroup) rootView.findViewById(R.id.controls_card);
697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mImageView = (ImageView) rootView.findViewById(R.id.image);
707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mDescriptionDock = (ViewGroup) rootView.findViewById(R.id.description_dock);
717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mControlsDock = (ViewGroup) rootView.findViewById(R.id.controls_dock);
727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mSecondaryControlsDock =
737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    (ViewGroup) rootView.findViewById(R.id.secondary_controls_dock);
747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mSpacer = rootView.findViewById(R.id.spacer);
757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        Presenter getPresenter(Object item, boolean primary) {
787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            ObjectAdapter adapter = primary ?
797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    ((PlaybackControlsRow) getRow()).getPrimaryActionsAdapter() :
807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                            ((PlaybackControlsRow) getRow()).getSecondaryActionsAdapter();
817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            if (adapter.getPresenterSelector() instanceof ControlButtonPresenterSelector) {
827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                ControlButtonPresenterSelector selector =
837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                        (ControlButtonPresenterSelector) adapter.getPresenterSelector();
847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                return primary ? selector.getPrimaryPresenter() :
857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    selector.getSecondaryPresenter();
867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            }
877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            return adapter.getPresenter(item);
887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private int mBackgroundColor = Color.TRANSPARENT;
927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private boolean mBackgroundColorSet;
936dca725412977bb56b933bdec120e31909233cdbCraig Stout    private int mProgressColor = Color.TRANSPARENT;
946dca725412977bb56b933bdec120e31909233cdbCraig Stout    private boolean mProgressColorSet;
957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private boolean mSecondaryActionsHidden;
967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private Presenter mDescriptionPresenter;
977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private PlaybackControlsPresenter mPlaybackControlsPresenter;
987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private ControlBarPresenter mSecondaryControlsPresenter;
997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Constructor for a PlaybackControlsRowPresenter.
1027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     *
1037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * @param descriptionPresenter Presenter for displaying item details.
1047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public PlaybackControlsRowPresenter(Presenter descriptionPresenter) {
1067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        setHeaderPresenter(null);
1077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        setSelectEffectEnabled(false);
1087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mDescriptionPresenter = descriptionPresenter;
1107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPlaybackControlsPresenter = new PlaybackControlsPresenter(R.layout.lb_playback_controls);
1117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryControlsPresenter = new ControlBarPresenter(R.layout.lb_control_bar);
1127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Constructor for a PlaybackControlsRowPresenter.
1167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public PlaybackControlsRowPresenter() {
1187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        this(null);
1197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets the listener for {@link Action} click events.
1237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public void setOnActionClickedListener(OnActionClickedListener listener) {
1257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPlaybackControlsPresenter.setOnActionClickedListener(listener);
1267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryControlsPresenter.setOnActionClickedListener(listener);
1277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Gets the listener for {@link Action} click events.
1317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public OnActionClickedListener getOnActionClickedListener() {
1337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mPlaybackControlsPresenter.getOnActionClickedListener();
1347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets the background color.  If not set, a default from the theme will be used.
1387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public void setBackgroundColor(int color) {
1407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mBackgroundColor = color;
1417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mBackgroundColorSet = true;
1427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Returns the background color.  If no background color was set, transparent
1467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * is returned.
1477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public int getBackgroundColor() {
1497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mBackgroundColor;
1507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1536dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Sets the primary color for the progress bar.  If not set, a default from
1546dca725412977bb56b933bdec120e31909233cdbCraig Stout     * the theme will be used.
1556dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
1566dca725412977bb56b933bdec120e31909233cdbCraig Stout    public void setProgressColor(int color) {
1576dca725412977bb56b933bdec120e31909233cdbCraig Stout        mProgressColor = color;
1586dca725412977bb56b933bdec120e31909233cdbCraig Stout        mProgressColorSet = true;
1596dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
1606dca725412977bb56b933bdec120e31909233cdbCraig Stout
1616dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
1626dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Returns the primary color for the progress bar.  If no color was set, transparent
1636dca725412977bb56b933bdec120e31909233cdbCraig Stout     * is returned.
1646dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
1656dca725412977bb56b933bdec120e31909233cdbCraig Stout    public int getProgressColor() {
1666dca725412977bb56b933bdec120e31909233cdbCraig Stout        return mProgressColor;
1676dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
1686dca725412977bb56b933bdec120e31909233cdbCraig Stout
1696dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
1707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets the secondary actions to be hidden behind a "more actions" button.
1717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * When "more actions" is selected, the primary actions are replaced with
1727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * the secondary actions.
1737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public void setSecondaryActionsHidden(boolean hidden) {
1757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryActionsHidden = hidden;
1767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Returns true if secondary actions are hidden.
1807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public boolean areSecondaryActionsHidden() {
1827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mSecondaryActionsHidden;
1837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private int getDefaultBackgroundColor(Context context) {
1867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        TypedValue outValue = new TypedValue();
1877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        context.getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true);
1887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return context.getResources().getColor(outValue.resourceId);
1897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1916dca725412977bb56b933bdec120e31909233cdbCraig Stout    private int getDefaultProgressColor(Context context) {
1926dca725412977bb56b933bdec120e31909233cdbCraig Stout        TypedValue outValue = new TypedValue();
1936dca725412977bb56b933bdec120e31909233cdbCraig Stout        context.getTheme().resolveAttribute(R.attr.playbackProgressPrimaryColor, outValue, true);
1946dca725412977bb56b933bdec120e31909233cdbCraig Stout        return context.getResources().getColor(outValue.resourceId);
1956dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
1966dca725412977bb56b933bdec120e31909233cdbCraig Stout
1977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    @Override
1987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) {
1997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        View v = LayoutInflater.from(parent.getContext())
2007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            .inflate(R.layout.lb_playback_controls_row, parent, false);
2017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ViewHolder vh = new ViewHolder(v);
2027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        initRow(vh);
2037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return vh;
2047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private void initRow(ViewHolder vh) {
2077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mCardHeight = vh.mCard.getLayoutParams().height;
2087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams();
2107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsDockMarginStart = lp.getMarginStart();
2117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsDockMarginEnd = lp.getMarginEnd();
2127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        if (mDescriptionPresenter != null) {
2147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mDescriptionVh = mDescriptionPresenter.onCreateViewHolder(vh.mDescriptionDock);
2157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mDescriptionDock.addView(vh.mDescriptionVh.view);
2167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
2177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2186dca725412977bb56b933bdec120e31909233cdbCraig Stout        vh.mControlsVh = (PlaybackControlsPresenter.ViewHolder)
2196dca725412977bb56b933bdec120e31909233cdbCraig Stout                mPlaybackControlsPresenter.onCreateViewHolder(vh.mControlsDock);
2206dca725412977bb56b933bdec120e31909233cdbCraig Stout        mPlaybackControlsPresenter.setProgressColor(vh.mControlsVh,
2216dca725412977bb56b933bdec120e31909233cdbCraig Stout                mProgressColorSet ? mProgressColor :
2226dca725412977bb56b933bdec120e31909233cdbCraig Stout                        getDefaultProgressColor(vh.mControlsDock.getContext()));
2237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsDock.addView(vh.mControlsVh.view);
2247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mSecondaryControlsVh =
2267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                mSecondaryControlsPresenter.onCreateViewHolder(vh.mSecondaryControlsDock);
2277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        if (!mSecondaryActionsHidden) {
2287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mSecondaryControlsDock.addView(vh.mSecondaryControlsVh.view);
2297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
2307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private void setBackground(View view) {
2337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        view.setBackgroundColor(mBackgroundColorSet ?
2347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                mBackgroundColor : getDefaultBackgroundColor(view.getContext()));
2357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ShadowHelper.getInstance().setZ(view, 0f);
2367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    @Override
2397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) {
2407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        super.onBindRowViewHolder(holder, item);
2417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ViewHolder vh = (ViewHolder) holder;
2437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow();
2447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPlaybackControlsPresenter.enableSecondaryActions(mSecondaryActionsHidden);
2467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        if (row.getItem() == null) {
2487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            LayoutParams lp = vh.mCard.getLayoutParams();
2497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.height = LayoutParams.WRAP_CONTENT;
2507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mCard.setLayoutParams(lp);
2517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mDescriptionDock.setVisibility(View.GONE);
2527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mSpacer.setVisibility(View.GONE);
2537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        } else {
2547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            LayoutParams lp = vh.mCard.getLayoutParams();
2557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.height = vh.mCardHeight;
2567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mCard.setLayoutParams(lp);
2577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mDescriptionDock.setVisibility(View.VISIBLE);
2587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            if (vh.mDescriptionVh != null) {
2597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                mDescriptionPresenter.onBindViewHolder(vh.mDescriptionVh, row.getItem());
2607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            }
2617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mSpacer.setVisibility(View.VISIBLE);
2627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
2637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams();
2657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        if (row.getImageDrawable() == null || row.getItem() == null) {
2667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            setBackground(vh.mControlsDock);
2677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mCard.setBackgroundColor(Color.TRANSPARENT);
2687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.setMarginStart(0);
2697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.setMarginEnd(0);
270e5b67be786d519377ae275ef76f3ad72187183d5Craig Stout            mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, true);
2717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        } else {
2727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mImageView.setImageDrawable(row.getImageDrawable());
2737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            setBackground(vh.mCard);
2747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mControlsDock.setBackgroundColor(Color.TRANSPARENT);
2757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.setMarginStart(vh.mControlsDockMarginStart);
2767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.setMarginEnd(vh.mControlsDockMarginEnd);
277e5b67be786d519377ae275ef76f3ad72187183d5Craig Stout            mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, false);
2787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
2797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsDock.setLayoutParams(lp);
2807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsBoundData.adapter = row.getPrimaryActionsAdapter();
2827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsBoundData.secondaryActionsAdapter = row.getSecondaryActionsAdapter();
2837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsBoundData.presenter = vh.getPresenter(
2847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                row.getPrimaryActionsAdapter().get(0), true);
2857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPlaybackControlsPresenter.onBindViewHolder(vh.mControlsVh, vh.mControlsBoundData);
2867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mSecondaryBoundData.adapter = row.getSecondaryActionsAdapter();
2887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mSecondaryBoundData.presenter = vh.getPresenter(
2897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                row.getSecondaryActionsAdapter().get(0), false);
2907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryControlsPresenter.onBindViewHolder(vh.mSecondaryControlsVh,
2917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                vh.mSecondaryBoundData);
2926dca725412977bb56b933bdec120e31909233cdbCraig Stout
2936dca725412977bb56b933bdec120e31909233cdbCraig Stout        mPlaybackControlsPresenter.setTotalTime(vh.mControlsVh, row.getTotalTime());
2946dca725412977bb56b933bdec120e31909233cdbCraig Stout        mPlaybackControlsPresenter.setCurrentTime(vh.mControlsVh, row.getCurrentTime());
2956dca725412977bb56b933bdec120e31909233cdbCraig Stout        mPlaybackControlsPresenter.setSecondaryProgress(vh.mControlsVh, row.getBufferedProgress());
2966dca725412977bb56b933bdec120e31909233cdbCraig Stout        row.setOnPlaybackStateChangedListener(vh.mListener);
2977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    @Override
3007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    protected void onUnbindRowViewHolder(RowPresenter.ViewHolder holder) {
3017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ViewHolder vh = (ViewHolder) holder;
3026dca725412977bb56b933bdec120e31909233cdbCraig Stout        PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow();
3036dca725412977bb56b933bdec120e31909233cdbCraig Stout
3047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        if (vh.mDescriptionVh != null) {
3057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mDescriptionPresenter.onUnbindViewHolder(vh.mDescriptionVh);
3067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
3077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPlaybackControlsPresenter.onUnbindViewHolder(vh.mControlsVh);
3087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryControlsPresenter.onUnbindViewHolder(vh.mSecondaryControlsVh);
3096dca725412977bb56b933bdec120e31909233cdbCraig Stout        row.setOnPlaybackStateChangedListener(null);
3106dca725412977bb56b933bdec120e31909233cdbCraig Stout
3116dca725412977bb56b933bdec120e31909233cdbCraig Stout        super.onUnbindRowViewHolder(holder);
3127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
3137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout}
314