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 MpSettingForm.cpp
19 * @brief This is the implementation file for SettingForm class.
25 #include <FUiScenes.h>
26 #include "MpAllListPresentationModel.h"
27 #include "MpNowPlayContentPanel.h"
28 #include "MpSceneRegister.h"
29 #include "MpSettingForm.h"
30 #include "MpSettingPresentationModel.h"
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 static const int SETTING_ITEM_HEIGHT = 115;
43 static const int ID_MAIN_DEFAULT_PLAYLIST_ITEM = 1;
44 static const int ID_SUB_MOST_PLAYED_ITEM = 0;
45 static const int ID_SUB_RECENTLY_PLAYED_ITEM = 1;
46 static const int ID_SUB_RECENTLY_ADD_ITEM = 2;
48 static const int ID_MAIN_AUTO_OFF_ITEM = 0;
49 static const int ID_SUB_ZERO_ITEM = 0;
50 static const int ID_SUB_FIFTEEN_ITEM = 1;
51 static const int ID_SUB_THIRTY_ITEM = 2;
52 static const int ID_SUB_ONE_HOUR_ITEM = 3;
53 static const int ID_SUB_ONE_HOUR_THIRTY_ITEM = 4;
54 static const int ID_SUB_TWO_HOURS_ITEM = 5;
56 static const int ID_MAIN_DEFAULT_PLAYLIST_ITEM_COUNT = 3;
57 static const int ID_MAIN_AUTO_OFF_ITEM_COUNT = 6;
58 static const unsigned int COLOR_SUB_TEXT_SETTINGS = Color32<42, 137, 194>::Value;
60 SettingForm::SettingForm(void)
61 : __pSettingPresentationModel(null)
62 , __pSettingTableView(null)
68 SettingForm::~SettingForm(void)
75 SettingForm::Initialize(void)
78 Construct(IDL_SETTING_FORM);
83 SettingForm::OnInitializing(void)
87 SetFormBackEventListener(this);
89 __pSettingTableView = static_cast<GroupedTableView*>(GetControl(IDC_GROUPEDTABLEVIEW_CONTENT_LIST));
90 __pSettingTableView->SetItemProvider(this);
91 __pSettingTableView->AddGroupedTableViewItemEventListener(*this);
93 __pSettingPresentationModel = SettingPresentationModel::GetInstance();
94 // __pSettingPresentationModel->InitializeSettingValue();
95 __pPresentationModel = AllListPresentationModel::GetInstance();
96 __pSettingTableView->UpdateTableView();
97 __pSettingTableView->CollapseAllGroup();
98 // for (int itemIndex = 0; itemIndex < ID_MAIN_DEFAULT_PLAYLIST_ITEM_COUNT; itemIndex++)
100 // __pSettingTableView->SetItemChecked(0, itemIndex, __pSettingPresentationModel->IsTabEnable(itemIndex));
102 __pSettingTableView->SetItemChecked(ID_MAIN_AUTO_OFF_ITEM, __pSettingPresentationModel->GetAutoOffTime(), true);
110 SettingForm::OnTerminating(void)
112 AppLogDebug("ENTER");
113 result r = E_SUCCESS;
115 /*Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
116 Form* pForm = static_cast<Form*>(pFrame->GetControl(CONTENT_FORM_REQUSEST_ID));
119 AppLogDebug("AForm");
120 pForm->SendUserEvent(0, null);
122 // __pSettingPresentationModel->DestroySettingPresentationModel();
129 SettingForm::GetGroupCount(void)
131 AppLogDebug("ENTER");
137 SettingForm::GetItemCount(int groupIndex)
139 AppLogDebug("ENTER");
144 case ID_MAIN_DEFAULT_PLAYLIST_ITEM:
146 itemCount = ID_MAIN_DEFAULT_PLAYLIST_ITEM_COUNT;
150 case ID_MAIN_AUTO_OFF_ITEM:
152 itemCount = ID_MAIN_AUTO_OFF_ITEM_COUNT;
164 SettingForm::CreateGroupItem(int groupIndex, int itemWidth)
166 AppLogDebug("ENTER %d", groupIndex);
167 RelativeLayout layout;
170 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
171 pItem->Construct(layout, Dimension(itemWidth, SETTING_ITEM_HEIGHT));
172 Panel* pGroupTableViewItem = new (std::nothrow) Panel();
175 case ID_MAIN_DEFAULT_PLAYLIST_ITEM:
177 if (IsFailed(pGroupTableViewItem->Construct(IDL_SETTING_PLAYLIST_SET_ITEM_PANEL)))
179 AppLogDebug("Construct(IDL_SETTING_PLAYLIST_SET_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
180 delete pGroupTableViewItem;
187 case ID_MAIN_AUTO_OFF_ITEM:
189 Label* pSubTextLabel = null;
190 Label* pMainTextLabel = null;
192 if (IsFailed(pGroupTableViewItem->Construct(IDL_SETTING_OFF_SET_ITEM_PANEL)))
194 AppLogDebug("Construct(IDL_SETTING_PLAYLIST_SET_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
195 delete pGroupTableViewItem;
200 pSubTextLabel = static_cast<Label*>(pGroupTableViewItem->GetControl(IDC_LABEL_SUB_TEXT));
201 pSubTextLabel->SetText(GetAutoOffString());
202 pSubTextLabel->AddTouchEventListener(*this);
203 pMainTextLabel = static_cast<Label*>(pGroupTableViewItem->GetControl(IDC_LABEL_MAIN_TEXT));
204 pMainTextLabel->AddTouchEventListener(*this);
205 static_cast<Label*>(pGroupTableViewItem->GetControl(IDC_LABEL_EX))->AddTouchEventListener(*this);
206 pItem->AddKeyEventListener(*this);
207 pItem->AddFocusEventListener(*this);
215 pItem->AddControl(pGroupTableViewItem);
216 pItem->SetIndividualSelectionEnabled(pGroupTableViewItem, true);
217 CommonUtil::SetLayoutFitToContainer(*pItem, *pGroupTableViewItem);
224 SettingForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
226 AppLogDebug("ENTER");
232 SettingForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
234 AppLogDebug("ENTER");
235 RelativeLayout layout;
238 TableViewItem* pItem = new (std::nothrow) TableViewItem();
239 Panel* pGroupTableViewItem = new (std::nothrow) Panel();
241 result r = pGroupTableViewItem->Construct(IDL_GROUPEDTABLEVIEW_ITEM_PANEL);
242 TryCatch(r == E_SUCCESS, delete pItem, "pGroupTableViewItem->Construct(%s)", GetErrorMessage(r));
244 if (groupIndex == ID_MAIN_DEFAULT_PLAYLIST_ITEM)
246 r = pItem->Construct(layout, Dimension(W_CLIENT_AREA, SETTING_ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_MARK);
247 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
249 Label* pMainText = static_cast<Label*>(pGroupTableViewItem->GetControl(IDC_LABEL_MAIN_TEXT));
253 case ID_SUB_MOST_PLAYED_ITEM:
255 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_MOST_PLAYED"));
259 case ID_SUB_RECENTLY_PLAYED_ITEM:
261 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_PLAYLIST_RECENTLY_PLAYED"));
265 case ID_SUB_RECENTLY_ADD_ITEM:
267 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_RECENTLY_ADDED"));
277 r = pItem->Construct(layout, Dimension(W_CLIENT_AREA, SETTING_ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_RADIO);
278 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
280 Label* pMainText = static_cast<Label*>(pGroupTableViewItem->GetControl(IDC_LABEL_MAIN_TEXT));
284 case ID_SUB_ZERO_ITEM:
286 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_NOT_USED"));
290 case ID_SUB_FIFTEEN_ITEM:
292 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_OPT_AFTER_15_MIN_ABB"));
296 case ID_SUB_THIRTY_ITEM:
298 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_30_MIN"));
302 case ID_SUB_ONE_HOUR_ITEM:
304 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_1_HOUR"));
308 case ID_SUB_ONE_HOUR_THIRTY_ITEM:
310 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_POP_AFTER_1_HOUR_30_MIN"));
314 case ID_SUB_TWO_HOURS_ITEM:
316 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_2_HOURS"));
325 pItem->AddControl(pGroupTableViewItem);
326 pItem->SetIndividualSelectionEnabled(pGroupTableViewItem, true);
327 CommonUtil::SetLayoutFitToContainer(*pItem, *pGroupTableViewItem);
333 AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
334 delete pGroupTableViewItem;
339 SettingForm::UpdateItem(int groupIndex, int itemIndex, TableViewItem* pItem)
341 AppLogDebug("ENTER");
346 SettingForm::UpdateGroupItem(int groupIndex, TableViewGroupItem* pItem)
348 AppLogDebug("ENTER");
349 if (groupIndex == ID_MAIN_AUTO_OFF_ITEM)
351 Label* pLabelSubtext = static_cast<Label*>(pItem->GetControl(IDC_LABEL_SUB_TEXT, true));
352 pLabelSubtext->SetText(GetAutoOffString());
353 pLabelSubtext->Invalidate(false);
355 __pSettingTableView->Invalidate(true);
360 SettingForm::GetDefaultItemHeight(void)
362 AppLogDebug("ENTER");
364 return SETTING_ITEM_HEIGHT;
368 SettingForm::GetDefaultGroupItemHeight(void)
370 AppLogDebug("ENTER");
372 return SETTING_ITEM_HEIGHT;
376 SettingForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
378 AppLogDebug("ENTER");
384 SettingForm::OnGroupedTableViewGroupItemStateChanged(GroupedTableView& tableView, int groupIndex, TableViewGroupItem* pItem, TableViewItemStatus status)
386 AppLogDebug("ENTER");
387 if (tableView.IsGroupExpanded(groupIndex) == true)
389 Label* pLabel = static_cast<Label*>(pItem->GetControl(IDC_LABEL_EX, true));
390 Bitmap* pBitmap = ResourceManager::GetBitmapN(L"00_button_expand_closed.png");
391 pLabel->SetBackgroundBitmap(*pBitmap);
392 pLabel->Invalidate(false);
395 if (groupIndex == ID_MAIN_AUTO_OFF_ITEM)
397 Label* pLabelSubtext = static_cast<Label*>(pItem->GetControl(IDC_LABEL_SUB_TEXT, true));
398 pLabelSubtext->SetText(GetAutoOffString());
399 pLabelSubtext->Invalidate(false);
402 AppLogDebug("CollapseGroup %d",groupIndex);
403 tableView.CollapseGroup(groupIndex);
407 Label* pLabel = static_cast<Label*>(pItem->GetControl(IDC_LABEL_EX, true));
408 Bitmap* pBitmap = ResourceManager::GetBitmapN(L"00_button_expand_opened.png");
409 pLabel->SetBackgroundBitmap(*pBitmap);
410 pLabel->Invalidate(false);
413 AppLogDebug("ExpandGroup %d",groupIndex);
414 tableView.ExpandGroup(groupIndex);
420 SettingForm::OnGroupedTableViewItemStateChanged(GroupedTableView& tableView, int groupIndex, int itemIndex, TableViewItem* pItem, TableViewItemStatus status)
422 AppLogDebug("ENTER");
423 bool isChecked = false;
426 case ID_MAIN_DEFAULT_PLAYLIST_ITEM:
428 if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
432 __pSettingPresentationModel->SetTabEnable(itemIndex, isChecked);
433 Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
434 Form* pForm = static_cast<Form*>(pFrame->GetControl(CONTENT_FORM_REQUSEST_ID));
437 AppLogDebug("AForm");
438 pForm->SendUserEvent(0, null);
443 case ID_MAIN_AUTO_OFF_ITEM:
445 int timerInterval = 0;
446 result r = E_SUCCESS;
447 timerInterval = __pSettingPresentationModel->SetAutoOffTime(itemIndex);
449 for (int i = 0; i < __pSettingTableView->GetItemCountAt(ID_MAIN_AUTO_OFF_ITEM); i++)
453 AppLogDebug("true : %d", i);
454 __pSettingTableView->SetItemChecked(groupIndex, i, true);
458 AppLogDebug("false : %d", i);
459 __pSettingTableView->SetItemChecked(groupIndex, i, false);
463 if (r == E_STORAGE_FULL)
465 int messageResult = 0;
466 MessageBox messageBox;
467 __pSettingTableView->SetItemChecked(groupIndex, itemIndex, false);
468 __pSettingTableView->SetItemChecked(groupIndex, __pSettingPresentationModel->GetAutoOffTime(), true);
469 messageBox.Construct(L"",IDS_STORAGE_FULL,MSGBOX_STYLE_NONE,COUNT_MESSAGE_BOX_TIMEOUT);
470 messageBox.ShowAndWait(messageResult);
471 App::GetInstance()->Terminate();
475 if (timerInterval >= 0)
477 __pPresentationModel->StartAutoOffTimer(timerInterval);
478 tableView.RefreshItem(groupIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
482 //show message of IDS_UNABLE_TO_CHANGE_SETTINGS
483 __pSettingTableView->SetItemChecked(groupIndex, itemIndex, false);
484 __pSettingTableView->SetItemChecked(groupIndex, __pSettingPresentationModel->GetAutoOffTime(), true);
485 int messgeResult = 0;
486 MessageBox messageBox;
487 // messageBox.Construct(L"Error", ResourceManager::GetString(L"IDS_UNABLE_TO_CHANGE_SETTINGS"), MSGBOX_STYLE_NONE,3000);
488 messageBox.Construct(L"Error", L"Unable to change the setting.", MSGBOX_STYLE_NONE,3000);
489 messageBox.ShowAndWait(messgeResult);
501 SettingForm::OnGroupedTableViewContextItemActivationStateChanged(GroupedTableView& tableView, int groupIndex, int itemIndex, TableViewContextItem* pContextItem, bool activated)
503 AppLogDebug("ENTER");
508 SettingForm::OnFocusGained(const Control& source)
510 AppLogDebug("ENTER");
515 SettingForm::OnFocusLost(const Control& source)
517 AppLogDebug("ENTER");
518 const TableViewGroupItem* pSourcePanel = dynamic_cast<const TableViewGroupItem*>(&source);
520 if (pSourcePanel != null)
522 Label* pLabel = static_cast<Label*>(pSourcePanel->GetControl(IDC_LABEL_SUB_TEXT,true));
526 pLabel->SetTextColor(COLOR_SUB_TEXT_SETTINGS);
527 pLabel->Invalidate(false);
535 SettingForm::OnKeyLongPressed(const Control& source, KeyCode keyCode)
537 AppLogDebug("ENTER");
542 SettingForm::OnKeyPressed(const Control& source, KeyCode keyCode)
544 AppLogDebug("ENTER %ls", source.GetName().GetPointer());
545 if(keyCode == KEY_ENTER)
547 const TableViewGroupItem* pSourcePanel = dynamic_cast<const TableViewGroupItem*>(&source);
549 if (pSourcePanel != null)
551 Label* pLabel = static_cast<Label*>(pSourcePanel->GetControl(IDC_LABEL_SUB_TEXT,true));
555 pLabel->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
556 pLabel->Invalidate(false);
564 SettingForm::OnKeyReleased(const Control& source, KeyCode keyCode)
566 AppLogDebug("ENTER %ls", source.GetName().GetPointer());
567 if (keyCode == KEY_ENTER)
569 const TableViewGroupItem* pSourcePanel = dynamic_cast<const TableViewGroupItem*>(&source);
571 if (pSourcePanel != null)
573 Label* pLabel = static_cast<Label*>(pSourcePanel->GetControl(IDC_LABEL_SUB_TEXT,true));
577 pLabel->SetTextColor(COLOR_SUB_TEXT_SETTINGS);
578 pLabel->Invalidate(false);
586 SettingForm::OnTouchCanceled(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
588 AppLogDebug("ENTER %ls",source.GetName().GetPointer());
589 if (source.GetName().Equals(IDC_LABEL_SUB_TEXT,true)
590 || source.GetName().Equals(IDC_LABEL_MAIN_TEXT,true)
591 || source.GetName().Equals(IDC_LABEL_EX,true))
593 Panel* pSourcePanel = dynamic_cast<Panel*>(source.GetParent());
596 Label* pLabel = static_cast<Label*>(pSourcePanel->GetControl(IDC_LABEL_SUB_TEXT,true));
599 pLabel->SetTextColor(COLOR_SUB_TEXT_SETTINGS);
607 SettingForm::OnTouchMoved(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
609 AppLogDebug("ENTER %ls",source.GetName().GetPointer());
610 if (source.GetName().Equals(IDC_LABEL_SUB_TEXT,true)
611 || source.GetName().Equals(IDC_LABEL_MAIN_TEXT,true)
612 || source.GetName().Equals(IDC_LABEL_EX,true))
614 Panel* pSourcePanel = dynamic_cast<Panel*>(source.GetParent());
617 Label* pLabel = static_cast<Label*>(pSourcePanel->GetControl(IDC_LABEL_SUB_TEXT,true));
620 pLabel->SetTextColor(COLOR_SUB_TEXT_SETTINGS);
628 SettingForm::OnTouchPressed(const Control& source, const Point& currentPosition, const TouchEventInfo & touchInfo)
630 AppLogDebug("ENTER %ls", source.GetName().GetPointer());
631 if (source.GetName().Equals(IDC_LABEL_SUB_TEXT,true)
632 || source.GetName().Equals(IDC_LABEL_MAIN_TEXT,true)
633 || source.GetName().Equals(IDC_LABEL_EX,true))
635 Panel* pSourcePanel = dynamic_cast<Panel*>(source.GetParent());
638 Label* pLabel = static_cast<Label*>(pSourcePanel->GetControl(IDC_LABEL_SUB_TEXT,true));
641 pLabel->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
642 // pLabel->Invalidate(false);
650 SettingForm::OnTouchReleased(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
652 AppLogDebug("ENTER %ls",source.GetName().GetPointer());
653 if (source.GetName().Equals(IDC_LABEL_SUB_TEXT,true)
654 || source.GetName().Equals(IDC_LABEL_MAIN_TEXT,true)
655 || source.GetName().Equals(IDC_LABEL_EX,true))
657 Panel* pSourcePanel = dynamic_cast<Panel*>(source.GetParent());
660 Label* pLabel = static_cast<Label*>(pSourcePanel->GetControl(IDC_LABEL_SUB_TEXT,true));
663 pLabel->SetTextColor(COLOR_SUB_TEXT_SETTINGS);
664 // pLabel->Invalidate(false);
672 SettingForm::OnActionPerformed(const Control& source, int actionId)
674 AppLogDebug("ENTER");
679 SettingForm::OnFormBackRequested(Form& source)
681 AppLogDebug("ENTER");
682 SceneManager* pSceneManager = SceneManager::GetInstance();
683 AppAssert(pSceneManager);
684 result r = pSceneManager->GoBackward(BackwardSceneTransition());
687 __pSettingPresentationModel->DestroySettingPresentationModel();
688 UiApp* pApp = UiApp::GetInstance();
695 SettingForm::OnSceneActivatedN(const SceneId& previousSceneId,
696 const SceneId& currentSceneId,
699 AppLogDebug("ENTER");
700 SceneManager* pSceneManager = SceneManager::GetInstance();
701 AppAssert(pSceneManager);
703 CommonUtil::SetSimpleTitleStyle(*GetHeader(), ResourceManager::GetString(L"IDS_MUSIC_BODY_MUSIC_SETTINGS"));
707 pArgs->RemoveAll(true);
714 SettingForm::OnSceneDeactivated(const SceneId& currentSceneId,
715 const SceneId& nextSceneId)
717 AppLogDebug("ENTER");
722 SettingForm::GetAutoOffString(void)
724 AppLogDebug("ENTER");
725 switch (__pSettingPresentationModel->GetAutoOffTime())
727 case ID_SUB_ZERO_ITEM:
729 return ResourceManager::GetString(L"IDS_MUSIC_BODY_NOT_USED");
733 case ID_SUB_FIFTEEN_ITEM:
735 return ResourceManager::GetString(L"IDS_MUSIC_OPT_AFTER_15_MIN_ABB");
739 case ID_SUB_THIRTY_ITEM:
741 return ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_30_MIN");
745 case ID_SUB_ONE_HOUR_ITEM:
747 return ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_1_HOUR");
751 case ID_SUB_ONE_HOUR_THIRTY_ITEM:
753 return ResourceManager::GetString(L"IDS_MUSIC_POP_AFTER_1_HOUR_30_MIN");
757 case ID_SUB_TWO_HOURS_ITEM:
759 return ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_2_HOURS");
768 return ResourceManager::GetString(L"IDS_MUSIC_BODY_NOT_USED");