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");
83 SetMinimumSize(Dimension(W_POPUP + HORIZONTAL_PADDING, popupHeight));
84 TryReturn(r == E_SUCCESS, r, "CallOptionPopup::SetMinSize() failed");
87 Application::GetInstance()->GetAppResource()->GetString(L"IDS_CANCEL", strText);
88 Button* pCancelButton = new (std::nothrow) Button();
89 r = pCancelButton->Construct(Rectangle(VERTICAL_PADDING, listHeight + CANCEL_BUTTON_PADDING , W_CANCEL_BUTTON, H_CANCEL_BUTTON), strText);
90 pCancelButton->SetActionId(IDA_BUTTON_CANCEL_OPTIONS_POPUP);
91 pCancelButton->AddActionEventListener(*this);
92 r = AddControl(*pCancelButton);
93 TryReturn(r == E_SUCCESS, r, "CallOptionPopup::AddControl() failed");
95 ListView* pListView = new (std::nothrow) ListView();
96 pListView->Construct(Rectangle(0, 0, W_POPUP, listHeight), true, SCROLL_STYLE_FADE_OUT);
97 pListView->AddListViewItemEventListener(*this);
98 pListView->SetItemProvider(*this);
99 r = AddControl(*pListView);
107 CallOptionPopup::ConstructListData(void)
109 result r = E_FAILURE;
111 //fetch active call list
112 ArrayListT<AppCallInfo>* pCallList = static_cast<ArrayListT<AppCallInfo>*>(__callPresenter.GetCallListN());
113 if (pCallList != null && pCallList->GetCount() > 0)
115 String optionStr(L"");
116 String* pFirstOption = new (std::nothrow) String();
117 String* pSecondOption = new (std::nothrow) String();
118 String* pThirdOption = null;
119 if (pCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
121 //2 calls(Active+Held) present - 3 options are shown
122 for (int index = 0;index < pCallList->GetCount(); index++)
124 AppCallInfo callInfo;
125 pCallList->GetAt(index,callInfo);
128 if (callInfo.IsConferenceCall() == true)
130 String option = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");;
131 if (callInfo.IsOnHold() == true)
133 option = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
135 optionStr.Format(option.GetLength(), option.GetPointer(), callInfo.GetCallerListCount());
139 //show display name, if available, Else show contact number
140 String* pDisplayName = callInfo.FetchCallerNameN();
141 if (pDisplayName->IsEmpty() == true)
143 //If contact number is also not present show unknown
144 if(callInfo.GetContactNumber().IsEmpty() == false)
146 pDisplayName->Append(callInfo.GetContactNumber());
150 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
153 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION5");
154 optionStr.Append(*pDisplayName);
158 //Check whether to show as 1st or 2nd option
159 if (callInfo.IsOnHold() == false)
161 pFirstOption->Append(optionStr);
165 pSecondOption->Append(optionStr);
169 pThirdOption = new (std::nothrow) String();
170 pThirdOption->Append(AppUtility::GetResourceString(L"IDS_CALL_OPTION6"));
174 //only one call - 2 options are shown.
175 AppCallInfo firstCallInfo;
176 pCallList->GetAt(0,firstCallInfo);
177 if (firstCallInfo.IsConferenceCall() == false)
179 //show display name if available, else show contact number
180 String* pDisplayName = firstCallInfo.FetchCallerNameN();
181 if (pDisplayName->IsEmpty() == true)
183 if(firstCallInfo.GetContactNumber().IsEmpty() == false)
185 pDisplayName->Append(firstCallInfo.GetContactNumber());
189 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
192 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION1");
193 pFirstOption->Format((optionStr.GetLength() + pDisplayName->GetLength()),optionStr.GetPointer(),pDisplayName->GetPointer());
195 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION2");
196 pSecondOption->Append(optionStr + *pDisplayName);
201 String optionStr2(L"");
202 if (firstCallInfo.IsOnHold() == true)
204 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION8");
205 optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
209 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION7");
210 optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");
212 pFirstOption->Format(optionStr.GetLength(), optionStr.GetPointer(), firstCallInfo.GetCallerListCount());
213 pSecondOption->Format(optionStr2.GetLength(), optionStr2.GetPointer(), firstCallInfo.GetCallerListCount());
217 __pOptionsList = new (std::nothrow) ArrayList(SingleObjectDeleter);
218 __pOptionsList->Construct();
219 __pOptionsList->Add(pFirstOption);
220 __pOptionsList->Add(pSecondOption);
221 if (pThirdOption != null)
223 __pOptionsList->Add(pThirdOption);
226 pCallList->RemoveAll();
233 CallOptionPopup::OnListViewItemStateChanged(ListView& listView, int index,
234 int elementId, ListItemStatus status)
236 Popup::SetShowState(false);
237 __popupListener.OnItemSelected(elementId);
242 CallOptionPopup::GetItemCount(void)
244 if (__pOptionsList != null)
246 return __pOptionsList->GetCount();
252 CallOptionPopup::CreateItem(int index, int itemWidth)
254 int elementId = ANSERWING_OPTION_HOLD_SINGLE_CALL;
255 String* strText = static_cast<String*>(__pOptionsList->GetAt(index));
256 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
257 CustomItem* pItem = new CustomItem();
258 pItem->Construct(Dimension(itemWidth, W_LIST_ITEM), style);
259 if (__pOptionsList->GetCount() == 2)
263 elementId = ANSERWING_OPTION_END_SINGLE_CALL;
268 elementId = ANSERWING_OPTION_REPLACE_ACTIVE_CALL;
271 elementId = ANSERWING_OPTION_REPLACE_HELD_CALL;
275 elementId = ANSERWING_OPTION_END_ALL_CALLS;
278 pItem->AddElement(Rectangle(HORIZONTAL_PADDING, 0, W_POPUP - HORIZONTAL_PADDING, H_LIST_ITEM), elementId, *strText);
283 CallOptionPopup::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
291 CallOptionPopup::OnActionPerformed(const Control& source, int actionId)
295 case IDA_BUTTON_CANCEL_OPTIONS_POPUP:
297 Popup::SetShowState(false);
298 __popupListener.OnItemSelected(IDA_BUTTON_CANCEL_OPTIONS_POPUP);