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 SetFormBackEventListener(this);
78 NfcForm::OnInitializing(void)
80 CreateHeader(ResourceManager::GetString(L"IDS_NFC_BODY_NFC"));
83 if (__pNfcPresentationModelInstance == null)
85 __pNfcPresentationModelInstance = NfcPresentationModel::GetInstance();
86 if (__pNfcPresentationModelInstance != null)
88 __pNfcPresentationModelInstance->SetNfcEventListener(this);
96 NfcForm::OnTerminating(void)
98 SetFormBackEventListener(null);
99 __pNfcPresentationModelInstance->SetNfcEventListener(null);
104 NfcForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
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)
150 NfcForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
152 SceneManager* pSceneManager = SceneManager::GetInstance();
153 AppAssert(pSceneManager);
155 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
159 NfcForm::GetGroupCount(void)
162 if (__isPredefinedItem)
164 groupCount = NFC_SUPPORT_PREDEFINED_ITEM_GROUP_COUNT;
168 groupCount = NFC_NOT_SUPPORT_PREDEFINED_ITEM_GROUP_COUNT;
174 NfcForm::GetItemCount(int groupIndex)
177 if (groupIndex == ID_GROUP_NFC)
179 itemCount = ID_GROUP_NFC_ITEM_COUNT;
181 else if (groupIndex == ID_GROUP_NFC_PREDEFINED_ITEM)
183 itemCount = ID_GROUP_NFC_PREDEFINED_ITEM_COUNT;
189 NfcForm::CreateGroupItem(int groupIndex, int itemWidth)
191 AppLogDebug("ENTER");
192 AppLogDebug("group[%d] width[%d]", groupIndex, itemWidth);
194 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
195 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
196 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
197 Rectangle itemMainRectangle;
198 int fontSize = GetFontSize();
200 Label* pLabel = null;
202 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
208 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
213 case ID_GROUP_NFC_HELP:
215 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP / DIVIDE_BY_TWO;
216 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");
217 itemHeight = GetHeightForStringArea(groupText, itemWidth - W_TEXT_GAP, fontSize) + H_TEXT_GAP;
221 case ID_GROUP_NFC_PREDEFINED_ITEM:
223 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
224 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
228 case ID_GROUP_NFC_PREDEFINED_ITEM_HELP:
230 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP / DIVIDE_BY_TWO;
231 groupText = ResourceManager::GetString(L"IDS_NFC_BODY_YOU_CAN_BEAM_PREDEFINED_ITEMS_TO_ANOTHER_NFC_DEVICE_JUST_BRING_THE_DEVICES_CLOSE_TOGETHER_MSG");
232 itemHeight = GetHeightForStringArea(groupText, itemWidth - W_TEXT_GAP, fontSize) + H_TEXT_GAP;
238 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
239 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
244 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
245 itemMainRectangle.y = yItemOffset;
246 itemMainRectangle.width = itemWidth;
247 itemMainRectangle.height = itemHeight + H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
249 RelativeLayout relativeLayout;
250 relativeLayout.Construct();
252 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
253 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
255 pLabel = new (std::nothrow) Label();
256 pLabel->Construct(itemMainRectangle, groupText);
257 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
258 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
259 pLabel->SetTextConfig(fontSize, style);
260 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
262 pItem->AddControl(pLabel);
263 pItem->SetEnabled(false);
264 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
265 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
266 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
272 NfcForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
274 AppLogDebug("group[%d] item[%d] width[%d]", groupIndex, itemIndex, itemWidth);
275 int itemHeight = H_GROUP_ITEM_DEFAULT;
276 int fontSize = GetFontSize();
277 Rectangle itemMainRectangle;
278 Rectangle itemSubRectangle;
283 ItemTypeOneLine(itemMainRectangle);
284 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
286 TableViewItem* pItem = new (std::nothrow) TableViewItem();
296 itemMainText = ResourceManager::GetString(L"IDS_NFC_BODY_NFC");
297 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
301 case ID_GROUP_NFC_PREDEFINED_ITEM:
303 if (__pResevedPushCandidatesAppidList->GetCount() != 0)
305 int selectItemIndex = __pNfcPredefinedItemPresentationModelInstance->GetSelectNfcReservedPushCandidatesAppIdIndex();
306 itemSubText = *static_cast<String*>(__pResevedPushCandidatesAppidList->GetAt(selectItemIndex));
308 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
309 itemMainText = ResourceManager::GetString(L"IDS_NFC_BODY_PREDEFINED_ITEM_ABB");
310 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
316 AppLogDebug("CreateItem is error");
322 RelativeLayout relativeLayout;
323 relativeLayout.Construct();
325 result r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
328 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
333 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
335 Label* pLabel = new (std::nothrow) Label();
338 AppLogDebug("pLabel is null");
342 r = pLabel->Construct(itemMainRectangle, itemMainText);
345 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
350 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
351 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
352 pLabel->SetTextColor(COLOR_MAIN_TEXT);
354 pItem->AddControl(pLabel);
355 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
356 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
357 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
359 if (groupIndex == ID_GROUP_NFC_PREDEFINED_ITEM)
361 Label* pSecondLineLabel = new (std::nothrow) Label();
362 if (pSecondLineLabel == null)
364 AppLogDebug("pLabel is null");
368 r = pSecondLineLabel->Construct(itemSubRectangle, itemSubText);
371 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
372 delete pSecondLineLabel;
376 pSecondLineLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
377 pSecondLineLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
378 pSecondLineLabel->SetTextColor(COLOR_SUB_TEXT);
380 pItem->AddControl(pSecondLineLabel);
381 relativeLayout.SetMargin(*pSecondLineLabel, itemSubRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
382 relativeLayout.SetRelation(*pSecondLineLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
383 relativeLayout.SetRelation(*pSecondLineLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
389 NfcForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
391 AppLogDebug("ENTER");
400 NfcForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
402 AppLogDebug("ENTER");
411 NfcForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
413 AppLogDebug("groupIndex [%d] itemIndex [%d]", groupIndex, itemIndex);
414 if ((groupIndex != 0)
417 AppLogDebug("OnGroupedTableViewGroupItemStateChanged is Error");
420 if (__pNfcPresentationModelInstance == null)
422 AppLogDebug("__pNfcPresentationModelInstance is null");
432 AppLogDebug("nfc turn on or off");
433 __pTableView->SetItemChecked(groupIndex, itemIndex, !__pTableView->IsItemChecked(groupIndex, itemIndex));
437 ToggleNfcActivateStatus(status);
441 case ID_GROUP_NFC_PREDEFINED_ITEM:
443 bool NfcReservedPushActivated = __pNfcPredefinedItemPresentationModelInstance->IsNfcReservedPushActivated();
444 __pTableView->SetItemChecked(ID_GROUP_NFC_PREDEFINED_ITEM, ID_GROUP_ITEM_NFC_PREDEFINED_ITEM, NfcReservedPushActivated);
445 SceneManager* pSceneManager = SceneManager::GetInstance();
446 AppAssert(pSceneManager);
447 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_NFC_PREDEFINED_ITEM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
453 AppLogDebug("OnGroupedTableViewItemStateChanged is error");
460 NfcForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
465 NfcForm::GetDefaultGroupItemHeight(void)
467 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
471 NfcForm::GetDefaultItemHeight(void)
473 return H_GROUP_ITEM_DEFAULT;
477 NfcForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
479 if ((groupIndex != ID_GROUP_NFC_HELP)
480 && (groupIndex != ID_GROUP_NFC_PREDEFINED_ITEM_HELP))
482 AppLogDebug("groupIndex is not ID_GROUP_FONT_TEXT");
486 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
489 AppLogDebug("pLabel is null");
493 Rectangle clientRect = GetClientAreaBounds();
494 Rectangle itemRect = pItem->GetBounds();
495 String groupText = pLabel->GetText();
496 int fontSize = GetFontSize();
497 int itemHeight = GetHeightForStringArea(groupText, clientRect.width, fontSize) + H_TEXT_GAP;
499 itemRect.height = itemHeight;
501 pLabel->SetBounds(pLabel->GetX(), pLabel->GetY(), clientRect.width, itemHeight);
502 pItem->SetBounds(itemRect);
506 NfcForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
511 NfcForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
516 NfcForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
521 NfcForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
523 __pTableView->RefreshItem(ID_GROUP_NFC_HELP, ID_GROUP_NFC_HELP_TEXT_LABEL, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
524 if (__isPredefinedItem)
526 __pTableView->RefreshItem(ID_GROUP_NFC_PREDEFINED_ITEM_HELP, ID_GROUP_NFC_PREDEFINED_ITEM_HELP_TEXT_LABEL, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
532 NfcForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
535 if (requestId == REFRESH_REQUEST_EVENT)
539 if (__pNfcPredefinedItemPresentationModelInstance == null)
541 __pNfcPredefinedItemPresentationModelInstance = NfcPredefinedItemPresentationModel::GetInstance();
544 if (__pNfcPredefinedItemPresentationModelInstance == null)
546 AppLogDebug("__pNfcPredefinedItemPresentationModelInstance == null");
550 if (__pNfcPredefinedItemPresentationModelInstance != null)
552 __pNfcPredefinedItemPresentationModelInstance->InitReservedPushCandidatesList();
553 __pResevedPushCandidatesAppidList = __pNfcPredefinedItemPresentationModelInstance->GetAllListReservedPushCandidatesAppIdList();
554 if (__pResevedPushCandidatesAppidList != null)
556 if (__pResevedPushCandidatesAppidList->GetCount() > 0)
558 __isPredefinedItem = true;
562 __isPredefinedItem = false;
566 __pTableView->UpdateTableView();
567 bool nfcActivated = false;
568 if (__pNfcPresentationModelInstance != null)
570 nfcActivated = __pNfcPresentationModelInstance->IsNfcActivated();
572 __pTableView->SetItemChecked(0, 0, nfcActivated);
573 if (__isPredefinedItem)
575 __pTableView->SetItemEnabled(ID_GROUP_NFC_PREDEFINED_ITEM, 0, nfcActivated);
576 bool NfcReservedPushActivated = __pNfcPredefinedItemPresentationModelInstance->IsNfcReservedPushActivated();
577 __pTableView->SetItemChecked(ID_GROUP_NFC_PREDEFINED_ITEM, ID_GROUP_ITEM_NFC_PREDEFINED_ITEM, NfcReservedPushActivated);
582 pArgs->RemoveAll(true);
589 NfcForm::ToggleNfcActivateStatus(Tizen::Ui::Controls::TableViewItemStatus itemStatus)
591 if (__pNfcPresentationModelInstance == null)
593 AppLogDebug("__pNfcPresentationModelInstance is null");
596 result r = E_SUCCESS;
600 case TABLE_VIEW_ITEM_STATUS_CHECKED:
602 r = __pNfcPresentationModelInstance->ActivateNfc();
605 AppLogDebug("Nfc active is failed %s", GetErrorMessage(r));
609 if (__isPredefinedItem)
611 __pTableView->SetItemEnabled(ID_GROUP_NFC_PREDEFINED_ITEM, 0, true);
616 case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
618 r = __pNfcPresentationModelInstance->DeactivateNfc();
621 AppLogDebug("Nfc deactive is failed %s", GetErrorMessage(r));
625 if (__isPredefinedItem)
627 __pTableView->SetItemEnabled(ID_GROUP_NFC_PREDEFINED_ITEM, 0, false);
640 NfcForm::OnNfcPresentationModelEventCompleted(NfcPresentationModelEvent requestEvent, result r)
642 AppLog("requestEvent = %d", requestEvent);
643 if ((requestEvent == NFC_PRESENTATION_MODEL_EVENT_ACTIVATED)
644 || (requestEvent == NFC_PRESENTATION_MODEL_EVENT_DEACTIVATED))