Flora license update
[apps/osp/Home.git] / src / HmProgressPanel.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        HmProgressPanel.cpp
19  * @brief       Keeps implementation of ProgressPanel Implementation
20  */
21 #include <FBase.h>
22 #include <FGraphics.h>
23 #include <FMedia.h>
24 #include <FUiAnimations.h>
25 #include "HmApplicationUtils.h"
26 #include "HmProgressPanel.h"
27 #include "HmTypes.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::Media;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Animations;
36 using namespace Tizen::Ui::Controls;
37
38 ProgressPanel::ProgressPanel(void)
39         : __pAnimationFrameList(null)
40         , __pAnimation(null)
41 {
42
43 }
44 ProgressPanel::~ProgressPanel(void)
45 {
46         if (__pAnimationFrameList != null)
47         {
48                 __pAnimationFrameList->RemoveAll(true);
49                 delete __pAnimationFrameList;
50         }
51 }
52
53 result
54 ProgressPanel::Construct(const Tizen::Graphics::Rectangle& controlRectangle)
55 {
56         result r = E_SUCCESS;
57         long duration = DURATION_FOR_EACH_IMAGE / MAX_BITMAP_COUNT;
58         r = Panel::Construct(controlRectangle);
59         TryCatch(r == E_SUCCESS, , "Panel::Construct failed with error = %s", GetErrorMessage(r));
60         __pAnimationFrameList = new (std::nothrow) ArrayList();
61         __pAnimationFrameList->Construct();
62
63         // Create Bitmaps
64         for (int bmpCount = 0; bmpCount < MAX_BITMAP_COUNT; bmpCount++)
65         {
66                 Bitmap* pProgressBitmap = null;
67                 String bitmapName(WAIT_CURSOR_IMAGE_BASE);
68                 bitmapName.Append(bmpCount);
69                 bitmapName.Append(BITMAP_EXTENSION);
70
71                 pProgressBitmap = ApplicationUtils::GetResourceBitmapN(bitmapName);
72
73                 if (pProgressBitmap != null)
74                 {
75                         AnimationFrame* pProgressAniFrame = new (std::nothrow) AnimationFrame(*pProgressBitmap, duration);
76
77                         if (pProgressAniFrame != null)
78                         {
79                                 r = __pAnimationFrameList->Add(pProgressAniFrame);
80
81                                 if (IsFailed(r))
82                                 {
83                                         delete pProgressAniFrame;
84                                         pProgressAniFrame = null;
85                                 }
86                         }
87
88                         delete pProgressBitmap;
89                         pProgressBitmap = null;
90                 }
91         }
92
93         // Create Animation
94         __pAnimation = new (std::nothrow) Animation();
95         r = __pAnimation->Construct(Rectangle((controlRectangle.width / 2 - WAIT_CURSUR_DIMESION / 2), (controlRectangle.height / 2 - WAIT_CURSUR_DIMESION / 2),
96                                                                                   WAIT_CURSUR_DIMESION, WAIT_CURSUR_DIMESION), *__pAnimationFrameList);
97         TryCatch(r == E_SUCCESS, , "__pAnimation->Construct failed with error = %s", GetErrorMessage(r));
98         __pAnimation->SetRepeatCount(REPEAT_COUNT);
99         r = AddControl(__pAnimation);
100         TryCatch(r == E_SUCCESS, , "AddControl(__pAnimation) failed with error = %s", GetErrorMessage(r));
101
102         return r;
103
104 CATCH:
105
106         if (__pAnimation != null)
107         {
108                 delete __pAnimation;
109                 __pAnimation = null;
110         }
111
112         if (__pAnimationFrameList)
113         {
114                 __pAnimationFrameList->RemoveAll(true);
115                 delete __pAnimationFrameList;
116                 __pAnimationFrameList = null;
117         }
118
119         return r;
120 }
121
122 result
123 ProgressPanel::StartAnimation(void)
124 {
125
126         result r = E_SUCCESS;
127         bool animatorFailed = false;
128         ControlAnimator* pAniControlAnimator = null;
129
130         TryReturn(__pAnimation != null, E_INVALID_STATE, "Animation is not yet constructed");
131
132         pAniControlAnimator = __pAnimation->GetControlAnimator();
133
134         if (pAniControlAnimator != null)
135         {
136                 if (pAniControlAnimator->GetStatus() == ANIMATOR_STATUS_PLAYING)
137                 {
138                         r = pAniControlAnimator->StopAllAnimations();
139                 }
140
141                 if (r == E_SUCCESS)
142                 {
143                         r = pAniControlAnimator->SetShowState(true);
144
145                         if (IsFailed(r))
146                         {
147                                 animatorFailed = true;
148                         }
149                 }
150                 else
151                 {
152                         animatorFailed = true;
153                 }
154
155                 if (animatorFailed)
156                 {
157                         r = __pAnimation->SetShowState(true);
158                 }
159
160                 __pAnimation->Play();
161                 RequestRedraw(true);
162         }
163         else
164         {
165                 return E_FAILURE;
166         }
167         return r;
168 }
169
170 result
171 ProgressPanel::StopAnimation(void)
172 {
173
174         result r = E_SUCCESS;
175         bool animatorFailed = false;
176         ControlAnimator* pAniControlAnimator = null;
177
178         TryReturn(__pAnimation != null, E_INVALID_STATE, "Animation is not yet constructed");
179         pAniControlAnimator = __pAnimation->GetControlAnimator();
180
181         if (pAniControlAnimator != null)
182         {
183                 if (pAniControlAnimator->GetStatus() == ANIMATOR_STATUS_PLAYING)
184                 {
185                         r = pAniControlAnimator->StopAllAnimations();
186                 }
187
188                 if (r == E_SUCCESS)
189                 {
190                         r = pAniControlAnimator->SetShowState(false);
191
192                         if (IsFailed(r))
193                         {
194                                 animatorFailed = true;
195                         }
196                 }
197                 else
198                 {
199                         animatorFailed = true;
200                 }
201
202                 if (animatorFailed)
203                 {
204                         r = __pAnimation->SetShowState(false);
205                 }
206
207                 __pAnimation->Stop();
208         }
209         else
210         {
211                 r = E_FAILURE;
212         }
213
214         return r;
215 }