2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file MpNowPlayContentPanel.cpp
19 * @brief This is the implementation file for NowPlayContentPanel class.
22 #include "MpNowPlayContentPanel.h"
23 #include "MpResourceManager.h"
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;
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);
41 static const Tizen::Graphics::Color COLOR_NOW_PLAY_TITLE (90, 99, 104);
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";
46 static const Tizen::Base::String PLAYING_TEXT = L"PlayIcon";
47 static const Tizen::Base::String PLAY_FORM_TEXT = L"PlayForm";
49 static const int SLIDER_MAX_VALUE = 100;
51 NowPlayContentPanel::NowPlayContentPanel(void)
57 NowPlayContentPanel::~NowPlayContentPanel(void)
60 if (__pPresentationModel != null)
62 __pPresentationModel->RemoveMusicPlayerEventListener(*this);
68 NowPlayContentPanel::Initialize(void)
73 __pPresentationModel = PlayerPresentationModel::GetInstance();
75 r = Construct(Rectangle(INIT_VALUE, INIT_VALUE, W_NOW_PLAY_BAR, H_NOW_PLAY_BAR));
79 return E_INVALID_STATE;
82 // SetBackgroundColor(COLOR_NOW_PLAY_PANEL);
84 __pThumbnailLabel = new (std::nothrow) Label();
85 __pThumbnailLabel->Construct(RECT_MUSIC_THUMBNAIL, L"");
87 __pPlayStatusLabel = new (std::nothrow) Label();
88 __pPlayStatusLabel->Construct(RECT_MUSIC_THUMBNAIL, L"");
89 __pPlayStatusLabel->SetName(PLAYING_TEXT);
90 __pPlayStatusLabel->AddTouchEventListener(*this);
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);
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));
103 __pTouchLabel = new (std::nothrow) Label();
104 __pTouchLabel->Construct(RECT_MUSIC_TOUCH, L"");
105 __pTouchLabel->SetName(PLAY_FORM_TEXT);
106 __pTouchLabel->AddTouchEventListener(*this);
108 AddControl(__pPlayStateSlider);
109 AddControl(__pThumbnailLabel);
110 AddControl(__pPlayStatusLabel);
111 AddControl(__pTitleLabel);
112 AddControl(__pTouchLabel);
114 __pPresentationModel->AddMusicPlayerEventListener(*this);
116 Bitmap* SongThumbnail = null;
119 int SongDuration = 0;
121 SongThumbnail = __pPresentationModel->GetPlayContentThumbnail();
122 songTitle = *__pPresentationModel->GetPlayContentTitle();
123 songArtist = *__pPresentationModel->GetPlayContentArtist();
124 SongDuration = __pPresentationModel->GetPlayContentDuration();
127 titleBar.Format(STRING_LENGTH, L"%ls / %ls", songTitle.GetPointer(), songArtist.GetPointer());
129 __pThumbnailLabel->SetBackgroundBitmap(*SongThumbnail);
131 switch (__pPresentationModel->GetPlayerState())
133 case PLAYER_STATE_PLAYING:
135 __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PAUSE));
139 case PLAYER_STATE_PAUSED:
141 __pPresentationModel->Pause();
142 __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PLAY));
150 __pTitleLabel->SetText(titleBar);
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));
166 NowPlayContentPanel::GetPlayStatus(void)
168 AppLogDebug("ENTER");
170 bool StatusDisplay = true;
172 switch (__pPresentationModel->GetPlayerState())
174 case PLAYER_STATE_PAUSED:
176 case PLAYER_STATE_PLAYING:
178 case PLAYER_STATE_OPENING:
187 StatusDisplay = false;
194 return StatusDisplay;
198 NowPlayContentPanel::OnPlayStateChanged(Tizen::Media::PlayerState playerState)
200 AppLogDebug("ENTER");
201 if (playerState == PLAYER_STATE_PLAYING)
203 __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PAUSE));
207 __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PLAY));
209 __pPlayStatusLabel->Invalidate(true);
214 NowPlayContentPanel::OnPlayContentChanged(int currentContentIndex)
216 AppLogDebug("ENTER");
217 ContentInformation* pContentInfoStruct = __pPresentationModel->GetContentInfoN(currentContentIndex);
218 if (pContentInfoStruct == null)
223 Bitmap* pAlbumArt = __pPresentationModel->GetContentAlbumArtN(currentContentIndex);
226 titleBar.Format(STRING_LENGTH, L"%ls / %ls", pContentInfoStruct->TitleName.GetPointer(), pContentInfoStruct->ArtistName.GetPointer());
228 __pThumbnailLabel->SetBackgroundBitmap(*pAlbumArt);
229 __pThumbnailLabel->Invalidate(true);
231 __pTitleLabel->SetText(titleBar);
232 __pTitleLabel->Invalidate(true);
234 __pPlayStateSlider->SetRange(INIT_VALUE, SLIDER_MAX_VALUE);
236 delete pContentInfoStruct;
237 pContentInfoStruct = null;
245 NowPlayContentPanel::OnPlayTimeChanged(const Tizen::Base::String& currentDuration, int currentPosition)
247 AppLogDebug("ENTER");
248 __pPlayStateSlider->SetValue(currentPosition);
249 __pPlayStateSlider->Invalidate(true);
254 NowPlayContentPanel::OnPlayVolumeBarStateChanged(void)
256 AppLogDebug("ENTER");
261 NowPlayContentPanel::OnPlayPresentationModelDestroying(void)
263 AppLogDebug("ENTER");
264 if (__pPresentationModel != null)
266 __pPresentationModel = null;
272 NowPlayContentPanel::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
274 AppLogDebug("ENTER");
275 if (__pPresentationModel == null)
280 if (source.GetName().Equals(PLAYING_TEXT, true))
282 switch (__pPresentationModel->GetPlayerState())
284 case PLAYER_STATE_PLAYING:
286 __pPresentationModel->Pause();
287 // __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PLAY));
291 /* case PLAYER_STATE_PAUSED:
293 case PLAYER_STATE_ENDOFCLIP:
295 __pPresentationModel->Play(__pPresentationModel->GetCurrentContentIndex(), __pPlayStateSlider->GetValue(), true);
296 __pPlayStatusLabel->SetBackgroundBitmap(*ResourceManager::GetBitmapN(PLAYING_ICON_PAUSE));
303 __pPresentationModel->Play(__pPresentationModel->GetCurrentContentIndex(), __pPlayStateSlider->GetValue(), true);
309 else if (source.GetName().Equals(PLAY_FORM_TEXT, true))
311 SceneManager* pSceneManager = SceneManager::GetInstance();
312 AppAssert(pSceneManager);
314 if (pSceneManager->GetCurrentSceneId().Equals(IDSCN_MUSIC_SETTING, true))
316 IListT<SceneId>* sceneList = pSceneManager->GetSceneHistoryN();
318 IEnumeratorT<SceneId>* pEnum = sceneList->GetEnumeratorN();
320 while (pEnum->MoveNext() == E_SUCCESS)
322 pEnum->GetCurrent(sceneID);
324 if (sceneID.Equals(SceneId(IDSCN_PLAYER)) == false)
326 pSceneManager->AddToSceneHistory(sceneID);
332 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER, SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY));
336 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER));
343 NowPlayContentPanel::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
345 AppLogDebug("ENTER");
350 NowPlayContentPanel::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
352 AppLogDebug("ENTER");
357 NowPlayContentPanel::OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
359 AppLogDebug("ENTER");
364 NowPlayContentPanel::OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
366 AppLogDebug("ENTER");
371 NowPlayContentPanel::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
373 AppLogDebug("ENTER");