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 StPrivacyForm.cpp
19 * @brief This is the implementation file for PrivacyForm class.
22 #include <FSecurity.h>
23 #include "StPrivacyForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
28 using namespace Tizen::App::Package;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Base::Utility;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Security;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
38 static const int ID_GROUP_COUNT = 1;
40 PrivacyForm::PrivacyForm(void)
41 : __pPrivacyManager(null)
42 , __privacyPackageList(null)
46 PrivacyForm::~PrivacyForm(void)
51 PrivacyForm::CreateFooter(void)
53 Footer* pFooter = GetFooter();
56 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
57 pFooter->SetBackButton();
58 pFooter->AddActionEventListener(*this);
60 SetFormBackEventListener(this);
64 PrivacyForm::OnInitializing(void)
68 result r = InitPrivacyAppPackageList();
71 AppLogDebug("InitPrivacyAppPackageList");
75 CreateHeader(ResourceManager::GetString(L"IDS_COM_BODY_PRIVACY"));
77 UpdateTableViewAndNoContent();
83 PrivacyForm::OnTerminating(void)
85 __pPrivacyManager = null;
87 if (__privacyPackageList != null)
89 __privacyPackageList->RemoveAll(true);
90 __privacyPackageList = null;
93 int controlCount = GetControlCount();
94 for (int i = 0; i < controlCount; i++)
96 RemoveControl(GetControl(0));
100 SetFormBackEventListener(null);
105 PrivacyForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
107 AppLogDebug("Enter");
114 UpdateTableViewAndNoContent();
118 PrivacyForm::InitPrivacyAppPackageList(void)
120 __pPrivacyManager = PrivacyManager::GetInstance();
121 if (__pPrivacyManager == null)
123 AppLogDebug("pPrivacyManager is null");
127 __privacyPackageList = static_cast<ArrayList*>(__pPrivacyManager->GetPrivacyAppPackageListN());
129 if (__privacyPackageList == null)
131 AppLogDebug("__privacyPackageList is null");
138 PrivacyForm::GetDisplayPackageName(int itemIndex)
142 if (__privacyPackageList == null)
147 String packageId = *static_cast<String*>(__privacyPackageList->GetAt(itemIndex));
148 if (packageId.IsEmpty() == true)
150 AppLogDebug("packageId is empty");
154 PackageManager* pPackageManager = PackageManager::GetInstance();
155 if (pPackageManager == null)
157 AppLogDebug("pPackageManager is null");
161 PackageInfo* pPackageInfo = pPackageManager->GetPackageInfoN(packageId);
162 if (pPackageInfo == null)
164 AppLogDebug("pPackageInfo is null. GetDisplayName fail");
167 return pPackageInfo->GetDisplayName();
173 PrivacyForm::GetUsedPrivacyService(int itemIndex)
177 if (__privacyPackageList == null)
182 ArrayList* pPrivacyServiceList = static_cast<ArrayList*>(__privacyPackageList->GetAt(itemIndex));
183 if (pPrivacyServiceList == null)
185 AppLogDebug("pPrivacyServiceList is null");
189 String packageId = *static_cast<String*>(__privacyPackageList->GetAt(itemIndex));
191 ArrayList* privacyListInfo = static_cast<ArrayList*>(__pPrivacyManager->GetPrivacyInfoListN(packageId));
192 if (privacyListInfo == null)
194 AppLogDebug("privacyListInfo null");
198 int serviceCount = privacyListInfo->GetCount();
199 for (int index = 0; index < serviceCount; index++)
201 PrivacyInfo* pPrivacyService = static_cast<PrivacyInfo*>(privacyListInfo->GetAt(index));
204 String key = pPrivacyService->GetDisplayName();
206 StringTokenizer stringTokenizer(key, L"/");
207 while (stringTokenizer.HasMoreTokens() == true)
209 stringTokenizer.GetNextToken(tokenData);
212 result.Append(tokenData);
214 if (index != (serviceCount - 1))
216 result.Append(L", ");
223 PrivacyForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
228 PrivacyForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
230 SceneManager* pSceneManager = SceneManager::GetInstance();
231 AppAssert(pSceneManager);
233 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
237 PrivacyForm::GetGroupCount(void)
239 AppLogDebug("ENTER");
240 return ID_GROUP_COUNT;
244 PrivacyForm::GetItemCount(int groupIndex)
248 itemCount = GetPackageListCount();
249 AppLogDebug("GetItemCount %d", itemCount);
255 PrivacyForm::CreateGroupItem(int groupIndex, int itemWidth)
257 AppLogDebug("ENTER");
259 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
260 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
261 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
262 Rectangle itemMainRectangle;
264 Label* pLabel = null;
265 int fontSize = GetFontSize();
267 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
269 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
270 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
272 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
273 itemMainRectangle.y = yItemOffset;
274 itemMainRectangle.width = itemWidth;
275 itemMainRectangle.height = itemHeight;
277 RelativeLayout relativeLayout;
278 relativeLayout.Construct();
280 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
281 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
283 pLabel = new (std::nothrow) Label();
284 pLabel->Construct(itemMainRectangle, groupText);
285 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
286 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
287 pLabel->SetTextConfig(fontSize, style);
288 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
290 pItem->AddControl(pLabel);
291 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
292 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
293 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
294 pItem->SetEnabled(false);
300 PrivacyForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
302 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
304 Rectangle itemMainRectangle;
305 Rectangle itemSubRectangle;
306 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
309 String fontReturnValue;
310 Label* pLabel = null;
312 int fontSize = GetFontSize();
313 int itemHeight = H_GROUP_ITEM_DEFAULT;
314 Rectangle detailArrow;
316 itemMainText = GetDisplayPackageName(itemIndex);
317 itemSubText = GetUsedPrivacyService(itemIndex);
319 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
320 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
322 RelativeLayout relativeLayout;
323 relativeLayout.Construct();
325 TableViewItem* pItem = new (std::nothrow) TableViewItem();
327 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
328 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
330 pLabel = new (std::nothrow) Label();
331 pLabel->Construct(itemMainRectangle, itemMainText);
332 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
333 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
334 pLabel->SetTextColor(COLOR_MAIN_TEXT);
336 pItem->AddControl(pLabel);
337 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
338 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
340 pLabel = new (std::nothrow) Label();
341 pLabel->Construct(itemSubRectangle, itemSubText);
342 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
343 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
344 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
345 pLabel->SetTextColor(COLOR_SUB_TEXT);
347 pItem->AddControl(pLabel);
348 relativeLayout.SetMargin(*pLabel, itemSubRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
349 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
350 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
356 PrivacyForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
358 AppLogDebug("ENTER");
367 PrivacyForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
369 AppLogDebug("ENTER");
378 PrivacyForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
380 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
382 SceneManager* pSceneManager = SceneManager::GetInstance();
383 AppAssert(pSceneManager);
385 ArrayList* pPrivacyServiceData = new (std::nothrow) ArrayList(SingleObjectDeleter);
386 pPrivacyServiceData->Construct();
388 Label* firstLineLabel = static_cast<Label*>(pItem->GetControl(0));
389 Label* secondLineLabel = static_cast<Label*>(pItem->GetControl(1));
391 String packageId = *static_cast<String*>(__privacyPackageList->GetAt(itemIndex));
392 pPrivacyServiceData->Add(new (std::nothrow) String(packageId));
396 pPrivacyServiceData->Add(new (std::nothrow) String(firstLineLabel->GetText()));
401 pPrivacyServiceData->Add(new (std::nothrow) String(secondLineLabel->GetText()));
404 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PRIVACY_DETAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pPrivacyServiceData);
408 PrivacyForm::GetDefaultGroupItemHeight(void)
410 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
414 PrivacyForm::GetDefaultItemHeight(void)
416 return H_GROUP_ITEM_DEFAULT;
420 PrivacyForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
425 PrivacyForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
431 PrivacyForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
436 PrivacyForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
441 PrivacyForm::GetPackageListCount(void)
443 if (__privacyPackageList == null)
445 AppLogDebug("__privacyPackageList is null");
449 return __privacyPackageList->GetCount();
453 PrivacyForm::UpdateTableViewAndNoContent(void)
455 bool createTableView = false;
456 if (__pTableView != null)
458 if (GetPackageListCount() != 0)
460 __pTableView->UpdateTableView();
466 if (GetPackageListCount() != 0)
468 createTableView = true;
472 if (__pTableView != null)
474 int tableViewControlCount = __pTableView->GetControlCount();
475 for (int i = 0; i < tableViewControlCount; i++)
477 __pTableView->RemoveControl(__pTableView->GetControl(0));
479 // __pTableView->RemoveAllControls();
482 int controlCount = GetControlCount();
483 for (int i = 0; i < controlCount; i++)
485 RemoveControl(GetControl(0));
487 // RemoveAllControls();
492 __pTableView->UpdateTableView();
496 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
499 Rectangle clientRect = GetClientAreaBounds();
500 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
502 int bitmapWidth = pBitmp->GetWidth();
503 int bitmapHeight = pBitmp->GetHeight();
504 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
505 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
506 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
508 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
509 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
511 Label* pLabel = new (std::nothrow) Label();
512 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
513 pLabel->SetName(NO_CONTENTS);
514 pLabel->SetBackgroundBitmap(*pBitmp);
516 yPos = yPos + bitmapHeight;
518 Label* pLabelNoContents = new (std::nothrow) Label();
519 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
520 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
521 pLabelNoContents->SetTextColor(textColor);
522 pLabelNoContents->SetText(labelText);
525 AddControl(pLabelNoContents);
531 PrivacyForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
533 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
536 Rectangle clientRect = GetClientAreaBounds();
537 Rectangle labelBound = pLabel->GetBounds();
539 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
540 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
542 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
543 yPos = yPos + pLabel->GetBounds().height;
544 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
545 if (pTextLabel != null)
547 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));