2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file CallCallOptionPopup.cpp
19 * @brief Call Options Popup class
25 #include <FGraphics.h>
28 #include "CallOptionPopup.h"
29 #include "CallAppUtility.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Base::Utility;
34 using namespace Tizen::App;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Social;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 const int W_POPUP = 620;
42 const int H_POPUP = 712;
43 const int W_CANCEL_BUTTON = 400;
44 const int H_CANCEL_BUTTON = 72;
45 const int CANCEL_BUTTON_PADDING = 20;
46 const int H_LIST_ITEM = 112;
47 const int W_LIST_ITEM = 112;
48 const int HORIZONTAL_PADDING = 16;
49 const int VERTICAL_PADDING = 110;
50 const int IDA_BUTTON_CANCEL_OPTIONS_POPUP = 502;
51 static const wchar_t* IDL_CALL_OPTION_POPUP = L"IDL_CALL_OPTION_POPUP";
53 CallOptionPopup::CallOptionPopup(IPopupItemSelectListener& listener, CallPresentationModel& callPresenter)
54 : __pOptionsList(null)
55 , __popupListener(listener)
56 , __callPresenter(callPresenter)
60 CallOptionPopup::~CallOptionPopup(void)
62 if (__pOptionsList != null)
64 delete __pOptionsList;
65 __pOptionsList = null;
70 CallOptionPopup::Initialize(void)
73 r = Construct(IDL_CALL_OPTION_POPUP);
74 TryReturn(r == E_SUCCESS, r, "CallOptionPopup construction failed");
76 r = ConstructListData();
77 TryReturn(r == E_SUCCESS, r, "List data not available");
79 int listHeight = H_LIST_ITEM * __pOptionsList->GetCount();
80 int popupHeight = H_CANCEL_BUTTON + listHeight + CANCEL_BUTTON_PADDING + VERTICAL_PADDING;
81 r = SetSize(Dimension(W_POPUP + HORIZONTAL_PADDING, popupHeight));
82 TryReturn(r == E_SUCCESS, r, "CallOptionPopup::SetSize() failed");
85 Application::GetInstance()->GetAppResource()->GetString(L"IDS_CANCEL", strText);
86 Button* pCancelButton = new (std::nothrow) Button();
87 r = pCancelButton->Construct(Rectangle(VERTICAL_PADDING, listHeight + CANCEL_BUTTON_PADDING , W_CANCEL_BUTTON, H_CANCEL_BUTTON), strText);
88 pCancelButton->SetActionId(IDA_BUTTON_CANCEL_OPTIONS_POPUP);
89 pCancelButton->AddActionEventListener(*this);
90 r = AddControl(*pCancelButton);
91 TryReturn(r == E_SUCCESS, r, "CallOptionPopup::AddControl() failed");
93 ListView* pListView = new (std::nothrow) ListView();
94 pListView->Construct(Rectangle(0, 0, W_POPUP - HORIZONTAL_PADDING, listHeight), true, SCROLL_STYLE_FADE_OUT);
95 pListView->AddListViewItemEventListener(*this);
96 pListView->SetItemProvider(*this);
97 r = AddControl(*pListView);
103 CallOptionPopup::ConstructListData(void)
105 result r = E_FAILURE;
107 //fetch active call list
108 ArrayListT<CallInfo>* pCallList = static_cast<ArrayListT<CallInfo>*>(__callPresenter.GetCallListN());
109 if (pCallList != null && pCallList->GetCount() > 0)
111 String optionStr(L"");
112 String* pFirstOption = new (std::nothrow) String();
113 String* pSecondOption = new (std::nothrow) String();
114 String* pThirdOption = null;
115 if (pCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
117 //2 calls(Active+Held) present - 3 options are shown
118 for (int index = 0;index < pCallList->GetCount(); index++)
121 pCallList->GetAt(index,callInfo);
124 if (callInfo.IsConferenceCall() == true)
126 String option = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");;
127 if (callInfo.IsOnHold() == true)
129 option = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
131 optionStr.Format(option.GetLength(), option.GetPointer(), callInfo.GetCallerListCount());
135 //show display name, if available, Else show contact number
136 String* pDisplayName = callInfo.FetchCallerNameN();
137 if (pDisplayName->IsEmpty() == true)
139 //If contact number is also not present show unknown
140 if(callInfo.GetContactNumber().IsEmpty() == false)
142 pDisplayName->Append(callInfo.GetContactNumber());
146 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
149 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION5");
150 optionStr.Append(*pDisplayName);
154 //Check whether to show as 1st or 2nd option
155 if (callInfo.IsOnHold() == false)
157 pFirstOption->Append(optionStr);
161 pSecondOption->Append(optionStr);
165 pThirdOption = new (std::nothrow) String();
166 pThirdOption->Append(AppUtility::GetResourceString(L"IDS_CALL_OPTION6"));
170 //only one call - 2 options are shown.
171 CallInfo firstCallInfo;
172 pCallList->GetAt(0,firstCallInfo);
173 if (firstCallInfo.IsConferenceCall() == false)
175 //show display name if available, else show contact number
176 String* pDisplayName = firstCallInfo.FetchCallerNameN();
177 if (pDisplayName->IsEmpty() == true)
179 if(firstCallInfo.GetContactNumber().IsEmpty() == false)
181 pDisplayName->Append(firstCallInfo.GetContactNumber());
185 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
188 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION1");
189 pFirstOption->Format((optionStr.GetLength() + pDisplayName->GetLength()),optionStr.GetPointer(),pDisplayName->GetPointer());
191 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION2");
192 pSecondOption->Append(optionStr + *pDisplayName);
197 String optionStr2(L"");
198 if (firstCallInfo.IsOnHold() == true)
200 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION8");
201 optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
205 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION7");
206 optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");
208 pFirstOption->Format(optionStr.GetLength(), optionStr.GetPointer(), firstCallInfo.GetCallerListCount());
209 pSecondOption->Format(optionStr2.GetLength(), optionStr2.GetPointer(), firstCallInfo.GetCallerListCount());
213 __pOptionsList = new (std::nothrow) ArrayList(SingleObjectDeleter);
214 __pOptionsList->Construct();
215 __pOptionsList->Add(pFirstOption);
216 __pOptionsList->Add(pSecondOption);
217 if (pThirdOption != null)
219 __pOptionsList->Add(pThirdOption);
222 pCallList->RemoveAll();
229 CallOptionPopup::OnListViewItemStateChanged(ListView& listView, int index,
230 int elementId, ListItemStatus status)
232 Popup::SetShowState(false);
233 __popupListener.OnItemSelected(elementId);
238 CallOptionPopup::GetItemCount(void)
240 if (__pOptionsList != null)
242 return __pOptionsList->GetCount();
248 CallOptionPopup::CreateItem(int index, int itemWidth)
250 int elementId = ANSERWING_OPTION_HOLD_SINGLE_CALL;
251 String* strText = static_cast<String*>(__pOptionsList->GetAt(index));
252 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
253 CustomItem* pItem = new CustomItem();
254 pItem->Construct(Dimension(itemWidth, W_LIST_ITEM), style);
255 if (__pOptionsList->GetCount() == 2)
259 elementId = ANSERWING_OPTION_END_SINGLE_CALL;
264 elementId = ANSERWING_OPTION_REPLACE_ACTIVE_CALL;
267 elementId = ANSERWING_OPTION_REPLACE_HELD_CALL;
271 elementId = ANSERWING_OPTION_END_ALL_CALLS;
274 pItem->AddElement(Rectangle(HORIZONTAL_PADDING, 0, W_POPUP - HORIZONTAL_PADDING, H_LIST_ITEM), elementId, *strText);
279 CallOptionPopup::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
287 CallOptionPopup::OnActionPerformed(const Control& source, int actionId)
291 case IDA_BUTTON_CANCEL_OPTIONS_POPUP:
293 Popup::SetShowState(false);
294 __popupListener.OnItemSelected(IDA_BUTTON_CANCEL_OPTIONS_POPUP);