Fix for N_SE-48378 N_SE-48015
[apps/osp/Call.git] / src / CallIncomingCallForm.cpp
index 85b0e36..77274d1 100644 (file)
@@ -1,7 +1,7 @@
 //
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
@@ -19,7 +19,6 @@
  * @brief      Incoming Call form implementation
  */
 #include <FBaseColIList.h>
-#include <FMessaging.h>
 #include "CallIncomingCallForm.h"
 #include "CallAppUtility.h"
 #include "CallSettingsManager.h"
@@ -32,7 +31,6 @@ using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Graphics;
-using namespace Tizen::Messaging;
 using namespace Tizen::Ui;
 using namespace Tizen::Ui::Animations;
 using namespace Tizen::Ui::Controls;
@@ -83,6 +81,7 @@ const int H_LIST_TEXT_ITEM = 111;
 const int X_SEND_TEXT_ITEM = 484;
 const int Y_SEND_TEXT_ITEM = 20;
 const int W_SEND_TEXT_ITEM = 220;
+const int W_SEND_BUTTON_MARGIN = 14;
 const int H_SEND_TEXT_ITEM = 72;
 const int X_PHOTO_LBL = 166;
 const int Y_PHOTO_LBL = 232;
@@ -137,16 +136,6 @@ const wchar_t* IDI_REJECT_ARROW_VISUAL_ELE_NAME = L"RejectArrowVisEle";
 const wchar_t* IDI_REJECT_FINAL_VISUAL_ELE_NAME = L"RejectFinalVisEle";
 const wchar_t* IDI_ACCEPT_FINAL_VISUAL_ELE_NAME = L"AcceptFinalVisEle";
 
-class SmsListener
-       : public Object
-       , public ISmsListener
-{
-public:
-               void  OnSmsMessageSent(result r)
-               {
-               }
-};
-
 IncomingCallForm::IncomingCallForm(void)
        : BaseForm(FORMTYPE_INCOMINGCALL)
 {
@@ -217,25 +206,7 @@ IncomingCallForm::OnInitializing(void)
        }
        HideRejectPanel();
 
-       Button* pButtonRejectMessage = static_cast<Button*>(GetControl(IDC_REJECT_MESSAGE_BUTTON));
-       if (pButtonRejectMessage)
-       {
-               SetBitmapToRejectMessageButton(IDS_REJECT_MESSAGE_BTN,IDB_REJECT_MESSAGE_BG,
-                                                                          IDB_REJECT_MESSAGE_UP_ARROW, IDB_REJECT_MESSAGE_ICON, false, false);
-               SetBitmapToRejectMessageButton(IDS_REJECT_MESSAGE_BTN,IDB_REJECT_MESSAGE_BG,
-                                                                          IDB_REJECT_MESSAGE_UP_ARROW, IDB_REJECT_MESSAGE_ICON, false, true);
-               pButtonRejectMessage->SetActionId(IDA_SHOW_REJECT_CALL_MESSAGE_PANEL);
-               pButtonRejectMessage->AddActionEventListener(*this);
-       }
 
-       //Get Reject list from Settings Manager
-       IMapT<int,String>* pMsgMap = SettingsManager::GetInstance()->GetRejectMessageListN();
-       if(pMsgMap != null)
-       {
-               __pRejectMessageList = pMsgMap->GetValuesN();
-               delete pMsgMap;
-               pMsgMap = null;
-       }
        InitializeTableView();
 
        __pAcceptCircle = AppUtility::GetBitmapFromResourcesN(IDB_ACCEPT_CIRCLE_ICON, W_DIAL_LABEL, H_DIAL_LABEL);
@@ -420,7 +391,6 @@ IncomingCallForm::InitializeFooter(void)
                footerItemCreate.Construct(IDA_CREATE_REJECT_CALL_MESSAGE);
                footerItemCreate.SetText(AppUtility::GetResourceString(IDS_REJECT_MESSAGE_CREATE));
                pFooter->AddItem(footerItemCreate);
-               pFooter->SetBackButton();
                pFooter->SetShowState(false);
        }
 }
