Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StWallpaperForm.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                StWallpaperForm.cpp
19  * @brief               This is the implementation file for WallpaperForm class.
20  */
21
22 #include <FIo.h>
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26 #include "StWallpaperForm.h"
27
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Io;
33 using namespace Tizen::System;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
37
38 static const int ID_GROUP_WALLPAPER_COUNT = 1;
39 static const int ID_GROUP_WALLPAPER_ITEM_COUNT = 3;
40 static const int ID_HOME_SCREEN_WALLPAPER = 0;
41 static const int ID_LOCK_SCREEN_WALLPAPER = 1;
42 static const int ID_HOME_AND_LOCK_SCREEN_WALLPAPER = 2;
43
44 WallpaperForm::WallpaperForm(void)
45 {
46 }
47
48 WallpaperForm::~WallpaperForm(void)
49 {
50 }
51
52 void
53 WallpaperForm::CreateFooter(void)
54 {
55         Footer* pFooter = GetFooter();
56         AppAssert(pFooter);
57
58         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
59         pFooter->SetBackButton();
60         pFooter->AddActionEventListener(*this);
61
62         SetFormBackEventListener(this);
63 }
64
65 result
66 WallpaperForm::OnInitializing(void)
67 {
68         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MAINDISPLAY_WALLPAPER"));
69         CreateFooter();
70
71         CreateTableView();
72
73         AppLogDebug("ENTER");
74
75         return E_SUCCESS;
76 }
77
78 result
79 WallpaperForm::OnTerminating(void)
80 {
81         SetFormBackEventListener(null);
82         return E_SUCCESS;
83 }
84
85 void
86 WallpaperForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
87 {
88         __pTableView->UpdateTableView();
89 }
90
91 void
92 WallpaperForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
93 {
94 }
95
96 void
97 WallpaperForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
98 {
99         SceneManager* pSceneManager = SceneManager::GetInstance();
100         AppAssert(pSceneManager);
101
102         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
103 }
104
105 int
106 WallpaperForm::GetGroupCount(void)
107 {
108         AppLogDebug("ENTER");
109         return ID_GROUP_WALLPAPER_COUNT;
110 }
111
112 int
113 WallpaperForm::GetItemCount(int groupIndex)
114 {
115         return ID_GROUP_WALLPAPER_ITEM_COUNT;
116 }
117
118 TableViewGroupItem*
119 WallpaperForm::CreateGroupItem(int groupIndex, int itemWidth)
120 {
121         AppLogDebug("ENTER");
122
123         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
124         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
125         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
126         Rectangle itemRectangle;
127         String groupText;
128         Label* pLabel = null;
129         int fontSize = GetFontSize();
130
131         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
132
133         itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
134         itemRectangle.y = yItemOffset;
135         itemRectangle.width = itemWidth;
136         itemRectangle.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(itemRectangle, groupText);
146         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
147         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
148         pLabel->SetTextConfig(fontSize, style);
149         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
150
151         pItem->AddControl(pLabel);
152         relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
153         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
154         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
155         pItem->SetEnabled(false);
156
157         return pItem;
158 }
159
160 TableViewItem*
161 WallpaperForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
162 {
163         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
164         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
165         int itemHeight = H_GROUP_ITEM_DEFAULT;
166         String itemText;
167         Rectangle itemRectangle;
168         Label* pLabel = null;
169         int fontSize = GetFontSize();
170
171         switch (itemIndex)
172         {
173         case ID_HOME_SCREEN_WALLPAPER:
174                 {
175                         itemText = ResourceManager::GetString(L"IDS_ST_HEADER_HOME_SCREEN");
176                 }
177                 break;
178
179         case ID_LOCK_SCREEN_WALLPAPER:
180                 {
181                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_LOCK_SCREEN");
182                 }
183                 break;
184
185         case ID_HOME_AND_LOCK_SCREEN_WALLPAPER:
186                 {
187                         itemText = L"Home and lock screen wallpaper";
188                 }
189                 break;
190
191         default:
192                 break;
193         }
194
195         TableViewItem* pItem = new (std::nothrow) TableViewItem();
196
197         RelativeLayout relativeLayout;
198         relativeLayout.Construct();
199
200         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
201         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
202
203         ItemTypeOneLine(itemRectangle);
204         pLabel = new (std::nothrow) Label();
205         pLabel->Construct(itemRectangle, itemText);
206         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
207         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
208         pLabel->SetTextColor(COLOR_MAIN_TEXT);
209
210         pItem->AddControl(pLabel);
211         relativeLayout.SetMargin(*pLabel, 0, 0, 0, 0);
212         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
213         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
214
215         return pItem;
216 }
217
218 bool
219 WallpaperForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
220 {
221         AppLogDebug("ENTER");
222
223         delete pItem;
224         pItem = null;
225
226         return true;
227 }
228
229 bool
230 WallpaperForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
231 {
232         AppLogDebug("ENTER");
233
234         delete pItem;
235         pItem = null;
236
237         return true;
238 }
239
240 void
241 WallpaperForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
242 {
243         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
244         SceneManager* pSceneManager = SceneManager::GetInstance();
245         AppAssert(pSceneManager);
246
247         ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
248         if (pArgs == null)
249         {
250                 AppLogDebug("pArgs is null");
251                 return;
252         }
253
254         result r = pArgs->Construct();
255         if (IsFailed(r))
256         {
257                 delete pArgs;
258                 pArgs = null;
259                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
260                 return;
261         }
262
263         pArgs->Add(*(new (std::nothrow) String(Integer::ToString(itemIndex))));
264         switch (itemIndex)
265         {
266         case ID_HOME_SCREEN_WALLPAPER:
267                 {
268                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WALLPAPER_ALBUM_LIST, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
269                 }
270                 break;
271
272         case ID_LOCK_SCREEN_WALLPAPER:
273                 {
274                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WALLPAPER_ALBUM_LIST, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
275                 }
276                 break;
277
278         case ID_HOME_AND_LOCK_SCREEN_WALLPAPER:
279                 {
280                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WALLPAPER_ALBUM_LIST, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
281                 }
282                 break;
283
284         default:
285                 {
286                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WALLPAPER_ALBUM_LIST, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
287                 }
288                 break;
289         }
290 }
291
292 int
293 WallpaperForm::GetDefaultGroupItemHeight(void)
294 {
295         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
296 }
297
298 int
299 WallpaperForm::GetDefaultItemHeight(void)
300 {
301         return H_GROUP_ITEM_DEFAULT;
302 }
303
304 void
305 WallpaperForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
306 {
307 }
308
309 void
310 WallpaperForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
311 {
312 }
313
314 void
315 WallpaperForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
316 {
317 }
318
319 void
320 WallpaperForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
321 {
322 }