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 = callInfo.FetchCallerNameN();
142 if (pDisplayName->IsEmpty() == true)
144 //If contact number is also not present show unknown
145 if(callInfo.GetContactNumber().IsEmpty() == false)
147 pDisplayName->Append(callInfo.GetContactNumber());
151 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
154 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION5");
155 optionStr.Append(*pDisplayName);
159 //Check whether to show as 1st or 2nd option
160 if (callInfo.IsOnHold() == false)
162 pFirstOption->Append(optionStr);
166 pSecondOption->Append(optionStr);
170 pThirdOption = new (std::nothrow) String();
171 pThirdOption->Append(AppUtility::GetResourceString(L"IDS_CALL_OPTION6"));
175 //only one call - 2 options are shown.
176 AppCallInfo firstCallInfo;
177 pCallList->GetAt(0,firstCallInfo);
178 if (firstCallInfo.IsConferenceCall() == false)
180 //show display name if available, else show contact number
181 String* pDisplayName = firstCallInfo.FetchCallerNameN();
182 if (pDisplayName->IsEmpty() == true)
184 if(firstCallInfo.GetContactNumber().IsEmpty() == false)
186 pDisplayName->Append(firstCallInfo.GetContactNumber());
190 pDisplayName->Append(AppUtility::GetResourceString(IDS_NUMBER_UNKNOWN));
193 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION1");
194 pFirstOption->Format((optionStr.GetLength() + pDisplayName->GetLength()),optionStr.GetPointer(),pDisplayName->GetPointer());
196 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION2");
197 pSecondOption->Append(optionStr + *pDisplayName);
202 String optionStr2(L"");
203 if (firstCallInfo.IsOnHold() == true)
205 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION8");
206 optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION3");
210 optionStr = AppUtility::GetResourceString(L"IDS_CALL_OPTION7");
211 optionStr2 = AppUtility::GetResourceString(L"IDS_CALL_OPTION4");
213 pFirstOption->Format(optionStr.GetLength(), optionStr.GetPointer(), firstCallInfo.GetCallerListCount());
214 pSecondOption->Format(optionStr2.GetLength(), optionStr2.GetPointer(), firstCallInfo.GetCallerListCount());
218 __pOptionsList = new (std::nothrow) ArrayList(SingleObjectDeleter);
219 __pOptionsList->Construct();
220 __pOptionsList->Add(pFirstOption);
221 __pOptionsList->Add(pSecondOption);
222 if (pThirdOption != null)
224 __pOptionsList->Add(pThirdOption);
227 pCallList->RemoveAll();
234 CallOptionPopup::OnListViewItemStateChanged(ListView& listView, int index,
235 int elementId, ListItemStatus status)
237 Popup::SetShowState(false);
240 elementId = ANSERWING_OPTION_HOLD_SINGLE_CALL;
241 if (__pOptionsList->GetCount() == 2)
245 elementId = ANSERWING_OPTION_END_SINGLE_CALL;
250 elementId = ANSERWING_OPTION_REPLACE_ACTIVE_CALL;
253 elementId = ANSERWING_OPTION_REPLACE_HELD_CALL;
257 elementId = ANSERWING_OPTION_END_ALL_CALLS;
261 __popupListener.OnItemSelected(elementId);
266 CallOptionPopup::GetItemCount(void)
268 if (__pOptionsList != null)
270 return __pOptionsList->GetCount();
276 CallOptionPopup::CreateItem(int index, int itemWidth)
278 int elementId = ANSERWING_OPTION_HOLD_SINGLE_CALL;
279 String* strText = static_cast<String*>(__pOptionsList->GetAt(index));
280 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
281 CustomItem* pItem = new CustomItem();
282 pItem->Construct(Dimension(itemWidth, W_LIST_ITEM), style);
283 if (__pOptionsList->GetCount() == 2)
287 elementId = ANSERWING_OPTION_END_SINGLE_CALL;
292 elementId = ANSERWING_OPTION_REPLACE_ACTIVE_CALL;
295 elementId = ANSERWING_OPTION_REPLACE_HELD_CALL;
299 elementId = ANSERWING_OPTION_END_ALL_CALLS;
302 pItem->AddElement(Rectangle(HORIZONTAL_PADDING, 0, W_POPUP - HORIZONTAL_PADDING, H_LIST_ITEM), elementId, *strText);
307 CallOptionPopup::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
315 CallOptionPopup::OnActionPerformed(const Control& source, int actionId)
319 case IDA_BUTTON_CANCEL_OPTIONS_POPUP:
321 Popup::SetShowState(false);
322 __popupListener.OnItemSelected(IDA_BUTTON_CANCEL_OPTIONS_POPUP);
332 CallOptionPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
334 AppLogDebug("Enter");
335 Popup::SetShowState(false);
336 __popupListener.OnItemSelected(IDA_BUTTON_CANCEL_OPTIONS_POPUP);