Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnSpeedDialPopup.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (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    PhnSpeedDialPopup.cpp
19  * @brief   Speed dial popup class
20  */
21 #include <FApp.h>
22 #include <FSocial.h>
23 #include <FSystem.h>
24 #include <FUi.h>
25 #include <FGraphics.h>
26 #include <FMedia.h>
27
28 #include "PhnSpeedDialPopup.h"
29 #include "PhnSettingsConstants.h"
30 #include "PhnAppUtility.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Utility;
35 using namespace Tizen::App;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Social;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
41
42 const int W_POPUP = 620;
43 const int H_POPUP = 712;
44 const int W_CANCEL_BUTTON = 400;
45 const int H_CANCEL_BUTTON = 72;
46 const int CANCEL_BUTTON_PADDING = 40;
47 const int H_LIST_ITEM = 112;
48 const int W_LIST_ITEM = 112;
49 const int HORIZONTAL_PADDING = 16;
50 const int VERTICAL_PADDING = 110;
51 static const wchar_t* IDL_SPEED_DIAL_POPUP = L"IDL_SPEED_DIAL_POPUP";
52
53 SpeedDialPopup::SpeedDialPopup(IPopupItemSelectListener& listener)
54         : __pCancelButton(null)
55         , __popupListener(listener)
56         , __pListItemArray(null)
57 {
58
59 }
60
61 SpeedDialPopup::~SpeedDialPopup(void)
62 {
63         if (__pListItemArray != null)
64         {
65                 delete __pListItemArray;
66         }
67 }
68
69 int
70 SpeedDialPopup::Initialize(void)
71 {
72         result r = E_SUCCESS;
73         Construct(IDL_SPEED_DIAL_POPUP);
74         ConstructListData();
75         String strText;
76         __pCancelButton = static_cast<Button*> (GetControl(L"IDC_CLOSE_BUTTON"));
77         __pCancelButton->SetActionId(IDA_BUTTON_CLOSE_SPEED_DIAL_POPUP);
78         __pCancelButton->AddActionEventListener(*this);
79
80         ListView* __pList = static_cast<ListView*> (GetControl(L"IDC_LISTVIEW"));
81         __pList->AddListViewItemEventListener(*this);
82         __pList->SetItemProvider(*this);
83         AddControl(*__pList);
84
85         return r;
86
87 }
88
89 void
90 SpeedDialPopup::ConstructListData(void)
91 {
92         __pListItemArray =  new (std::nothrow) ArrayList();
93         __pListItemArray->Construct(2);
94         String optionStr = AppUtility::GetResourceString(L"IDS_CHANGE_CONTACT");
95         String* listItem1 = new (std::nothrow) String(optionStr);
96         __pListItemArray->Add(*listItem1);
97         optionStr.Clear();
98         optionStr = AppUtility::GetResourceString(L"IDS_REMOVE_CONTACT");
99         String* listItem2 = new (std::nothrow) String(optionStr);
100         __pListItemArray->Add(*listItem2);
101 }
102
103 void
104 SpeedDialPopup::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId,
105                                                                                    Tizen::Ui::Controls::ListItemStatus status)
106 {
107         Popup::SetShowState(false);
108         __popupListener.OnItemSelected(elementId);
109         return;
110 }
111
112 void
113 SpeedDialPopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index,
114                                                                         Tizen::Ui::Controls::SweepDirection direction)
115 {
116         return;
117 }
118
119 void
120 SpeedDialPopup::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId,
121                                                                                                   Tizen::Ui::Controls::ListContextItemStatus state)
122 {
123
124         return;
125 }
126
127 void
128 SpeedDialPopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId,
129                                                                                   bool& invokeListViewItemCallback)
130 {
131         return;
132 }
133
134 int
135 SpeedDialPopup::GetItemCount(void)
136 {
137         if (__pListItemArray != null)
138         {
139                 return __pListItemArray->GetCount();
140         }
141         return 0;
142 }
143
144 Tizen::Ui::Controls::ListItemBase*
145 SpeedDialPopup::CreateItem(int index, int itemWidth)
146 {
147         int elementId = 0;
148         String* strText = static_cast<String*>(__pListItemArray->GetAt(index));
149         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
150         CustomItem* pItem = new (std::nothrow) CustomItem();
151         pItem->Construct(Dimension(itemWidth, W_LIST_ITEM), style);
152         if (index == 0)
153         {
154                 elementId = IDA_UPDATE_SPEED_DIAL;
155         }
156         else
157         {
158                 elementId = IDA_REMOVE_SPEED_DIAL;
159         }
160         pItem->AddElement(Rectangle(HORIZONTAL_PADDING, 0, W_POPUP - HORIZONTAL_PADDING, H_LIST_ITEM), elementId, *strText);
161         return pItem;
162 }
163
164 bool
165 SpeedDialPopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
166 {
167         delete pItem;
168         pItem = null;
169         return true;
170 }
171
172
173 void
174 SpeedDialPopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
175 {
176         switch (actionId)
177         {
178         case IDA_BUTTON_CLOSE_SPEED_DIAL_POPUP:
179         {
180                 Popup::SetShowState(false);
181                 __popupListener.OnItemSelected(IDA_BUTTON_CLOSE_SPEED_DIAL_POPUP);
182                 break;
183         }
184         }
185 }