PlaybackControlsRowPresenter.java revision d20507e0f5ac7ad021f42ca87c294787246f0591
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 { 396b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout public final Presenter.ViewHolder mDescriptionViewHolder; 407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mCard; 417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ImageView mImageView; 427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mDescriptionDock; 437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mControlsDock; 447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mSecondaryControlsDock; 457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final View mSpacer; 46d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout final View mBottomSpacer; 477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout int mCardHeight; 487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout int mControlsDockMarginStart; 497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout int mControlsDockMarginEnd; 506dca725412977bb56b933bdec120e31909233cdbCraig Stout PlaybackControlsPresenter.ViewHolder mControlsVh; 517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout Presenter.ViewHolder mSecondaryControlsVh; 527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout PlaybackControlsPresenter.BoundData mControlsBoundData = 537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout new PlaybackControlsPresenter.BoundData(); 547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ControlBarPresenter.BoundData mSecondaryBoundData = new ControlBarPresenter.BoundData(); 554cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout final PlaybackControlsRow.OnPlaybackStateChangedListener mListener = 566dca725412977bb56b933bdec120e31909233cdbCraig Stout new PlaybackControlsRow.OnPlaybackStateChangedListener() { 574cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout @Override 584cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout public void onCurrentTimeChanged(int ms) { 594cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout mPlaybackControlsPresenter.setCurrentTime(mControlsVh, ms); 604cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout } 614cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout @Override 624cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout public void onBufferedProgressChanged(int ms) { 634cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout mPlaybackControlsPresenter.setSecondaryProgress(mControlsVh, ms); 644cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout } 654cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout }; 664cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout final OnItemViewSelectedListener mOnItemViewSelectedListener = 674cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout new OnItemViewSelectedListener() { 684cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout @Override 694cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, 704cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout RowPresenter.ViewHolder rowViewHolder, Row row) { 714cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout if (getOnItemViewSelectedListener() != null) { 724cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout getOnItemViewSelectedListener().onItemSelected(itemViewHolder, item, 734cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout ViewHolder.this, getRow()); 744cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout } 754cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout } 766dca725412977bb56b933bdec120e31909233cdbCraig Stout }; 777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 786b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout ViewHolder(View rootView, Presenter descriptionPresenter) { 797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout super(rootView); 807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mCard = (ViewGroup) rootView.findViewById(R.id.controls_card); 817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mImageView = (ImageView) rootView.findViewById(R.id.image); 827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mDescriptionDock = (ViewGroup) rootView.findViewById(R.id.description_dock); 837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mControlsDock = (ViewGroup) rootView.findViewById(R.id.controls_dock); 847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsDock = 857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout (ViewGroup) rootView.findViewById(R.id.secondary_controls_dock); 867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSpacer = rootView.findViewById(R.id.spacer); 87d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout mBottomSpacer = rootView.findViewById(R.id.bottom_spacer); 886b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout mDescriptionViewHolder = descriptionPresenter == null ? null : 896b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout descriptionPresenter.onCreateViewHolder(mDescriptionDock); 906b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout if (mDescriptionViewHolder != null) { 916b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout mDescriptionDock.addView(mDescriptionViewHolder.view); 926b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout } 937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout Presenter getPresenter(Object item, boolean primary) { 967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ObjectAdapter adapter = primary ? 977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ((PlaybackControlsRow) getRow()).getPrimaryActionsAdapter() : 987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ((PlaybackControlsRow) getRow()).getSecondaryActionsAdapter(); 997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (adapter.getPresenterSelector() instanceof ControlButtonPresenterSelector) { 1007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ControlButtonPresenterSelector selector = 1017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout (ControlButtonPresenterSelector) adapter.getPresenterSelector(); 1027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return primary ? selector.getPrimaryPresenter() : 1037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout selector.getSecondaryPresenter(); 1047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return adapter.getPresenter(item); 1067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private int mBackgroundColor = Color.TRANSPARENT; 1107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private boolean mBackgroundColorSet; 1116dca725412977bb56b933bdec120e31909233cdbCraig Stout private int mProgressColor = Color.TRANSPARENT; 1126dca725412977bb56b933bdec120e31909233cdbCraig Stout private boolean mProgressColorSet; 1137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private boolean mSecondaryActionsHidden; 1147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private Presenter mDescriptionPresenter; 1157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private PlaybackControlsPresenter mPlaybackControlsPresenter; 1167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private ControlBarPresenter mSecondaryControlsPresenter; 1177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Constructor for a PlaybackControlsRowPresenter. 1207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * 1217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * @param descriptionPresenter Presenter for displaying item details. 1227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public PlaybackControlsRowPresenter(Presenter descriptionPresenter) { 1247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setHeaderPresenter(null); 1257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setSelectEffectEnabled(false); 1267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mDescriptionPresenter = descriptionPresenter; 1287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter = new PlaybackControlsPresenter(R.layout.lb_playback_controls); 1297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter = new ControlBarPresenter(R.layout.lb_control_bar); 1307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Constructor for a PlaybackControlsRowPresenter. 1347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public PlaybackControlsRowPresenter() { 1367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout this(null); 1377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Sets the listener for {@link Action} click events. 1417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public void setOnActionClickedListener(OnActionClickedListener listener) { 1437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.setOnActionClickedListener(listener); 1447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.setOnActionClickedListener(listener); 1457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Gets the listener for {@link Action} click events. 1497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public OnActionClickedListener getOnActionClickedListener() { 1517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return mPlaybackControlsPresenter.getOnActionClickedListener(); 1527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Sets the background color. If not set, a default from the theme will be used. 1567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public void setBackgroundColor(int color) { 1587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mBackgroundColor = color; 1597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mBackgroundColorSet = true; 1607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Returns the background color. If no background color was set, transparent 1647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * is returned. 1657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public int getBackgroundColor() { 1677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return mBackgroundColor; 1687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1716dca725412977bb56b933bdec120e31909233cdbCraig Stout * Sets the primary color for the progress bar. If not set, a default from 1726dca725412977bb56b933bdec120e31909233cdbCraig Stout * the theme will be used. 1736dca725412977bb56b933bdec120e31909233cdbCraig Stout */ 1746dca725412977bb56b933bdec120e31909233cdbCraig Stout public void setProgressColor(int color) { 1756dca725412977bb56b933bdec120e31909233cdbCraig Stout mProgressColor = color; 1766dca725412977bb56b933bdec120e31909233cdbCraig Stout mProgressColorSet = true; 1776dca725412977bb56b933bdec120e31909233cdbCraig Stout } 1786dca725412977bb56b933bdec120e31909233cdbCraig Stout 1796dca725412977bb56b933bdec120e31909233cdbCraig Stout /** 1806dca725412977bb56b933bdec120e31909233cdbCraig Stout * Returns the primary color for the progress bar. If no color was set, transparent 1816dca725412977bb56b933bdec120e31909233cdbCraig Stout * is returned. 1826dca725412977bb56b933bdec120e31909233cdbCraig Stout */ 1836dca725412977bb56b933bdec120e31909233cdbCraig Stout public int getProgressColor() { 1846dca725412977bb56b933bdec120e31909233cdbCraig Stout return mProgressColor; 1856dca725412977bb56b933bdec120e31909233cdbCraig Stout } 1866dca725412977bb56b933bdec120e31909233cdbCraig Stout 1876dca725412977bb56b933bdec120e31909233cdbCraig Stout /** 1887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Sets the secondary actions to be hidden behind a "more actions" button. 1897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * When "more actions" is selected, the primary actions are replaced with 1907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * the secondary actions. 1917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public void setSecondaryActionsHidden(boolean hidden) { 1937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryActionsHidden = hidden; 1947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Returns true if secondary actions are hidden. 1987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public boolean areSecondaryActionsHidden() { 2007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return mSecondaryActionsHidden; 2017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 203d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout /** 204d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout * Shows or hides space at the bottom of the playback controls row. 205d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout * This allows the row to hug the bottom of the display when no 206d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout * other rows are present. 207d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout */ 208d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout public void showBottomSpace(ViewHolder vh, boolean show) { 209d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout vh.mBottomSpacer.setVisibility(show ? View.VISIBLE : View.GONE); 210d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout } 211d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout 2127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private int getDefaultBackgroundColor(Context context) { 2137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout TypedValue outValue = new TypedValue(); 2147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout context.getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true); 2157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return context.getResources().getColor(outValue.resourceId); 2167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2186dca725412977bb56b933bdec120e31909233cdbCraig Stout private int getDefaultProgressColor(Context context) { 2196dca725412977bb56b933bdec120e31909233cdbCraig Stout TypedValue outValue = new TypedValue(); 2206dca725412977bb56b933bdec120e31909233cdbCraig Stout context.getTheme().resolveAttribute(R.attr.playbackProgressPrimaryColor, outValue, true); 2216dca725412977bb56b933bdec120e31909233cdbCraig Stout return context.getResources().getColor(outValue.resourceId); 2226dca725412977bb56b933bdec120e31909233cdbCraig Stout } 2236dca725412977bb56b933bdec120e31909233cdbCraig Stout 2247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout @Override 2257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) { 2267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout View v = LayoutInflater.from(parent.getContext()) 2277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout .inflate(R.layout.lb_playback_controls_row, parent, false); 2286b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout ViewHolder vh = new ViewHolder(v, mDescriptionPresenter); 2297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout initRow(vh); 2307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return vh; 2317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private void initRow(ViewHolder vh) { 2347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCardHeight = vh.mCard.getLayoutParams().height; 2357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams(); 2377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDockMarginStart = lp.getMarginStart(); 2387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDockMarginEnd = lp.getMarginEnd(); 2397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2406dca725412977bb56b933bdec120e31909233cdbCraig Stout vh.mControlsVh = (PlaybackControlsPresenter.ViewHolder) 2416dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.onCreateViewHolder(vh.mControlsDock); 2426dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.setProgressColor(vh.mControlsVh, 2436dca725412977bb56b933bdec120e31909233cdbCraig Stout mProgressColorSet ? mProgressColor : 2446dca725412977bb56b933bdec120e31909233cdbCraig Stout getDefaultProgressColor(vh.mControlsDock.getContext())); 2454cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout mPlaybackControlsPresenter.setOnItemViewSelectedListener(vh.mOnItemViewSelectedListener); 2467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDock.addView(vh.mControlsVh.view); 2477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryControlsVh = 2497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.onCreateViewHolder(vh.mSecondaryControlsDock); 2507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (!mSecondaryActionsHidden) { 2517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryControlsDock.addView(vh.mSecondaryControlsVh.view); 2527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2534cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout mSecondaryControlsPresenter.setOnItemViewSelectedListener(vh.mOnItemViewSelectedListener); 2547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private void setBackground(View view) { 2577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout view.setBackgroundColor(mBackgroundColorSet ? 2587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mBackgroundColor : getDefaultBackgroundColor(view.getContext())); 2597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ShadowHelper.getInstance().setZ(view, 0f); 2607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout @Override 2637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) { 2647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout super.onBindRowViewHolder(holder, item); 2657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ViewHolder vh = (ViewHolder) holder; 2677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow(); 2687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.enableSecondaryActions(mSecondaryActionsHidden); 2707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (row.getItem() == null) { 2727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout LayoutParams lp = vh.mCard.getLayoutParams(); 2737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.height = LayoutParams.WRAP_CONTENT; 2747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCard.setLayoutParams(lp); 2757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mDescriptionDock.setVisibility(View.GONE); 2767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSpacer.setVisibility(View.GONE); 2777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } else { 2787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout LayoutParams lp = vh.mCard.getLayoutParams(); 2797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.height = vh.mCardHeight; 2807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCard.setLayoutParams(lp); 2817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mDescriptionDock.setVisibility(View.VISIBLE); 2826b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout if (vh.mDescriptionViewHolder != null) { 2836b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout mDescriptionPresenter.onBindViewHolder(vh.mDescriptionViewHolder, row.getItem()); 2847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSpacer.setVisibility(View.VISIBLE); 2867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams(); 2897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (row.getImageDrawable() == null || row.getItem() == null) { 2907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setBackground(vh.mControlsDock); 2917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCard.setBackgroundColor(Color.TRANSPARENT); 2927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginStart(0); 2937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginEnd(0); 294e5b67be786d519377ae275ef76f3ad72187183d5Craig Stout mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, true); 2957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } else { 2967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mImageView.setImageDrawable(row.getImageDrawable()); 2977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setBackground(vh.mCard); 2987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDock.setBackgroundColor(Color.TRANSPARENT); 2997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginStart(vh.mControlsDockMarginStart); 3007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginEnd(vh.mControlsDockMarginEnd); 301e5b67be786d519377ae275ef76f3ad72187183d5Craig Stout mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, false); 3027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDock.setLayoutParams(lp); 3047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsBoundData.adapter = row.getPrimaryActionsAdapter(); 3067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsBoundData.secondaryActionsAdapter = row.getSecondaryActionsAdapter(); 3077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsBoundData.presenter = vh.getPresenter( 3087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout row.getPrimaryActionsAdapter().get(0), true); 3097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.onBindViewHolder(vh.mControlsVh, vh.mControlsBoundData); 3107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryBoundData.adapter = row.getSecondaryActionsAdapter(); 3127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryBoundData.presenter = vh.getPresenter( 3137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout row.getSecondaryActionsAdapter().get(0), false); 3147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.onBindViewHolder(vh.mSecondaryControlsVh, 3157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryBoundData); 3166dca725412977bb56b933bdec120e31909233cdbCraig Stout 3176dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.setTotalTime(vh.mControlsVh, row.getTotalTime()); 3186dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.setCurrentTime(vh.mControlsVh, row.getCurrentTime()); 3196dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.setSecondaryProgress(vh.mControlsVh, row.getBufferedProgress()); 3206dca725412977bb56b933bdec120e31909233cdbCraig Stout row.setOnPlaybackStateChangedListener(vh.mListener); 3217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout @Override 3247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout protected void onUnbindRowViewHolder(RowPresenter.ViewHolder holder) { 3257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ViewHolder vh = (ViewHolder) holder; 3266dca725412977bb56b933bdec120e31909233cdbCraig Stout PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow(); 3276dca725412977bb56b933bdec120e31909233cdbCraig Stout 3286b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout if (vh.mDescriptionViewHolder != null) { 3296b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout mDescriptionPresenter.onUnbindViewHolder(vh.mDescriptionViewHolder); 3307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.onUnbindViewHolder(vh.mControlsVh); 3327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.onUnbindViewHolder(vh.mSecondaryControlsVh); 3336dca725412977bb56b933bdec120e31909233cdbCraig Stout row.setOnPlaybackStateChangedListener(null); 3346dca725412977bb56b933bdec120e31909233cdbCraig Stout 3356dca725412977bb56b933bdec120e31909233cdbCraig Stout super.onUnbindRowViewHolder(holder); 3367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout} 338