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 StWallpaperAlbumListForm.cpp
19 * @brief This is the implementation file for WallpaperAlbumListForm class.
22 #include "StSettingScenesList.h"
24 #include "StWallpaperAlbumListForm.h"
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::System;
30 using namespace Tizen::Ui;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Scenes;
34 static const int W_FOLDER_SIZE = 334;
35 static const int H_FOLDER_SIZE = 334;
37 static const int W_LARGE_SIZE_TEXT_GAP = 110;
38 static const int W_HUGE_SIZE_PORTRAIT_TEXT_GAP = 90;
39 static const int W_HUGE_SIZE_LANDSCAPE_TEXT_GAP = 220;
40 static const int LINE_COUNT_DEFAULT = 1;
41 static const int BASE_FORM_DEFAULT_MARGIN = 32;
43 WallpaperAlbumListForm::WallpaperAlbumListForm(void)
45 , __pPresentationModel(null)
46 , __pIconListView(null)
50 WallpaperAlbumListForm::~WallpaperAlbumListForm(void)
55 WallpaperAlbumListForm::Initialize(void)
58 Form::Construct(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
59 SetOrientationAutoMode();
60 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
61 return GetLastResult();
65 WallpaperAlbumListForm::SetOrientationAutoMode(void)
67 this->SetOrientation(ORIENTATION_AUTOMATIC_FOUR_DIRECTION);
68 this->AddOrientationEventListener(*this);
72 WallpaperAlbumListForm::CreateHeader(const Tizen::Base::String& textTitle)
74 Header* pHeader = GetHeader();
76 pHeader->SetStyle(HEADER_STYLE_TITLE);
77 pHeader->SetTitleText(textTitle);
81 WallpaperAlbumListForm::CreateFooter(void)
83 Footer* pFooter = GetFooter();
86 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
88 SetFormBackEventListener(this);
92 WallpaperAlbumListForm::OnInitializing(void)
94 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
99 WallpaperAlbumListForm::OnTerminating(void)
101 AppLogDebug("ENTER");
102 if (__pPresentationModel != null)
104 __pPresentationModel = null;
107 if (__pIconListView != null)
109 __pIconListView = null;
112 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
117 WallpaperAlbumListForm::GetItemCount(void)
123 WallpaperAlbumListForm::CreateItem(int index)
125 AppLogDebug("ENTER : index(%d)", index);
127 Bitmap* pBitmap = __pPresentationModel->CreateMergeBitmapN(index);
131 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
132 pIconListview->Construct(*pBitmap);
136 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
137 return pIconListview;
140 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
145 WallpaperAlbumListForm::DeleteItem(int index, IconListViewItem* pItem)
152 WallpaperAlbumListForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
154 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
156 SceneManager* pSceneManager = SceneManager::GetInstance();
158 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
159 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(index));
160 ArrayList* pAlbumPathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
161 pAlbumPathList->Construct();
164 String allAlbumsString = ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS");
165 pAlbumPathList->Add(new (std::nothrow) String(allAlbumsString));
167 for (int i = 0; i < pAlbumInfo->GetDirectoryCount(); i++)
169 pAlbumPathList->Add(new (std::nothrow) String(pAlbumInfo->GetDirectory(i)));
172 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WALLPAPER_ALBUM_LIST_DETAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pAlbumPathList);
174 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
178 WallpaperAlbumListForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
180 SceneManager* pSceneManager = SceneManager::GetInstance();
181 AppAssert(pSceneManager);
183 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
187 WallpaperAlbumListForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
189 if (__pPresentationModel == null)
191 __pPresentationModel = WallpaperAlbumListPresentationModel::GetInstance();
195 String* selectHomeLock = static_cast<String*>(pArgs->GetAt(0));
196 __pPresentationModel->SetHomeLockArgument(selectHomeLock);
199 __pPresentationModel->InitializeAlbumInfoList();
200 __itemCount = __pPresentationModel->GetFolderCount();
201 UpdateIconListView();
202 CreateHeader(ResourceManager::GetString(L"IDS_MP_BODY_ADD_IMAGE"));
206 WallpaperAlbumListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
211 WallpaperAlbumListForm::CreateIconListView(void)
213 if (__pIconListView != null)
215 __pIconListView->UpdateList();
218 Dimension itemSize(W_FOLDER_SIZE, H_FOLDER_SIZE);
220 __pIconListView = new (std::nothrow) IconListView();
221 __pIconListView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
222 itemSize, ICON_LIST_VIEW_STYLE_NORMAL, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
223 __pIconListView->SetItemProvider(*this);
224 __pIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
225 __pIconListView->AddIconListViewItemEventListener(*this);
227 AddControl(__pIconListView);
233 WallpaperAlbumListForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
235 if (__pIconListView != null)
237 __pIconListView->SetBounds(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
241 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
244 Rectangle clientRect = GetClientAreaBounds();
245 Rectangle labelBound = pLabel->GetBounds();
247 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
248 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
250 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
251 yPos = yPos + pLabel->GetBounds().height;
252 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
253 if (pTextLabel != null)
255 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
263 WallpaperAlbumListForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
265 if (requestId == REFRESH_REQUEST_EVENT)
267 __pPresentationModel->InitializeAlbumInfoList();
268 __itemCount = __pPresentationModel->GetFolderCount();
269 UpdateIconListView();
272 pArgs->RemoveAll(true);
279 WallpaperAlbumListForm::UpdateIconListView(void)
281 bool createIconListView = true;
282 if (__itemCount == 0)
284 createIconListView = false;
286 if (__pIconListView != null)
288 if (createIconListView)
290 __pIconListView->UpdateList();
295 int controlCount = GetControlCount();
296 for (int i = 0; i < controlCount; i++)
298 RemoveControl(GetControl(0));
300 // RemoveAllControls();
302 if (createIconListView)
304 CreateIconListView();
308 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
311 Rectangle clientRect = GetClientAreaBounds();
312 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
314 int bitmapWidth = pBitmp->GetWidth();
315 int bitmapHeight = pBitmp->GetHeight();
316 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
317 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
318 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
320 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
321 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
323 Label* pLabel = new (std::nothrow) Label();
324 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
325 pLabel->SetName(NO_CONTENTS);
326 pLabel->SetBackgroundBitmap(*pBitmp);
328 yPos = yPos + bitmapHeight;
330 Label* pLabelNoContents = new (std::nothrow) Label();
331 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
332 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
333 pLabelNoContents->SetTextColor(textColor);
334 pLabelNoContents->SetText(labelText);
337 AddControl(pLabelNoContents);
343 WallpaperAlbumListForm::GetHeightForStringArea(const Tizen::Base::String source, int width, int fontSize) const
349 int lineCount = LINE_COUNT_DEFAULT;
350 int margin = BASE_FORM_DEFAULT_MARGIN + RELATIVE_LAYOUT_RIGHT_MARGIN;
351 if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
353 OrientationStatus orientationStatus = GetOrientationStatus();
354 if (((orientationStatus == ORIENTATION_STATUS_PORTRAIT)
355 || (orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE))
356 && (fontSize == FONT_MAIN_TEXT_SIZE_HUGE))
358 width -= W_HUGE_SIZE_PORTRAIT_TEXT_GAP;
360 else if (((orientationStatus == ORIENTATION_STATUS_LANDSCAPE)
361 || (orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
362 && (fontSize == FONT_MAIN_TEXT_SIZE_HUGE))
364 width -= W_HUGE_SIZE_LANDSCAPE_TEXT_GAP;
366 width -= W_LARGE_SIZE_TEXT_GAP;
368 int boudwidth = width - margin;
369 font.Construct(FONT_STYLE_PLAIN, fontSize);
371 for (int i = 0; i < source.GetLength(); i++)
373 temp.Append(source[i]);
374 font.GetTextExtent(temp, temp.GetLength(), dim);
375 if (dim.width > boudwidth)
378 temp.Append(source[i]);
383 return dim.height * lineCount;
387 WallpaperAlbumListForm::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
389 AppLogDebug("ENTER");
390 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
392 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
394 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));