Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / CipherMessage / CipherMessage / project / src / WaitPopup.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.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
8 //
9 //     http://www.tizenopensource.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 #include <FBase.h>
19 #include <FApp.h>
20 #include <FMedia.h>
21 #include <FGraphics.h>
22 #include <WaitPopup.h>
23
24
25 const int POPUP_X =     400;
26 const int POPUP_Y =     300;
27
28
29 using namespace Osp::Base;
30 using namespace Osp::Ui;
31 using namespace Osp::Ui::Controls;
32 using namespace Osp::Graphics;
33 using namespace Osp::Base::Collection;
34
35 WaitPopup::WaitPopup()
36         : __pPopup(null)
37         , __pAnimation(null)
38         , __pAnimationFrameList(null)
39         , __pThread(null)
40         , __terminateThread(false)
41 {
42 }
43
44 WaitPopup::~WaitPopup()
45 {
46         HidePopup();
47 }
48
49 Osp::Base::Object*
50 WaitPopup::Run(void)
51 {
52         return null;
53 }
54
55 result
56 WaitPopup::ShowPopup(String szTitle)
57 {
58
59     result r = E_SUCCESS;
60     long duration  = 0;
61     Dimension dim(POPUP_X, POPUP_Y);
62     Bitmap *pBitmap1 = null;
63     Bitmap *pBitmap2 = null;
64     Bitmap *pBitmap3 = null;
65     Bitmap *pBitmap4 = null;
66     Bitmap *pBitmap5 = null;
67     Bitmap *pBitmap6 = null;
68     Bitmap *pBitmap7 = null;
69     Bitmap *pBitmap8 = null;
70     AnimationFrame *pAniFrame1 = null;
71     AnimationFrame *pAniFrame2 = null;
72     AnimationFrame *pAniFrame3 = null;
73     AnimationFrame *pAniFrame4 = null;
74     AnimationFrame *pAniFrame5 = null;
75     AnimationFrame *pAniFrame6 = null;
76     AnimationFrame *pAniFrame7 = null;
77     AnimationFrame *pAniFrame8 = null;
78
79     if (__pPopup != null)
80         return E_SUCCESS;
81     // Create a Popup
82         __pPopup = new Popup();
83         if (null == __pPopup)
84         {
85                 return E_OUT_OF_MEMORY;
86         }
87         r = __pPopup->Construct(true, dim);
88         r = __pPopup->SetTitleText(szTitle);
89 //      r = __pPopup->SetPosition(50, 10);
90
91         // Create Bitmap
92         Osp::App::AppResource *pAppResource = Osp::App::Application::GetInstance()->GetAppResource();
93         if (null == pAppResource)
94         {
95                 r = E_FAILURE;
96                 goto CATCH;
97         }
98
99         pBitmap1 = pAppResource->GetBitmapN(L"/white/progressing00_big.png");
100         if (null == pBitmap1)
101         {
102                 r = E_FAILURE;
103                 goto CATCH;
104         }
105         pBitmap2 = pAppResource->GetBitmapN(L"/white/progressing01_big.png");
106         if (null == pBitmap2)
107         {
108                 r = E_FAILURE;
109                 goto CATCH;
110         }
111         pBitmap3 = pAppResource->GetBitmapN(L"/white/progressing02_big.png");
112         if (null == pBitmap3)
113         {
114                 r = E_FAILURE;
115                 goto CATCH;
116         }
117         pBitmap4 = pAppResource->GetBitmapN(L"/white/progressing03_big.png");
118         if (null == pBitmap4)
119         {
120                 r = E_FAILURE;
121                 goto CATCH;
122         }
123         pBitmap5 = pAppResource->GetBitmapN(L"/white/progressing04_big.png");
124         if (null == pBitmap5)
125         {
126                 r = E_FAILURE;
127                 goto CATCH;
128         }
129         pBitmap6 = pAppResource->GetBitmapN(L"/white/progressing05_big.png");
130         if (null == pBitmap6)
131         {
132                 r = E_FAILURE;
133                 goto CATCH;
134         }
135         pBitmap7 = pAppResource->GetBitmapN(L"/white/progressing06_big.png");
136         if (null == pBitmap7)
137         {
138                 r = E_FAILURE;
139                 goto CATCH;
140         }
141         pBitmap8 = pAppResource->GetBitmapN(L"/white/progressing07_big.png");
142         if (null == pBitmap8)
143         {
144                 r = E_FAILURE;
145                 goto CATCH;
146         }
147
148         // Create AnimationFrames
149         duration = 500 / 8;
150         pAniFrame1 = new AnimationFrame(*pBitmap1, duration);
151         if (null == pAniFrame1)
152         {
153                 r = E_FAILURE;
154                 goto CATCH;
155         }
156         pAniFrame2 = new AnimationFrame(*pBitmap2, duration);
157         if (null == pAniFrame2)
158         {
159                 r = E_FAILURE;
160                 goto CATCH;
161         }
162         pAniFrame3 = new AnimationFrame(*pBitmap3, duration);
163         if (null == pAniFrame3)
164         {
165                 r = E_FAILURE;
166                 goto CATCH;
167         }
168         pAniFrame4 = new AnimationFrame(*pBitmap4, duration);
169         if (null == pAniFrame4)
170         {
171                 r = E_FAILURE;
172                 goto CATCH;
173         }
174         pAniFrame5 = new AnimationFrame(*pBitmap5, duration);
175         if (null == pAniFrame5)
176         {
177                 r = E_FAILURE;
178                 goto CATCH;
179         }
180         pAniFrame6 = new AnimationFrame(*pBitmap6, duration);
181         if (null == pAniFrame6)
182         {
183                 r = E_FAILURE;
184                 goto CATCH;
185         }
186         pAniFrame7 = new AnimationFrame(*pBitmap7, duration);
187         if (null == pAniFrame7)
188         {
189                 r = E_FAILURE;
190                 goto CATCH;
191         }
192         pAniFrame8 = new AnimationFrame(*pBitmap8, duration);
193         if (null == pAniFrame8)
194         {
195                 r = E_FAILURE;
196                 goto CATCH;
197         }
198
199         // Create AnimationList
200         __pAnimationFrameList = new ArrayList();
201         if (null == __pAnimationFrameList)
202         {
203                 r = E_FAILURE;
204                 goto CATCH;
205         }
206
207         __pAnimationFrameList->Construct();
208         __pAnimationFrameList->Add(*pAniFrame1);
209         __pAnimationFrameList->Add(*pAniFrame2);
210         __pAnimationFrameList->Add(*pAniFrame3);
211         __pAnimationFrameList->Add(*pAniFrame4);
212         __pAnimationFrameList->Add(*pAniFrame5);
213         __pAnimationFrameList->Add(*pAniFrame6);
214         __pAnimationFrameList->Add(*pAniFrame7);
215         __pAnimationFrameList->Add(*pAniFrame8);
216
217         // Create Animation
218         __pAnimation = new Animation();
219         if (null == __pAnimation)
220         {
221                 r = E_FAILURE;
222                 goto CATCH;
223         }
224
225         __pAnimation->Construct(Osp::Graphics::Rectangle((POPUP_X / 2) - 75, (POPUP_Y / 2) - 105, 120, 120), *__pAnimationFrameList);
226         __pAnimation->SetRepeatCount(10000);
227         __pPopup->AddControl(*__pAnimation);
228
229         __pPopup->SetShowState(true);
230         __pPopup->Show();
231
232
233         __pAnimation->Play();
234
235
236 CATCH:
237
238         // Deallocate a Bitmap.
239         if (pBitmap1)
240                 delete pBitmap1;
241         if (pBitmap2)
242                 delete pBitmap2;
243         if (pBitmap3)
244                 delete pBitmap3;
245         if (pBitmap4)
246                 delete pBitmap4;
247         if (pBitmap5)
248                 delete pBitmap5;
249         if (pBitmap6)
250                 delete pBitmap6;
251         if (pBitmap7)
252                 delete pBitmap7;
253         if (pBitmap8)
254                 delete pBitmap8;
255
256         if (IsFailed(r))
257         {
258                 AppLog("CipherMessage: Failed to Create Waiting Popup.");
259                 if (__pAnimationFrameList)
260                 {
261                         delete __pAnimationFrameList;
262                         __pAnimationFrameList = null;
263                 }
264
265                 if (__pPopup)
266                 {
267                         delete __pPopup;
268                         __pPopup = null;
269                 }
270         }
271
272     return E_SUCCESS;
273 }
274
275 void
276 WaitPopup::HidePopup(void)
277 {
278         if (__pPopup)
279         {
280                 __pPopup->SetShowState(false);
281                 __pPopup->Show();
282                 delete __pPopup;
283                 __pPopup = null;
284         }
285
286         if (__pAnimationFrameList)
287         {
288                 __pAnimationFrameList->RemoveAll(true);
289                 delete __pAnimationFrameList;
290                 __pAnimationFrameList = null;
291         }
292 }