Fixed N_SE-38563, N_SE-38552
[apps/osp/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->SetBackButton();
56         pFooter->AddActionEventListener(*this);
57
58         SetFormBackEventListener(this);
59 }
60
61 result
62 MemoryForm::OnInitializing(void)
63 {
64         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MEMORY"));
65         CreateFooter();
66         CreateTableView();
67
68         AppLogDebug("ENTER");
69
70         return E_SUCCESS;
71 }
72
73 result
74 MemoryForm::OnTerminating(void)
75 {
76         __pTableView = null;
77
78         SetFormBackEventListener(null);
79         return E_SUCCESS;
80 }
81
82 void
83 MemoryForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
84 {
85         __pTableView->UpdateTableView();
86 }
87
88 void
89 MemoryForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
90 {
91 }
92
93 void
94 MemoryForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
95 {
96         SceneManager* pSceneManager = SceneManager::GetInstance();
97         AppAssert(pSceneManager);
98
99         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
100 }
101
102 int
103 MemoryForm::GetGroupCount(void)
104 {
105         AppLogDebug("ENTER");
106         return ID_GROUP_COUNT;
107 }
108
109 int
110 MemoryForm::GetItemCount(int groupIndex)
111 {
112         int itemCount = 0;
113
114         if (groupIndex == ID_GROUP_MEMORY_MAIN)
115         {
116                 itemCount = ID_GROUP_MEMORY_MAIN_ITEM_COUNT;
117         }
118
119         return itemCount;
120 }
121
122 TableViewGroupItem*
123 MemoryForm::CreateGroupItem(int groupIndex, int itemWidth)
124 {
125         AppLogDebug("ENTER");
126
127         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
128         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
129         Rectangle itemMainRectangle;
130         String groupText;
131         Label* pLabel = null;
132
133         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
134
135         itemMainRectangle.x = X_GROUP_INDEX_DEFAULT_LABEL;
136         itemMainRectangle.y = Y_GROUP_INDEX_DEFAULT_LABEL;
137         itemMainRectangle.width = itemWidth;
138         itemMainRectangle.height = itemHeight;
139
140         RelativeLayout relativeLayout;
141         relativeLayout.Construct();
142
143         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
144         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
145
146         pLabel = new (std::nothrow) Label();
147         pLabel->Construct(itemMainRectangle, groupText);
148         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
149         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
150         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
151
152         pItem->AddControl(pLabel);
153         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
154         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
155         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
156         pItem->SetEnabled(false);
157
158         return pItem;
159 }
160
161 TableViewItem*
162 MemoryForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
163 {
164         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
165
166         Rectangle itemMainRectangle;
167         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
168         String itemMainText;
169         Label* pLabel = null;
170         int fontSize = GetFontSize();
171
172         ItemTypeOneLine(itemMainRectangle);
173
174         if (itemIndex == ID_ITEM_MEMORY_MAIN_MEMORY_STATUS)
175         {
176                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MEMORY_STATUS");
177         }
178
179         TableViewItem* pItem = new (std::nothrow) TableViewItem();
180
181         RelativeLayout relativeLayout;
182         relativeLayout.Construct();
183
184         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
185         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
186
187         pLabel = new (std::nothrow) Label();
188         pLabel->Construct(itemMainRectangle, itemMainText);
189         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
190         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
191         pLabel->SetTextColor(COLOR_MAIN_TEXT);
192
193         pItem->AddControl(pLabel);
194         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
195         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
196         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
197
198         return pItem;
199 }
200
201 bool
202 MemoryForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
203 {
204         AppLogDebug("ENTER");
205
206         delete pItem;
207         pItem = null;
208
209         return true;
210 }
211
212 bool
213 MemoryForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
214 {
215         AppLogDebug("ENTER");
216
217         delete pItem;
218         pItem = null;
219
220         return true;
221 }
222
223 void
224 MemoryForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
225 {
226         SceneManager* pSceneManager = SceneManager::GetInstance();
227         AppAssert(pSceneManager);
228
229         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
230
231         if (itemIndex == ID_ITEM_MEMORY_MAIN_MEMORY_STATUS)
232         {
233                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_MEMORY_STATUS, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
234         }
235 }
236
237 int
238 MemoryForm::GetDefaultGroupItemHeight(void)
239 {
240         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
241 }
242
243 int
244 MemoryForm::GetDefaultItemHeight(void)
245 {
246         return H_GROUP_ITEM_DEFAULT;
247 }
248
249 void
250 MemoryForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
251 {
252 }
253
254 void
255 MemoryForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
256 {
257 }
258
259 void
260 MemoryForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
261 {
262 }
263
264 void
265 MemoryForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
266 {
267 }