Applied latest source code
[apps/native/preloaded/Clock.git] / src / ClkDaylightSavingPopUp.cpp
1 //
2 // Tizen Native SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        DaylightSavingPopUp.cpp
20  * @brief       This file contains the definitions of the DayLightSavingPopup class.
21  */
22
23 #include <FAppUiApp.h>
24 #include <FUiScenes.h>
25
26 #include "ClkCommonLib.h"
27 #include "ClkDaylightSavingPopUp.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
36
37
38 static const int ID_FORMAT_OFF = 501;
39 static const int ID_FORMAT_1_HOUR = 502 ;
40 static const int ID_FORMAT_2_HOURS = 503 ;
41 static const int ID_CANCEL_BUTTON = 504;
42
43 const RequestId REQUEST_CANCEL_CLICKED = 10001;
44
45 IDstTimeEventListener::IDstTimeEventListener(void)
46 {
47
48 }
49
50 IDstTimeEventListener::~IDstTimeEventListener(void)
51 {
52
53 }
54
55 DaylightSavingPopUp::DaylightSavingPopUp(void)
56 :__pList(null)
57 {
58
59 }
60
61 DaylightSavingPopUp::~DaylightSavingPopUp(void)
62 {
63
64 }
65
66 bool
67 DaylightSavingPopUp::Initialize(void)
68 {
69         Button* pCancelButton = null;
70         Popup::Construct(L"IDL_DST_POPUP");
71
72         __pList = static_cast<ListView*>(GetControl(L"IDC_POPUP_LIST"));
73
74         if (__pList == null)
75         {
76                 return false;
77         }
78
79         __pList->SetItemProvider(*this);
80         __pList->AddListViewItemEventListener(*this);
81
82         pCancelButton = static_cast< Button* >(GetControl(L"IDC_BUTTON", true));
83
84         if (pCancelButton != null)
85         {
86                 pCancelButton->AddActionEventListener(*this);
87                 pCancelButton->SetActionId(ID_CANCEL_BUTTON);
88         }
89
90         SetPropagatedKeyEventListener(this);
91         return true;
92
93 }
94
95 result
96 DaylightSavingPopUp::OnTerminating(void)
97 {
98         result r = E_SUCCESS;
99         return r;
100 }
101
102 void
103 DaylightSavingPopUp::OnActionPerformed(const Control& source, int actionId)
104 {
105         switch (actionId)
106         {
107         case ID_CANCEL_BUTTON:
108         {
109                 Popup::SetShowState(false);
110                 Popup::Show();
111                 Form *pWorldClockForm = dynamic_cast<Form*>(UiApp::GetInstance()->GetFrameAt(0)->GetCurrentForm());
112                 if(pWorldClockForm != NULL)
113                 {
114                         pWorldClockForm->SendUserEvent(REQUEST_CANCEL_CLICKED, null);
115                 }
116         }
117         break;
118         default:
119                 break;
120         }
121         return;
122 }
123
124 void
125 DaylightSavingPopUp::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
126 {
127         switch(index)
128         {
129         case 0:
130         {
131                 __pList->SetItemChecked(0,true);
132                 __pList->SetItemChecked(1,false);
133                 __pList->SetItemChecked(2,false);
134
135                 if (__pListener != null)
136                 {
137                         __pListener->OnDaylightSavingPopUpItemSelected(0);
138                 }
139
140         }
141         break;
142         case 1:
143         {
144                 __pList->SetItemChecked(0,false);
145                 __pList->SetItemChecked(1,true);
146                 __pList->SetItemChecked(2,false);
147
148                 if (__pListener != null)
149                 {
150                         __pListener->OnDaylightSavingPopUpItemSelected(1);
151                 }
152
153         }
154         break;
155
156         case 2:
157         {
158                 __pList->SetItemChecked(0,false);
159                 __pList->SetItemChecked(1,false);
160                 __pList->SetItemChecked(2,true);
161
162                 if (__pListener != null)
163                 {
164                         __pListener->OnDaylightSavingPopUpItemSelected(2);
165                 }
166
167         }
168         break;
169
170         default:
171                 break;
172         }
173
174         __pList->Invalidate(true);
175 }
176
177 ListItemBase*
178 DaylightSavingPopUp::CreateItem(int index, int itemWidth)
179 {
180         result r = E_FAILURE;
181         ListAnnexStyle style = LIST_ANNEX_STYLE_RADIO;
182         int listItemWidth = 112;
183
184         CustomItem* pItem = new (std::nothrow) CustomItem();
185         r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemWidth), style);
186         pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color::GetColor(COLOR_ID_WHITE));
187
188
189         if (IsFailed(r))
190         {
191                 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
192                 return null;
193         }
194
195         switch (index)
196         {
197
198         case 0:
199         {
200                 pItem->AddElement(Rectangle(0, 0, GetClientAreaBounds().width, listItemWidth), ID_FORMAT_OFF, L"Off", true);
201         }
202         break;
203
204         case 1:
205         {
206                 pItem->AddElement(Rectangle(0, 0, GetClientAreaBounds().width, listItemWidth), ID_FORMAT_1_HOUR, L"1 hour", true);
207         }
208         break;
209
210         case 2:
211         {
212                 pItem->AddElement(Rectangle(0, 0, GetClientAreaBounds().width, listItemWidth), ID_FORMAT_2_HOURS, L"2 hours", true);
213         }
214         break;
215         default:
216                 break;
217         }
218
219         return pItem;
220 }
221
222 bool
223 DaylightSavingPopUp::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
224 {
225         return true;
226 }
227
228 int
229 DaylightSavingPopUp::GetItemCount(void)
230 {
231         return 3;
232 }
233
234 void
235 DaylightSavingPopUp::SetEventListner(IDstTimeEventListener* listner)
236 {
237         __pListener = listner;
238 }
239
240 void
241 DaylightSavingPopUp::SetDstIndex(int index)
242 {
243         __pList->SetItemChecked(index,true);
244
245         if ( index == 0)
246         {
247                 __pList->SetItemChecked(1,false);
248                 __pList->SetItemChecked(2,false);
249         }
250         else if (index == 1)
251         {
252                 __pList->SetItemChecked(0,false);
253                 __pList->SetItemChecked(2,false);
254         }
255         else if (index == 2)
256         {
257                 __pList->SetItemChecked(0,false);
258                 __pList->SetItemChecked(1,false);
259         }
260
261         __pList->Invalidate(true);
262 }
263
264 bool
265 DaylightSavingPopUp::OnKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
266 {
267         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
268         {
269                 Popup::SetShowState(false);
270                 Popup::Show();
271                 Form *pWorldClockForm = dynamic_cast<Form*>(UiApp::GetInstance()->GetFrameAt(0)->GetCurrentForm());
272                 if(pWorldClockForm != NULL)
273                 {
274                         pWorldClockForm->SendUserEvent(REQUEST_CANCEL_CLICKED, null);
275                 }
276         }
277
278         return false;
279 }