2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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 SetPropagatedKeyEventListener(this);
93 r = AddControl(pCancelButton);
94 TryReturn(r == E_SUCCESS, r, "CallOptionPopup::AddControl() failed");
96 ListView* pListView = new (std::nothrow) ListView();
97 pListView->Construct(Rectangle(0, 0, W_POPUP + HORIZONTAL_PADDING, listHeight), true, SCROLL_STYLE_FADE_OUT);
98 pListView->AddListViewItemEventListener(*this);
99 pListView->SetItemProvider(*this);
100 r = AddControl(pListView);
108 CallOptionPopup::ConstructListData(void)
110 result r = E_FAILURE;
112 //fetch active call list
113 ArrayListT<AppCallInfo>* pCallList = static_cast<ArrayListT<AppCallInfo>*>(__callPresenter.GetCallListN());
114 if (pCallList != null && pCallList->GetCount() > 0)
116 String optionStr(L"");
117 String* pFirstOption = new (std::nothrow) String();
118 String* pSecondOption = new (std::nothrow) String();
119 String* pThirdOption = null;
120 if (pCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
122 //2 calls(Active+Held) present - 3 options are shown
123 for (int index = 0;index < pCallList->GetCount(); index++)
125 AppCallInfo callInfo;
126 pCallList->GetAt(index,callInfo);
129 if (callInfo.IsConferenceCall() == true)
131 String option = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");;
132 if (callInfo.IsOnHold() == true)
134 option = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
136 optionStr.Format(option.GetLength(), option.GetPointer(), callInfo.GetCallerListCount());
140 //show display name, if available, Else show contact number
141 String* pDisplayName = null;
142 if(callInfo.GetContactNumber().IsEmpty() == false)
144 pDisplayName = callInfo.FetchLatestCallerNameN(callInfo.GetContactNumber());
148 pDisplayName = new (std::nothrow) String(L"");
150 if (pDisplayName->IsEmpty() == true)
152 //If contact number is also not present show unknown
153 if(callInfo.GetContactNumber().IsEmpty() == false)
155 pDisplayName->Append(callInfo.GetContactNumber());
159 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
162 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION5");
163 optionStr.Append(*pDisplayName);
167 //Check whether to show as 1st or 2nd option
168 if (callInfo.IsOnHold() == false)
170 pFirstOption->Append(optionStr);
174 pSecondOption->Append(optionStr);
178 pThirdOption = new (std::nothrow) String();
179 pThirdOption->Append(AppUtility::GetResourceString(L"IDS_CALL_OPTION6"));
183 //only one call - 2 options are shown.
184 AppCallInfo firstCallInfo;
185 pCallList->GetAt(0,firstCallInfo);
186 if (firstCallInfo.IsConferenceCall() == false)
188 //show display name if available, else show contact number
189 String* pDisplayName = null;
190 if(firstCallInfo.GetContactNumber().IsEmpty() == false)
192 pDisplayName = firstCallInfo.FetchLatestCallerNameN(firstCallInfo.GetContactNumber());
196 pDisplayName = new (std::nothrow) String(L"");
198 if (pDisplayName->IsEmpty() == true)
200 if(firstCallInfo.GetContactNumber().IsEmpty() == false)
202 pDisplayName->Append(firstCallInfo.GetContactNumber());
206 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
209 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION1");
210 pFirstOption->Format((optionStr.GetLength() + pDisplayName->GetLength()),optionStr.GetPointer(),pDisplayName->GetPointer());
212 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION2");
213 pSecondOption->Append(optionStr + *pDisplayName);
218 String optionStr2(L"");
219 if (firstCallInfo.IsOnHold() == true)
221 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION8");
222 optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
226 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION7");
227 optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");
229 pFirstOption->Format(optionStr.GetLength(), optionStr.GetPointer(), firstCallInfo.GetCallerListCount());
230 pSecondOption->Format(optionStr2.GetLength(), optionStr2.GetPointer(), firstCallInfo.GetCallerListCount());
234 __pOptionsList = new (std::nothrow) ArrayList(SingleObjectDeleter);
235 __pOptionsList->Construct();
236 __pOptionsList->Add(pFirstOption);
237 __pOptionsList->Add(pSecondOption);
238 if (pThirdOption != null)
240 __pOptionsList->Add(pThirdOption);
243 pCallList->RemoveAll();
250 CallOptionPopup::OnListViewItemStateChanged(ListView& listView, int index,
251 int elementId, ListItemStatus status)
253 Popup::SetShowState(false);
256 elementId = ANSERWING_OPTION_HOLD_SINGLE_CALL;
257 if (__pOptionsList->GetCount() == 2)
261 elementId = ANSERWING_OPTION_END_SINGLE_CALL;
266 elementId = ANSERWING_OPTION_REPLACE_ACTIVE_CALL;
269 elementId = ANSERWING_OPTION_REPLACE_HELD_CALL;
273 elementId = ANSERWING_OPTION_END_ALL_CALLS;
277 __popupListener.OnItemSelected(elementId);
282 CallOptionPopup::GetItemCount(void)
284 if (__pOptionsList != null)
286 return __pOptionsList->GetCount();
292 CallOptionPopup::CreateItem(int index, int itemWidth)
294 int elementId = ANSERWING_OPTION_HOLD_SINGLE_CALL;
295 String* strText = static_cast<String*>(__pOptionsList->GetAt(index));
296 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
297 CustomItem* pItem = new CustomItem();
298 pItem->Construct(Dimension(itemWidth, W_LIST_ITEM), style);
299 if (__pOptionsList->GetCount() == 2)
303 elementId = ANSERWING_OPTION_END_SINGLE_CALL;
308 elementId = ANSERWING_OPTION_REPLACE_ACTIVE_CALL;
311 elementId = ANSERWING_OPTION_REPLACE_HELD_CALL;
315 elementId = ANSERWING_OPTION_END_ALL_CALLS;
318 pItem->AddElement(Rectangle(HORIZONTAL_PADDING, 0, W_POPUP - HORIZONTAL_PADDING, H_LIST_ITEM), elementId, *strText);
323 CallOptionPopup::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
331 CallOptionPopup::OnActionPerformed(const Control& source, int actionId)
335 case IDA_BUTTON_CANCEL_OPTIONS_POPUP:
337 Popup::SetShowState(false);
338 __popupListener.OnItemSelected(IDA_BUTTON_CANCEL_OPTIONS_POPUP);
348 CallOptionPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
350 AppLogDebug("Enter");
351 if(keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
353 Popup::SetShowState(false);
354 __popupListener.OnItemSelected(IDA_BUTTON_CANCEL_OPTIONS_POPUP);