@@ -582,11 +552,7 @@ IncomingCallForm::OnTerminating(void)
 }
 
 void
-IncomingCallForm::OnActionPerformed(const Control& source, int actionId)
-{
-       switch (actionId)
-       {
-       case IDA_SHOW_REJECT_CALL_MESSAGE_PANEL: // applicable in all form states
+IncomingCallForm::ShowRejectMessagePanel(void)
        {
                Panel* pKeysPanel = static_cast<Panel*>(GetControl(IDC_REJECT_PANEL));
                if (pKeysPanel)
@@ -608,6 +574,7 @@ IncomingCallForm::OnActionPerformed(const Control& source, int actionId)
                        }
 
                        pMessageList->SetBounds(tmpRect.x, tmpRect.y, tmpRect.width, listHeight);
+                       pMessageList->UpdateTableView();
                        tmpRect = pKeysPanel->GetBounds();
                        pKeysPanel->SetBounds(tmpRect.x, tmpRect.y, tmpRect.width, H_MESSAGE_BG_BITMAP /*+ H_REJECT_VIEW_FOOTER*/ + listHeight);
 
@@ -615,21 +582,10 @@ IncomingCallForm::OnActionPerformed(const Control& source, int actionId)
                        pButtonReject->SetActionId(IDA_CANCEL_REJECT_CALL_MESSAGE_PANEL);
                        pButtonReject->AddActionEventListener(*this);
                        pButtonReject->SetEnabled(true);
-                       pButtonReject->SetFocus();
+                       //pButtonReject->SetFocus();
 
                        ShowRejectMessageFooter();
 
-               /*      pButtonReject = static_cast<Button*>(pKeysPanel->GetControl(IDC_BACK_BUTTON));
-                       pButtonReject->SetActionId(IDA_CANCEL_REJECT_CALL_MESSAGE_PANEL);
-                       pButtonReject->AddActionEventListener(*this);
-                       pButtonReject->SetEnabled(true);
-                       pButtonReject->SetFocus();
-
-                       Button* pButtonCreate = static_cast<Button*>(pKeysPanel->GetControl(IDC_CREATE_BUTTON));
-                       pButtonCreate->SetActionId(IDA_CREATE_REJECT_CALL_MESSAGE);
-                       pButtonCreate->AddActionEventListener(*this);
-                       pButtonCreate->SetEnabled(true);
-                       pButtonCreate->SetFocus();*/
 
                        pKeysPanel->SetFocus();
                        pKeysPanel->Draw();
@@ -642,37 +598,53 @@ IncomingCallForm::OnActionPerformed(const Control& source, int actionId)
                        pButtonRejectMessage->Draw();
                }
        }
