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 PhnCallButtonsPanel.cpp
19 * @brief Base class for all Call forms
21 #include "PhnCallButtonsPanel.h"
22 #include "PhnAppUtility.h"
25 using namespace Tizen::App;
26 using namespace Tizen::Base;
27 using namespace Tizen::Ui;
28 using namespace Tizen::Ui::Controls;
29 using namespace Tizen::Graphics;
31 //Constants - Scene name
32 const wchar_t* IDC_ADDJOINCALL_BUTTON = L"IDC_ADDJOINCALL_BUTTON";
33 const wchar_t* IDC_KEYPAD_BUTTON = L"IDC_KEYPAD_BUTTON";
34 const wchar_t* IDC_MUTE_BUTTON = L"IDC_MUTE_BUTTON";
35 const wchar_t* IDC_CONTACT_BUTTON = L"IDC_CONTACT_BUTTON";
36 const wchar_t* IDC_SPEAKER_BUTTON = L"IDC_SPEAKER_BUTTON";
37 const wchar_t* IDC_VOICECALL_BUTTON = L"IDC_VOICECALL_BUTTON";
38 const wchar_t* IDC_VIDEOCALL_BUTTON = L"IDC_VIDEOCALL_BUTTON";
39 const wchar_t* IDC_MSG_BUTTON = L"IDC_MSG_BUTTON";
40 const wchar_t* IDC_ENDCALL_BUTTON = L"IDC_ENDCALL_BUTTON";
43 const int W_BG_BITMAP = 80;
44 const int H_BG_BITMAP = 80;
45 const int Y_BG_BITMAP_POS = 56;
46 const int IDI_TEXT_SIZE = 38;
47 const int IDI_VERTICAL_SPACE = 6;
49 CallButtonsPanel::CallButtonsPanel(void)
53 CallButtonsPanel::~CallButtonsPanel(void)
55 //Empty Implementation
59 CallButtonsPanel::ConstructPanel(IActionEventListener* pEventListener, FormType parentFormType)
61 if (pEventListener == null)
68 //set action listener & save form state
69 __pActionListener = pEventListener;
70 __parentFormType = parentFormType;
72 switch (__parentFormType)
74 case FORMTYPE_ENDCALL:
75 r = Construct(IDL_END_CALL_PANEL);
79 r = Construct(IDL_CALL_PANEL);
83 TryCatch(r == E_SUCCESS, , "CallButtonsPanel::Initialize() resource not found");
91 CallButtonsPanel::OnInitializing(void)
95 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetParent()->GetLandscapeLayoutN());
96 if (pRelativeLayout != null)
98 pRelativeLayout->SetHorizontalFitPolicy(*this, FIT_POLICY_PARENT);
99 pRelativeLayout->SetRelation(*this, *GetParent(), RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
100 delete pRelativeLayout;
103 pRelativeLayout = dynamic_cast<RelativeLayout*>(GetParent()->GetPortraitLayoutN());
104 if (pRelativeLayout != null)
106 pRelativeLayout->SetHorizontalFitPolicy(*this, FIT_POLICY_PARENT);
107 pRelativeLayout->SetRelation(*this, *GetParent(), RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
108 delete pRelativeLayout;
111 //Set background bitmap
112 r = AddBackgroundBitmap();
117 //set buttons as child controls
118 switch (__parentFormType)
120 case FORMTYPE_ENDCALL:
121 r = ConstructEndCallPanel();
125 r = ConstructActiveCallPanel();
140 CallButtonsPanel::OnTerminating(void)
142 //remove all child controls...
148 CallButtonsPanel::SetSpeakerButtonState(CommandIds cmdId)
151 String speakerButtonId(IDC_SPEAKER_BUTTON);
152 Button* pButton = static_cast<Button*>(GetControl(speakerButtonId));
153 //Check if Button exist and needs to change state.
154 if(pButton == null || pButton->GetActionId() == cmdId)
159 String btnName = AppUtility::GetResourceString(IDS_SPEAKER_BTN_NAME);
160 AddKeyPadActionListener(speakerButtonId, cmdId);
165 SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_OFF_ICON, BTN_NORMAL);
166 SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_OFF_PRESS_ICON, BTN_PRESS);
167 SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_OFF_DIM_ICON, BTN_DIM);
171 case IDA_SPEAKER_OFF:
173 SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_ON_ICON, BTN_NORMAL);
174 SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_ON_PRESS_ICON, BTN_PRESS);
175 SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_ON_DIM_ICON, BTN_DIM);
185 CallButtonsPanel::SetMuteButtonState(CommandIds cmdId)
187 String muteButtonId(IDC_MUTE_BUTTON);
188 Button* pButton = static_cast<Button*>(GetControl(muteButtonId));
189 //Check if Button exist and needs to change state.
190 if(pButton == null || pButton->GetActionId() == cmdId)
195 String btnName = AppUtility::GetResourceString(IDS_MUTE_BTN_NAME);
196 AddKeyPadActionListener(muteButtonId, cmdId);
201 SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_ON_ICON, BTN_NORMAL);
202 SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_ON_PRESS_ICON, BTN_PRESS);
203 SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_ON_DIM_ICON, BTN_DIM);
209 SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_OFF_ICON, BTN_NORMAL);
210 SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_OFF_PRESS_ICON, BTN_PRESS);
211 SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_OFF_DIM_ICON, BTN_DIM);
221 CallButtonsPanel::SetKeypadButtonState(CommandIds cmdId)
223 String keypadButtonId(IDC_KEYPAD_BUTTON);
224 Button* pButton = static_cast<Button*>(GetControl(keypadButtonId));
225 //Check if Button exist and needs to change state.
226 if(pButton == null || pButton->GetActionId() == cmdId)
231 String btnName = AppUtility::GetResourceString(IDS_KEYPAD_BTN_NAME);
232 AddKeyPadActionListener(keypadButtonId, cmdId);
235 case IDA_CLOSE_NUMKEYPAD:
237 SetBitmapsToButton(keypadButtonId, btnName, IDB_HIDE_KEYPAD_ICON, BTN_NORMAL);
238 SetBitmapsToButton(keypadButtonId, btnName, IDB_HIDE_KEYPAD_PRESS_ICON, BTN_PRESS);
239 SetBitmapsToButton(keypadButtonId, btnName, IDB_HIDE_KEYPAD_DIM_ICON, BTN_DIM);
243 case IDA_OPEN_NUMKEYPAD:
245 SetBitmapsToButton(keypadButtonId, btnName, IDB_CLOSE_KEYPAD_ICON, BTN_NORMAL);
246 SetBitmapsToButton(keypadButtonId, btnName, IDB_CLOSE_KEYPAD_PRESS_ICON, BTN_PRESS);
247 SetBitmapsToButton(keypadButtonId, btnName, IDB_CLOSE_KEYPAD_DIM_ICON, BTN_DIM);
257 CallButtonsPanel::AddBackgroundBitmap(void)
259 result r = E_FAILURE;
261 Rectangle panelRect = GetBounds();
262 //Set BackGround bitmap
263 Bitmap* pBgBitmap = null;
264 AppResource* pAppResource = AppResource::GetInstance();
267 pBgBitmap = pAppResource->GetBitmapN(IDB_BACKGROUND_BITMAP);
270 Label* pBackgroundLabel = new (std::nothrow) Label();
271 pBackgroundLabel->Construct(Rectangle(0, 1, panelRect.width, panelRect.height), L"");
272 pBackgroundLabel->SetBackgroundBitmap(*pBgBitmap);
273 r = AddControl(*pBackgroundLabel);
275 //always display in background
276 SetControlAlwaysAtBottom(*pBackgroundLabel, true);
286 CallButtonsPanel::ConstructEndCallPanel(void)
288 result r = E_SUCCESS;
289 Rectangle relativeCtrlRect = GetBounds();
292 String voiceButtonId(IDC_VOICECALL_BUTTON);
293 String btnName = AppUtility::GetResourceString(IDS_VOICE_CALL_BTN_NAME);
294 SetBitmapsToButton(voiceButtonId, btnName, IDB_VOICE_CALL_ICON, BTN_NORMAL);
295 SetBitmapsToButton(voiceButtonId, btnName, IDB_VOICE_CALL_PRESS_ICON, BTN_PRESS);
296 SetBitmapsToButton(voiceButtonId, btnName, IDB_VOICE_CALL_DIM_ICON, BTN_DIM);
297 AddKeyPadActionListener(voiceButtonId, IDA_VOICE_CALL);
300 String videoButtonId(IDC_VIDEOCALL_BUTTON);
301 btnName = AppUtility::GetResourceString(IDS_VIDEO_CALL_BTN_NAME);
302 SetBitmapsToButton(videoButtonId, btnName, IDB_VIDEO_CALL_ICON, BTN_NORMAL);
303 SetBitmapsToButton(videoButtonId, btnName, IDB_VIDEO_CALL_PRESS_ICON, BTN_PRESS);
304 SetBitmapsToButton(videoButtonId, btnName, IDB_VIDEO_CALL_DIM_ICON, BTN_DIM);
305 AddKeyPadActionListener(videoButtonId, IDA_VIDEO_CALL);
308 String msgButtonId(IDC_MSG_BUTTON);
309 btnName = AppUtility::GetResourceString(IDS_MSG_BTN_NAME);
310 SetBitmapsToButton(msgButtonId, btnName, IDB_MESSAGE_ICON, BTN_NORMAL);
311 SetBitmapsToButton(msgButtonId, btnName, IDB_MESSAGE_PRESS_ICON, BTN_PRESS);
312 SetBitmapsToButton(msgButtonId, btnName, IDB_MESSAGE_DIM_ICON, BTN_DIM);
313 AddKeyPadActionListener(msgButtonId, IDA_MESSAGE);
319 CallButtonsPanel::ConstructActiveCallPanel(void)
321 result r = E_SUCCESS;
324 String endButtonId(IDC_ENDCALL_BUTTON);
325 String btnName = AppUtility::GetResourceString(IDS_ENDCALL_BTN_NAME);
326 SetBitmapsToButton(endButtonId, btnName, IDB_END_CALL_ICON, BTN_NORMAL);
327 SetBitmapsToButton(endButtonId, btnName, IDB_END_CALL_PRESS_ICON, BTN_PRESS);
328 SetBitmapsToButton(endButtonId, btnName, IDB_END_CALL_DIM_ICON, BTN_DIM);
330 //Add or Join call based on form state
331 String addJoinButtonId(IDC_ADDJOINCALL_BUTTON);
332 switch (__parentFormType)
334 case FORMTYPE_OUTGOINGCALL:
335 case FORMTYPE_ACTIVECALL:
336 case FORMTYPE_EMERGENCYOUTGOINGCALL:
337 case FORMTYPE_EMERGENCYACTIVECALL:
340 AddKeyPadActionListener(endButtonId, IDA_END_CALL);
342 btnName = AppUtility::GetResourceString(IDS_ADDCALL_BTN_NAME);
343 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_ICON, BTN_NORMAL);
344 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_PRESS_ICON, BTN_PRESS);
345 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_DIM_ICON, BTN_DIM);
346 AddKeyPadActionListener(addJoinButtonId, IDA_ADD_CALL);
350 case FORMTYPE_ACTIVECONFCALL:
353 AddKeyPadActionListener(endButtonId, IDA_END_CONF_CALL);
355 btnName = AppUtility::GetResourceString(IDS_ADDCALL_BTN_NAME);
356 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_ICON, BTN_NORMAL);
357 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_PRESS_ICON, BTN_PRESS);
358 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_DIM_ICON, BTN_DIM);
359 AddKeyPadActionListener(addJoinButtonId, IDA_ADD_CALL);
363 case FORMTYPE_MULTIPLECALLS:
366 AddKeyPadActionListener(endButtonId, IDA_END_CALL);
368 btnName = AppUtility::GetResourceString(IDS_JOINCALL_BTN_NAME);
369 SetBitmapsToButton(addJoinButtonId, btnName, IDB_JOIN_CALL_ICON, BTN_NORMAL);
370 SetBitmapsToButton(addJoinButtonId, btnName, IDB_JOIN_CALL_PRESS_ICON, BTN_PRESS);
371 SetBitmapsToButton(addJoinButtonId, btnName, IDB_JOIN_CALL_DIM_ICON, BTN_DIM);
372 AddKeyPadActionListener(addJoinButtonId, IDA_JOIN_CALL);
380 //Keypad is closed, bt default
381 SetKeypadButtonState(IDA_OPEN_NUMKEYPAD);
382 //Speaker is off, by default
383 SetSpeakerButtonState(IDA_SPEAKER);
384 //Mute is off, by default
385 SetMuteButtonState(IDA_MUTE);
387 String contactButtonId(IDC_CONTACT_BUTTON);
388 btnName = AppUtility::GetResourceString(IDS_CONTACT_BTN_NAME);
389 SetBitmapsToButton(contactButtonId, btnName, IDB_CONTACT_ICON, BTN_NORMAL);
390 SetBitmapsToButton(contactButtonId, btnName, IDB_CONTACT_PRESS_ICON, BTN_PRESS);
391 SetBitmapsToButton(contactButtonId, btnName, IDB_CONTACT_DIM_ICON, BTN_DIM);
392 AddKeyPadActionListener(contactButtonId, IDA_OPEN_CONTACTS);
394 //ToDO: For now disabling the contact button as there is no way to launch contact app control
396 Button* pButton = static_cast<Button*>(GetControl(IDC_CONTACT_BUTTON));
397 pButton->SetEnabled(false);
398 //disable all keys except 'Speaker' keys while dialing outgoing call
399 if (__parentFormType == FORMTYPE_OUTGOINGCALL || __parentFormType == FORMTYPE_EMERGENCYOUTGOINGCALL
400 || __parentFormType == FORMTYPE_EMERGENCYACTIVECALL)
402 DisableKeysForOutgoingCall();
409 CallButtonsPanel::SetBitmapsToButton(const String& buttonId, const String& buttonName, const String& imgPath, ButtonState state)
411 Button* pButton = static_cast<Button*>(GetControl(buttonId));
414 //Fetch Bitmap from resource
415 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(imgPath,
416 W_BG_BITMAP, H_BG_BITMAP);
418 //Create a new canvas
419 Canvas* pCanvas = new (std::nothrow) Canvas;
420 pCanvas->Construct(Rectangle(0, 0, pButton->GetBounds().width, pButton->GetBounds().height));
423 Point bitmapPos(0, 0);
424 bitmapPos.SetPosition(((pCanvas->GetBounds().width - pBitmap->GetWidth()) / 2), Y_BG_BITMAP_POS);
425 SetEnrichedTextToButton(buttonName, pCanvas, state, (bitmapPos.y + pBitmap->GetHeight() + IDI_VERTICAL_SPACE));
427 //set normal bitmap to canvas
428 pCanvas->DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
430 //Set the final Bitmap to Button
431 Bitmap* pActualBgBmp = new (std::nothrow) Bitmap();
432 pActualBgBmp->Construct(*pCanvas, pCanvas->GetBounds());
438 pButton->SetNormalBackgroundBitmap(*pActualBgBmp);
444 Bitmap* highlightedBmp = AppUtility::GetBitmapFromResourcesN(L"C01-1_icon_button_press.png",236,237);
445 if(highlightedBmp != null)
447 pButton->SetHighlightedBackgroundBitmap(*highlightedBmp);
448 delete highlightedBmp;
449 highlightedBmp = null;
451 pButton->SetPressedBitmap(Point(0,0),*pActualBgBmp);
457 pButton->SetDisabledBitmap(Point(0, 0), *pActualBgBmp);
461 pButton->Invalidate(true);
470 CallButtonsPanel::SetEnrichedTextToButton(const String& buttonName, Canvas* pCanvas, ButtonState state, int verticalPos)
473 Color textColor(255, 255, 255);
477 textColor.SetAlpha(255);
481 textColor.SetAlpha(127);
485 textColor.SetAlpha(77);
490 font.Construct(FONT_STYLE_PLAIN, IDI_TEXT_SIZE);
491 Dimension textDimension;
492 font.GetTextExtent(buttonName, buttonName.GetLength(), textDimension);
493 textDimension.height = textDimension.height + font.GetDescender();
494 TextElement* pTextElement = new (std::nothrow) TextElement();
495 pTextElement->Construct(buttonName);
496 pTextElement->SetTextColor(textColor);
497 pTextElement->SetFont(font);
499 EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
500 pEnrichedText->Construct(textDimension);
501 pEnrichedText->Add(*pTextElement);
504 Point textPos(((pCanvas->GetBounds().width - pEnrichedText->GetWidth()) / 2), verticalPos);
505 pCanvas->DrawText(textPos, *pEnrichedText);
508 pEnrichedText->RemoveAll(true);
509 delete pEnrichedText;
513 CallButtonsPanel::AddKeyPadActionListener(const String& buttonId, CommandIds cmdId)
515 Button* pButton = static_cast<Button*>(GetControl(buttonId));
518 pButton->SetActionId(cmdId);
519 pButton->AddActionEventListener(*__pActionListener);
524 CallButtonsPanel::DisableKeysForOutgoingCall(void)
527 EnableAddCallButton(false);
530 Button* pButton = static_cast<Button*>(GetControl(IDC_KEYPAD_BUTTON));
531 pButton->SetEnabled(false);
534 pButton = static_cast<Button*>(GetControl(IDC_MUTE_BUTTON));
535 pButton->SetEnabled(false);
538 pButton = static_cast<Button*>(GetControl(IDC_CONTACT_BUTTON));
539 pButton->SetEnabled(false);
543 CallButtonsPanel::SetEndCallPanelState(bool isEnabled)
546 Button* pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON));
547 pButton->SetEnabled(isEnabled);
550 pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON));
551 pButton->SetEnabled(isEnabled);
554 pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON));
555 pButton->SetEnabled(isEnabled);
559 CallButtonsPanel::EnableAddCallButton(bool enable)
562 Button* pButton = static_cast<Button*>(GetControl(IDC_ADDJOINCALL_BUTTON));
563 if(pButton != null && pButton->GetActionId() == IDA_ADD_CALL)
565 pButton->SetEnabled(enable);
570 CallButtonsPanel::SetButtonPosition(void)
572 switch (__parentFormType)
574 case FORMTYPE_ENDCALL:
577 Button* pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON));
578 SetControlAlwaysOnTop(*pButton,true);
581 pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON));
582 SetControlAlwaysOnTop(*pButton,true);
585 pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON));
586 SetControlAlwaysOnTop(*pButton,true);
587 Label* pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL1"));
588 SetControlAlwaysOnTop(*pLabel,true);
589 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL5"));
590 SetControlAlwaysOnTop(*pLabel,true);
591 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL6"));
592 SetControlAlwaysOnTop(*pLabel,true);
593 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL7"));
594 SetControlAlwaysOnTop(*pLabel,true);
595 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL8"));
596 SetControlAlwaysOnTop(*pLabel,true);
603 Button* pButton = static_cast<Button*>(GetControl(IDC_KEYPAD_BUTTON));
604 SetControlAlwaysOnTop(*pButton,true);
606 pButton = static_cast<Button*>(GetControl(IDC_MUTE_BUTTON));
607 SetControlAlwaysOnTop(*pButton,true);
609 pButton = static_cast<Button*>(GetControl(IDC_CONTACT_BUTTON));
610 SetControlAlwaysOnTop(*pButton,true);
611 //Add or Join call based on form state
612 pButton = static_cast<Button*>(GetControl(IDC_ADDJOINCALL_BUTTON));
613 SetControlAlwaysOnTop(*pButton,true);
615 pButton = static_cast<Button*>(GetControl(IDC_ENDCALL_BUTTON));
616 SetControlAlwaysOnTop(*pButton,true);
618 pButton = static_cast<Button*>(GetControl(IDC_SPEAKER_BUTTON));
619 SetControlAlwaysOnTop(*pButton,true);
620 Label* pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL1"));
621 SetControlAlwaysOnTop(*pLabel,true);
622 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL1"));
623 SetControlAlwaysOnTop(*pLabel,true);
624 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL2"));
625 SetControlAlwaysOnTop(*pLabel,true);
626 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL4"));
627 SetControlAlwaysOnTop(*pLabel,true);
628 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL5"));
629 SetControlAlwaysOnTop(*pLabel,true);
630 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL6"));
631 SetControlAlwaysOnTop(*pLabel,true);
632 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL7"));
633 SetControlAlwaysOnTop(*pLabel,true);
634 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL8"));
635 SetControlAlwaysOnTop(*pLabel,true);
636 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL9"));
637 SetControlAlwaysOnTop(*pLabel,true);
638 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL10"));
639 SetControlAlwaysOnTop(*pLabel,true);
640 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL11"));
641 SetControlAlwaysOnTop(*pLabel,true);
642 pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL12"));
643 SetControlAlwaysOnTop(*pLabel,true);