Applied latest source code
[apps/native/preloaded/Clock.git] / src / ClkSortByPopUp.cpp
1 //
2 // Tizen Native SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.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 /**
19  * @file:       ClkSortByPopUp.cpp
20  * @brief       This CPP file contains the declarations of the SortByPopUp
21  */
22
23 #include <FAppUiApp.h>
24 #include <FUiScenes.h>
25
26 #include "ClkCommonLib.h"
27 #include "ClkSortByPopUp.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::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
36
37 static const int ID_FORMAT_RECENT = 501;
38 static const int ID_FORMAT_TIME = 502 ;
39 static const int ID_CANCEL_BUTTON = 504;
40
41
42 ISortByEventListener::ISortByEventListener(void)
43 {
44
45 }
46
47 ISortByEventListener::~ISortByEventListener(void)
48 {
49
50 }
51
52 SortByPopUp::SortByPopUp(void)
53 :__pList(null),
54  __pShareList(null)
55 {
56
57 }
58
59 SortByPopUp::~SortByPopUp(void)
60 {
61         AppLog("SortByPopUp::~SortByPopUp");
62 }
63
64 bool
65 SortByPopUp::Initialize(void)
66 {
67         Button* pCancelButton = null;
68         Popup::Construct(L"IDL_SORT_BY");
69
70         __pList = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW1"));
71
72         if (__pList == null)
73         {
74                 return false;
75         }
76
77         __pList->SetItemProvider(*this);
78         __pList->AddListViewItemEventListener(*this);
79         __pList->SetItemChecked(0, true);
80
81         pCancelButton = static_cast< Button* >(GetControl(L"IDC_BUTTON1", true));
82         if (pCancelButton != null)
83         {
84                 pCancelButton->AddActionEventListener(*this);
85                 pCancelButton->SetActionId(ID_CANCEL_BUTTON);
86         }
87
88         SetPropagatedKeyEventListener(this);
89         return true;
90 }
91
92 result
93 SortByPopUp::OnTerminating(void)
94 {
95         result r = E_SUCCESS;
96         return r;
97 }
98
99 void
100 SortByPopUp::OnActionPerformed(const Control& source, int actionId)
101 {
102         switch (actionId)
103         {
104         case ID_CANCEL_BUTTON:
105         {
106                 Popup::SetShowState(false);
107                 Popup::Show();
108         }
109         break;
110         default:
111                 break;
112         }
113         return;
114 }
115
116 void
117 SortByPopUp::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
118 {
119         switch (index)
120         {
121         case 0:
122         {
123                 if (__pList != NULL )
124                 {
125                         __pList->SetItemChecked(0,true);
126                         __pList->SetItemChecked(1,false);
127                 }
128
129                 if(__pListener != NULL)
130                 {
131                         __pListener->OnSortByPopUpItemSelected(SORTBY_RECENT);
132                 }
133         }
134         break;
135         case 1:
136         {
137                 if (__pList != NULL )
138                 {
139                         __pList->SetItemChecked(0,false);
140                         __pList->SetItemChecked(1,true);
141                 }
142
143                 if( __pListener != NULL)
144                 {
145                         __pListener->OnSortByPopUpItemSelected(SORTBY_TIME);
146                 }
147
148         }
149         break;
150
151         default:
152                 break;
153         }
154
155         if (__pList != NULL )
156         {
157                 __pList->Invalidate(true);
158         }
159 }
160
161 ListItemBase*
162 SortByPopUp::CreateItem(int index, int itemWidth)
163 {
164         result r = E_FAILURE;
165         ListAnnexStyle style = LIST_ANNEX_STYLE_RADIO;
166         int listItemWidth = 112;
167
168         CustomItem* pItem = new (std::nothrow) CustomItem();
169         r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemWidth), style);
170         //pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color::GetColor(COLOR_ID_WHITE));
171
172         pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color(255, 255, 255));
173         pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, Color(86, 135, 193));
174         pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, Color(86, 135, 193));
175
176         if (IsFailed(r))
177         {
178                 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
179                 delete pItem;
180                 pItem = null ;
181                 return null;
182         }
183
184         switch (index)
185         {
186         case 0:
187         {
188                 pItem->AddElement(Rectangle(0, 0, GetClientAreaBounds().width, listItemWidth), ID_FORMAT_RECENT,CommonUtil::GetString(L"IDS_COM_BUTTON_RECENT"), true);
189         }
190         break;
191
192         case 1:
193         {
194                 pItem->AddElement(Rectangle(0, 0, GetClientAreaBounds().width, listItemWidth), ID_FORMAT_TIME,CommonUtil::GetString(L"IDS_WCL_TAB_TIME"), true);
195         }
196         break;
197
198         default:
199                 break;
200         }
201         return pItem;
202 }
203
204 bool
205 SortByPopUp::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
206 {
207         return true;
208 }
209
210 int
211 SortByPopUp::GetItemCount(void)
212 {
213         return 2;
214 }
215
216 ISortByEventListener*
217 SortByPopUp::GetEventListner(void)
218 {
219         return __pListener;
220 }
221
222 void
223 SortByPopUp::SetEventListner(ISortByEventListener* listner)
224 {
225         __pListener = listner;
226 }
227
228 void
229 SortByPopUp::SetDstIndex(int index)
230 {
231         __pList->SetItemChecked(index,true);
232
233         if ( index == 0)
234         {
235                 __pList->SetItemChecked(1,false);
236         }
237         else if (index == 1)
238         {
239                 __pList->SetItemChecked(0,false);
240         }
241         __pList->Invalidate(true);
242 }
243
244 bool
245 SortByPopUp::OnKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
246 {
247         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
248         {
249                 Popup::SetShowState(false);
250                 Popup::Show();
251         }
252
253         return false;
254 }