Applied latest source code
[apps/native/preloaded/Clock.git] / src / ClkAlarmRingingLockPanel.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        ClkAlarmRingingLockPanel.cpp
20  * @brief               This header file contains the definitions of the AlarmRingingLockPanel class.
21  *
22  */
23
24 #include <FApp.h>
25 #include <FGraphics.h>
26 #include <FUiAnimations.h>
27 #include "ClkAlarmRingingLockPanel.h"
28 #include "ClkTypes.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Runtime;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Animations;
36 using namespace Tizen::Ui::Controls;
37
38 AlarmRingingLockPanel::AlarmRingingLockPanel()
39         : __commandId(ALARM_RINGING_PANEL_COUNT)
40         , __controlRestPosition(0, 0)
41         , __isDragging(false)
42         , __pEventListener(null)
43         , __pSnoozeArrowBitmap(null)
44         , __pSnoozeArrowPressedBitmap(null)
45         , __pSnoozeLabel(null)
46         , __pSnoozePanel(null)
47         , __pStopArrowBitmap(null)
48         , __pStopArrowPressedBitmap(null)
49         , __pStopLabel(null)
50         , __pStopPanel(null)
51         , __pUpdateTimer(null)
52 {
53
54 }
55
56 AlarmRingingLockPanel::~AlarmRingingLockPanel()
57 {
58         if (__pUpdateTimer != null)
59         {
60                 __pUpdateTimer->Cancel();
61                 delete __pUpdateTimer;
62                 __pUpdateTimer = null;
63         }
64
65         if (__pSnoozeArrowBitmap != null)
66         {
67                 delete __pSnoozeArrowBitmap;
68         }
69
70         if (__pSnoozeArrowPressedBitmap != null)
71         {
72                 delete __pSnoozeArrowPressedBitmap;
73         }
74
75         if (__pStopArrowBitmap != null)
76         {
77                 delete __pStopArrowBitmap;
78         }
79
80         if (__pStopArrowPressedBitmap != null)
81         {
82                 delete __pStopArrowPressedBitmap;
83         }
84
85
86 }
87
88 result
89 AlarmRingingLockPanel::Construct(Rectangle controlRect)
90 {
91         result r = E_SUCCESS;
92         Label* pSnoozeArrowLabel3 = null;
93         Label* pSnoozeArrowLabel2 = null;
94         Label* pStopArrowLabel3 = null;
95         Label* pStopArrowLabel2 = null;
96         Bitmap* pArrowBitmap = null;
97         int arrowBitmapWidth = 255;
98         int arrowBitmapHeight1 = 60;
99         int arrowBitmapHeight2 = 80;
100         int alphaConstant = 100;
101         AppResource* pAppResource = UiApp::GetInstance()->GetAppResource();
102
103         r = Panel::Construct(L"IDL_ALARM_RINGING_LOCK_PANEL");
104         TryCatch(r == E_SUCCESS, , "Panel::Construct failed with error %s", GetErrorMessage(r));
105
106         __pSnoozePanel = static_cast<Panel*>(GetControl(L"IDC_SNOOZE_PANEL", true));
107         __pSnoozePanel->AddTouchEventListener(*this);
108
109         __pStopPanel = static_cast<Panel*>(GetControl(L"IDC_STOP_PANEL", true));
110         __pStopPanel->AddTouchEventListener(*this);
111
112         __pSnoozeLabel = static_cast<Label*>(__pSnoozePanel->GetControl(L"IDC_SNOOZE_LABEL", true));
113         __pSnoozeLabel->AddTouchEventListener(*this);
114
115         __pStopLabel = static_cast<Label*>(__pStopPanel->GetControl(L"IDC_STOP_LABEL", true));
116         __pStopLabel->AddTouchEventListener(*this);
117
118         pArrowBitmap = pAppResource->GetBitmapN(IDB_RINGER_LOCK_SNOOZE_RIGHT_ARROW);
119         __pSnoozeArrowBitmap = pAppResource->GetBitmapN(IDB_RINGER_LOCK_SNOOZE);
120         __pSnoozeLabel->SetBackgroundBitmap(*__pSnoozeArrowBitmap);
121         __pStopArrowBitmap = pAppResource->GetBitmapN(IDB_RINGER_LOCK_STOP);
122         __pStopLabel->SetBackgroundBitmap(*__pStopArrowBitmap);
123
124         if (pArrowBitmap != null)
125         {
126                 pSnoozeArrowLabel3 = static_cast<Label*>(__pSnoozePanel->GetControl(L"IDC_SNOOZE_ARROW_LABEL3", true));
127                 pArrowBitmap->SetAlphaConstant((arrowBitmapWidth * arrowBitmapHeight1) / alphaConstant);
128                 pSnoozeArrowLabel3->SetBackgroundBitmap(*pArrowBitmap);
129                 pSnoozeArrowLabel2 = static_cast<Label*>(__pSnoozePanel->GetControl(L"IDC_SNOOZE_ARROW_LABEL2", true));
130                 pArrowBitmap->SetAlphaConstant((arrowBitmapWidth * arrowBitmapHeight2) / alphaConstant);
131                 pSnoozeArrowLabel2->SetBackgroundBitmap(*pArrowBitmap);
132                 delete pArrowBitmap;
133         }
134
135         pArrowBitmap = pAppResource->GetBitmapN(IDB_RINGER_LOCK_STOP_LEFT_ARROW);
136
137         if (pArrowBitmap != null)
138         {
139                 pStopArrowLabel3 = static_cast<Label*>(__pStopPanel->GetControl(L"IDC_STOP_ARROW_LABEL3", true));
140                 pArrowBitmap->SetAlphaConstant((arrowBitmapWidth * arrowBitmapHeight1) / alphaConstant);
141                 pStopArrowLabel3->SetBackgroundBitmap(*pArrowBitmap);
142                 pStopArrowLabel2 = static_cast<Label*>(__pStopPanel->GetControl(L"IDC_STOP_ARROW_LABEL2", true));
143                 pArrowBitmap->SetAlphaConstant((arrowBitmapWidth * arrowBitmapHeight2) / alphaConstant);
144                 pStopArrowLabel2->SetBackgroundBitmap(*pArrowBitmap);
145                 delete pArrowBitmap;
146         }
147
148         __pUpdateTimer = new (std::nothrow) Timer();
149         __pUpdateTimer->Construct(*this);
150 CATCH:
151         return r;
152 }
153
154 void
155 AlarmRingingLockPanel::SetAlarmRinignigCommandListener(IAlarmRingingLockPanelEvent* pEventListener)
156 {
157         __pEventListener = pEventListener;
158 }
159
160 void
161 AlarmRingingLockPanel::OnTouchPressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
162 {
163
164         if (source.Equals(*__pSnoozeLabel))
165         {
166                 __commandId = ALARM_RINGING_PANEL_SNOOZE;
167         }
168         else if (source.Equals(*__pStopLabel))
169         {
170                 __commandId = ALARM_RINGING_PANEL_STOP;
171         }
172         else
173         {
174                 __commandId = ALARM_RINGING_PANEL_COUNT;
175         }
176
177 }
178
179 void
180 AlarmRingingLockPanel::OnTouchReleased(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
181 {
182         int subValue = 0;
183
184         if (GetBounds().width > 720)
185         {
186                 subValue = 320;
187         }
188         else
189         {
190                 subValue = 100;
191         }
192
193         if (__isDragging && __commandId != ALARM_RINGING_PANEL_COUNT)
194         {
195                 bool isUnlocked = false;
196
197                 if (source.Equals(*__pSnoozeLabel))
198                 {
199                         Rectangle snoozeRect = __pSnoozePanel->GetBounds();
200
201                         if (currentPosition.x > ((snoozeRect.x + snoozeRect.width) - subValue))
202                         {
203
204                                 if (currentPosition.y > MIN_Y_TOUCH_POSITION && currentPosition.y < MAX_Y_TOUCH_POSITION)
205                                 {
206                                         isUnlocked = true;
207                                 }
208
209                         }
210                 }
211                 else if (source.Equals(*__pStopLabel))
212                 {
213                         Rectangle stopRect = __pStopLabel->GetBounds();
214                         AppLogDebug("AJAY::CurrentPosition = %d and %d",currentPosition.x,GetWidth() - stopRect.width);
215                         if (currentPosition.x > -(GetWidth() - stopRect.width) && currentPosition.x <= -(stopRect.x))
216                         {
217
218                                 if (currentPosition.y > MIN_Y_TOUCH_POSITION && currentPosition.y < MAX_Y_TOUCH_POSITION)
219                                 {
220                                         isUnlocked = true;
221                                 }
222                         }
223                 }
224
225                 if (__pEventListener != null && isUnlocked)
226                 {
227                         __pEventListener->OnAlarmRingingLockEvent(__commandId);
228                 }
229                 else
230                 {
231                         __pUpdateTimer->Start(DURATION_RINGING_UI_UPDATION);
232                 }
233
234                 __isDragging = false;
235                 __commandId = ALARM_RINGING_PANEL_COUNT;
236         }
237 }
238
239 void
240 AlarmRingingLockPanel::OnTouchMoved(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
241 {
242         if (__commandId != ALARM_RINGING_PANEL_COUNT)
243         {
244                 if (__commandId == ALARM_RINGING_PANEL_SNOOZE)
245                 {
246                         if (source.Equals(*__pSnoozeLabel))
247                         {
248                                 if (currentPosition.y > MIN_Y_TOUCH_POSITION && currentPosition.y < MAX_Y_TOUCH_POSITION &&
249                                         currentPosition.x > (__pSnoozeLabel->GetPosition().x + CONTROL_WIDTH_OFFSET))
250                                 {
251                                         __isDragging = true;
252                                         __pUpdateTimer->Start(DURATION_RINGING_UI_UPDATION);
253                                 }
254                         }
255                 }
256
257                 if (__commandId == ALARM_RINGING_PANEL_STOP)
258                 {
259                         if (source.Equals(*__pStopLabel))
260                         {
261                                 if (currentPosition.y > MIN_Y_TOUCH_POSITION && currentPosition.y < MAX_Y_TOUCH_POSITION &&
262                                         currentPosition.x < -(__pStopLabel->GetPosition().x - CONTROL_WIDTH_OFFSET))
263                                 {
264                                         __isDragging = true;
265                                         __pUpdateTimer->Start(DURATION_RINGING_UI_UPDATION);
266                                 }
267                         }
268                 }
269         }
270 }
271
272 void
273 AlarmRingingLockPanel::OnTimerExpired(Timer& timer)
274 {
275         if (timer.Equals(*__pUpdateTimer))
276         {
277                 if (__isDragging)
278                 {
279                         if (__pSnoozeArrowPressedBitmap == null)
280                         {
281                                 __pSnoozeArrowPressedBitmap = App::GetInstance()->GetAppResource()->GetBitmapN(IDB_RINGER_LOCK_SNOOZE_PRESSED);
282                         }
283
284                         if (__pSnoozeArrowPressedBitmap != null && __commandId == ALARM_RINGING_PANEL_SNOOZE)
285                         {
286                                 __pSnoozeLabel->SetBackgroundBitmap(*__pSnoozeArrowPressedBitmap);
287                                 __pSnoozeLabel->Invalidate(false);
288                         }
289
290                         if (__pStopArrowPressedBitmap == null)
291                         {
292                                 __pStopArrowPressedBitmap = App::GetInstance()->GetAppResource()->GetBitmapN(IDB_RINGER_LOCK_STOP_PRESSED);
293                         }
294
295                         if (__pStopArrowPressedBitmap != null && __commandId == ALARM_RINGING_PANEL_STOP)
296                         {
297                                 __pStopLabel->SetBackgroundBitmap(*__pStopArrowPressedBitmap);
298                                 __pStopLabel->Invalidate(true);
299                         }
300
301                 }
302                 else
303                 {
304                         if (__pSnoozeArrowBitmap != null)
305                         {
306                                 __pSnoozeLabel->SetBackgroundBitmap(*__pSnoozeArrowBitmap);
307                                 __pSnoozeLabel->Invalidate(false);
308                         }
309
310                         if (__pStopArrowBitmap != null)
311                         {
312                                 __pStopLabel->SetBackgroundBitmap(*__pStopArrowBitmap);
313                                 __pStopLabel->Invalidate(false);
314                         }
315                 }
316         }
317 }
318