2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 FWebCtrl_WebNotification.cpp
20 * @brief The file contains the definition of _WebNotification class.
23 #include <FBaseRtTimer.h>
24 #include <FBaseSysLog.h>
25 #include <FSysVibrator.h>
26 #include <FSys_VibratorImpl.h>
27 #include <FUiAnimControlAnimator.h>
28 #include <FUiAnimPointAnimation.h>
29 #include <FUiAnimFloatAnimation.h>
30 #include <FUiAnimAnimationTransaction.h>
31 #include <FUiCtrlButton.h>
33 #include "FWebCtrl_WebImpl.h"
34 #include "FWebCtrl_WebNotificationHandler.h"
35 #include "FWebCtrl_WebNotification.h"
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Runtime;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Ui;
42 using namespace Tizen::Ui::Animations;
43 using namespace Tizen::Ui::Controls;
45 namespace Tizen { namespace Web { namespace Controls
48 _WebNotification::_WebNotification(void)
49 : __pNotificationHandler(null)
57 _WebNotification::~_WebNotification(void)
62 _WebNotification::Construct(Ewk_Context *pContext, uint64_t notificationId, Tizen::Web::Controls::_WebImpl* pImpl)
65 // _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
66 // Dimension screenRect = _ControlManager::GetInstance()->GetScreenSize();
68 Rectangle rect(NOTIFCATION_RECT_AREA);
71 __pContext = pContext;
72 __notificationId = notificationId;
74 r = Window::Construct(rect, true, true);
75 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
78 Window::SetOwner(&pImpl->GetPublic());
79 __pNotificationHandler = std::unique_ptr<_WebNotificationHandler>(new (std::nothrow) _WebNotificationHandler());
80 SysTryReturnResult(NID_WEB_CTRL, __pNotificationHandler.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
82 r = __pNotificationHandler->Construct(this);
83 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
85 SetPropagatedTouchEventListener(__pNotificationHandler.get());
86 __pTimer = std::unique_ptr<Timer>( new (std::nothrow) Timer());
87 SysTryReturnResult(NID_WEB_CTRL, __pTimer.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
89 r = __pTimer->Construct(*this);
90 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
97 _WebNotification::SetText(const String& text)
99 __pNotificationHandler->SetText(text);
103 _WebNotification::GetText(void) const
105 return __pNotificationHandler->GetText();
110 _WebNotification::OnDraw(void)
112 result r = E_SUCCESS;
113 SysTryReturnResult(NID_WEB_CTRL, __pNotificationHandler.get(), E_SYSTEM, "Failed to find Impl Instance.");
115 std::unique_ptr<Canvas> pCanvas(GetCanvasN());
116 SysTryReturnResult(NID_WEB_CTRL, pCanvas.get(), GetLastResult(), "[%s] Error Propagated.", GetErrorMessage(GetLastResult()));
118 r = __pNotificationHandler->DrawNotification(*pCanvas);
125 _WebNotification::OnClicked()
127 SysTryReturnVoidResult(NID_WEB_CTRL, __pContext != null, E_SYSTEM, "[E_SYSTEM] Context instance not found.");
128 ewk_notification_clicked(__pContext,__notificationId);
132 _WebNotification::LaunchNotification()
134 result r = E_SUCCESS;
135 std::unique_ptr<Button> pButton( new (std::nothrow) Button());
136 SysTryReturnResult(NID_WEB_CTRL, pButton.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
138 r = pButton->Construct(Rectangle(NOTIFCATION_BUTTON_AREA));
139 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
141 pButton->SetText(L"x"); //Need to add bit map
142 pButton->AddActionEventListener(*this);
144 r = AddControl(pButton.get());
149 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
151 Point start(0,-200),end;
152 PointAnimation pointAnimation(Point(0, 0), Point(0, 0), 0, ANIMATION_INTERPOLATOR_LINEAR);
156 pointAnimation.SetStartValue(start);
157 pointAnimation.SetEndValue(end);
158 pointAnimation.SetDuration(2000);
159 pointAnimation.SetAutoReverseEnabled(false);
161 ControlAnimator *pAnimator = this->GetControlAnimator();
162 r = pAnimator->StartUserAnimation(ANIMATION_TARGET_POSITION, pointAnimation);
163 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Error Propagated.", GetErrorMessage(r));
165 __pTimer->Start(15000);
171 _WebNotification::OnTimerExpired(Timer& timer)
174 int transactionId = 0;
179 ParallelAnimationGroup showAnim;
180 FloatAnimation floatAnim(start, end, duration, ANIMATION_INTERPOLATOR_LINEAR);
181 showAnim.AddAnimation(ANIMATION_TARGET_ALPHA, floatAnim);
183 AnimationTransaction::Begin(transactionId);
185 ControlAnimator *pAnimator = this->GetControlAnimator();
186 pAnimator->SetAnimation(ANIMATION_TRIGGER_SHOW_STATE_CHANGE, &showAnim);
187 pAnimator->SetShowState(static_cast< int >(start));
189 AnimationTransaction::Commit();
194 _WebNotification::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)