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;
1719025301f907b7b706bec652304b39761086e39bCraig Stoutimport android.util.TypedValue;
187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.content.Context;
1919025301f907b7b706bec652304b39761086e39bCraig Stoutimport android.content.res.TypedArray;
207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.Bitmap;
217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.BitmapFactory;
227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.Canvas;
237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.Color;
247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.Paint;
257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.PorterDuff;
267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.PorterDuffColorFilter;
277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.drawable.BitmapDrawable;
287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.drawable.Drawable;
2960bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stoutimport android.view.KeyEvent;
307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout/**
32a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout * A {@link Row} of playback controls to be displayed by a {@link PlaybackControlsRowPresenter}.
337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * This row consists of some optional item detail, a series of primary actions,
357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * and an optional series of secondary actions.
367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
37a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout * <p>
387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Controls are specified via an {@link ObjectAdapter} containing one or more
397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * {@link Action}s.
40a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout * </p>
41a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout * <p>
427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Adapters should have their {@link PresenterSelector} set to an instance of
437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * {@link ControlButtonPresenterSelector}.
44a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout * </p>
457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */
467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutpublic class PlaybackControlsRow extends Row {
477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
4919025301f907b7b706bec652304b39761086e39bCraig Stout     * Base class for an action comprised of a series of icons.
507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
5119025301f907b7b706bec652304b39761086e39bCraig Stout    public static abstract class MultiAction extends Action {
5219025301f907b7b706bec652304b39761086e39bCraig Stout        private int mIndex;
5319025301f907b7b706bec652304b39761086e39bCraig Stout        private Drawable[] mDrawables;
5405805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout        private String[] mLabels;
55eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        private String[] mLabels2;
567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor
5919025301f907b7b706bec652304b39761086e39bCraig Stout         * @param id The id of the Action.
607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
6119025301f907b7b706bec652304b39761086e39bCraig Stout        public MultiAction(int id) {
6219025301f907b7b706bec652304b39761086e39bCraig Stout            super(id);
6319025301f907b7b706bec652304b39761086e39bCraig Stout        }
6419025301f907b7b706bec652304b39761086e39bCraig Stout
6519025301f907b7b706bec652304b39761086e39bCraig Stout        /**
6619025301f907b7b706bec652304b39761086e39bCraig Stout         * Sets the array of drawables.  The size of the array defines the range
6719025301f907b7b706bec652304b39761086e39bCraig Stout         * of valid indices for this action.
6819025301f907b7b706bec652304b39761086e39bCraig Stout         */
6919025301f907b7b706bec652304b39761086e39bCraig Stout        public void setDrawables(Drawable[] drawables) {
7019025301f907b7b706bec652304b39761086e39bCraig Stout            mDrawables = drawables;
7119025301f907b7b706bec652304b39761086e39bCraig Stout            setIndex(0);
727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
74eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        /**
75eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * Sets the array of strings used as labels.  The size of the array defines the range
76eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * of valid indices for this action.  The labels are used to define the accessibility
77eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * content description unless secondary labels are provided.
78eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         */
7905805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout        public void setLabels(String[] labels) {
8005805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            mLabels = labels;
8105805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setIndex(0);
8205805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout        }
8305805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout
847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
85eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * Sets the array of strings used as secondary labels.  These labels are used
86eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * in place of the primary labels for accessibility content description only.
87eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         */
88eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        public void setSecondaryLabels(String[] labels) {
89eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            mLabels2 = labels;
90eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            setIndex(0);
91eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        }
92eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
93eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        /**
94eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * Returns the number of actions.
957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
96eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        public int getActionCount() {
97eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            if (mDrawables != null) {
98eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                return mDrawables.length;
99eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            }
100eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            if (mLabels != null) {
101eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                return mLabels.length;
102eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            }
103eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            return 0;
1047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
1057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
10719025301f907b7b706bec652304b39761086e39bCraig Stout         * Returns the drawable at the given index.
1087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
10919025301f907b7b706bec652304b39761086e39bCraig Stout        public Drawable getDrawable(int index) {
110eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            return mDrawables == null ? null : mDrawables[index];
1117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
1127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
11405805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout         * Returns the label at the given index.
11505805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout         */
11605805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout        public String getLabel(int index) {
117eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            return mLabels == null ? null : mLabels[index];
118eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        }
119eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
120eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        /**
121eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * Returns the secondary label at the given index.
122eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         */
123eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        public String getSecondaryLabel(int index) {
124eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            return mLabels2 == null ? null : mLabels2[index];
12505805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout        }
12605805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout
12705805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout        /**
12819025301f907b7b706bec652304b39761086e39bCraig Stout         * Increments the index, wrapping to zero once the end is reached.
1297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
13019025301f907b7b706bec652304b39761086e39bCraig Stout        public void nextIndex() {
131eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            setIndex(mIndex < getActionCount() - 1 ? mIndex + 1 : 0);
13219025301f907b7b706bec652304b39761086e39bCraig Stout        }
13319025301f907b7b706bec652304b39761086e39bCraig Stout
13419025301f907b7b706bec652304b39761086e39bCraig Stout        /**
13519025301f907b7b706bec652304b39761086e39bCraig Stout         * Sets the current index.
13619025301f907b7b706bec652304b39761086e39bCraig Stout         */
13719025301f907b7b706bec652304b39761086e39bCraig Stout        public void setIndex(int index) {
13819025301f907b7b706bec652304b39761086e39bCraig Stout            mIndex = index;
139eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            if (mDrawables != null) {
140eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                setIcon(mDrawables[mIndex]);
141eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            }
14205805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            if (mLabels != null) {
14305805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout                setLabel1(mLabels[mIndex]);
14405805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            }
145eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            if (mLabels2 != null) {
146eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                setLabel2(mLabels2[mIndex]);
147eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            }
14819025301f907b7b706bec652304b39761086e39bCraig Stout        }
14919025301f907b7b706bec652304b39761086e39bCraig Stout
15019025301f907b7b706bec652304b39761086e39bCraig Stout        /**
151a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout         * Returns the current index.
15219025301f907b7b706bec652304b39761086e39bCraig Stout         */
15319025301f907b7b706bec652304b39761086e39bCraig Stout        public int getIndex() {
15419025301f907b7b706bec652304b39761086e39bCraig Stout            return mIndex;
15519025301f907b7b706bec652304b39761086e39bCraig Stout        }
15619025301f907b7b706bec652304b39761086e39bCraig Stout    }
15719025301f907b7b706bec652304b39761086e39bCraig Stout
15819025301f907b7b706bec652304b39761086e39bCraig Stout    /**
15919025301f907b7b706bec652304b39761086e39bCraig Stout     * An action displaying icons for play and pause.
16019025301f907b7b706bec652304b39761086e39bCraig Stout     */
16119025301f907b7b706bec652304b39761086e39bCraig Stout    public static class PlayPauseAction extends MultiAction {
16219025301f907b7b706bec652304b39761086e39bCraig Stout        /**
16319025301f907b7b706bec652304b39761086e39bCraig Stout         * Action index for the play icon.
16419025301f907b7b706bec652304b39761086e39bCraig Stout         */
16519025301f907b7b706bec652304b39761086e39bCraig Stout        public static int PLAY = 0;
16619025301f907b7b706bec652304b39761086e39bCraig Stout
16719025301f907b7b706bec652304b39761086e39bCraig Stout        /**
16819025301f907b7b706bec652304b39761086e39bCraig Stout         * Action index for the pause icon.
16919025301f907b7b706bec652304b39761086e39bCraig Stout         */
17019025301f907b7b706bec652304b39761086e39bCraig Stout        public static int PAUSE = 1;
17119025301f907b7b706bec652304b39761086e39bCraig Stout
17219025301f907b7b706bec652304b39761086e39bCraig Stout        /**
17319025301f907b7b706bec652304b39761086e39bCraig Stout         * Constructor
17419025301f907b7b706bec652304b39761086e39bCraig Stout         * @param context Context used for loading resources.
17519025301f907b7b706bec652304b39761086e39bCraig Stout         */
17619025301f907b7b706bec652304b39761086e39bCraig Stout        public PlayPauseAction(Context context) {
17719025301f907b7b706bec652304b39761086e39bCraig Stout            super(R.id.lb_control_play_pause);
17819025301f907b7b706bec652304b39761086e39bCraig Stout            Drawable[] drawables = new Drawable[2];
17919025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[PLAY] = getStyledDrawable(context,
18019025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_play);
18119025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[PAUSE] = getStyledDrawable(context,
18219025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_pause);
18319025301f907b7b706bec652304b39761086e39bCraig Stout            setDrawables(drawables);
184cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
18505805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            String[] labels = new String[drawables.length];
18605805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[PLAY] = context.getString(R.string.lb_playback_controls_play);
18705805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[PAUSE] = context.getString(R.string.lb_playback_controls_pause);
18805805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabels(labels);
18960bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            addKeyCode(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
19060bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            addKeyCode(KeyEvent.KEYCODE_MEDIA_PLAY);
19160bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            addKeyCode(KeyEvent.KEYCODE_MEDIA_PAUSE);
192cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
1937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * An action displaying an icon for fast forward.
1977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
198eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout    public static class FastForwardAction extends MultiAction {
1997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
2007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor
2017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * @param context Context used for loading resources.
2027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
2037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        public FastForwardAction(Context context) {
204eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            this(context, 1);
205eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        }
206eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
207eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        /**
208eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * Constructor
209eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * @param context Context used for loading resources.
210eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * @param numSpeeds Number of supported fast forward speeds.
211eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         */
212eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        public FastForwardAction(Context context, int numSpeeds) {
2137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            super(R.id.lb_control_fast_forward);
214eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
215eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            if (numSpeeds < 1) {
216eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                throw new IllegalArgumentException("numSpeeds must be > 0");
217eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            }
218eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            Drawable[] drawables = new Drawable[numSpeeds];
219eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            drawables[0] = getStyledDrawable(context,
220eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                    R.styleable.lbPlaybackControlsActionIcons_fast_forward);
221eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            setDrawables(drawables);
222eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
223eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            String[] labels = new String[getActionCount()];
224eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            labels[0] = context.getString(R.string.lb_playback_controls_fast_forward);
225eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
226eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            String[] labels2 = new String[getActionCount()];
227eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            labels2[0] = labels[0];
228eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
229eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            for (int i = 1; i < numSpeeds; i++) {
230eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                int multiplier = i + 1;
231eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                labels[i] = context.getResources().getString(
232eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                        R.string.lb_control_display_fast_forward_multiplier, multiplier);
233eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                labels2[i] = context.getResources().getString(
234eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                        R.string.lb_playback_controls_fast_forward_multiplier, multiplier);
235eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            }
236eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            setLabels(labels);
237eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            setSecondaryLabels(labels2);
23860bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            addKeyCode(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD);
239cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
2407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
2437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * An action displaying an icon for rewind.
2447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
245eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout    public static class RewindAction extends MultiAction {
2467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
2477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor
2487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * @param context Context used for loading resources.
2497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
2507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        public RewindAction(Context context) {
251eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            this(context, 1);
252eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        }
253eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
254eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        /**
255eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * Constructor
256eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * @param context Context used for loading resources.
257eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         * @param numSpeeds Number of supported fast forward speeds.
258eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout         */
259eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout        public RewindAction(Context context, int numSpeeds) {
2607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            super(R.id.lb_control_fast_rewind);
261eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
262eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            if (numSpeeds < 1) {
263eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                throw new IllegalArgumentException("numSpeeds must be > 0");
264eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            }
265eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            Drawable[] drawables = new Drawable[numSpeeds];
266eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            drawables[0] = getStyledDrawable(context,
267eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                    R.styleable.lbPlaybackControlsActionIcons_rewind);
268eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            setDrawables(drawables);
269eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
270eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            String[] labels = new String[getActionCount()];
271eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            labels[0] = context.getString(R.string.lb_playback_controls_rewind);
272eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
273eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            String[] labels2 = new String[getActionCount()];
274eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            labels2[0] = labels[0];
275eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout
276eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            for (int i = 1; i < numSpeeds; i++) {
277eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                int multiplier = i + 1;
278eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                labels[i] = labels[i] = context.getResources().getString(
279eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                        R.string.lb_control_display_rewind_multiplier, multiplier);
280eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                labels2[i] = context.getResources().getString(
281eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout                        R.string.lb_playback_controls_rewind_multiplier, multiplier);
282eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            }
283eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            setLabels(labels);
284eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            setSecondaryLabels(labels2);
28560bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            addKeyCode(KeyEvent.KEYCODE_MEDIA_REWIND);
286cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
2877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
2907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * An action displaying an icon for skip next.
2917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
2927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public static class SkipNextAction extends Action {
2937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
2947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor
2957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * @param context Context used for loading resources.
2967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
2977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        public SkipNextAction(Context context) {
2987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            super(R.id.lb_control_skip_next);
29919025301f907b7b706bec652304b39761086e39bCraig Stout            setIcon(getStyledDrawable(context,
30019025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_skip_next));
30105805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabel1(context.getString(R.string.lb_playback_controls_skip_next));
30260bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            addKeyCode(KeyEvent.KEYCODE_MEDIA_NEXT);
303cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
3047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
3057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
3077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * An action displaying an icon for skip previous.
3087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
3097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public static class SkipPreviousAction extends Action {
3107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
3117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor
3127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * @param context Context used for loading resources.
3137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
3147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        public SkipPreviousAction(Context context) {
3157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            super(R.id.lb_control_skip_previous);
31619025301f907b7b706bec652304b39761086e39bCraig Stout            setIcon(getStyledDrawable(context,
31719025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_skip_previous));
31805805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabel1(context.getString(R.string.lb_playback_controls_skip_previous));
31960bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            addKeyCode(KeyEvent.KEYCODE_MEDIA_PREVIOUS);
320cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
3217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
3227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
3242401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang     * An action displaying an icon for picture-in-picture.
3252401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang     */
3262401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang    public static class PictureInPictureAction extends Action {
3272401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang        /**
3282401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang         * Constructor
3292401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang         * @param context Context used for loading resources.
3302401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang         */
3312401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang        public PictureInPictureAction(Context context) {
3322401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang            super(R.id.lb_control_picture_in_picture);
3332401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang            setIcon(getStyledDrawable(context,
3342401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang                    R.styleable.lbPlaybackControlsActionIcons_picture_in_picture));
3352401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang            setLabel1(context.getString(R.string.lb_playback_controls_picture_in_picture));
3362401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang            addKeyCode(KeyEvent.KEYCODE_WINDOW);
3372401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang        }
3382401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang    }
3392401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang
3402401804c25909d3b271f5d5aea8f9d1b2168fc07Dongwon Kang    /**
3417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * An action displaying an icon for "more actions".
3427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
3437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public static class MoreActions extends Action {
3447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
3457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor
3467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * @param context Context used for loading resources.
3477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
3487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        public MoreActions(Context context) {
3497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            super(R.id.lb_control_more_actions);
3507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            setIcon(context.getResources().getDrawable(R.drawable.lb_ic_more));
35105805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabel1(context.getString(R.string.lb_playback_controls_more_actions));
352cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
3537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
3547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
35619025301f907b7b706bec652304b39761086e39bCraig Stout     * A base class for displaying a thumbs action.
3577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
35819025301f907b7b706bec652304b39761086e39bCraig Stout    public static abstract class ThumbsAction extends MultiAction {
35919025301f907b7b706bec652304b39761086e39bCraig Stout        /**
36019025301f907b7b706bec652304b39761086e39bCraig Stout         * Action index for the solid thumb icon.
36119025301f907b7b706bec652304b39761086e39bCraig Stout         */
36219025301f907b7b706bec652304b39761086e39bCraig Stout        public static int SOLID = 0;
36319025301f907b7b706bec652304b39761086e39bCraig Stout
36419025301f907b7b706bec652304b39761086e39bCraig Stout        /**
36519025301f907b7b706bec652304b39761086e39bCraig Stout         * Action index for the outline thumb icon.
36619025301f907b7b706bec652304b39761086e39bCraig Stout         */
36719025301f907b7b706bec652304b39761086e39bCraig Stout        public static int OUTLINE = 1;
36819025301f907b7b706bec652304b39761086e39bCraig Stout
3697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
3707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor
3717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * @param context Context used for loading resources.
3727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
37319025301f907b7b706bec652304b39761086e39bCraig Stout        public ThumbsAction(int id, Context context, int solidIconIndex, int outlineIconIndex) {
37419025301f907b7b706bec652304b39761086e39bCraig Stout            super(id);
37519025301f907b7b706bec652304b39761086e39bCraig Stout            Drawable[] drawables = new Drawable[2];
37619025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[SOLID] = getStyledDrawable(context, solidIconIndex);
37719025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[OUTLINE] = getStyledDrawable(context, outlineIconIndex);
37819025301f907b7b706bec652304b39761086e39bCraig Stout            setDrawables(drawables);
37919025301f907b7b706bec652304b39761086e39bCraig Stout        }
38019025301f907b7b706bec652304b39761086e39bCraig Stout    }
38119025301f907b7b706bec652304b39761086e39bCraig Stout
38219025301f907b7b706bec652304b39761086e39bCraig Stout    /**
38319025301f907b7b706bec652304b39761086e39bCraig Stout     * An action displaying an icon for thumbs up.
38419025301f907b7b706bec652304b39761086e39bCraig Stout     */
38519025301f907b7b706bec652304b39761086e39bCraig Stout    public static class ThumbsUpAction extends ThumbsAction {
3867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        public ThumbsUpAction(Context context) {
38719025301f907b7b706bec652304b39761086e39bCraig Stout            super(R.id.lb_control_thumbs_up, context,
38819025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_thumb_up,
38919025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_thumb_up_outline);
390eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            String[] labels = new String[getActionCount()];
39105805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[SOLID] = context.getString(R.string.lb_playback_controls_thumb_up);
39205805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[OUTLINE] = context.getString(R.string.lb_playback_controls_thumb_up_outline);
39305805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabels(labels);
394cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
3957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
3967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
3987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * An action displaying an icon for thumbs down.
3997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
40019025301f907b7b706bec652304b39761086e39bCraig Stout    public static class ThumbsDownAction extends ThumbsAction {
4017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        public ThumbsDownAction(Context context) {
40219025301f907b7b706bec652304b39761086e39bCraig Stout            super(R.id.lb_control_thumbs_down, context,
40319025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_thumb_down,
40419025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_thumb_down_outline);
405eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout            String[] labels = new String[getActionCount()];
40605805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[SOLID] = context.getString(R.string.lb_playback_controls_thumb_down);
40705805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[OUTLINE] = context.getString(R.string.lb_playback_controls_thumb_down_outline);
40805805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabels(labels);
409cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
4107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
4117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
412cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    /**
4137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * An action for displaying three repeat states: none, one, or all.
4147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
41519025301f907b7b706bec652304b39761086e39bCraig Stout    public static class RepeatAction extends MultiAction {
41619025301f907b7b706bec652304b39761086e39bCraig Stout        /**
41719025301f907b7b706bec652304b39761086e39bCraig Stout         * Action index for the repeat-none icon.
41819025301f907b7b706bec652304b39761086e39bCraig Stout         */
4196dca725412977bb56b933bdec120e31909233cdbCraig Stout        public static int NONE = 0;
42019025301f907b7b706bec652304b39761086e39bCraig Stout
42119025301f907b7b706bec652304b39761086e39bCraig Stout        /**
42219025301f907b7b706bec652304b39761086e39bCraig Stout         * Action index for the repeat-all icon.
42319025301f907b7b706bec652304b39761086e39bCraig Stout         */
42419025301f907b7b706bec652304b39761086e39bCraig Stout        public static int ALL = 1;
42519025301f907b7b706bec652304b39761086e39bCraig Stout
42619025301f907b7b706bec652304b39761086e39bCraig Stout        /**
42719025301f907b7b706bec652304b39761086e39bCraig Stout         * Action index for the repeat-one icon.
42819025301f907b7b706bec652304b39761086e39bCraig Stout         */
42919025301f907b7b706bec652304b39761086e39bCraig Stout        public static int ONE = 2;
4307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
4317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
4327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor
4337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * @param context Context used for loading resources.
4347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
4357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        public RepeatAction(Context context) {
43646443cb5b092f1d9156342645088eead9da026f6Dake Gu            this(context, getIconHighlightColor(context));
43719025301f907b7b706bec652304b39761086e39bCraig Stout        }
43819025301f907b7b706bec652304b39761086e39bCraig Stout
43919025301f907b7b706bec652304b39761086e39bCraig Stout        /**
44019025301f907b7b706bec652304b39761086e39bCraig Stout         * Constructor
44119025301f907b7b706bec652304b39761086e39bCraig Stout         * @param context Context used for loading resources
44219025301f907b7b706bec652304b39761086e39bCraig Stout         * @param highlightColor Color to display the repeat-all and repeat0one icons.
44319025301f907b7b706bec652304b39761086e39bCraig Stout         */
44419025301f907b7b706bec652304b39761086e39bCraig Stout        public RepeatAction(Context context, int highlightColor) {
44519025301f907b7b706bec652304b39761086e39bCraig Stout            this(context, highlightColor, highlightColor);
44619025301f907b7b706bec652304b39761086e39bCraig Stout        }
44719025301f907b7b706bec652304b39761086e39bCraig Stout
44819025301f907b7b706bec652304b39761086e39bCraig Stout        /**
44919025301f907b7b706bec652304b39761086e39bCraig Stout         * Constructor
45019025301f907b7b706bec652304b39761086e39bCraig Stout         * @param context Context used for loading resources
45119025301f907b7b706bec652304b39761086e39bCraig Stout         * @param repeatAllColor Color to display the repeat-all icon.
45219025301f907b7b706bec652304b39761086e39bCraig Stout         * @param repeatOneColor Color to display the repeat-one icon.
45319025301f907b7b706bec652304b39761086e39bCraig Stout         */
45419025301f907b7b706bec652304b39761086e39bCraig Stout        public RepeatAction(Context context, int repeatAllColor, int repeatOneColor) {
4557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            super(R.id.lb_control_repeat);
45619025301f907b7b706bec652304b39761086e39bCraig Stout            Drawable[] drawables = new Drawable[3];
45719025301f907b7b706bec652304b39761086e39bCraig Stout            BitmapDrawable repeatDrawable = (BitmapDrawable) getStyledDrawable(context,
45819025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_repeat);
45919025301f907b7b706bec652304b39761086e39bCraig Stout            BitmapDrawable repeatOneDrawable = (BitmapDrawable) getStyledDrawable(context,
46019025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_repeat_one);
46119025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[NONE] = repeatDrawable;
46246443cb5b092f1d9156342645088eead9da026f6Dake Gu            drawables[ALL] = repeatDrawable == null ? null
46346443cb5b092f1d9156342645088eead9da026f6Dake Gu                    : new BitmapDrawable(context.getResources(),
46446443cb5b092f1d9156342645088eead9da026f6Dake Gu                            createBitmap(repeatDrawable.getBitmap(), repeatAllColor));
46546443cb5b092f1d9156342645088eead9da026f6Dake Gu            drawables[ONE] = repeatOneDrawable == null ? null
46646443cb5b092f1d9156342645088eead9da026f6Dake Gu                    : new BitmapDrawable(context.getResources(),
46746443cb5b092f1d9156342645088eead9da026f6Dake Gu                            createBitmap(repeatOneDrawable.getBitmap(), repeatOneColor));
46819025301f907b7b706bec652304b39761086e39bCraig Stout            setDrawables(drawables);
469cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
47005805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            String[] labels = new String[drawables.length];
47105805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            // Note, labels denote the action taken when clicked
47205805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[NONE] = context.getString(R.string.lb_playback_controls_repeat_all);
47305805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[ALL] = context.getString(R.string.lb_playback_controls_repeat_one);
47405805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[ONE] = context.getString(R.string.lb_playback_controls_repeat_none);
47505805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabels(labels);
476cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
47719025301f907b7b706bec652304b39761086e39bCraig Stout    }
47819025301f907b7b706bec652304b39761086e39bCraig Stout
47919025301f907b7b706bec652304b39761086e39bCraig Stout    /**
48019025301f907b7b706bec652304b39761086e39bCraig Stout     * An action for displaying a shuffle icon.
48119025301f907b7b706bec652304b39761086e39bCraig Stout     */
48219025301f907b7b706bec652304b39761086e39bCraig Stout    public static class ShuffleAction extends MultiAction {
48319025301f907b7b706bec652304b39761086e39bCraig Stout        public static int OFF = 0;
48419025301f907b7b706bec652304b39761086e39bCraig Stout        public static int ON = 1;
4857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
4867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
48719025301f907b7b706bec652304b39761086e39bCraig Stout         * Constructor
48819025301f907b7b706bec652304b39761086e39bCraig Stout         * @param context Context used for loading resources.
4897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
49019025301f907b7b706bec652304b39761086e39bCraig Stout        public ShuffleAction(Context context) {
49146443cb5b092f1d9156342645088eead9da026f6Dake Gu            this(context, getIconHighlightColor(context));
4927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
4937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
4947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
49519025301f907b7b706bec652304b39761086e39bCraig Stout         * Constructor
49619025301f907b7b706bec652304b39761086e39bCraig Stout         * @param context Context used for loading resources.
49719025301f907b7b706bec652304b39761086e39bCraig Stout         * @param highlightColor Color for the highlighted icon state.
4987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
49919025301f907b7b706bec652304b39761086e39bCraig Stout        public ShuffleAction(Context context, int highlightColor) {
50019025301f907b7b706bec652304b39761086e39bCraig Stout            super(R.id.lb_control_shuffle);
50119025301f907b7b706bec652304b39761086e39bCraig Stout            BitmapDrawable uncoloredDrawable = (BitmapDrawable) getStyledDrawable(context,
50219025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_shuffle);
50319025301f907b7b706bec652304b39761086e39bCraig Stout            Drawable[] drawables = new Drawable[2];
50419025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[OFF] = uncoloredDrawable;
50519025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[ON] = new BitmapDrawable(context.getResources(),
50619025301f907b7b706bec652304b39761086e39bCraig Stout                    createBitmap(uncoloredDrawable.getBitmap(), highlightColor));
50719025301f907b7b706bec652304b39761086e39bCraig Stout            setDrawables(drawables);
508cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
50905805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            String[] labels = new String[drawables.length];
51005805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[OFF] = context.getString(R.string.lb_playback_controls_shuffle_enable);
51105805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[ON] = context.getString(R.string.lb_playback_controls_shuffle_disable);
51205805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabels(labels);
513cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
51419025301f907b7b706bec652304b39761086e39bCraig Stout    }
51519025301f907b7b706bec652304b39761086e39bCraig Stout
51619025301f907b7b706bec652304b39761086e39bCraig Stout    /**
51719025301f907b7b706bec652304b39761086e39bCraig Stout     * An action for displaying a HQ (High Quality) icon.
51819025301f907b7b706bec652304b39761086e39bCraig Stout     */
51919025301f907b7b706bec652304b39761086e39bCraig Stout    public static class HighQualityAction extends MultiAction {
52019025301f907b7b706bec652304b39761086e39bCraig Stout        public static int OFF = 0;
52119025301f907b7b706bec652304b39761086e39bCraig Stout        public static int ON = 1;
5227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
5237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
52419025301f907b7b706bec652304b39761086e39bCraig Stout         * Constructor
52519025301f907b7b706bec652304b39761086e39bCraig Stout         * @param context Context used for loading resources.
5267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
52719025301f907b7b706bec652304b39761086e39bCraig Stout        public HighQualityAction(Context context) {
52846443cb5b092f1d9156342645088eead9da026f6Dake Gu            this(context, getIconHighlightColor(context));
5297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
5306dca725412977bb56b933bdec120e31909233cdbCraig Stout
5316dca725412977bb56b933bdec120e31909233cdbCraig Stout        /**
53219025301f907b7b706bec652304b39761086e39bCraig Stout         * Constructor
53319025301f907b7b706bec652304b39761086e39bCraig Stout         * @param context Context used for loading resources.
53419025301f907b7b706bec652304b39761086e39bCraig Stout         * @param highlightColor Color for the highlighted icon state.
5356dca725412977bb56b933bdec120e31909233cdbCraig Stout         */
53619025301f907b7b706bec652304b39761086e39bCraig Stout        public HighQualityAction(Context context, int highlightColor) {
53719025301f907b7b706bec652304b39761086e39bCraig Stout            super(R.id.lb_control_high_quality);
53819025301f907b7b706bec652304b39761086e39bCraig Stout            BitmapDrawable uncoloredDrawable = (BitmapDrawable) getStyledDrawable(context,
53919025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_high_quality);
54019025301f907b7b706bec652304b39761086e39bCraig Stout            Drawable[] drawables = new Drawable[2];
54119025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[OFF] = uncoloredDrawable;
54219025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[ON] = new BitmapDrawable(context.getResources(),
54319025301f907b7b706bec652304b39761086e39bCraig Stout                    createBitmap(uncoloredDrawable.getBitmap(), highlightColor));
54419025301f907b7b706bec652304b39761086e39bCraig Stout            setDrawables(drawables);
545cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
54605805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            String[] labels = new String[drawables.length];
54705805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[OFF] = context.getString(R.string.lb_playback_controls_high_quality_enable);
54805805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[ON] = context.getString(R.string.lb_playback_controls_high_quality_disable);
54905805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabels(labels);
550cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
5517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
5527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
5537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
55419025301f907b7b706bec652304b39761086e39bCraig Stout     * An action for displaying a CC (Closed Captioning) icon.
5557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
55619025301f907b7b706bec652304b39761086e39bCraig Stout    public static class ClosedCaptioningAction extends MultiAction {
55719025301f907b7b706bec652304b39761086e39bCraig Stout        public static int OFF = 0;
55819025301f907b7b706bec652304b39761086e39bCraig Stout        public static int ON = 1;
55919025301f907b7b706bec652304b39761086e39bCraig Stout
5607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
5617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor
5627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * @param context Context used for loading resources.
5637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
56419025301f907b7b706bec652304b39761086e39bCraig Stout        public ClosedCaptioningAction(Context context) {
56546443cb5b092f1d9156342645088eead9da026f6Dake Gu            this(context, getIconHighlightColor(context));
56619025301f907b7b706bec652304b39761086e39bCraig Stout        }
56719025301f907b7b706bec652304b39761086e39bCraig Stout
56819025301f907b7b706bec652304b39761086e39bCraig Stout        /**
56919025301f907b7b706bec652304b39761086e39bCraig Stout         * Constructor
57019025301f907b7b706bec652304b39761086e39bCraig Stout         * @param context Context used for loading resources.
57119025301f907b7b706bec652304b39761086e39bCraig Stout         * @param highlightColor Color for the highlighted icon state.
57219025301f907b7b706bec652304b39761086e39bCraig Stout         */
57319025301f907b7b706bec652304b39761086e39bCraig Stout        public ClosedCaptioningAction(Context context, int highlightColor) {
574ed838f628cbf453b8df555c88f00a9eb69d507a9Dake Gu            super(R.id.lb_control_closed_captioning);
57519025301f907b7b706bec652304b39761086e39bCraig Stout            BitmapDrawable uncoloredDrawable = (BitmapDrawable) getStyledDrawable(context,
57619025301f907b7b706bec652304b39761086e39bCraig Stout                    R.styleable.lbPlaybackControlsActionIcons_closed_captioning);
57719025301f907b7b706bec652304b39761086e39bCraig Stout            Drawable[] drawables = new Drawable[2];
57819025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[OFF] = uncoloredDrawable;
57919025301f907b7b706bec652304b39761086e39bCraig Stout            drawables[ON] = new BitmapDrawable(context.getResources(),
58019025301f907b7b706bec652304b39761086e39bCraig Stout                    createBitmap(uncoloredDrawable.getBitmap(), highlightColor));
58119025301f907b7b706bec652304b39761086e39bCraig Stout            setDrawables(drawables);
582cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
58305805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            String[] labels = new String[drawables.length];
58405805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[OFF] = context.getString(R.string.lb_playback_controls_closed_captioning_enable);
58505805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            labels[ON] = context.getString(R.string.lb_playback_controls_closed_captioning_disable);
58605805862fe972a3e3c0d199b7eb3a80fc5bdd7b6Craig Stout            setLabels(labels);
587cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
5887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
5897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
5907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private static Bitmap createBitmap(Bitmap bitmap, int color) {
5917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        Bitmap dst = bitmap.copy(bitmap.getConfig(), true);
5927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        Canvas canvas = new Canvas(dst);
5937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        Paint paint = new Paint();
5947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
5957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        canvas.drawBitmap(bitmap, 0, 0, paint);
5967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return dst;
5977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
5987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
59946443cb5b092f1d9156342645088eead9da026f6Dake Gu    private static int getIconHighlightColor(Context context) {
60019025301f907b7b706bec652304b39761086e39bCraig Stout        TypedValue outValue = new TypedValue();
60146443cb5b092f1d9156342645088eead9da026f6Dake Gu        if (context.getTheme().resolveAttribute(R.attr.playbackControlsIconHighlightColor,
60246443cb5b092f1d9156342645088eead9da026f6Dake Gu                outValue, true)) {
60346443cb5b092f1d9156342645088eead9da026f6Dake Gu            return outValue.data;
60446443cb5b092f1d9156342645088eead9da026f6Dake Gu        }
60546443cb5b092f1d9156342645088eead9da026f6Dake Gu        return context.getResources().getColor(R.color.lb_playback_icon_highlight_no_theme);
60619025301f907b7b706bec652304b39761086e39bCraig Stout    }
60719025301f907b7b706bec652304b39761086e39bCraig Stout
60819025301f907b7b706bec652304b39761086e39bCraig Stout    private static Drawable getStyledDrawable(Context context, int index) {
60919025301f907b7b706bec652304b39761086e39bCraig Stout        TypedValue outValue = new TypedValue();
61046443cb5b092f1d9156342645088eead9da026f6Dake Gu        if (!context.getTheme().resolveAttribute(
61146443cb5b092f1d9156342645088eead9da026f6Dake Gu                R.attr.playbackControlsActionIcons, outValue, false)) {
61246443cb5b092f1d9156342645088eead9da026f6Dake Gu            return null;
61346443cb5b092f1d9156342645088eead9da026f6Dake Gu        }
61419025301f907b7b706bec652304b39761086e39bCraig Stout        TypedArray array = context.getTheme().obtainStyledAttributes(outValue.data,
61519025301f907b7b706bec652304b39761086e39bCraig Stout                R.styleable.lbPlaybackControlsActionIcons);
61619025301f907b7b706bec652304b39761086e39bCraig Stout        Drawable drawable = array.getDrawable(index);
61719025301f907b7b706bec652304b39761086e39bCraig Stout        array.recycle();
61819025301f907b7b706bec652304b39761086e39bCraig Stout        return drawable;
61919025301f907b7b706bec652304b39761086e39bCraig Stout    }
62019025301f907b7b706bec652304b39761086e39bCraig Stout
6217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private Object mItem;
6227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private Drawable mImageDrawable;
6237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private ObjectAdapter mPrimaryActionsAdapter;
6247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private ObjectAdapter mSecondaryActionsAdapter;
6256dca725412977bb56b933bdec120e31909233cdbCraig Stout    private int mTotalTimeMs;
6266dca725412977bb56b933bdec120e31909233cdbCraig Stout    private int mCurrentTimeMs;
6276dca725412977bb56b933bdec120e31909233cdbCraig Stout    private int mBufferedProgressMs;
6286dca725412977bb56b933bdec120e31909233cdbCraig Stout    private OnPlaybackStateChangedListener mListener;
6297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
6307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
6317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Constructor for a PlaybackControlsRow that displays some details from
6327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * the given item.
6337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     *
6347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * @param item The main item for the row.
6357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
6367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public PlaybackControlsRow(Object item) {
6377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mItem = item;
6387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
6397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
6407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
6417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Constructor for a PlaybackControlsRow that has no item details.
6427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
6437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public PlaybackControlsRow() {
6447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
6457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
6467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
647a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * Returns the main item for the details page.
6487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
6497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public final Object getItem() {
6507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mItem;
6517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
6527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
6537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
6547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets a {link @Drawable} image for this row.
655a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * <p>If set after the row has been bound to a view, the adapter must be notified that
656a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * this row has changed.</p>
6577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     *
6587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * @param drawable The drawable to set.
6597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
6607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public final void setImageDrawable(Drawable drawable) {
6617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mImageDrawable = drawable;
6627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
6637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
6647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
6657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets a {@link Bitmap} for this row.
666a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * <p>If set after the row has been bound to a view, the adapter must be notified that
667a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * this row has changed.</p>
6687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     *
6697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * @param context The context to retrieve display metrics from.
6707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * @param bm The bitmap to set.
6717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
6727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public final void setImageBitmap(Context context, Bitmap bm) {
6737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mImageDrawable = new BitmapDrawable(context.getResources(), bm);
6747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
6757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
6767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
677a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * Returns the image {@link Drawable} of this row.
6787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     *
6797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * @return The overview's image drawable, or null if no drawable has been
6807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     *         assigned.
6817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
6827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public final Drawable getImageDrawable() {
6837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mImageDrawable;
6847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
6857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
6867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
6877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets the primary actions {@link ObjectAdapter}.
688a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * <p>If set after the row has been bound to a view, the adapter must be notified that
689a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * this row has changed.</p>
6907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
6917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public final void setPrimaryActionsAdapter(ObjectAdapter adapter) {
6927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPrimaryActionsAdapter = adapter;
6937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
6947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
6957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
6967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets the secondary actions {@link ObjectAdapter}.
697a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * <p>If set after the row has been bound to a view, the adapter must be notified that
698a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * this row has changed.</p>
6997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
7007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public final void setSecondaryActionsAdapter(ObjectAdapter adapter) {
7017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryActionsAdapter = adapter;
7027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
7037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
7047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
7057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Returns the primary actions {@link ObjectAdapter}.
7067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
7077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public final ObjectAdapter getPrimaryActionsAdapter() {
7087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mPrimaryActionsAdapter;
7097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
7107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
7117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
7127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Returns the secondary actions {@link ObjectAdapter}.
7137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
7147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public final ObjectAdapter getSecondaryActionsAdapter() {
7157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mSecondaryActionsAdapter;
7167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
7176dca725412977bb56b933bdec120e31909233cdbCraig Stout
7186dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
7196dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Sets the total time in milliseconds for the playback controls row.
720a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * <p>If set after the row has been bound to a view, the adapter must be notified that
721a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * this row has changed.</p>
7226dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
7236dca725412977bb56b933bdec120e31909233cdbCraig Stout    public void setTotalTime(int ms) {
7246dca725412977bb56b933bdec120e31909233cdbCraig Stout        mTotalTimeMs = ms;
7256dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
7266dca725412977bb56b933bdec120e31909233cdbCraig Stout
7276dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
7286dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Returns the total time in milliseconds for the playback controls row.
7296dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
7306dca725412977bb56b933bdec120e31909233cdbCraig Stout    public int getTotalTime() {
7316dca725412977bb56b933bdec120e31909233cdbCraig Stout        return mTotalTimeMs;
7326dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
7336dca725412977bb56b933bdec120e31909233cdbCraig Stout
7346dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
7356dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Sets the current time in milliseconds for the playback controls row.
736eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout     * If this row is bound to a view, the view will automatically
737eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout     * be updated to reflect the new value.
7386dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
7396dca725412977bb56b933bdec120e31909233cdbCraig Stout    public void setCurrentTime(int ms) {
7406dca725412977bb56b933bdec120e31909233cdbCraig Stout        if (mCurrentTimeMs != ms) {
7416dca725412977bb56b933bdec120e31909233cdbCraig Stout            mCurrentTimeMs = ms;
7426dca725412977bb56b933bdec120e31909233cdbCraig Stout            currentTimeChanged();
7436dca725412977bb56b933bdec120e31909233cdbCraig Stout        }
7446dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
7456dca725412977bb56b933bdec120e31909233cdbCraig Stout
7466dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
7476dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Returns the current time in milliseconds for the playback controls row.
7486dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
7496dca725412977bb56b933bdec120e31909233cdbCraig Stout    public int getCurrentTime() {
7506dca725412977bb56b933bdec120e31909233cdbCraig Stout        return mCurrentTimeMs;
7516dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
7526dca725412977bb56b933bdec120e31909233cdbCraig Stout
7536dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
7546dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Sets the buffered progress for the playback controls row.
755eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout     * If this row is bound to a view, the view will automatically
756eb66dab544c4c1eabe4d469b7cea348d4b01e664Craig Stout     * be updated to reflect the new value.
7576dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
7586dca725412977bb56b933bdec120e31909233cdbCraig Stout    public void setBufferedProgress(int ms) {
7596dca725412977bb56b933bdec120e31909233cdbCraig Stout        if (mBufferedProgressMs != ms) {
7606dca725412977bb56b933bdec120e31909233cdbCraig Stout            mBufferedProgressMs = ms;
7616dca725412977bb56b933bdec120e31909233cdbCraig Stout            bufferedProgressChanged();
7626dca725412977bb56b933bdec120e31909233cdbCraig Stout        }
7636dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
7646dca725412977bb56b933bdec120e31909233cdbCraig Stout
7656dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
7666dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Returns the buffered progress for the playback controls row.
7676dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
7686dca725412977bb56b933bdec120e31909233cdbCraig Stout    public int getBufferedProgress() {
7696dca725412977bb56b933bdec120e31909233cdbCraig Stout        return mBufferedProgressMs;
7706dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
7716dca725412977bb56b933bdec120e31909233cdbCraig Stout
77260bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout    /**
77360bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout     * Returns the Action associated with the given keycode, or null if no associated action exists.
77460bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout     * Searches the primary adapter first, then the secondary adapter.
77560bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout     */
77660bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout    public Action getActionForKeyCode(int keyCode) {
77760bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout        Action action = getActionForKeyCode(getPrimaryActionsAdapter(), keyCode);
77860bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout        if (action != null) {
77960bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            return action;
78060bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout        }
78160bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout        return getActionForKeyCode(getSecondaryActionsAdapter(), keyCode);
78260bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout    }
78360bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout
78460bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout    /**
78560bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout     * Returns the Action associated with the given keycode, or null if no associated action exists.
78660bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout     */
78760bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout    public Action getActionForKeyCode(ObjectAdapter adapter, int keyCode) {
78860bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout        if (adapter != mPrimaryActionsAdapter && adapter != mSecondaryActionsAdapter) {
78960bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            throw new IllegalArgumentException("Invalid adapter");
79060bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout        }
79160bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout        for (int i = 0; i < adapter.size(); i++) {
79260bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            Action action = (Action) adapter.get(i);
79360bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            if (action.respondsToKeyCode(keyCode)) {
79460bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout                return action;
79560bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout            }
79660bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout        }
79760bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout        return null;
79860bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout    }
79960bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout
8006dca725412977bb56b933bdec120e31909233cdbCraig Stout    interface OnPlaybackStateChangedListener {
8016dca725412977bb56b933bdec120e31909233cdbCraig Stout        public void onCurrentTimeChanged(int currentTimeMs);
8026dca725412977bb56b933bdec120e31909233cdbCraig Stout        public void onBufferedProgressChanged(int bufferedProgressMs);
8036dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
8046dca725412977bb56b933bdec120e31909233cdbCraig Stout
8056dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
8066dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Sets a listener to be called when the playback state changes.
8076dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
808b17fd9f977350717ba91e1d23a7296b69c02aa25Craig Stout    void setOnPlaybackStateChangedListener(OnPlaybackStateChangedListener listener) {
8096dca725412977bb56b933bdec120e31909233cdbCraig Stout        mListener = listener;
8106dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
8116dca725412977bb56b933bdec120e31909233cdbCraig Stout
8126dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
8136dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Returns the playback state listener.
8146dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
815b17fd9f977350717ba91e1d23a7296b69c02aa25Craig Stout    OnPlaybackStateChangedListener getOnPlaybackStateChangedListener() {
8166dca725412977bb56b933bdec120e31909233cdbCraig Stout        return mListener;
8176dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
8186dca725412977bb56b933bdec120e31909233cdbCraig Stout
8196dca725412977bb56b933bdec120e31909233cdbCraig Stout    private void currentTimeChanged() {
8206dca725412977bb56b933bdec120e31909233cdbCraig Stout        if (mListener != null) {
8216dca725412977bb56b933bdec120e31909233cdbCraig Stout            mListener.onCurrentTimeChanged(mCurrentTimeMs);
8226dca725412977bb56b933bdec120e31909233cdbCraig Stout        }
8236dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
8246dca725412977bb56b933bdec120e31909233cdbCraig Stout
8256dca725412977bb56b933bdec120e31909233cdbCraig Stout    private void bufferedProgressChanged() {
8266dca725412977bb56b933bdec120e31909233cdbCraig Stout        if (mListener != null) {
8276dca725412977bb56b933bdec120e31909233cdbCraig Stout            mListener.onBufferedProgressChanged(mBufferedProgressMs);
8286dca725412977bb56b933bdec120e31909233cdbCraig Stout        }
8296dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
8307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout}
831