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 StScreenTypeForm.cpp
19 * @brief This is the implementation file for ScreenTypeForm class.
22 #include "StScreenTypeForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
27 using namespace Tizen::App;
28 using namespace Tizen::App::Package;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
37 static const int ID_GROUP_COUNT = 1;
38 static const int ID_GROUP_MAX_ITEM_COUNT = 1;
39 static const int ID_INDEX_HOME_SCREEN_WALLPAPER = 0;
40 static const int ID_INDEX_LOCK_SCREEN_WALLPAPER = 1;
42 ScreenTypeForm::ScreenTypeForm(void)
44 , __pPackageAppInfoList(null)
48 ScreenTypeForm::~ScreenTypeForm(void)
53 ScreenTypeForm::CreateFooter(void)
55 Footer* pFooter = GetFooter();
58 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
59 pFooter->AddActionEventListener(*this);
61 SetFormBackEventListener(this);
65 ScreenTypeForm::OnInitializing(void)
71 ScreenTypeForm::OnTerminating(void)
73 RemovePackageInfoList();
76 SetFormBackEventListener(null);
81 ScreenTypeForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
85 SetWallpaperIndex(*static_cast<String*>(pArgs->GetAt(0)));
87 AppLogDebug("Screen Mode[%d] ( home::0 / Lock::1 )", GetWallpaperIndex());
89 InitPackageInfoList();
91 CreateHeader(GetTitleText());
92 UpdateTableViewAndNoContent();
95 if (__pPackageAppInfoList != null)
99 if (GetWallpaperIndex() == 0)
101 screenType = SETTING_INFO_KEY_SCREEN_TYPE_HOME;
105 screenType = SETTING_INFO_KEY_SCREEN_TYPE_LOCK;
107 result r = SettingInfo::GetValue(screenType, applicationId);
108 AppLogDebug("GetValue(%ls, ..) result=[%s]", applicationId.GetPointer(), GetErrorMessage(r));
110 for (int index = 0; index < __pPackageAppInfoList->GetCount(); index++)
112 PackageAppInfo* pPackageAppInfo = dynamic_cast<PackageAppInfo*>(__pPackageAppInfoList->GetAt(index));
115 if (applicationId.CompareTo(pPackageAppInfo->GetAppId()) == 0)
117 AppLogDebug("index [%d]", index);
118 if (__pTableView != null)
120 __pTableView->SetItemChecked(0, index, true);
130 AppLogDebug("pArgs Null");
135 ScreenTypeForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
140 ScreenTypeForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
142 SceneManager* pSceneManager = SceneManager::GetInstance();
143 AppAssert(pSceneManager);
145 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
149 ScreenTypeForm::GetGroupCount(void)
151 AppLogDebug("ENTER");
153 return ID_GROUP_COUNT;
157 ScreenTypeForm::GetItemCount(int groupIndex)
159 int itemCount = GetPackageAppInfoListCount();
161 AppLogDebug("GetItemCount %d", itemCount);
167 ScreenTypeForm::CreateGroupItem(int groupIndex, int itemWidth)
169 AppLogDebug("ENTER");
171 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
172 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
173 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
174 Rectangle itemMainRectangle;
176 Label* pLabel = null;
177 int fontSize = GetFontSize();
179 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
181 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
182 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
184 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
185 itemMainRectangle.y = yItemOffset;
186 itemMainRectangle.width = itemWidth;
187 itemMainRectangle.height = itemHeight;
189 RelativeLayout relativeLayout;
190 relativeLayout.Construct();
192 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
193 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
195 pLabel = new (std::nothrow) Label();
196 pLabel->Construct(itemMainRectangle, groupText);
197 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
198 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
199 pLabel->SetTextConfig(fontSize, style);
200 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
202 pItem->AddControl(pLabel);
203 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
204 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
205 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
206 pItem->SetEnabled(false);
212 ScreenTypeForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
214 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
216 Rectangle itemMainRectangle;
217 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_RADIO;
218 String itemMainText = L"";
219 String valueKeyString = L"";
220 String fontReturnValue;
221 Label* pLabel = null;
223 int fontSize = GetFontSize();
224 int itemHeight = H_GROUP_ITEM_DEFAULT;
226 itemMainText = GetItemString(itemIndex);
227 TableViewItem* pItem = new (std::nothrow) TableViewItem();
229 RelativeLayout relativeLayout;
230 relativeLayout.Construct();
232 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
233 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
235 ItemTypeOneLine(itemMainRectangle);
236 pLabel = new (std::nothrow) Label();
237 pLabel->Construct(itemMainRectangle, itemMainText);
238 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
239 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
240 pLabel->SetTextColor(COLOR_MAIN_TEXT);
242 pItem->AddControl(pLabel);
243 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
244 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
245 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
251 ScreenTypeForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
253 AppLogDebug("ENTER");
262 ScreenTypeForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
264 AppLogDebug("ENTER");
273 ScreenTypeForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
275 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
277 int groupCount = __pTableView->GetItemCountAt(groupIndex);
279 for (int index = 0; index < groupCount; index++)
281 if (index == itemIndex)
283 tableView.SetItemChecked(groupIndex, index, true);
287 tableView.SetItemChecked(groupIndex, index, false);
291 SceneManager* pSceneManager = SceneManager::GetInstance();
292 AppAssert(pSceneManager);
294 PackageAppInfo* pPackageAppInfo = static_cast <PackageAppInfo*>(__pPackageAppInfoList->GetAt(itemIndex));
295 AppLogDebug("AppId [%ls]", pPackageAppInfo->GetAppId().GetPointer());
298 if (GetWallpaperIndex() == 0)
300 screenType = SETTING_INFO_KEY_SCREEN_TYPE_HOME;
304 screenType = SETTING_INFO_KEY_SCREEN_TYPE_LOCK;
307 result r = SettingInfo::SetValueForPrivilegedKey(screenType, pPackageAppInfo->GetAppId());
308 AppLogDebug("SetValue(%ls, ..) result=[%s]", screenType.GetPointer(), GetErrorMessage(r));
310 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
314 ScreenTypeForm::GetTitleText(void)
318 switch (GetWallpaperIndex())
320 case ID_INDEX_HOME_SCREEN_WALLPAPER:
322 headerText = ResourceManager::GetString(L"IDS_ST_BODY_HOME_SCREEN_TYPE");
326 case ID_INDEX_LOCK_SCREEN_WALLPAPER:
328 headerText = ResourceManager::GetString(L"IDS_ST_BODY_SCREEN_LOCK_TYPE");
337 ScreenTypeForm::GetWallpaperIndex(void)
339 return __wallpaperIndex;
343 ScreenTypeForm::SetWallpaperIndex(Tizen::Base::String& whitchOne)
345 Integer::Parse(whitchOne, __wallpaperIndex);
349 ScreenTypeForm::GetDefaultGroupItemHeight(void)
351 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
355 ScreenTypeForm::GetDefaultItemHeight(void)
357 return H_GROUP_ITEM_DEFAULT;
361 ScreenTypeForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
366 ScreenTypeForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
372 ScreenTypeForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
377 ScreenTypeForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
382 ScreenTypeForm::InitPackageInfoList(void)
384 PackageManager* pPackageManager = PackageManager::GetInstance();
385 if (pPackageManager == null)
391 HashMap packageAppFilterMap;
392 packageAppFilterMap.Construct();
395 if (GetWallpaperIndex() == ID_INDEX_HOME_SCREEN_WALLPAPER)
397 pKey = new (std::nothrow) String(L"http://tizen.org/category/homeapp");
401 pKey = new (std::nothrow) String(L"http://tizen.org/category/lockapp");
404 Boolean* pValue = new (std::nothrow) Boolean(true);
405 r = packageAppFilterMap.Add(pKey, pValue);
407 __pPackageAppInfoList = pPackageManager->GetPackageAppInfoListN(packageAppFilterMap);
409 #if 1 // temp for debugging
410 AppLogDebug("Package app filter = [%ls]", pKey->GetPointer());
412 if (__pPackageAppInfoList)
414 for (int i = 0; i < __pPackageAppInfoList->GetCount(); i++)
416 PackageAppInfo* pPackageAppInfo = dynamic_cast<PackageAppInfo*>(__pPackageAppInfoList->GetAt(i));
419 AppLogDebug("[%d]-------------------------------------------------------", i+1);
420 AppLogDebug("AppId [%ls]", pPackageAppInfo->GetAppId().GetPointer());
421 AppLogDebug("Name [%ls]", pPackageAppInfo->GetAppName().GetPointer());
425 AppLogDebug("pPackageAppInfo is null.");
431 AppLogDebug("pList is null.");
435 if (__pPackageAppInfoList == null)
444 ScreenTypeForm::RemovePackageInfoList(void)
446 __pPackageAppInfoList = null;
450 ScreenTypeForm::GetPackageAppInfoListCount(void)
452 if(__pPackageAppInfoList)
454 return __pPackageAppInfoList->GetCount();
461 ScreenTypeForm::GetScreenType(void)
465 switch (GetWallpaperIndex())
467 case ID_INDEX_HOME_SCREEN_WALLPAPER:
469 screenType = SETTING_INFO_KEY_SCREEN_TYPE_HOME;
473 case ID_INDEX_LOCK_SCREEN_WALLPAPER:
475 screenType = SETTING_INFO_KEY_SCREEN_TYPE_LOCK;
481 AppLogDebug("Page index [%d]", GetWallpaperIndex());
489 ScreenTypeForm::GetItemString(int itemIndex)
492 String applicationId;
495 PackageAppInfo* pPackageAppInfo = static_cast<PackageAppInfo*>(__pPackageAppInfoList->GetAt(itemIndex));
498 applicationId = pPackageAppInfo->GetAppId();
500 if (applicationId.IsEmpty() == false)
502 if (applicationId.Equals(L"org.tizen.menu-screen", false))
505 returnValue = ResourceManager::GetString(L"IDS_ST_BODY_DEFAULT_HOME_SCREEN");
507 else if (applicationId.Equals(L"org.tizen.lockscreen", false))
510 returnValue = ResourceManager::GetString(L"IDS_ST_MBODY_SWIPE");
514 // Downloaded home/lock
515 displayName = pPackageAppInfo->GetAppDisplayName();
517 if (displayName.IsEmpty() == false)
519 returnValue = displayName;
523 returnValue = applicationId;
533 ScreenTypeForm::UpdateTableViewAndNoContent(void)
535 bool createTableView = false;
536 if (__pTableView != null)
538 if (GetPackageAppInfoListCount() != 0)
540 __pTableView->UpdateTableView();
546 if (GetPackageAppInfoListCount() != 0)
548 createTableView = true;
552 if (__pTableView != null)
554 int tableViewControlCount = __pTableView->GetControlCount();
555 for (int i = 0; i < tableViewControlCount; i++)
557 __pTableView->RemoveControl(__pTableView->GetControl(0));
559 // __pTableView->RemoveAllControls();
562 int controlCount = GetControlCount();
563 for (int i = 0; i < controlCount; i++)
565 RemoveControl(GetControl(0));
567 // RemoveAllControls();
572 __pTableView->UpdateTableView();
576 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
579 Rectangle clientRect = GetClientAreaBounds();
580 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
582 int bitmapWidth = pBitmp->GetWidth();
583 int bitmapHeight = pBitmp->GetHeight();
584 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
585 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
586 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
588 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
589 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
591 Label* pLabel = new (std::nothrow) Label();
592 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
593 pLabel->SetName(NO_CONTENTS);
594 pLabel->SetBackgroundBitmap(*pBitmp);
596 yPos = yPos + bitmapHeight;
598 Label* pLabelNoContents = new (std::nothrow) Label();
599 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
600 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
601 pLabelNoContents->SetTextColor(textColor);
602 pLabelNoContents->SetText(labelText);
605 AddControl(pLabelNoContents);
611 ScreenTypeForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
613 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
616 Rectangle clientRect = GetClientAreaBounds();
617 Rectangle labelBound = pLabel->GetBounds();
619 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
620 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
622 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
623 yPos = yPos + pLabel->GetBounds().height;
624 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
625 if (pTextLabel != null)
627 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));