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