Applied latest source code
[apps/native/preloaded/MusicPlayer.git] / src / MpNowPlayContentPanel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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
17 /**
18  * @file                MpNowPlayContentPanel.cpp
19  * @brief               This is the implementation file for NowPlayContentPanel class.
20  */
21
22 #include "MpNowPlayContentPanel.h"
23 #include "MpResourceManager.h"
24
25 using namespace Tizen::App;
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::Content;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Io;
31 using namespace Tizen::Media;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 static const Tizen::Graphics::Rectangle RECT_MUSIC_THUMBNAIL (32, 22, 76, 76);
37 static const Tizen::Graphics::Rectangle RECT_MUSIC_TOUCH (140, 0, 590, 120);
38 static const Tizen::Graphics::Rectangle RECT_MUSIC_TITLE (140, 5, 550, 38);
39 static const Tizen::Graphics::Rectangle RECT_SLIDER (120, 0, 600,120);
40
41 static const Tizen::Graphics::Color COLOR_NOW_PLAY_TITLE (90, 99, 104);
42
43 static const Tizen::Base::String PLAYING_ICON_PLAY = L"T02_now_playing_icon_play.png";
44 static const Tizen::Base::String PLAYING_ICON_PAUSE = L"T02_now_playing_icon_pause.png";
45
46 static const Tizen::Base::String PLAYING_TEXT = L"PlayIcon";
47 static const Tizen::Base::String PLAY_FORM_TEXT = L"PlayForm";
48
49 static const int SLIDER_MAX_VALUE = 100;
50
51 NowPlayContentPanel::NowPlayContentPanel(void)
52 {
53         AppLogDebug("ENTER");
54         AppLogDebug("EXIT");
55 }
56
57 NowPlayContentPanel::~NowPlayContentPanel(void)
58 {
59         AppLogDebug("ENTER");
60         if (__pPresentationModel != null)
61         {
62                 __pPresentationModel->RemoveMusicPlayerEventListener(*this);
63         }
64         AppLogDebug("EXIT");
65 }
66
67 result
68 NowPlayContentPanel::Initialize(void)
69 {
70         AppLogDebug("ENTER");
71         result r = E_SUCCESS;
72
73         __pPresentationModel = PlayerPresentationModel::GetInstance();
74
75         r = Construct(Rectangle(INIT_VALUE, INIT_VALUE, W_NOW_PLAY_BAR, H_NOW_PLAY_BAR));
76         if (IsFailed(r))
77         {
78                 AppLogDebug("EXIT");
79                 return E_INVALID_STATE;
80         }
81
82 //      SetBackgroundColor(COLOR_NOW_PLAY_PANEL);
83
84         __pThumbnailLabel = new (std::nothrow) Label();
85         __pThumbnailLabel->Construct(RECT_MUSIC_THUMBNAIL, L"");
86
87         __pPlayStatusLabel = new (std::nothrow) Label();
88         __pPlayStatusLabel->Construct(RECT_MUSIC_THUMBNAIL, L"");
89         __pPlayStatusLabel->SetName(PLAYING_TEXT);
90         __pPlayStatusLabel->AddTouchEventListener(*this);
91
92         __pTitleLabel = new (std::nothrow) Label();
93         __pTitleLabel->Construct(RECT_MUSIC_TITLE, L"");
94         __pTitleLabel->SetTextColor(COLOR_NOW_PLAY_TITLE);
95         __pTitleLabel->SetTextConfig(FONT_SIZE, LABEL_TEXT_STYLE_NORMAL);
96         __pTitleLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
97
98         __pPlayStateSlider = new (std::nothrow) Slider();
99         __pPlayStateSlider->Construct(RECT_SLIDER, BACKGROUND_STYLE_NONE, false, INIT_VALUE, SLIDER_MAX_VALUE);
100         __pPlayStateSlider->SetBarColor(Color::GetColor(COLOR_ID_WHITE));
101         __pPlayStateSlider->SetColor(Color::GetColor(COLOR_ID_BLUE));
102
103         __pTouchLabel = new (std::nothrow) Label();
104         __pTouchLabel->Construct(RECT_MUSIC_TOUCH, L"");
105         __pTouchLabel->SetName(PLAY_FORM_TEXT);
106         __pTouchLabel->AddTouchEventListener(*this);
107
108         AddControl(__pPlayStateSlider);
109         AddControl(__pThumbnailLabel);
110         AddControl(__pPlayStatusLabel);
111         AddControl(__pTitleLabel);
112         AddControl(__pTouchLabel);
113
114         __pPresentationModel->AddMusicPlayerEventListener(*this);
115
116         Bitmap* SongThumbnail = null;
117         String songTitle;
118         String songArtist;
119         int SongDuration = 0;
120
121         SongThumbnail = __pPresentationModel->GetPlayContentThumbnail();
122         songTitle = *__pPresentationModel->GetPlayContentTitle();
123         songArtist = *__pPresentationModel->GetPlayContentArtist();
124         SongDuration = __pPresentationModel->GetPlayContentDuration();
125
126         String titleBar;
127         titleBar.Format(STRING_LENGTH, L"%ls / %ls", songTitle.GetPointer(), songArtist.GetPointer());
128
129         __pThumbnailLabel->SetBackgroundBitmap(*SongThumbnail);
130
131         switch (__pPresentationModel->GetPlayerState())
132         {
133         case PLAYER_STATE_PLAYING:
134                 {
135                         __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PAUSE));
136                 }
137                 break;
138
139         case PLAYER_STATE_PAUSED:
140                 {
141                         __pPresentationModel->Pause();
142                         __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PLAY));
143                 }
144                 break;
145
146         default:
147                 break;
148         }
149
150         __pTitleLabel->SetText(titleBar);
151
152         __pPlayStateSlider->SetRange(INIT_VALUE, SLIDER_MAX_VALUE);
153         __pPlayStateSlider->SetValue(__pPresentationModel->GetPlayPosition());
154         __pPlayStateSlider->SetEnabled(false);
155         __pPlayStateSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_NORMAL, *ResourceManager::GetBitmapN(L"T02_player_progress_handle.png"));
156         __pPlayStateSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_DISABLED, *ResourceManager::GetBitmapN(L"T02_player_progress_handle.png"));
157         __pPlayStateSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_NORMAL, Color(255, 255, 255, 0));
158         __pPlayStateSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_DISABLED, Color(255, 255, 255, 0));
159
160         Invalidate(true);
161         AppLogDebug("EXIT");
162         return r;
163 }
164
165 bool
166 NowPlayContentPanel::GetPlayStatus(void)
167 {
168         AppLogDebug("ENTER");
169
170         bool StatusDisplay = true;
171
172         switch (__pPresentationModel->GetPlayerState())
173         {
174         case PLAYER_STATE_PAUSED:
175                 // fall through
176         case PLAYER_STATE_PLAYING:
177                 // fall through
178         case PLAYER_STATE_OPENING:
179                 {
180                         SetShowState(true);
181                 }
182                 break;
183
184         default:
185                 {
186                         SetShowState(false);
187                         StatusDisplay = false;
188                 }
189                 break;
190         }
191
192         Invalidate(true);
193         AppLogDebug("EXIT");
194         return StatusDisplay;
195 }
196
197 void
198 NowPlayContentPanel::OnPlayStateChanged(Tizen::Media::PlayerState playerState)
199 {
200         AppLogDebug("ENTER");
201         if (playerState == PLAYER_STATE_PLAYING)
202         {
203                 __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PAUSE));
204         }
205         else
206         {
207                 __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PLAY));
208         }
209         __pPlayStatusLabel->Invalidate(true);
210         AppLogDebug("EXIT");
211 }
212
213 void
214 NowPlayContentPanel::OnPlayContentChanged(int currentContentIndex)
215 {
216         AppLogDebug("ENTER");
217         ContentInformation* pContentInfoStruct = __pPresentationModel->GetContentInfoN(currentContentIndex);
218         if (pContentInfoStruct == null)
219         {
220                 return;
221         }
222
223         Bitmap* pAlbumArt = __pPresentationModel->GetContentAlbumArtN(currentContentIndex);
224
225         String titleBar;
226         titleBar.Format(STRING_LENGTH, L"%ls / %ls", pContentInfoStruct->TitleName.GetPointer(), pContentInfoStruct->ArtistName.GetPointer());
227
228         __pThumbnailLabel->SetBackgroundBitmap(*pAlbumArt);
229         __pThumbnailLabel->Invalidate(true);
230
231         __pTitleLabel->SetText(titleBar);
232         __pTitleLabel->Invalidate(true);
233
234         __pPlayStateSlider->SetRange(INIT_VALUE, SLIDER_MAX_VALUE);
235
236         delete pContentInfoStruct;
237         pContentInfoStruct = null;
238
239         delete pAlbumArt;
240         pAlbumArt = null;
241         AppLogDebug("EXIT");
242 }
243
244 void
245 NowPlayContentPanel::OnPlayTimeChanged(const Tizen::Base::String& currentDuration, int currentPosition)
246 {
247         AppLogDebug("ENTER");
248         __pPlayStateSlider->SetValue(currentPosition);
249         __pPlayStateSlider->Invalidate(true);
250         AppLogDebug("EXIT");
251 }
252
253 void
254 NowPlayContentPanel::OnPlayVolumeBarStateChanged(void)
255 {
256         AppLogDebug("ENTER");
257         AppLogDebug("EXIT");
258 }
259
260 void
261 NowPlayContentPanel::OnPlayPresentationModelDestroying(void)
262 {
263         AppLogDebug("ENTER");
264         if (__pPresentationModel != null)
265         {
266                 __pPresentationModel = null;
267         }
268         AppLogDebug("EXIT");
269 }
270
271 void
272 NowPlayContentPanel::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
273 {
274         AppLogDebug("ENTER");
275         if (__pPresentationModel == null)
276         {
277                 return;
278         }
279
280         if (source.GetName().Equals(PLAYING_TEXT, true))
281         {
282                 switch (__pPresentationModel->GetPlayerState())
283                 {
284                 case PLAYER_STATE_PLAYING:
285                         {
286                                 __pPresentationModel->Pause();
287 //                              __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PLAY));
288                         }
289                         break;
290
291 /*              case PLAYER_STATE_PAUSED:
292                         // fall through
293                 case PLAYER_STATE_ENDOFCLIP:
294                         {
295                                 __pPresentationModel->Play(__pPresentationModel->GetCurrentContentIndex(), __pPlayStateSlider->GetValue(), true);
296                                 __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PAUSE));
297                         }
298                         break;
299 */
300
301                 default:
302                         {
303                                 __pPresentationModel->Play(__pPresentationModel->GetCurrentContentIndex(), __pPlayStateSlider->GetValue(), true);
304                         }
305                         break;
306                 }
307                 Invalidate(true);
308         }
309         else if (source.GetName().Equals(PLAY_FORM_TEXT, true))
310         {
311                 SceneManager* pSceneManager = SceneManager::GetInstance();
312                 AppAssert(pSceneManager);
313
314                 if (pSceneManager->GetCurrentSceneId().Equals(IDSCN_MUSIC_SETTING, true))
315                 {
316                         IListT<SceneId>* sceneList = pSceneManager->GetSceneHistoryN();
317
318                         IEnumeratorT<SceneId>* pEnum = sceneList->GetEnumeratorN();
319                         SceneId sceneID;
320                         while (pEnum->MoveNext() == E_SUCCESS)
321                         {
322                                 pEnum->GetCurrent(sceneID);
323
324                                 if (sceneID.Equals(SceneId(IDSCN_PLAYER)) == false)
325                                 {
326                                         pSceneManager->AddToSceneHistory(sceneID);
327                                 }
328                         }
329                         delete pEnum;
330                         delete sceneList;
331
332                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER, SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY));
333                 }
334                 else
335                 {
336                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER));
337                 }
338         }
339         AppLogDebug("EXIT");
340 }
341
342 void
343 NowPlayContentPanel::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
344 {
345         AppLogDebug("ENTER");
346         AppLogDebug("EXIT");
347 }
348
349 void
350 NowPlayContentPanel::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
351 {
352         AppLogDebug("ENTER");
353         AppLogDebug("EXIT");
354 }
355
356 void
357 NowPlayContentPanel::OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
358 {
359         AppLogDebug("ENTER");
360         AppLogDebug("EXIT");
361 }
362
363 void
364 NowPlayContentPanel::OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
365 {
366         AppLogDebug("ENTER");
367         AppLogDebug("EXIT");
368 }
369
370 void
371 NowPlayContentPanel::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
372 {
373         AppLogDebug("ENTER");
374         AppLogDebug("EXIT");
375 }