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 StMemoryStatusForm.cpp
19 * @brief This is the implementation file for MemoryStatusForm class.
22 #include "StMemoryStatusForm.h"
23 #include "StResourceManager.h"
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Io;
31 using namespace Tizen::System;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
36 static const int ID_GROUP_MEMORY_STATUS_MAIN = 0;
38 static const int ID_GROUP_COUNT = 1;
40 static const int GROUP_TOTAL_ITEM_COUNT_DEFAULT = 1;
41 static const int GROUP_TOTAL_ITEM_COUNT_MAX = 2;
43 static const int AVILABLE_SPACE_BYTE_CHANGED = 1024;
44 static const int AVILABLE_SPACE_STRING_LIMIT = 10;
46 enum SdCardTranslateTabelGroupIndex
48 SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_BASE,
49 SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_0 = SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_BASE,
50 SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_1,
51 SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_2,
52 SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_MAX
57 SD_CARD_GROUP_ITEM_BASE,
58 SD_CARD_GROUP_ITEM_MOUNT = SD_CARD_GROUP_ITEM_BASE,
59 SD_CARD_GROUP_ITEM_UNMOUNT,
60 SD_CARD_GORUP_ITEM_AVAILABLE_SPACE,
61 SD_CARD_GORUP_ITEM_MAX
64 MemoryStatusForm::MemoryStatusForm(void)
65 : __pMmcStorageManagerInstance(null)
66 , __sdGroupTotalItemCount(0)
70 MemoryStatusForm::~MemoryStatusForm(void)
75 MemoryStatusForm::CreateFooter(void)
77 Footer* pFooter = GetFooter();
80 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
81 pFooter->SetBackButton();
82 pFooter->AddActionEventListener(*this);
84 SetFormBackEventListener(this);
88 MemoryStatusForm::OnInitializing(void)
90 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MEMORY_STATUS"));
94 SetDeviceManagerEventListner();
95 RefreshSdGroupItemIndex();
97 return InitMmcStorageManagerInstance();
101 MemoryStatusForm::OnTerminating(void)
103 RemoveDeviceManagerEventListner();
104 __pMmcStorageManagerInstance->RemoveMmcStorageMountListener(*this);
105 __pMmcStorageManagerInstance = null;
109 SetFormBackEventListener(null);
114 MemoryStatusForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
116 RefreshSdGroupItemIndex();
117 __pTableView->UpdateTableView();
121 MemoryStatusForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
126 MemoryStatusForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
128 SceneManager* pSceneManager = SceneManager::GetInstance();
129 AppAssert(pSceneManager);
131 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
135 MemoryStatusForm::GetGroupCount(void)
137 return ID_GROUP_COUNT;
141 MemoryStatusForm::GetItemCount(int groupIndex)
147 case ID_GROUP_MEMORY_STATUS_MAIN:
149 itemCount = __sdGroupTotalItemCount;
161 MemoryStatusForm::CreateGroupItem(int groupIndex, int itemWidth)
163 AppLogDebug("ENTER");
165 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
166 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
167 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
168 Rectangle itemMainRectangle;
170 Label* pLabel = null;
172 if (groupIndex == ID_GROUP_MEMORY_STATUS_MAIN)
174 groupText = ResourceManager::GetString(L"IDS_ST_BODY_SD_CARD");
177 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
179 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
180 itemHeight = H_GROUP_INDEX_DEFAULT;
182 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
183 itemMainRectangle.y = yItemOffset;
184 itemMainRectangle.width = itemWidth;
185 itemMainRectangle.height = itemHeight;
187 RelativeLayout relativeLayout;
188 relativeLayout.Construct();
190 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
191 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
193 pLabel = new (std::nothrow) Label();
194 pLabel->Construct(itemMainRectangle, groupText);
195 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
196 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
197 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
198 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
200 pItem->AddControl(pLabel);
201 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
202 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
203 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
204 pItem->SetEnabled(false);
210 MemoryStatusForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
212 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
214 bool isItemSubText = false;
215 Rectangle itemMainRectangle;
216 Rectangle itemSubRectangle;
217 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
220 String fontReturnValue;
221 int fontSize = GetFontSize();
226 case ID_GROUP_MEMORY_STATUS_MAIN:
228 switch (__sdGroupItemTranslateTable[itemIndex])
230 case SD_CARD_GROUP_ITEM_MOUNT:
232 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MOUNT_SD_CARD");
233 itemSubText = L"Insert SD card";
234 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
235 itemHeight = itemMainRectangle.height + itemSubRectangle.height;
236 isItemSubText = true;
240 case SD_CARD_GROUP_ITEM_UNMOUNT:
242 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_UNMOUNT_SD_CARD");;
243 ItemTypeOneLine(itemMainRectangle);
244 itemHeight = itemMainRectangle.height;
248 case SD_CARD_GORUP_ITEM_AVAILABLE_SPACE:
250 long long availableSpace = 0;
251 RuntimeInfo::GetValue(L"http://tizen.org/runtime/storage.available.external", availableSpace);
252 if (IsFailed(GetLastResult()))
256 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_AVAILABLE_SPACE");
257 float megabyteAvailableSpace = static_cast<float>(availableSpace) / (AVILABLE_SPACE_BYTE_CHANGED * AVILABLE_SPACE_BYTE_CHANGED);
258 if (megabyteAvailableSpace > AVILABLE_SPACE_BYTE_CHANGED)
260 float gigabyteAvailableSpace = megabyteAvailableSpace / AVILABLE_SPACE_BYTE_CHANGED;
261 itemSubText.Format(AVILABLE_SPACE_STRING_LIMIT, L"%.1f", gigabyteAvailableSpace);
262 itemSubText.Append(L" GB");
266 itemSubText.Format(AVILABLE_SPACE_STRING_LIMIT, L"%.0f", megabyteAvailableSpace);
267 itemSubText.Append(L" MB");
269 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
270 itemHeight = itemMainRectangle.height + itemSubRectangle.height;
271 isItemSubText = true;
285 TableViewItem* pItem = new (std::nothrow) TableViewItem();
286 RelativeLayout relativeLayout;
287 relativeLayout.Construct();
289 result r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
292 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
296 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
298 Label* pLabel = new (std::nothrow) Label();
301 AppLogDebug("pLabel is null");
304 r = pLabel->Construct(itemMainRectangle, itemMainText);
307 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
311 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
312 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
313 pLabel->SetTextColor(COLOR_MAIN_TEXT);
315 pItem->AddControl(pLabel);
316 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
317 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
318 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
320 if (isItemSubText == true)
322 Label* pSecondLabel = new (std::nothrow) Label();
323 if (pSecondLabel == null)
325 AppLogDebug("pLabel is null");
328 r = pSecondLabel->Construct(itemSubRectangle, itemSubText);
331 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
336 pSecondLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
337 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
339 pSecondLabel->SetTextColor(COLOR_SUB_TEXT);
341 pItem->AddControl(pSecondLabel);
342 relativeLayout.SetMargin(*pSecondLabel, itemSubRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
343 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
344 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
351 MemoryStatusForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
353 AppLogDebug("ENTER");
362 MemoryStatusForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
364 AppLogDebug("ENTER");
373 MemoryStatusForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
375 if ( __pMmcStorageManagerInstance == null)
377 AppLogDebug("__pMmcStorageManagerInstance is null");
383 case ID_GROUP_MEMORY_STATUS_MAIN:
385 switch (__sdGroupItemTranslateTable[itemIndex])
387 case SD_CARD_GROUP_ITEM_MOUNT:
389 result r = __pMmcStorageManagerInstance->Mount();
392 AppLogDebug("Mount failed(%s)", GetErrorMessage(r));
397 case SD_CARD_GROUP_ITEM_UNMOUNT:
399 result r = __pMmcStorageManagerInstance->Unmount();
402 AppLogDebug("Unmount failed(%s)", GetErrorMessage(r));
419 MemoryStatusForm::GetDefaultGroupItemHeight(void)
421 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
425 MemoryStatusForm::GetDefaultItemHeight(void)
427 return H_GROUP_ITEM_DEFAULT;
431 MemoryStatusForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
436 MemoryStatusForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
441 MemoryStatusForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
446 MemoryStatusForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
451 MemoryStatusForm::OnMmcStorageMounted(result r)
455 RefreshSdGroupItemIndex();
456 __pTableView->UpdateTableView();
458 AppLogDebug("Exit(%s)", GetErrorMessage(r));
462 MemoryStatusForm::OnMmcStorageUnmounted(result r)
466 RefreshSdGroupItemIndex();
467 __pTableView->UpdateTableView();
469 AppLogDebug("Exit(%s)", GetErrorMessage(r));
473 MemoryStatusForm::OnMmcStorageFormatted(result r)
478 MemoryStatusForm::InitMmcStorageManagerInstance(void)
480 __pMmcStorageManagerInstance = MmcStorageManager::GetInstance();
481 if (__pMmcStorageManagerInstance == null)
485 return __pMmcStorageManagerInstance->AddMmcStorageMountListener(*this);
489 MemoryStatusForm::SetDeviceManagerEventListner(void)
491 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
495 MemoryStatusForm::RemoveDeviceManagerEventListner(void)
497 DeviceManager::RemoveAllDeviceEventListeners();
501 MemoryStatusForm::RefreshSdGroupItemIndex(void)
503 __sdGroupTotalItemCount = GROUP_TOTAL_ITEM_COUNT_DEFAULT;
504 __sdGroupItemTranslateTable[SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_0] = SD_CARD_GROUP_ITEM_MOUNT;
505 if (IsSdMounted() == true)
507 __sdGroupTotalItemCount = GROUP_TOTAL_ITEM_COUNT_MAX;
508 __sdGroupItemTranslateTable[SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_0] = SD_CARD_GORUP_ITEM_AVAILABLE_SPACE;
509 __sdGroupItemTranslateTable[SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_1] = SD_CARD_GROUP_ITEM_UNMOUNT;
514 MemoryStatusForm::IsSdMounted(void)
517 DeviceManager::GetState(DEVICE_TYPE_STORAGE_CARD, sdCardState);
518 if (sdCardState.Equals(L"Mounted", false))