3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file ClkAlarmRingingLockPanel.cpp
20 * @brief This header file contains the definitions of the AlarmRingingLockPanel class.
25 #include <FGraphics.h>
26 #include <FUiAnimations.h>
27 #include "ClkAlarmRingingLockPanel.h"
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;
38 AlarmRingingLockPanel::AlarmRingingLockPanel()
39 : __commandId(ALARM_RINGING_PANEL_COUNT)
40 , __controlRestPosition(0, 0)
42 , __pEventListener(null)
43 , __pSnoozeArrowBitmap(null)
44 , __pSnoozeArrowPressedBitmap(null)
45 , __pSnoozeLabel(null)
46 , __pSnoozePanel(null)
47 , __pStopArrowBitmap(null)
48 , __pStopArrowPressedBitmap(null)
51 , __pUpdateTimer(null)
56 AlarmRingingLockPanel::~AlarmRingingLockPanel()
58 if (__pUpdateTimer != null)
60 __pUpdateTimer->Cancel();
61 delete __pUpdateTimer;
62 __pUpdateTimer = null;
65 if (__pSnoozeArrowBitmap != null)
67 delete __pSnoozeArrowBitmap;
70 if (__pSnoozeArrowPressedBitmap != null)
72 delete __pSnoozeArrowPressedBitmap;
75 if (__pStopArrowBitmap != null)
77 delete __pStopArrowBitmap;
80 if (__pStopArrowPressedBitmap != null)
82 delete __pStopArrowPressedBitmap;
89 AlarmRingingLockPanel::Construct(Rectangle controlRect)
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();
103 r = Panel::Construct(L"IDL_ALARM_RINGING_LOCK_PANEL");
104 TryCatch(r == E_SUCCESS, , "Panel::Construct failed with error %s", GetErrorMessage(r));
106 __pSnoozePanel = static_cast<Panel*>(GetControl(L"IDC_SNOOZE_PANEL", true));
107 __pSnoozePanel->AddTouchEventListener(*this);
109 __pStopPanel = static_cast<Panel*>(GetControl(L"IDC_STOP_PANEL", true));
110 __pStopPanel->AddTouchEventListener(*this);
112 __pSnoozeLabel = static_cast<Label*>(__pSnoozePanel->GetControl(L"IDC_SNOOZE_LABEL", true));
113 __pSnoozeLabel->AddTouchEventListener(*this);
115 __pStopLabel = static_cast<Label*>(__pStopPanel->GetControl(L"IDC_STOP_LABEL", true));
116 __pStopLabel->AddTouchEventListener(*this);
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);
124 if (pArrowBitmap != null)
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);
135 pArrowBitmap = pAppResource->GetBitmapN(IDB_RINGER_LOCK_STOP_LEFT_ARROW);
137 if (pArrowBitmap != null)
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);
148 __pUpdateTimer = new (std::nothrow) Timer();
149 __pUpdateTimer->Construct(*this);
155 AlarmRingingLockPanel::SetAlarmRinignigCommandListener(IAlarmRingingLockPanelEvent* pEventListener)
157 __pEventListener = pEventListener;
161 AlarmRingingLockPanel::OnTouchPressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
164 if (source.Equals(*__pSnoozeLabel))
166 __commandId = ALARM_RINGING_PANEL_SNOOZE;
168 else if (source.Equals(*__pStopLabel))
170 __commandId = ALARM_RINGING_PANEL_STOP;
174 __commandId = ALARM_RINGING_PANEL_COUNT;
180 AlarmRingingLockPanel::OnTouchReleased(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
184 if (GetBounds().width > 720)
193 if (__isDragging && __commandId != ALARM_RINGING_PANEL_COUNT)
195 bool isUnlocked = false;
197 if (source.Equals(*__pSnoozeLabel))
199 Rectangle snoozeRect = __pSnoozePanel->GetBounds();
201 if (currentPosition.x > ((snoozeRect.x + snoozeRect.width) - subValue))
204 if (currentPosition.y > MIN_Y_TOUCH_POSITION && currentPosition.y < MAX_Y_TOUCH_POSITION)
211 else if (source.Equals(*__pStopLabel))
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))
218 if (currentPosition.y > MIN_Y_TOUCH_POSITION && currentPosition.y < MAX_Y_TOUCH_POSITION)
225 if (__pEventListener != null && isUnlocked)
227 __pEventListener->OnAlarmRingingLockEvent(__commandId);
231 __pUpdateTimer->Start(DURATION_RINGING_UI_UPDATION);
234 __isDragging = false;
235 __commandId = ALARM_RINGING_PANEL_COUNT;
240 AlarmRingingLockPanel::OnTouchMoved(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
242 if (__commandId != ALARM_RINGING_PANEL_COUNT)
244 if (__commandId == ALARM_RINGING_PANEL_SNOOZE)
246 if (source.Equals(*__pSnoozeLabel))
248 if (currentPosition.y > MIN_Y_TOUCH_POSITION && currentPosition.y < MAX_Y_TOUCH_POSITION &&
249 currentPosition.x > (__pSnoozeLabel->GetPosition().x + CONTROL_WIDTH_OFFSET))
252 __pUpdateTimer->Start(DURATION_RINGING_UI_UPDATION);
257 if (__commandId == ALARM_RINGING_PANEL_STOP)
259 if (source.Equals(*__pStopLabel))
261 if (currentPosition.y > MIN_Y_TOUCH_POSITION && currentPosition.y < MAX_Y_TOUCH_POSITION &&
262 currentPosition.x < -(__pStopLabel->GetPosition().x - CONTROL_WIDTH_OFFSET))
265 __pUpdateTimer->Start(DURATION_RINGING_UI_UPDATION);
273 AlarmRingingLockPanel::OnTimerExpired(Timer& timer)
275 if (timer.Equals(*__pUpdateTimer))
279 if (__pSnoozeArrowPressedBitmap == null)
281 __pSnoozeArrowPressedBitmap = App::GetInstance()->GetAppResource()->GetBitmapN(IDB_RINGER_LOCK_SNOOZE_PRESSED);
284 if (__pSnoozeArrowPressedBitmap != null && __commandId == ALARM_RINGING_PANEL_SNOOZE)
286 __pSnoozeLabel->SetBackgroundBitmap(*__pSnoozeArrowPressedBitmap);
287 __pSnoozeLabel->Invalidate(false);
290 if (__pStopArrowPressedBitmap == null)
292 __pStopArrowPressedBitmap = App::GetInstance()->GetAppResource()->GetBitmapN(IDB_RINGER_LOCK_STOP_PRESSED);
295 if (__pStopArrowPressedBitmap != null && __commandId == ALARM_RINGING_PANEL_STOP)
297 __pStopLabel->SetBackgroundBitmap(*__pStopArrowPressedBitmap);
298 __pStopLabel->Invalidate(true);
304 if (__pSnoozeArrowBitmap != null)
306 __pSnoozeLabel->SetBackgroundBitmap(*__pSnoozeArrowBitmap);
307 __pSnoozeLabel->Invalidate(false);
310 if (__pStopArrowBitmap != null)
312 __pStopLabel->SetBackgroundBitmap(*__pStopArrowBitmap);
313 __pStopLabel->Invalidate(false);