Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / AnimationApp / AnimationApp / project / src / Panel3.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 #include "Panel3.h"
18 #include <FApp.h>
19
20 using namespace Osp::App;
21 using namespace Osp::Base;
22 using namespace Osp::Base::Collection;
23 using namespace Osp::Media;
24 using namespace Osp::Ui;
25 using namespace Osp::Ui::Controls;
26 using namespace Osp::Graphics;
27 using namespace Osp::Base::Runtime;
28
29 Panel3::Panel3(void):
30 __timerStatus(TIMER_INIT),
31 __progress(0),
32 __pListView(null),
33 __pTimer(null),
34 __pStartButton(null),
35 __pStopButton(null)
36 {
37
38 }
39 Panel3::~Panel3(void)
40 {
41         delete __pTimer;
42         delete __pHome;
43         delete __pMsg;
44         delete __pAlarm;
45
46         for (int i = 0; i < 8; i++)
47                 delete __pProgressBitmap[i];
48 }
49
50 result
51 Panel3::Construct(Osp::Graphics::Rectangle rect)
52 {
53         result r = E_SUCCESS;
54         Panel::Construct(rect);
55
56         // Create a Start Button
57         __pStartButton = new Button();
58         __pStartButton->Construct(Rectangle(20, rect.height-90, 210, 80));
59         __pStartButton->SetText(L"Start");
60         __pStartButton->SetActionId(ID_BUTTON_START);
61         __pStartButton->AddActionEventListener(*this);
62         AddControl(*__pStartButton);
63
64         // Create a Stop Button
65         __pStopButton = new Button();
66         __pStopButton->Construct(Rectangle(250, rect.height-90, 210, 80));
67         __pStopButton->SetText(L"Stop");
68         __pStopButton->SetActionId(ID_BUTTON_STOP);
69         __pStopButton->AddActionEventListener(*this);
70         __pStopButton->SetEnabled(false);
71         AddControl(*__pStopButton);
72
73         AppResource *pAppResource = Application::GetInstance()->GetAppResource();
74         // Create Bitmap
75         if (pAppResource)
76         {
77         __pHome = pAppResource->GetBitmapN(L"home_type3.png");
78         __pMsg = pAppResource->GetBitmapN(L"message_type3.png");
79         __pAlarm = pAppResource->GetBitmapN(L"alarm_type3.png");
80
81         __pProgressBitmap[0] = pAppResource->GetBitmapN("blue/progressing00_big.png");
82         __pProgressBitmap[1] = pAppResource->GetBitmapN("blue/progressing01_big.png");
83         __pProgressBitmap[2] = pAppResource->GetBitmapN("blue/progressing02_big.png");
84         __pProgressBitmap[3] = pAppResource->GetBitmapN("blue/progressing03_big.png");
85         __pProgressBitmap[4] = pAppResource->GetBitmapN("blue/progressing04_big.png");
86         __pProgressBitmap[5] = pAppResource->GetBitmapN("blue/progressing05_big.png");
87         __pProgressBitmap[6] = pAppResource->GetBitmapN("blue/progressing06_big.png");
88         __pProgressBitmap[7] = pAppResource->GetBitmapN("blue/progressing07_big.png");
89         }
90         // Create Timer
91         __pTimer = new Timer();
92         __pTimer->Construct(*this);
93
94         // Create a CustomList
95         __pListView = new ListView();
96         __pListView->Construct(Rectangle(0, 0, rect.width, rect.height-100), true, false);
97         __pListView->SetItemProvider(*this);
98         AddControl(*__pListView);
99
100         return r;
101 }
102
103 void
104 Panel3::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
105 {
106         switch(actionId)
107         {
108         case ID_BUTTON_START:
109                 {
110                         if (TIMER_START != __timerStatus)
111                         {
112                                 __pStartButton->SetEnabled(false);
113                                 __pStopButton->SetEnabled(true);
114
115                                 __timerStatus = TIMER_START;
116                                 __pTimer->Start(INTERVAL);
117                         }
118                 }
119                 break;
120         case ID_BUTTON_STOP:
121                 {
122                         __pStartButton->SetEnabled(true);
123                         __pStopButton->SetEnabled(false);
124
125                         __timerStatus = TIMER_STOP;
126                 }
127                 break;
128         }
129         Draw();
130 }
131
132 void
133 Panel3::OnTimerExpired(Osp::Base::Runtime::Timer &  timer)
134 {
135         result r;
136
137         if(__timerStatus == TIMER_STOP)
138         {
139                 __progress = 0;
140
141                 __pStartButton->SetEnabled(true);
142                 __pStopButton->SetEnabled(false);
143
144                 Draw();
145
146                 return;
147         }
148
149         r = __pTimer->Start(INTERVAL);
150         if (IsFailed(r))
151         {
152                 AppLogException("Timer Start Fail.");
153                 return;
154         }
155         __pListView->RefreshList(0, LIST_REFRESH_TYPE_ITEM_MODIFY);
156
157         __pStartButton->SetEnabled(false);
158         __pStopButton->SetEnabled(true);
159
160         Draw();
161 }
162
163 Osp::Ui::Controls::ListItemBase*
164 Panel3::CreateItem(int index, int itemWidth)
165 {
166         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
167         CustomItem* pItem = new CustomItem();
168
169         //ListView Setting
170         if (index == 0 && __timerStatus == TIMER_START)
171         {
172                 int index = __progress % 8;
173                 pItem->Construct(Osp::Graphics::Dimension(itemWidth,100), style);
174                 pItem->AddElement(Rectangle(10, 20, 60, 60), ID_FORMAT_BITMAP, *__pProgressBitmap[index], null, null);
175                 pItem->AddElement(Rectangle(80, 25, 200, 50), ID_FORMAT_STRING, L"Animating", true);
176                 __progress++;
177                 return pItem;
178         }
179         else
180         {
181                 switch (index % 3)
182                 {
183                 case 0:
184                 {
185                         style = LIST_ANNEX_STYLE_NORMAL;
186                         pItem->Construct(Osp::Graphics::Dimension(itemWidth,100), style);
187                         pItem->AddElement(Rectangle(10, 20, 60, 60), ID_FORMAT_BITMAP, *__pHome, null, null);
188                         pItem->AddElement(Rectangle(80, 25, 200, 50), ID_FORMAT_STRING, L"HOME", true);
189                         break;
190                 }
191                 case 1:
192                         style = LIST_ANNEX_STYLE_MARK;
193                         pItem->Construct(Osp::Graphics::Dimension(itemWidth,100), style);
194                         pItem->AddElement(Rectangle(10, 20, 60, 60), ID_FORMAT_BITMAP, *__pMsg, null, null);
195                         pItem->AddElement(Rectangle(80, 25, 200, 50), ID_FORMAT_STRING, L"Msg", true);
196                         break;
197                 case 2:
198                         style = LIST_ANNEX_STYLE_ONOFF_SLIDING;
199                         pItem->Construct(Osp::Graphics::Dimension(itemWidth,100), style);
200                         pItem->AddElement(Rectangle(10, 20, 60, 60), ID_FORMAT_BITMAP, *__pAlarm, null, null);
201                         pItem->AddElement(Rectangle(80, 25, 200, 50), ID_FORMAT_STRING, L"Alarm", true);
202                         break;
203
204                 default:
205                         break;
206                 }
207                 return pItem;
208         }
209 }
210
211 bool
212 Panel3::DeleteItem(int index, Osp::Ui::Controls::ListItemBase* pItem, int itemWidth)
213 {
214         delete pItem;
215         pItem = null;
216         return true;
217 }
218
219 int
220 Panel3::GetItemCount(void)
221 {
222         return 10;
223 }
224