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.
19 * @brief This is the implementation file for NfcForm class.
23 #include "StNfcForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
28 using namespace Tizen::App;
29 using namespace Tizen::App::Package;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::System;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
38 static const int ID_GROUP_NFC = 0;
39 static const int ID_GROUP_NFC_ITEM_COUNT = 1;
41 static const int ID_GROUP_NFC_HELP = 1;
42 static const int ID_GROUP_NFC_HELP_TEXT_LABEL = -1;
44 static const int ID_GROUP_NFC_PREDEFINED_ITEM = 2;
45 static const int ID_GROUP_NFC_PREDEFINED_ITEM_COUNT = 1;
46 static const int ID_GROUP_ITEM_NFC_PREDEFINED_ITEM = 0;
48 static const int ID_GROUP_NFC_PREDEFINED_ITEM_HELP = 3;
49 static const int ID_GROUP_NFC_PREDEFINED_ITEM_HELP_TEXT_LABEL = -1;
51 static const int NFC_NOT_SUPPORT_PREDEFINED_ITEM_GROUP_COUNT = 2;
52 static const int NFC_SUPPORT_PREDEFINED_ITEM_GROUP_COUNT = 4;
53 static const int W_TEXT_GAP = 30;
54 static const int H_TEXT_GAP = 20;
56 NfcForm::NfcForm(void)
57 : __pNfcPresentationModelInstance(null)
58 , __pNfcPredefinedItemPresentationModelInstance(null)
59 , __isPredefinedItem(false)
64 NfcForm::~NfcForm(void)
69 NfcForm::CreateFooter(void)
71 Footer* pFooter = GetFooter();
74 pFooter->SetBackButton();
75 SetFormBackEventListener(this);
79 NfcForm::OnInitializing(void)
81 CreateHeader(ResourceManager::GetString(L"IDS_NFC_BODY_NFC"));
89 NfcForm::OnTerminating(void)
91 SetFormBackEventListener(null);
96 NfcForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
98 if (__pNfcPresentationModelInstance == null)
100 __pNfcPresentationModelInstance = NfcPresentationModel::GetInstance();
101 if (__pNfcPresentationModelInstance != null)
103 __pNfcPresentationModelInstance->SetNfcEventListener(this);
106 if (__pNfcPredefinedItemPresentationModelInstance == null)
108 __pNfcPredefinedItemPresentationModelInstance = NfcPredefinedItemPresentationModel::GetInstance();
111 if (__pNfcPredefinedItemPresentationModelInstance == null)
113 AppLogDebug("__pNfcPredefinedItemPresentationModelInstance == null");
117 if (__pNfcPredefinedItemPresentationModelInstance != null)
119 __pNfcPredefinedItemPresentationModelInstance->InitReservedPushCandidatesList();
120 __pResevedPushCandidatesAppidList = __pNfcPredefinedItemPresentationModelInstance->GetAllListReservedPushCandidatesAppIdList();
121 if (__pResevedPushCandidatesAppidList != null)
123 if (__pResevedPushCandidatesAppidList->GetCount() > 0)
125 __isPredefinedItem = true;
129 __pTableView->UpdateTableView();
130 bool nfcActivated = false;
131 if (__pNfcPresentationModelInstance != null)
133 nfcActivated = __pNfcPresentationModelInstance->IsNfcActivated();
134 __pTableView->SetItemChecked(0, 0, nfcActivated);
136 if (__isPredefinedItem)
138 __pTableView->SetItemEnabled(ID_GROUP_NFC_PREDEFINED_ITEM, 0, nfcActivated);
139 bool NfcReservedPushActivated = __pNfcPredefinedItemPresentationModelInstance->IsNfcReservedPushActivated();
140 __pTableView->SetItemChecked(ID_GROUP_NFC_PREDEFINED_ITEM, ID_GROUP_ITEM_NFC_PREDEFINED_ITEM, NfcReservedPushActivated);
145 NfcForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
147 __pNfcPresentationModelInstance->SetNfcEventListener(null);
151 NfcForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
153 SceneManager* pSceneManager = SceneManager::GetInstance();
154 AppAssert(pSceneManager);
156 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
160 NfcForm::GetGroupCount(void)
163 if (__isPredefinedItem)
165 groupCount = NFC_SUPPORT_PREDEFINED_ITEM_GROUP_COUNT;
169 groupCount = NFC_NOT_SUPPORT_PREDEFINED_ITEM_GROUP_COUNT;
175 NfcForm::GetItemCount(int groupIndex)
178 if (groupIndex == ID_GROUP_NFC)
180 itemCount = ID_GROUP_NFC_ITEM_COUNT;
182 else if (groupIndex == ID_GROUP_NFC_PREDEFINED_ITEM)
184 itemCount = ID_GROUP_NFC_PREDEFINED_ITEM_COUNT;
190 NfcForm::CreateGroupItem(int groupIndex, int itemWidth)
192 AppLogDebug("ENTER");
193 AppLogDebug("group[%d] width[%d]", groupIndex, itemWidth);
195 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
196 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
197 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
198 Rectangle itemMainRectangle;
199 int fontSize = GetFontSize();
201 Label* pLabel = null;
203 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
209 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
210 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
214 case ID_GROUP_NFC_HELP:
216 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP / DIVIDE_BY_TWO;
217 groupText = ResourceManager::GetString(L"IDS_NFC_BODY_WHEN_NFC_IS_ON_YOU_CAN_SEND_OR_RECEIVE_DATA_WHEN_YOUR_DEVICE_TOUCHES_OTHER_NFC_CAPABLE_DEVICES_OR_NFC_TAGS");
218 itemHeight = GetHeightForStringArea(groupText, itemWidth - W_TEXT_GAP, fontSize) + H_TEXT_GAP;
222 case ID_GROUP_NFC_PREDEFINED_ITEM:
224 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
225 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
229 case ID_GROUP_NFC_PREDEFINED_ITEM_HELP:
231 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP / DIVIDE_BY_TWO;
232 groupText = ResourceManager::GetString(L"IDS_NFC_BODY_YOU_CAN_BEAM_PREDEFINED_ITEMS_TO_ANOTHER_NFC_DEVICE_JUST_BRING_THE_DEVICES_CLOSE_TOGETHER_MSG");
233 itemHeight = GetHeightForStringArea(groupText, itemWidth - W_TEXT_GAP, fontSize) + H_TEXT_GAP;
239 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
240 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
245 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
246 itemMainRectangle.y = yItemOffset;
247 itemMainRectangle.width = itemWidth;
248 itemMainRectangle.height = itemHeight + H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
250 RelativeLayout relativeLayout;
251 relativeLayout.Construct();
253 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
254 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
256 pLabel = new (std::nothrow) Label();
257 pLabel->Construct(itemMainRectangle, groupText);
258 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
259 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
260 pLabel->SetTextConfig(fontSize, style);
261 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
263 pItem->AddControl(pLabel);
264 pItem->SetEnabled(false);
265 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
266 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
267 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
273 NfcForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
275 AppLogDebug("group[%d] item[%d] width[%d]", groupIndex, itemIndex, itemWidth);
276 int itemHeight = H_GROUP_ITEM_DEFAULT;
277 int fontSize = GetFontSize();
278 Rectangle itemMainRectangle;
279 Rectangle itemSubRectangle;
284 ItemTypeOneLine(itemMainRectangle);
285 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
287 TableViewItem* pItem = new (std::nothrow) TableViewItem();
297 itemMainText = ResourceManager::GetString(L"IDS_NFC_BODY_NFC");
298 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
302 case ID_GROUP_NFC_PREDEFINED_ITEM:
304 if (__pResevedPushCandidatesAppidList->GetCount() != 0)
306 int selectItemIndex = __pNfcPredefinedItemPresentationModelInstance->GetSelectNfcReservedPushCandidatesAppIdIndex();
307 itemSubText = *static_cast<String*>(__pResevedPushCandidatesAppidList->GetAt(selectItemIndex));
309 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
310 itemMainText = ResourceManager::GetString(L"IDS_NFC_BODY_PREDEFINED_ITEM_ABB");
311 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
317 AppLogDebug("CreateItem is error");
323 RelativeLayout relativeLayout;
324 relativeLayout.Construct();
326 result r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
329 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
334 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
336 Label* pLabel = new (std::nothrow) Label();
339 AppLogDebug("pLabel is null");
343 r = pLabel->Construct(itemMainRectangle, itemMainText);
346 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
351 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
352 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
353 pLabel->SetTextColor(COLOR_MAIN_TEXT);
355 pItem->AddControl(pLabel);
356 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
357 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
358 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
360 if (groupIndex == ID_GROUP_NFC_PREDEFINED_ITEM)
362 Label* pSecondLineLabel = new (std::nothrow) Label();
363 if (pSecondLineLabel == null)
365 AppLogDebug("pLabel is null");
369 r = pSecondLineLabel->Construct(itemSubRectangle, itemSubText);
372 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
373 delete pSecondLineLabel;
377 pSecondLineLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
378 pSecondLineLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
379 pSecondLineLabel->SetTextColor(COLOR_SUB_TEXT);
381 pItem->AddControl(pSecondLineLabel);
382 relativeLayout.SetMargin(*pSecondLineLabel, itemSubRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
383 relativeLayout.SetRelation(*pSecondLineLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
384 relativeLayout.SetRelation(*pSecondLineLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
390 NfcForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
392 AppLogDebug("ENTER");
401 NfcForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
403 AppLogDebug("ENTER");
412 NfcForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
414 AppLogDebug("groupIndex [%d] itemIndex [%d]", groupIndex, itemIndex);
415 if ((groupIndex != 0)
418 AppLogDebug("OnGroupedTableViewGroupItemStateChanged is Error");
421 if (__pNfcPresentationModelInstance == null)
423 AppLogDebug("__pNfcPresentationModelInstance is null");
433 AppLogDebug("nfc turn on or off");
434 __pTableView->SetItemChecked(groupIndex, itemIndex, !__pTableView->IsItemChecked(groupIndex, itemIndex));
438 ToggleNfcActivateStatus(status);
439 __pTableView->UpdateTableView();
443 case ID_GROUP_NFC_PREDEFINED_ITEM:
445 bool NfcReservedPushActivated = __pNfcPredefinedItemPresentationModelInstance->IsNfcReservedPushActivated();
446 __pTableView->SetItemChecked(ID_GROUP_NFC_PREDEFINED_ITEM, ID_GROUP_ITEM_NFC_PREDEFINED_ITEM, NfcReservedPushActivated);
447 SceneManager* pSceneManager = SceneManager::GetInstance();
448 AppAssert(pSceneManager);
449 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_NFC_PREDEFINED_ITEM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
455 AppLogDebug("OnGroupedTableViewItemStateChanged is error");
462 NfcForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
467 NfcForm::GetDefaultGroupItemHeight(void)
469 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
473 NfcForm::GetDefaultItemHeight(void)
475 return H_GROUP_ITEM_DEFAULT;
479 NfcForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
481 if ((groupIndex != ID_GROUP_NFC_HELP)
482 && (groupIndex != ID_GROUP_NFC_PREDEFINED_ITEM_HELP))
484 AppLogDebug("groupIndex is not ID_GROUP_FONT_TEXT");
488 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
491 AppLogDebug("pLabel is null");
495 Rectangle clientRect = GetClientAreaBounds();
496 Rectangle itemRect = pItem->GetBounds();
497 String groupText = pLabel->GetText();
498 int fontSize = GetFontSize();
499 int itemHeight = GetHeightForStringArea(groupText, clientRect.width - W_TEXT_GAP, fontSize) + H_TEXT_GAP;
501 itemRect.height = itemHeight + H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
503 pLabel->SetBounds(clientRect.x, H_GROUP_INDEX_HELP_TEXT_TOP_GAP, clientRect.width, itemHeight);
504 pItem->SetBounds(itemRect);
508 NfcForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
513 NfcForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
518 NfcForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
523 NfcForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
525 __pTableView->RefreshItem(ID_GROUP_NFC_HELP, ID_GROUP_NFC_HELP_TEXT_LABEL, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
526 if (__isPredefinedItem)
528 __pTableView->RefreshItem(ID_GROUP_NFC_PREDEFINED_ITEM_HELP, ID_GROUP_NFC_PREDEFINED_ITEM_HELP_TEXT_LABEL, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
534 NfcForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
536 if (requestId == FRFRESH_REQUEST_EVENT)
540 __pTableView->UpdateTableView();
541 bool nfcActivated = false;
542 if (__pNfcPresentationModelInstance != null)
544 nfcActivated = __pNfcPresentationModelInstance->IsNfcActivated();
546 __pTableView->SetItemChecked(0, 0, nfcActivated);
547 if (__isPredefinedItem)
549 __pTableView->SetItemEnabled(ID_GROUP_NFC_PREDEFINED_ITEM, 0, nfcActivated);
550 bool NfcReservedPushActivated = __pNfcPredefinedItemPresentationModelInstance->IsNfcReservedPushActivated();
551 __pTableView->SetItemChecked(ID_GROUP_NFC_PREDEFINED_ITEM, ID_GROUP_ITEM_NFC_PREDEFINED_ITEM, NfcReservedPushActivated);
556 pArgs->RemoveAll(true);
563 NfcForm::ToggleNfcActivateStatus(Tizen::Ui::Controls::TableViewItemStatus itemStatus)
565 if (__pNfcPresentationModelInstance == null)
567 AppLogDebug("__pNfcPresentationModelInstance is null");
570 result r = E_SUCCESS;
574 case TABLE_VIEW_ITEM_STATUS_CHECKED:
576 r = __pNfcPresentationModelInstance->ActivateNfc();
579 AppLogDebug("Nfc active is failed %s", GetErrorMessage(r));
583 if (__isPredefinedItem)
585 __pTableView->SetItemEnabled(ID_GROUP_NFC_PREDEFINED_ITEM, 0, true);
590 case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
592 r = __pNfcPresentationModelInstance->DeactivateNfc();
595 AppLogDebug("Nfc deactive is failed %s", GetErrorMessage(r));
599 if (__isPredefinedItem)
601 __pTableView->SetItemEnabled(ID_GROUP_NFC_PREDEFINED_ITEM, 0, false);
614 NfcForm::OnNfcPresentationModelEventCompleted(NfcPresentationModelEvent requestEvent, result r)
616 AppLog("requestEvent = %d", requestEvent);
617 if ((requestEvent == NFC_PRESENTATION_MODEL_EVENT_ACTIVATED)
618 || (requestEvent == NFC_PRESENTATION_MODEL_EVENT_DEACTIVATED))