-       break;
-
-       case IDA_CREATE_REJECT_CALL_MESSAGE:
+void
+IncomingCallForm::HideRejectMessagePanel(void)
+{
+       HideRejectPanel();
+       Button* pButtonRejectMessage = static_cast<Button*>(GetControl(IDC_REJECT_MESSAGE_BUTTON));
+       if (pButtonRejectMessage)
        {
-               __pCallPresentor->RejectCall(__incomingCallHandle, true,*__pActiveContactNo);
-               ArrayListT<AppCallInfo>* pCallList  = static_cast<ArrayListT<AppCallInfo>*>(__pCallPresentor->GetCallListN());
-               if(pCallList != null && pCallList->GetCount() > 0)
+               pButtonRejectMessage->SetShowState(true);
+               RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
+               if (pRelativeLayout != null)
                {
-                       __pCallPresentor->HandleCallConnected(*pCallList);
+                       pRelativeLayout->SetRelation(*pButtonRejectMessage,*this,RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
+                       pRelativeLayout->Update();
+                       delete pRelativeLayout;
                }
-               pCallList = null;
+       }
+}
+
+void
+IncomingCallForm::OnActionPerformed(const Control& source, int actionId)
+{
+       switch (actionId)
+       {
+       case IDA_SHOW_REJECT_CALL_MESSAGE_PANEL: // applicable in all form states
+       {
+               ShowRejectMessagePanel();
        }
        break;
 
-       case IDA_CANCEL_REJECT_CALL_MESSAGE_PANEL:
+       case IDA_CREATE_REJECT_CALL_MESSAGE:
        {
-               HideRejectPanel();
-               SetFocus();
-               Button* pButtonRejectMessage = static_cast<Button*>(GetControl(IDC_REJECT_MESSAGE_BUTTON));
-               if (pButtonRejectMessage)
+               if(__pCallPresentor->IsAppControlRunning() == false)
                {
-                       pButtonRejectMessage->SetShowState(true);
-                       RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetLandscapeLayoutN());
-                       if (pRelativeLayout != null)
+                       __pCallPresentor->RejectCall(__incomingCallHandle, true,*__pActiveContactNo);
+                       ArrayListT<AppCallInfo>* pCallList  = static_cast<ArrayListT<AppCallInfo>*>(__pCallPresentor->GetCallListN());
+                       if(pCallList != null && pCallList->GetCount() > 0)
                        {
-                               pRelativeLayout->SetRelation(*pButtonRejectMessage,*this,RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
-                               pRelativeLayout->Update();
-                               delete pRelativeLayout;
+                               __pCallPresentor->HandleCallConnected(*pCallList);
                        }
+                       pCallList = null;
                }
+       }
+       break;
 
+       case IDA_CANCEL_REJECT_CALL_MESSAGE_PANEL:
+       {
+               HideRejectMessagePanel();
        }
        break;
 
@@ -684,42 +656,12 @@ IncomingCallForm::OnActionPerformed(const Control& source, int actionId)
        case IDA_SEND_REJECT_MSG6:
        {
                __pCallPresentor->RejectCall(__incomingCallHandle, false,*__pActiveContactNo);
-               SmsListener* pSmsListener = new (std::nothrow) SmsListener();
-               SmsManager* pSmsManager = new (std::nothrow) SmsManager();
-               result r = pSmsManager->Construct(*pSmsListener);
-               if (IsFailed(r) == false)
-               {
-                       RecipientList recipient;
-                       recipient.Add(RECIPIENT_TYPE_TO,*__pActiveContactNo);
-                       SmsMessage smsMessage;
-                       String textToBeSent;
-                       //calculate msgIndex
-                       int msgIndex = IDA_SEND_REJECT_MSG1;
-                       msgIndex = actionId - msgIndex;
-                       __pRejectMessageList->GetAt(msgIndex, textToBeSent);
-                       r = smsMessage.SetText(textToBeSent);
-                       if (IsFailed(r) == false)
-                       {
-                               r = pSmsManager->Send(smsMessage,recipient,true);
-                               if (IsFailed(r) == true)
-                               {
-                                       //todo: error message
-                               }
-                       }
-                       else
-                       {
-                               //todo: error message
-                       }
-               }
-               else
-               {
-                       //todo: error message
-               }
-               delete pSmsListener;
-               delete pSmsManager;
-               /*ArrayListT<CallInfo>* pCallList  = static_cast<ArrayListT<CallInfo>*>(__pCallPresentor->GetCallListN());
-               __pCallPresentor->HandleCallConnected(*pCallList);
-               pCallList = null;*/
+               String textToBeSent;
+               //calculate msgIndex
+               int msgIndex = IDA_SEND_REJECT_MSG1;
+               msgIndex = actionId - msgIndex;
+               __pRejectMessageList->GetAt(msgIndex, textToBeSent);
+               __pCallPresentor->SendMessage(textToBeSent,*__pActiveContactNo);
        }
        break;
 
@@ -732,6 +674,28 @@ void
 IncomingCallForm::OnSceneActivatedN(const SceneId& previousSceneId,    const SceneId& currentSceneId, IList* pArgs)
 {
        AddOrientationEventListener(*this);
+       //Get Reject list from Settings Manager
+       IMapT<int,String>* pMsgMap = SettingsManager::GetInstance()->GetRejectMessageListN();
+       if(pMsgMap != null)
+       {
+               if (__pRejectMessageList != null)
+               {
+                       delete __pRejectMessageList;
+                       __pRejectMessageList = null;
+               }
+               __pRejectMessageList = pMsgMap->GetValuesN();
+               delete pMsgMap;
+               pMsgMap = null;
+       }
+       //No reject messages
+       else
+       {
+               if (__pRejectMessageList != null)
+               {
+                       delete __pRejectMessageList;
+                       __pRejectMessageList = null;
+               }
+       }
        //listen to Foreground events
        CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
        pPhoneApp->AddAppStateChangeListener(*this);
@@ -740,6 +704,12 @@ IncomingCallForm::OnSceneActivatedN(const SceneId& previousSceneId,        const SceneI
                __pCallPresentor = CallPresentationModel::GetInstance();
        }
        __pCallPresentor->SetTelEventListener(this);
+       //Abort any AppControl Request running already to show incoming call screen
+       if (__pCallPresentor->IsAppControlRunning() == true)
+       {
+               __pCallPresentor->AbortAppControlRequest();
+       }
+
        HideRejectPanel();
 
        if(__pAcceptLabel->GetVisualElement()->GetChild(IDI_ACCEPT_VISUAL_ELE_NAME,true) == null)
@@ -826,7 +796,20 @@ IncomingCallForm::OnSceneActivatedN(const SceneId& previousSceneId,        const SceneI
        }
        CallApp* pCallApp = static_cast<CallApp*>(CallApp::GetInstance());
        pCallApp->SetTopMostWindow(true);
+       Button* pButtonRejectMessage = static_cast<Button*>(GetControl(IDC_REJECT_MESSAGE_BUTTON));
+       if (pButtonRejectMessage)
+       {
+               SetBitmapToRejectMessageButton(IDS_REJECT_MESSAGE_BTN,IDB_REJECT_MESSAGE_BG,
+                                                                          IDB_REJECT_MESSAGE_UP_ARROW, IDB_REJECT_MESSAGE_ICON, false, false);
+               SetBitmapToRejectMessageButton(IDS_REJECT_MESSAGE_BTN,IDB_REJECT_MESSAGE_BG,
+                                                                          IDB_REJECT_MESSAGE_UP_ARROW, IDB_REJECT_MESSAGE_ICON, false, true);
+               pButtonRejectMessage->SetActionId(IDA_SHOW_REJECT_CALL_MESSAGE_PANEL);
+               pButtonRejectMessage->AddActionEventListener(*this);
+       }
 
+       //This called here to handle the case when incoming call comes when
+       // add call is in foreground.
+       //__pCallPresentor->OnAppForeground();
 
 }
 
@@ -870,7 +853,6 @@ IncomingCallForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneI
 
        }
        CallApp* pCallApp = static_cast<CallApp*>(CallApp::GetInstance());
-       pCallApp->SetTopMostWindow(false);
        pCallApp->RemoveAppStateChangeListener(*this);
 }
 
@@ -925,7 +907,6 @@ void
 IncomingCallForm::InitializeTableView(void)
 {
        Panel* pKeysPanel = static_cast<Panel*>(GetControl(IDC_REJECT_PANEL));
-
        TableView* pMessageList = static_cast<TableView*>(pKeysPanel->GetControl(IDC_MSG_TABLEVIEW));
        pMessageList->SetItemProvider(this);
        pMessageList->AddTableViewItemEventListener(*this);
@@ -973,14 +954,14 @@ IncomingCallForm::CreateItem(int itemIndex, int itemWidth)
        pMsgLbl->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
        pMsgLbl->SetTextConfig(FONT_SIZE_MSG_TXT, LABEL_TEXT_STYLE_NORMAL);
        pMsgLbl->SetTextColor(COLOR_LIST_TEXT_NORMAL);
-       pItem->AddControl(*pMsgLbl);
+       pItem->AddControl(pMsgLbl);
 
        //Send Button
        if(isShowSendButton == true)
        {
                String sendText = AppUtility::GetResourceString(IDS_LIST_SEND_BUTTON);
                Button* pSendButton = new (std::nothrow) Button();
-               pSendButton->Construct(Rectangle(X_SEND_TEXT_ITEM, Y_SEND_TEXT_ITEM, W_SEND_TEXT_ITEM, H_SEND_TEXT_ITEM), sendText);
+               pSendButton->Construct(Rectangle(GetClientAreaBounds().width - W_SEND_BUTTON_MARGIN -W_SEND_TEXT_ITEM, Y_SEND_TEXT_ITEM, W_SEND_TEXT_ITEM, H_SEND_TEXT_ITEM), sendText);
                //set action id and listener
                int actionId = IDA_SEND_REJECT_MSG1;
                switch(itemIndex)
@@ -1038,8 +1019,8 @@ IncomingCallForm::ShowPersonDetails(const String& phoneNumber, const String& con
        SetTextToLabel(phoneNumber, contactLblName);
 
        //fetch contact details based on phone number
-       String* pDisplayName = pCallInfo->FetchCallerNameN();
-       Bitmap* pPhotoBitmap = pCallInfo->FetchCallerPhotoN();
+       String* pDisplayName = pCallInfo->FetchLatestCallerNameN(phoneNumber);
+       Bitmap* pPhotoBitmap = pCallInfo->FetchLatestCallerPhotoN(phoneNumber);
        ShowCallerPhoto(pPhotoBitmap);
 
        //free resources
@@ -1223,7 +1204,7 @@ IncomingCallForm::SetBitmapToRejectMessageButton(const String& btnName, const St
 
        //set button name
        String holdBtnName = AppUtility::GetResourceString(btnName);
-       Dimension textDimension;
+       FloatDimension textDimension;
        if (!holdBtnName.IsEmpty())
        {
                Font font;
@@ -1288,7 +1269,7 @@ IncomingCallForm::SetBitmapToRejectMessageButton(const String& btnName, const St
 void
 IncomingCallForm::OnTouchPressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
 {
-       __pCallPresentor->StopAlert();
+       //__pCallPresentor->StopAlert();
        if (currentPosition.x < VALID_TOUCH_X_OFFSET && currentPosition.y < VALID_TOUCH_Y_OFFSET)
        {
                Rectangle rect = source.GetBounds();
@@ -1324,12 +1305,12 @@ IncomingCallForm::OnTouchReleased(const Control& source, const Point& currentPos
                        if(__pRejectFinalVisElem == null)
                        {
                                __pRejectFinalVisElem = new (std::nothrow) VisualElement();
+                               __pRejectFinalVisElem->Construct();
+                               __pRejectFinalVisElem->SetName(IDI_REJECT_FINAL_VISUAL_ELE_NAME);
                        }
-                       __pRejectFinalVisElem->Construct();
                        __pRejectFinalVisElem->SetBounds(FloatRectangle(0, 0, W_DIAL_LABEL, H_DIAL_LABEL));
                        __pRejectFinalVisElem->SetShowState(true);
                        __pRejectFinalVisElem->SetOpacity(1.00f);
-                       __pRejectFinalVisElem->SetName(IDI_REJECT_FINAL_VISUAL_ELE_NAME);
                        if(__pRejectLabel->GetVisualElement()->GetChild(IDI_REJECT_FINAL_VISUAL_ELE_NAME,true) == null)
                        {
                                AppLogDebug("AttachChild __pRejectFinalVisElem");
@@ -1399,12 +1380,13 @@ IncomingCallForm::OnTouchReleased(const Control& source, const Point& currentPos
                        if(__pAcceptFinalVisElem == null)
                        {
                                __pAcceptFinalVisElem = new (std::nothrow) VisualElement();
+                               __pAcceptFinalVisElem->Construct();
+                               __pAcceptFinalVisElem->SetName(IDI_ACCEPT_FINAL_VISUAL_ELE_NAME);
                        }
-                       __pAcceptFinalVisElem->Construct();
                        __pAcceptFinalVisElem->SetBounds(FloatRectangle(0, 0, W_DIAL_LABEL, H_DIAL_LABEL));
-                       __pAcceptFinalVisElem->SetShowState(true);
                        __pAcceptFinalVisElem->SetOpacity(1.0f);
-                       __pAcceptFinalVisElem->SetName(IDI_ACCEPT_FINAL_VISUAL_ELE_NAME);
+
+
                        if(__pAcceptLabel->GetVisualElement()->GetChild(IDI_ACCEPT_FINAL_VISUAL_ELE_NAME,true) == null)
                        {
                                AppLogDebug("AttachChild __pAcceptFinalVisElem");
@@ -1477,7 +1459,6 @@ IncomingCallForm::OnTouchMoved(const Control& source, const Point& currentPositi
 void
 IncomingCallForm::OnItemSelected(int itemIndex)
 {
-
        ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
        pArgs->Construct();
 
@@ -1485,7 +1466,6 @@ IncomingCallForm::OnItemSelected(int itemIndex)
        Integer* argIndex = new (std::nothrow) Integer(itemIndex);
        pArgs->Add(argIndex);
        SendUserEvent(REQUEST_ITEM_SELECTED,pArgs);
-
 }
 
 void
@@ -1503,37 +1483,27 @@ IncomingCallForm::HandleMultipleCallSelection(int itemIndex)
        __pAcceptVisElem->SetOpacity(1.0f);
        __pRejectVisElem->SetOpacity(1.00f);
 
-       for (int i = 0; i < COUNT_ARROW_ELEMENTS; i++)
-       {
-               __pRejectArrowLabel = static_cast<Label*>(__pRejectArrowLabelsList->GetAt(i));
-               String RejectVisualEleName(IDI_REJECT_ARROW_VISUAL_ELE_NAME);
-               RejectVisualEleName.Append(i);
-               __pRejectArrowVisElem = __pRejectArrowLabel->GetVisualElement()->GetChild(RejectVisualEleName,true);
-               __pRejectArrowVisElem->SetOpacity(0.0f);
-               __pAcceptArrowLabel = static_cast<Label*>(__pAcceptArrowLabelsList->GetAt(i));
-               String AcceptVisualEleName(IDI_ACCEPT_ARROW_VISUAL_ELE_NAME);
-               AcceptVisualEleName.Append(i);
-               __pAcceptArrowVisElem = __pAcceptArrowLabel->GetVisualElement()->GetChild(AcceptVisualEleName,true);
-               __pAcceptArrowVisElem->SetOpacity(0.0f);
-       }
        if (__pRejectFinalVisElem != null)
        {
                __pRejectFinalVisElem->Destroy();
                __pRejectFinalVisElem = null;
        }
-
        if (__pAcceptFinalVisElem != null)
        {
                __pAcceptFinalVisElem->Destroy();
                __pAcceptFinalVisElem = null;
        }
+
        if (__pOptionPopup)
        {
                delete __pOptionPopup;
                __pOptionPopup = null;
        }
        //accept call
-       __pCallPresentor->AcceptIncomingCall(CallAnsweringOptions(itemIndex),__incomingCallHandle);
+       if(itemIndex != IDA_BUTTON_CANCEL_OPTIONS_POPUP)
+       {
+               __pCallPresentor->AcceptIncomingCall(CallAnsweringOptions(itemIndex),__incomingCallHandle);
+       }
 }
 
 void
@@ -1561,7 +1531,7 @@ IncomingCallForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
 {
        AppLogDebug("Enter");
        HideRejectPanel();
-       SetFocus();
+       //SetFocus();
        Button* pButtonRejectMessage = static_cast<Button*>(GetControl(IDC_REJECT_MESSAGE_BUTTON));
        if (pButtonRejectMessage)
        {
@@ -1576,19 +1546,98 @@ IncomingCallForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
 void
 IncomingCallForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
 {
+       Panel* pKeysPanel = static_cast<Panel*>(GetControl(IDC_REJECT_PANEL));
+       if(pKeysPanel->GetShowState() == true)
+       {
+               HideRejectMessagePanel();
+               ShowRejectMessagePanel();
+       }
+
        Button* pButtonRejectMessage = static_cast<Button*>(GetControl(IDC_REJECT_MESSAGE_BUTTON));
-       if (pButtonRejectMessage)
+       if (pButtonRejectMessage != null)
        {
                SetBitmapToRejectMessageButton(IDS_REJECT_MESSAGE_BTN,IDB_REJECT_MESSAGE_BG,
                                                                           IDB_REJECT_MESSAGE_UP_ARROW, IDB_REJECT_MESSAGE_ICON, false, false);
                SetBitmapToRejectMessageButton(IDS_REJECT_MESSAGE_BTN,IDB_REJECT_MESSAGE_BG,
                                                                           IDB_REJECT_MESSAGE_UP_ARROW, IDB_REJECT_MESSAGE_ICON, false, true);
+               pButtonRejectMessage->Invalidate(true);
        }
 
+       Button* pButtonReject = static_cast<Button*>(pKeysPanel->GetControl(IDC_REJECT_MESSAGE_CANCEL_BUTTON));
+       if (pButtonReject != null)
+       {
+               SetBitmapToRejectMessageButton(IDS_REJECT_MESSAGE_BTN,IDB_REJECT_MESSAGE_BG,
+                                                                          IDB_REJECT_MESSAGE_DOWN_ARROW, IDB_REJECT_MESSAGE_ICON, true, false);
+               SetBitmapToRejectMessageButton(IDS_REJECT_MESSAGE_BTN,IDB_REJECT_MESSAGE_BG,
+                                                                          IDB_REJECT_MESSAGE_DOWN_ARROW, IDB_REJECT_MESSAGE_ICON, true, true);
+               pButtonReject->Invalidate(true);
+       }
 }
 
 void
 IncomingCallForm::OnForeground(void)
 {
-       __pCallPresentor->OnAppForeground();
+       AppLogDebug("Enter");
+       //This is done so that when in IncomingCallForm and calloptionpopup is shown , now if
+       // focus goes away from popup by pressing cancel key from the host keyboard the focus shouldnt get lost
+       // but should focus the Reject message button immediately.
+       Button* pButtonRejectMessage = static_cast<Button*>(GetControl(IDC_REJECT_MESSAGE_BUTTON));
+       pButtonRejectMessage->SetFocus();
+       pButtonRejectMessage->Invalidate(true);
+//     __pCallPresentor->OnAppForeground();
+}
+
+void
+IncomingCallForm::OnScreenOff(void)
+{
+       __pCallPresentor->StopAlert();
+}
+
+void
+IncomingCallForm::CallDisconnected(void)
+{
+       //check if no call option popup is shown, then remain on incoming call screen.
+       //As user has neither accepted nor rejected incoming call.
+       if ((__pOptionPopup == null) || (__pOptionPopup->GetShowState() == false))
+       {
+               return;
+       }
+
+       //fetch already active call list and show updated option popup
+       ArrayListT<AppCallInfo>* pCallList  = static_cast<ArrayListT<AppCallInfo>*>(__pCallPresentor->GetCallListN());
+       if (pCallList != null && pCallList->GetCount() > 0)
+       {
+               //then atleast 1 active call exist.
+               AppCallInfo phnCallInfo;
+               pCallList->GetAt(0,phnCallInfo);
+               //Check if only 1 call exist and it is on Hold
+               if(pCallList->GetCount() == 1 && phnCallInfo.IsOnHold())
+               {
+                       //directly accept call
+                       __pCallPresentor->AcceptIncomingCall(ANSERWING_OPTION_ACCEPT_CALL,__incomingCallHandle);
+               }
+               else
+               {
+                       //Either 1 call exist and not "on Hold".
+                       //Or 2 calls exist.
+                       if(__pOptionPopup != null)
+                       {
+                               delete __pOptionPopup;
+                               __pOptionPopup = null;
+                       }
+                       __pOptionPopup = new (std::nothrow) CallOptionPopup(*this,*(__pCallPresentor));
+                       __pOptionPopup->Initialize();
+                       __pOptionPopup->SetShowState(true);
+                       __pOptionPopup->Draw();
+                       __pOptionPopup->Show();
+               }
+               pCallList->RemoveAll();
+       }
+       else
+       {
+               //no active call - Accept the  incoming call
+               __pCallPresentor->AcceptIncomingCall(ANSERWING_OPTION_ACCEPT_CALL,__incomingCallHandle);
+       }
+       delete pCallList;
+       pCallList = null;
 }