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)
71 MemoryStatusForm::~MemoryStatusForm(void)
76 MemoryStatusForm::CreateFooter(void)
78 Footer* pFooter = GetFooter();
81 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
82 pFooter->AddActionEventListener(*this);
84 SetFormBackEventListener(this);
88 MemoryStatusForm::OnInitializing(void)
90 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_STORAGE"));
93 SetDeviceManagerEventListner();
94 RefreshSdGroupItemIndex();
100 MemoryStatusForm::OnTerminating(void)
102 RemoveDeviceManagerEventListner();
103 if (__pMmcStorageManagerInstance)
105 __pMmcStorageManagerInstance->RemoveMmcStorageMountListener(*this);
106 __pMmcStorageManagerInstance = null;
111 SetFormBackEventListener(null);
116 MemoryStatusForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
118 RefreshSdGroupItemIndex();
119 __pTableView->UpdateTableView();
123 MemoryStatusForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
128 MemoryStatusForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
130 SceneManager* pSceneManager = SceneManager::GetInstance();
131 AppAssert(pSceneManager);
133 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
137 MemoryStatusForm::GetGroupCount(void)
139 return ID_GROUP_COUNT;
143 MemoryStatusForm::GetItemCount(int groupIndex)
149 case ID_GROUP_MEMORY_STATUS_MAIN:
151 itemCount = __sdGroupTotalItemCount;
163 MemoryStatusForm::CreateGroupItem(int groupIndex, int itemWidth)
165 AppLogDebug("ENTER");
167 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
168 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
169 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
170 Rectangle itemMainRectangle;
172 Label* pLabel = null;
174 if (groupIndex == ID_GROUP_MEMORY_STATUS_MAIN)
176 groupText = ResourceManager::GetString(L"IDS_ST_BODY_SD_CARD");
179 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
181 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
182 itemHeight = H_GROUP_INDEX_DEFAULT;
184 itemMainRectangle.x = X_GROUP_DEFAULT;
185 itemMainRectangle.y = yItemOffset;
186 itemMainRectangle.width = itemWidth;
187 itemMainRectangle.height = itemHeight;
189 RelativeLayout relativeLayout;
190 relativeLayout.Construct();
192 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
193 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
195 pLabel = new (std::nothrow) Label();
196 pLabel->Construct(itemMainRectangle, groupText);
197 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
198 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
199 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
200 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
202 pItem->AddControl(pLabel);
203 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
204 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
205 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
206 pItem->SetEnabled(false);
212 MemoryStatusForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
214 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
216 bool isItemSubText = false;
217 Rectangle itemMainRectangle;
218 Rectangle itemSubRectangle;
219 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
222 String fontReturnValue;
223 int fontSize = GetFontSize();
228 case ID_GROUP_MEMORY_STATUS_MAIN:
230 switch (__sdGroupItemTranslateTable[itemIndex])
232 case SD_CARD_GROUP_ITEM_MOUNT:
234 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MOUNT_SD_CARD");
235 itemSubText = L"Insert SD card";
236 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
237 itemHeight = itemMainRectangle.height + itemSubRectangle.height;
238 isItemSubText = true;
242 case SD_CARD_GROUP_ITEM_UNMOUNT:
244 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_UNMOUNT_SD_CARD");;
245 ItemTypeOneLine(itemMainRectangle);
246 itemHeight = itemMainRectangle.height;
250 case SD_CARD_GORUP_ITEM_AVAILABLE_SPACE:
252 long long availableSpace = 0;
253 RuntimeInfo::GetValue(L"http://tizen.org/runtime/storage.available.external", availableSpace);
254 if (IsFailed(GetLastResult()))
258 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_AVAILABLE_SPACE");
259 float megabyteAvailableSpace = static_cast<float>(availableSpace) / (AVILABLE_SPACE_BYTE_CHANGED * AVILABLE_SPACE_BYTE_CHANGED);
260 if (megabyteAvailableSpace > AVILABLE_SPACE_BYTE_CHANGED)
262 float gigabyteAvailableSpace = megabyteAvailableSpace / AVILABLE_SPACE_BYTE_CHANGED;
263 itemSubText.Format(AVILABLE_SPACE_STRING_LIMIT, L"%.1f", gigabyteAvailableSpace);
264 itemSubText.Append(L" GB");
268 itemSubText.Format(AVILABLE_SPACE_STRING_LIMIT, L"%.0f", megabyteAvailableSpace);
269 itemSubText.Append(L" MB");
271 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
272 itemHeight = itemMainRectangle.height + itemSubRectangle.height;
273 isItemSubText = true;
287 TableViewItem* pItem = new (std::nothrow) TableViewItem();
288 RelativeLayout relativeLayout;
289 relativeLayout.Construct();
291 result r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
294 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
298 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
300 Label* pLabel = new (std::nothrow) Label();
303 AppLogDebug("pLabel is null");
306 r = pLabel->Construct(itemMainRectangle, itemMainText);
309 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
313 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
314 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
315 pLabel->SetTextColor(COLOR_MAIN_TEXT);
316 if (groupIndex == ID_GROUP_MEMORY_STATUS_MAIN && itemIndex == SD_CARD_GROUP_ITEM_BASE)
318 pLabel->AddTouchEventListener(*this);
320 pItem->AddControl(pLabel);
321 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
322 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
323 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
325 if (isItemSubText == true)
327 __pLabel = new (std::nothrow) Label();
328 if (__pLabel == null)
330 AppLogDebug("pLabel is null");
333 r = __pLabel->Construct(itemSubRectangle, itemSubText);
336 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
341 __pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
342 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
343 __pLabel->AddTouchEventListener(*this);
344 __pLabel->SetTextColor(COLOR_SUB_TEXT);
346 pItem->AddControl(__pLabel);
347 pItem->AddKeyEventListener(*this);
348 pItem->AddFocusEventListener(*this);
349 relativeLayout.SetMargin(*__pLabel, itemSubRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
350 relativeLayout.SetRelation(*__pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
351 relativeLayout.SetRelation(*__pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
358 MemoryStatusForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
360 AppLogDebug("ENTER");
369 MemoryStatusForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
371 AppLogDebug("ENTER");
380 MemoryStatusForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
384 case ID_GROUP_MEMORY_STATUS_MAIN:
386 switch (__sdGroupItemTranslateTable[itemIndex])
388 case SD_CARD_GROUP_ITEM_MOUNT:
390 if (__pMmcStorageManagerInstance == null)
392 InitMmcStorageManagerInstance();
395 result r = __pMmcStorageManagerInstance->Mount();
398 AppLogDebug("Mount failed(%s)", GetErrorMessage(r));
403 case SD_CARD_GROUP_ITEM_UNMOUNT:
405 if (__pMmcStorageManagerInstance == null)
407 InitMmcStorageManagerInstance();
410 result r = __pMmcStorageManagerInstance->Unmount();
413 AppLogDebug("Unmount failed(%s)", GetErrorMessage(r));
430 MemoryStatusForm::GetDefaultGroupItemHeight(void)
432 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
436 MemoryStatusForm::GetDefaultItemHeight(void)
438 return H_GROUP_ITEM_DEFAULT;
442 MemoryStatusForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
447 MemoryStatusForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
452 MemoryStatusForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
457 MemoryStatusForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
462 MemoryStatusForm::OnMmcStorageMounted(result r)
467 RefreshSdGroupItemIndex();
468 __pTableView->UpdateTableView();
470 AppLogDebug("Exit(%s)", GetErrorMessage(r));
474 MemoryStatusForm::OnMmcStorageUnmounted(result r)
478 RefreshSdGroupItemIndex();
479 __pTableView->UpdateTableView();
481 AppLogDebug("Exit(%s)", GetErrorMessage(r));
485 MemoryStatusForm::OnMmcStorageFormatted(result r)
490 MemoryStatusForm::InitMmcStorageManagerInstance(void)
492 __pMmcStorageManagerInstance = MmcStorageManager::GetInstance();
493 if (__pMmcStorageManagerInstance == null)
497 return __pMmcStorageManagerInstance->AddMmcStorageMountListener(*this);
501 MemoryStatusForm::SetDeviceManagerEventListner(void)
503 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
507 MemoryStatusForm::RemoveDeviceManagerEventListner(void)
509 DeviceManager::RemoveAllDeviceEventListeners();
513 MemoryStatusForm::RefreshSdGroupItemIndex(void)
515 __sdGroupTotalItemCount = GROUP_TOTAL_ITEM_COUNT_DEFAULT;
516 __sdGroupItemTranslateTable[SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_0] = SD_CARD_GROUP_ITEM_MOUNT;
517 if (IsSdMounted() == true)
519 __sdGroupTotalItemCount = GROUP_TOTAL_ITEM_COUNT_MAX;
520 __sdGroupItemTranslateTable[SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_0] = SD_CARD_GORUP_ITEM_AVAILABLE_SPACE;
521 __sdGroupItemTranslateTable[SD_CARD_TRANSLATE_TABLE_GROUP_INDEX_1] = SD_CARD_GROUP_ITEM_UNMOUNT;
526 MemoryStatusForm::IsSdMounted(void)
529 DeviceManager::GetState(DEVICE_TYPE_STORAGE_CARD, sdCardState);
530 if (sdCardState.Equals(L"Mounted", false))
538 MemoryStatusForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
541 if (deviceType == DEVICE_TYPE_STORAGE_CARD)
543 RefreshSdGroupItemIndex();
544 __pTableView->UpdateTableView();
550 MemoryStatusForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
552 __pLabel->SetTextColor(COLOR_SUB_TEXT);
553 __pLabel->Invalidate(false);
557 MemoryStatusForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
559 __pLabel->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
560 __pLabel->Invalidate(false);
564 MemoryStatusForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
566 __pLabel->SetTextColor(COLOR_SUB_TEXT);
567 __pLabel->Invalidate(false);
571 MemoryStatusForm::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
573 __pLabel->SetTextColor(COLOR_SUB_TEXT);
574 __pLabel->Invalidate(false);
578 MemoryStatusForm::OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
581 if(keyCode == KEY_ENTER)
584 __pLabel->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
585 __pLabel->Invalidate(false);
590 MemoryStatusForm::OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
593 if(keyCode == KEY_ENTER)
596 __pLabel->SetTextColor(COLOR_SUB_TEXT);
597 __pLabel->Invalidate(false);
602 MemoryStatusForm::OnKeyLongPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
607 MemoryStatusForm::OnFocusLost(const Tizen::Ui::Control& source)
610 __pLabel->SetTextColor(COLOR_SUB_TEXT);
611 __pLabel->Invalidate(false);
615 MemoryStatusForm::OnFocusGained(const Tizen::Ui::Control& source)