• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.car.stream;
17 
18 import android.app.PendingIntent;
19 import android.graphics.Bitmap;
20 import android.os.Bundle;
21 
22 /**
23  * An extension to {@link StreamCard} that holds data for media playback controls.
24  */
25 public class MediaPlaybackExtension extends StreamCardExtension {
26     private static final String TITLE_KEY = "title_key";
27     private static final String SUBTITLE_KEY = "subtitle_key";
28     private static final String ALBUM_ART_ICON_KEY = "album_art_icon";
29     private static final String ACCENT_COLOR_KEY = "accent_color";
30     private static final String CAN_SKIP_TO_NEXT_KEY = "can_skip_to_next";
31     private static final String CAN_SKIP_TO_PREV_KEY = "can_skip_to_prev";
32     private static final String HAS_PAUSE_KEY = "has_pause";
33     private static final String IS_PLAYING_KEY = "is_playing";
34     private static final String APP_NAME_KEY = "app_name";
35 
36     private static final String SKIP_TO_NEXT_ACTION_KEY = "skip_to_next_action";
37     private static final String SKIP_TO_PREVIOUS_ACTION_KEY = "skip_to_previous_action";
38     private static final String PLAY_ACTION_KEY = "play_action";
39     private static final String PAUSE_ACTION_KEY = "pause_action";
40     private static final String STOP_ACTION_KEY = "stop_action";
41 
42     private String mTitle;
43     private String mSubTitle;
44     private Bitmap mAlbumArt;
45     private int mAppAccentColor;
46     private String mAppName;
47 
48     private boolean mCanSkipToNext = false;
49     private boolean mCanSkipToPrevious = false;
50     private boolean mHasPause = false;
51     private boolean mIsPlaying = false;
52 
53     private PendingIntent mPauseAction;
54     private PendingIntent mSkipToNextAction;
55     private PendingIntent mSkipToPreviousAction;
56     private PendingIntent mPlayAction;
57     private PendingIntent mStopAction;
58 
59     public static final Creator<MediaPlaybackExtension> CREATOR
60             = new BundleableCreator<>(MediaPlaybackExtension.class);
61 
MediaPlaybackExtension()62     public MediaPlaybackExtension() {}
63 
MediaPlaybackExtension( String title, String subtitle, Bitmap albumArt, int appAccentColor, boolean canSkipToNext, boolean canSkipToPrevious, boolean hasPause, boolean isPlaying, String appName, PendingIntent stopAction, PendingIntent pauseAction, PendingIntent playAction, PendingIntent skipToNextAction, PendingIntent skipToPreviousAction)64     public MediaPlaybackExtension(
65             String title,
66             String subtitle,
67             Bitmap albumArt,
68             int appAccentColor,
69             boolean canSkipToNext,
70             boolean canSkipToPrevious,
71             boolean hasPause,
72             boolean isPlaying,
73             String appName,
74             PendingIntent stopAction,
75             PendingIntent pauseAction,
76             PendingIntent playAction,
77             PendingIntent skipToNextAction,
78             PendingIntent skipToPreviousAction) {
79 
80         mTitle = title;
81         mSubTitle = subtitle;
82         mAlbumArt = albumArt;
83         mAppAccentColor = appAccentColor;
84         mCanSkipToNext = canSkipToNext;
85         mCanSkipToPrevious = canSkipToPrevious;
86         mHasPause = hasPause;
87         mIsPlaying = isPlaying;
88         mAppName = appName;
89 
90         mStopAction = stopAction;
91         mPauseAction = pauseAction;
92         mPlayAction = playAction;
93         mSkipToNextAction = skipToNextAction;
94         mSkipToPreviousAction = skipToPreviousAction;
95     }
96 
getTitle()97     public String getTitle() {
98         return mTitle;
99     }
100 
getSubtitle()101     public String getSubtitle() {
102         return mSubTitle;
103     }
104 
getAlbumArt()105     public Bitmap getAlbumArt() {
106         return mAlbumArt;
107     }
108 
getAppAccentColor()109     public int getAppAccentColor() {
110         return mAppAccentColor;
111     }
112 
canSkipToNext()113     public boolean canSkipToNext() {
114         return mCanSkipToNext;
115     }
116 
canSkipToPrevious()117     public boolean canSkipToPrevious() {
118         return mCanSkipToPrevious;
119     }
120 
hasPause()121     public boolean hasPause() {
122         return mHasPause;
123     }
124 
isPlaying()125     public boolean isPlaying() {
126         return mIsPlaying;
127     }
128 
getAppName()129     public String getAppName() {
130         return mAppName;
131     }
132 
getStopAction()133     public PendingIntent getStopAction() {
134         return mStopAction;
135     }
136 
getPlayAction()137     public PendingIntent getPlayAction() {
138         return mPlayAction;
139     }
140 
getSkipToPreviousAction()141     public PendingIntent getSkipToPreviousAction() {
142         return mSkipToPreviousAction;
143     }
144 
getSkipToNextAction()145     public PendingIntent getSkipToNextAction() {
146         return mSkipToNextAction;
147     }
148 
getPauseAction()149     public PendingIntent getPauseAction() {
150         return mPauseAction;
151     }
152 
153     @Override
writeToBundle(Bundle bundle)154     protected void writeToBundle(Bundle bundle) {
155         bundle.putString(TITLE_KEY, mTitle);
156         bundle.putString(SUBTITLE_KEY, mSubTitle);
157         bundle.putParcelable(ALBUM_ART_ICON_KEY, mAlbumArt);
158         bundle.putBoolean(CAN_SKIP_TO_NEXT_KEY, mCanSkipToNext);
159         bundle.putBoolean(CAN_SKIP_TO_PREV_KEY, mCanSkipToPrevious);
160         bundle.putBoolean(HAS_PAUSE_KEY, mHasPause);
161         bundle.putBoolean(IS_PLAYING_KEY, mIsPlaying);
162         bundle.putInt(ACCENT_COLOR_KEY, mAppAccentColor);
163         bundle.putString(APP_NAME_KEY, mAppName);
164 
165         bundle.putParcelable(STOP_ACTION_KEY, mStopAction);
166         bundle.putParcelable(PLAY_ACTION_KEY, mPlayAction);
167         bundle.putParcelable(PAUSE_ACTION_KEY, mPauseAction);
168         bundle.putParcelable(SKIP_TO_NEXT_ACTION_KEY, mSkipToNextAction);
169         bundle.putParcelable(SKIP_TO_PREVIOUS_ACTION_KEY, mSkipToPreviousAction);
170     }
171 
172     @Override
readFromBundle(Bundle bundle)173     protected void readFromBundle(Bundle bundle) {
174         mTitle = bundle.getString(TITLE_KEY);
175         mSubTitle = bundle.getString(SUBTITLE_KEY);
176         mAlbumArt = bundle.getParcelable(ALBUM_ART_ICON_KEY);
177         mCanSkipToNext = bundle.getBoolean(CAN_SKIP_TO_NEXT_KEY);
178         mCanSkipToPrevious = bundle.getBoolean(CAN_SKIP_TO_PREV_KEY);
179         mHasPause = bundle.getBoolean(HAS_PAUSE_KEY);
180         mIsPlaying = bundle.getBoolean(IS_PLAYING_KEY);
181         mAppAccentColor = bundle.getInt(ACCENT_COLOR_KEY);
182         mAppName = bundle.getString(APP_NAME_KEY);
183 
184         mStopAction = bundle.getParcelable(STOP_ACTION_KEY);
185         mPlayAction = bundle.getParcelable(PLAY_ACTION_KEY);
186         mPauseAction = bundle.getParcelable(PAUSE_ACTION_KEY);
187         mSkipToNextAction = bundle.getParcelable(SKIP_TO_NEXT_ACTION_KEY);
188         mSkipToPreviousAction = bundle.getParcelable(SKIP_TO_PREVIOUS_ACTION_KEY);
189     }
190 }
191