Applied latest source code
[apps/native/preloaded/Settings.git] / src / StMemoryForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                StMemoryForm.cpp
19  * @brief               This is the implementation file for MemoryForm class.
20  */
21
22 #include "StMemoryForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
32
33 static const int ID_GROUP_MEMORY_MAIN = 0;
34
35 static const int ID_GROUP_MEMORY_MAIN_ITEM_COUNT = 1;
36 static const int ID_ITEM_MEMORY_MAIN_MEMORY_STATUS = 0;
37
38 static const int ID_GROUP_COUNT = 1;
39
40 MemoryForm::MemoryForm(void)
41 {
42 }
43
44 MemoryForm::~MemoryForm(void)
45 {
46 }
47
48 void
49 MemoryForm::CreateFooter(void)
50 {
51         Footer* pFooter = GetFooter();
52         AppAssert(pFooter);
53
54         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
55         pFooter->AddActionEventListener(*this);
56
57         SetFormBackEventListener(this);
58 }
59
60 result
61 MemoryForm::OnInitializing(void)
62 {
63         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MEMORY"));
64         CreateTableView();
65
66         AppLogDebug("ENTER");
67
68         return E_SUCCESS;
69 }
70
71 result
72 MemoryForm::OnTerminating(void)
73 {
74         __pTableView = null;
75
76         SetFormBackEventListener(null);
77         return E_SUCCESS;
78 }
79
80 void
81 MemoryForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
82 {
83         __pTableView->UpdateTableView();
84 }
85
86 void
87 MemoryForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
88 {
89 }
90
91 void
92 MemoryForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
93 {
94         SceneManager* pSceneManager = SceneManager::GetInstance();
95         AppAssert(pSceneManager);
96
97         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
98 }
99
100 int
101 MemoryForm::GetGroupCount(void)
102 {
103         AppLogDebug("ENTER");
104         return ID_GROUP_COUNT;
105 }
106
107 int
108 MemoryForm::GetItemCount(int groupIndex)
109 {
110         int itemCount = 0;
111
112         if (groupIndex == ID_GROUP_MEMORY_MAIN)
113         {
114                 itemCount = ID_GROUP_MEMORY_MAIN_ITEM_COUNT;
115         }
116
117         return itemCount;
118 }
119
120 TableViewGroupItem*
121 MemoryForm::CreateGroupItem(int groupIndex, int itemWidth)
122 {
123         AppLogDebug("ENTER");
124
125         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
126         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
127         Rectangle itemMainRectangle;
128         String groupText;
129         Label* pLabel = null;
130
131         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
132
133         itemMainRectangle.x = X_GROUP_INDEX_DEFAULT_LABEL;
134         itemMainRectangle.y = Y_GROUP_INDEX_DEFAULT_LABEL;
135         itemMainRectangle.width = itemWidth;
136         itemMainRectangle.height = itemHeight;
137
138         RelativeLayout relativeLayout;
139         relativeLayout.Construct();
140
141         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
142         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
143
144         pLabel = new (std::nothrow) Label();
145         pLabel->Construct(itemMainRectangle, groupText);
146         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
147         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
148         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
149
150         pItem->AddControl(pLabel);
151         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
152         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
153         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
154         pItem->SetEnabled(false);
155
156         return pItem;
157 }
158
159 TableViewItem*
160 MemoryForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
161 {
162         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
163
164         Rectangle itemMainRectangle;
165         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
166         String itemMainText;
167         Label* pLabel = null;
168         int fontSize = GetFontSize();
169
170         ItemTypeOneLine(itemMainRectangle);
171
172         if (itemIndex == ID_ITEM_MEMORY_MAIN_MEMORY_STATUS)
173         {
174                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MEMORY_STATUS");
175         }
176
177         TableViewItem* pItem = new (std::nothrow) TableViewItem();
178
179         RelativeLayout relativeLayout;
180         relativeLayout.Construct();
181
182         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
183         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
184
185         pLabel = new (std::nothrow) Label();
186         pLabel->Construct(itemMainRectangle, itemMainText);
187         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
188         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
189         pLabel->SetTextColor(COLOR_MAIN_TEXT);
190
191         pItem->AddControl(pLabel);
192         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
193         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
194         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
195
196         return pItem;
197 }
198
199 bool
200 MemoryForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
201 {
202         AppLogDebug("ENTER");
203
204         delete pItem;
205         pItem = null;
206
207         return true;
208 }
209
210 bool
211 MemoryForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
212 {
213         AppLogDebug("ENTER");
214
215         delete pItem;
216         pItem = null;
217
218         return true;
219 }
220
221 void
222 MemoryForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
223 {
224         SceneManager* pSceneManager = SceneManager::GetInstance();
225         AppAssert(pSceneManager);
226
227         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
228
229         if (itemIndex == ID_ITEM_MEMORY_MAIN_MEMORY_STATUS)
230         {
231                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_MEMORY_STATUS, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
232         }
233 }
234
235 int
236 MemoryForm::GetDefaultGroupItemHeight(void)
237 {
238         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
239 }
240
241 int
242 MemoryForm::GetDefaultItemHeight(void)
243 {
244         return H_GROUP_ITEM_DEFAULT;
245 }
246
247 void
248 MemoryForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
249 {
250 }
251
252 void
253 MemoryForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
254 {
255 }
256
257 void
258 MemoryForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
259 {
260 }
261
262 void
263 MemoryForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
264 {
265 }