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 StHomeAndLockScreenForm.cpp
19 * @brief This is the implementation file for HomeAndLockScreenForm class.
22 #include "StHomeAndLockScreenForm.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::Io;
33 using namespace Tizen::Media;
34 using namespace Tizen::System;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
39 static const wchar_t* APPCONTROL_PROVIDER_ID_GALLERY = L"tizen.gallery";
40 static const wchar_t* APPCONTROL_OPERATION_ID_GALLERY = L"http://tizen.org/appcontrol/operation/pick";
42 static const wchar_t* APPCONTROL_PROVIDER_ID_IMAGE_VIEWER = L"tizen.imageviewer";
43 static const wchar_t* APPCONTROL_OPERATION_ID_IMAGE_VIEWER = L"http://tizen.org/appcontrol/operation/image/crop";
45 static const wchar_t* APPCONTROL_SELECT_KEY_GALLERY = L"http://tizen.org/appcontrol/data/selection_mode";
46 static const wchar_t* APPCONTROL_SELECT_VALUE_GALLERY = L"single";
48 static const wchar_t* APPCONTROL_SELECT_KEY_IMAGE = L"http://tizen.org/appcontrol/data/image/crop_mode";
49 static const wchar_t* APPCONTROL_SELECT_VALUE_IMAGE = L"fit_to_screen";
51 static const wchar_t* APPCONTROL_DATA_SELECT_KEY_GALLERY = L"http://tizen.org/appcontrol/data/selected";
53 static const int ID_INDEX_HOME_SCREEN_WALLPAPER = 0;
54 static const int ID_INDEX_LOCK_SCREEN_WALLPAPER = 1;
56 static const int ID_GROUP_SCREEN_TYPE = 0;
58 static const int ID_GROUP_SCREEN_WALLPAPER = 1;
60 static const int ID_GROUP_COUNT = 2;
61 static const int ID_GROUP_MAX_ITEM_COUNT = 1;
63 HomeAndLockScreenForm::HomeAndLockScreenForm(void)
64 : __isRunningAppControl(false)
69 HomeAndLockScreenForm::~HomeAndLockScreenForm(void)
74 HomeAndLockScreenForm::CreateFooter(void)
76 Footer* pFooter = GetFooter();
79 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
80 pFooter->AddActionEventListener(*this);
82 SetFormBackEventListener(this);
86 HomeAndLockScreenForm::OnInitializing(void)
92 HomeAndLockScreenForm::OnTerminating(void)
97 SetFormBackEventListener(null);
104 HomeAndLockScreenForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
108 SetWallpaperIndex(*static_cast<String*>(pArgs->GetAt(0)));
110 AppLogDebug("Screen Mode[%d] ( home::0 / Lock::1 )", GetWallpaperIndex());
112 CreateHeader(GetTitleText());
114 AppLogDebug("ENTER");
116 __pTableView->UpdateTableView();
118 else if (previousSceneId.Equals(IDSCN_SCREEN_TYPE, false))
120 __pTableView->RefreshItem(0,0,TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
124 AppLogDebug("pArgs Null");
129 HomeAndLockScreenForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
134 HomeAndLockScreenForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
136 if (__isRunningAppControl)
138 AppLogDebug("busy status");
142 SceneManager* pSceneManager = SceneManager::GetInstance();
143 AppAssert(pSceneManager);
145 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
149 HomeAndLockScreenForm::GetGroupCount(void)
151 AppLogDebug("ENTER");
152 return ID_GROUP_COUNT;
156 HomeAndLockScreenForm::GetItemCount(int groupIndex)
158 int itemCount = ID_GROUP_MAX_ITEM_COUNT;
160 AppLogDebug("GetItemCount %d", itemCount);
166 HomeAndLockScreenForm::CreateGroupItem(int groupIndex, int itemWidth)
168 AppLogDebug("ENTER");
170 int itemHeight = H_GROUP_INDEX_DEFAULT;;
172 Rectangle itemMainRectangle;
174 Label* pLabel = null;
176 groupText = GetGroupText(groupIndex);
178 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
179 itemMainRectangle.y = yItemOffset;
180 itemMainRectangle.width = itemWidth;
181 itemMainRectangle.height = itemHeight;
183 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
185 RelativeLayout relativeLayout;
186 relativeLayout.Construct();
188 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
189 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
191 pLabel = new (std::nothrow) Label();
192 pLabel->Construct(itemMainRectangle, groupText);
193 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
194 pLabel->SetTextVerticalAlignment(ALIGNMENT_BOTTOM);
195 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
196 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
198 pItem->AddControl(pLabel);
199 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
200 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
201 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
202 pItem->SetEnabled(false);
208 HomeAndLockScreenForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
210 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
212 Rectangle itemMainRectangle;
213 Rectangle itemSubRectangle;
214 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
217 String fontReturnValue;
218 Label* pLabel = null;
220 int fontSize = GetFontSize();
222 itemMainText = GetGroupItemText(groupIndex);
224 ItemTypeOneLine(itemMainRectangle);
225 itemHeight = itemMainRectangle.height;
227 if (groupIndex == ID_GROUP_SCREEN_TYPE)
229 itemSubText = GetGroupItemSelectedText();
230 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
231 itemHeight = itemMainRectangle.height + itemSubRectangle.height;
234 TableViewItem* pItem = new (std::nothrow) TableViewItem();
236 RelativeLayout relativeLayout;
237 relativeLayout.Construct();
239 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
240 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
242 pLabel = new (std::nothrow) Label();
243 pLabel->Construct(itemMainRectangle, itemMainText);
244 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
245 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
246 pLabel->SetTextColor(COLOR_MAIN_TEXT);
248 if (groupIndex == ID_GROUP_SCREEN_TYPE)
250 pLabel->AddTouchEventListener(*this);
251 pItem->AddKeyEventListener(*this);
252 pItem->AddFocusEventListener(*this);
255 pItem->AddControl(pLabel);
257 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
258 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
260 if (groupIndex == ID_GROUP_SCREEN_TYPE)
262 __pLabel = new (std::nothrow) Label();
263 __pLabel->Construct(itemSubRectangle, itemSubText);
264 __pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
265 __pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
266 __pLabel->SetTextColor(COLOR_SUB_TEXT);
267 __pLabel->AddTouchEventListener(*this);
269 pItem->AddControl(__pLabel);
271 relativeLayout.SetRelation(*__pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
272 relativeLayout.SetRelation(*__pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
278 HomeAndLockScreenForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
280 AppLogDebug("ENTER");
289 HomeAndLockScreenForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
291 AppLogDebug("ENTER");
300 HomeAndLockScreenForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
302 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
304 if (__isRunningAppControl)
306 AppLogDebug("busy status");
310 SceneManager* pSceneManager = SceneManager::GetInstance();
311 AppAssert(pSceneManager);
313 ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
316 AppLogDebug("pArgs is null");
319 result r = pArgs->Construct();
322 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
324 pArgs->Add(new (std::nothrow) String(Integer::ToString(GetWallpaperIndex())));
326 if (groupIndex == ID_GROUP_SCREEN_WALLPAPER)
328 // to launch gallery app control
329 LaunchGalleryAppControl();
333 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCREEN_TYPE, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
338 HomeAndLockScreenForm::GetDefaultGroupItemHeight(void)
340 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
344 HomeAndLockScreenForm::GetDefaultItemHeight(void)
346 return H_GROUP_ITEM_DEFAULT;
350 HomeAndLockScreenForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
355 HomeAndLockScreenForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
359 case ID_GROUP_SCREEN_TYPE:
362 Label* pSecondLabel = static_cast<Label*>(pItem->GetControl(1));
363 itemSubText = GetGroupItemSelectedText();
364 pSecondLabel->SetText(itemSubText);
365 pSecondLabel->Invalidate(false);
376 HomeAndLockScreenForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
381 HomeAndLockScreenForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
386 HomeAndLockScreenForm::SetWallpaperIndex(Tizen::Base::String& whitchOne)
388 Integer::Parse(whitchOne, __wallpaperIndex);
392 HomeAndLockScreenForm::GetWallpaperIndex(void)
394 return __wallpaperIndex;
398 HomeAndLockScreenForm::GetTitleText(void)
402 switch (GetWallpaperIndex())
404 case ID_INDEX_HOME_SCREEN_WALLPAPER:
406 headerText = ResourceManager::GetString(L"IDS_ST_HEADER_HOME_SCREEN");
410 case ID_INDEX_LOCK_SCREEN_WALLPAPER:
412 headerText = ResourceManager::GetString(L"IDS_ST_BODY_LOCK_SCREEN");
421 HomeAndLockScreenForm::GetGroupText(int groupIndex)
427 case ID_GROUP_SCREEN_TYPE:
429 if (GetWallpaperIndex())
431 groupText = ResourceManager::GetString(L"IDS_ST_BODY_LOCK_SCREEN");
435 groupText = ResourceManager::GetString(L"IDS_ST_HEADER_HOME_SCREEN");
440 case ID_GROUP_SCREEN_WALLPAPER:
442 groupText = ResourceManager::GetString(L"IDS_ST_BODY_MAINDISPLAY_WALLPAPER");
451 HomeAndLockScreenForm::GetGroupItemText(int groupIndex)
457 case ID_GROUP_SCREEN_TYPE:
459 if (GetWallpaperIndex())
461 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SCREEN_LOCK_TYPE");
465 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_HOME_SCREEN_TYPE");
470 case ID_GROUP_SCREEN_WALLPAPER:
472 if (GetWallpaperIndex())
474 itemMainText = ResourceManager::GetString(L"IDS_ST_MBODY_LOCK_SCREEN_WALLPAPER_M_NOUN");
478 itemMainText = ResourceManager::GetString(L"IDS_ST_MBODY_HOME_SCREEN_WALLPAPER");
488 HomeAndLockScreenForm::GetGroupItemSelectedText(void)
492 String applicationId;
494 if (GetWallpaperIndex() == 0)
496 screenType = SETTING_INFO_KEY_SCREEN_TYPE_HOME;
500 screenType = SETTING_INFO_KEY_SCREEN_TYPE_LOCK;
503 result r = SettingInfo::GetValue(screenType, applicationId);
504 AppLogDebug("GetValue(%ls, ..) result=[%s]", screenType.GetPointer(), GetErrorMessage(r));
508 AppLog("AppId=[%ls]", applicationId.GetPointer());
510 if (applicationId.Equals(L"org.tizen.menu-screen", false))
513 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DEFAULT_HOME_SCREEN");
515 else if (applicationId.Equals(L"org.tizen.lockscreen", false))
518 itemMainText = ResourceManager::GetString(L"IDS_ST_MBODY_SWIPE");
522 // Downloaded home/lock
523 PackageManager* pMgr = PackageManager::GetInstance();
524 PackageAppInfo* pPackageAppInfo = pMgr->GetPackageAppInfoN(applicationId);
527 itemMainText = pPackageAppInfo->GetAppDisplayName();
528 delete pPackageAppInfo;
537 HomeAndLockScreenForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
539 __isRunningAppControl = false;
541 AppLogDebug("appControlResult = %d", appControlResult);
543 if (appId.Equals(String(APPCONTROL_PROVIDER_ID_GALLERY)) &&
544 operationId.Equals(String(APPCONTROL_OPERATION_ID_GALLERY)))
546 if (appControlResult == APP_CTRL_RESULT_SUCCEEDED)
548 AppLog("Image crop succeeded.");
549 // use cropped image.
552 IMapEnumerator* pEnum = pExtraData->GetMapEnumeratorN();
553 if (pEnum->MoveNext() == E_SUCCESS)
555 String* pKey = dynamic_cast<String*>(pEnum->GetKey());
556 if (pKey && pKey->Equals(String(APPCONTROL_DATA_SELECT_KEY_GALLERY)))
558 // The value is IList
559 IList* pValueList = dynamic_cast<IList*>(pEnum->GetValue());
562 String* pSrcPath = dynamic_cast<String*>(pValueList->GetAt(0));
564 if (pSrcPath != null && pSrcPath->GetLength() > 0)
568 ImageFormat imageFormat;
569 result r = ImageBuffer::GetImageInfo(*pSrcPath, imageFormat, width, height);
573 MessageBox unsupportedMessageBox;
574 unsupportedMessageBox.Construct(L"", ResourceManager::GetString(L"IDS_RSSR_BODY_INVALID_FORMAT"), MSGBOX_STYLE_NONE, 3000);
575 unsupportedMessageBox.ShowAndWait(modalResult);
578 String dstPath = Application::GetInstance()->GetAppSharedPath() + PATH_DATA_DIRECTORY;
580 r = imgBuf.Construct(*pSrcPath);
584 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
587 if (__wallpaperIndex == 0)
589 dstPath.Append(L"home.jpg");
590 r = imgBuf.EncodeToFile(dstPath, IMG_FORMAT_JPG, true, 100);
593 AppLogDebug("Wallpaper EncodeToFile Failed [%s]", GetErrorMessage(r));
594 ShowMessageBox(L"", L"System error occured.");
597 AppLogDebug("FilePath = %S", dstPath.GetPointer());
599 r = SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN, dstPath);
602 AppLogDebug("Wallpaper Screen SetValue is Fail [%s]", GetErrorMessage(r));
605 else if (__wallpaperIndex == 1)
607 dstPath.Append(L"lock.jpg");
608 imgBuf.EncodeToFile(dstPath, IMG_FORMAT_JPG, true, 100);
611 AppLogDebug("Wallpaper EncodeToFile Failed [%s]", GetErrorMessage(r));
612 ShowMessageBox(L"", L"System error occured.");
615 AppLogDebug("FilePath = %S", dstPath.GetPointer());
617 r = SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN_LOCK, dstPath);
620 AppLogDebug("Wallpaper Lock Screen SetValue is Fail [%s]", GetErrorMessage(r));
630 else if (appControlResult == APP_CTRL_RESULT_FAILED)
632 AppLog("Image crop failed.");
635 else if (appControlResult == APP_CTRL_RESULT_CANCELED)
637 AppLog("Image crop was canceled.");
640 else if (appControlResult == APP_CTRL_RESULT_TERMINATED)
642 AppLog("Image crop was terminated.");
645 else if (appControlResult == APP_CTRL_RESULT_ABORTED)
647 AppLog("Image crop was aborted.");
655 HomeAndLockScreenForm::LaunchGalleryAppControl()
657 String mime = L"*/*";
659 extraData.Construct();
660 String selectKey = APPCONTROL_SELECT_KEY_GALLERY;
661 String selectVal = APPCONTROL_SELECT_VALUE_GALLERY;
662 String selectKeyImage = APPCONTROL_SELECT_KEY_IMAGE;
663 String selectValImage = APPCONTROL_SELECT_VALUE_IMAGE;
665 extraData.Add(&selectKey, &selectVal);
666 extraData.Add(&selectKeyImage, &selectValImage);
668 AppControl* pAc = AppManager::FindAppControlN(APPCONTROL_PROVIDER_ID_GALLERY,
669 APPCONTROL_OPERATION_ID_GALLERY);
672 if (pAc->Start(null, &mime, &extraData, this) == E_SUCCESS)
674 __isRunningAppControl = true;
682 HomeAndLockScreenForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
684 __pLabel->SetTextColor(COLOR_SUB_TEXT);
685 __pLabel->Invalidate(false);
689 HomeAndLockScreenForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
691 __pLabel->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
692 __pLabel->Invalidate(false);
696 HomeAndLockScreenForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
698 __pLabel->SetTextColor(COLOR_SUB_TEXT);
699 __pLabel->Invalidate(false);
703 HomeAndLockScreenForm::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
705 __pLabel->SetTextColor(COLOR_SUB_TEXT);
706 __pLabel->Invalidate(false);
710 HomeAndLockScreenForm::OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
713 if(keyCode == KEY_ENTER)
716 __pLabel->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
717 __pLabel->Invalidate(false);
722 HomeAndLockScreenForm::OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
725 if(keyCode == KEY_ENTER)
728 __pLabel->SetTextColor(COLOR_SUB_TEXT);
729 __pLabel->Invalidate(false);
734 HomeAndLockScreenForm::OnKeyLongPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
739 HomeAndLockScreenForm::OnFocusLost(const Tizen::Ui::Control& source)
742 __pLabel->SetTextColor(COLOR_SUB_TEXT);
743 __pLabel->Invalidate(false);
747 HomeAndLockScreenForm::OnFocusGained(const Tizen::Ui::Control& source)