IncomingCall.xaml.cs 4.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
IncomingCall.xaml.cs
Copyright (C) 2016  Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 16 17 18 19 20 21 22 23 24
*/

using System;
using Linphone.Model;
using Windows.UI.Xaml.Controls;
using System.ComponentModel;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml;
using Windows.UI.Core;
using System.Diagnostics;
25
using System.Collections.Generic;
26

Erwan Croze's avatar
Erwan Croze committed
27
namespace Linphone.Views {
28

Erwan Croze's avatar
Erwan Croze committed
29
    public partial class IncomingCall : Page {
30 31
        private String _callingNumber;

Erwan Croze's avatar
Erwan Croze committed
32
        public IncomingCall() {
33 34
            this.InitializeComponent();
            SystemNavigationManager.GetForCurrentView().BackRequested += Back_requested;
Erwan Croze's avatar
Erwan Croze committed
35
            if (!LinphoneManager.Instance.Core.VideoSupported() || !LinphoneManager.Instance.Core.VideoCaptureEnabled) {
36 37 38 39
                //AnswerVideo.Visibility = Visibility.Collapsed;
            }
        }

Erwan Croze's avatar
Erwan Croze committed
40
        private void Back_requested(object sender, BackRequestedEventArgs e) {
41
            LinphoneManager.Instance.EndCurrentCall();
Erwan Croze's avatar
Erwan Croze committed
42
            if (Frame.CanGoBack) {
43 44 45 46 47 48 49
                Frame.GoBack();
            }
        }

        /// <summary>
        /// Remove this entry from the back stack to ensure the user won't navigate to it with the back button
        /// </summary>
Erwan Croze's avatar
Erwan Croze committed
50
        protected override void OnNavigatedFrom(NavigationEventArgs e) {
51 52
            //if (!e.IsNavigationInitiator)
            //{
Erwan Croze's avatar
Erwan Croze committed
53 54
            //if we leave the application, we consider it as a call rejection
            // LinphoneManager.Instance.EndCurrentCall();
55 56 57
            //}

            base.OnNavigatedFrom(e);
Erwan Croze's avatar
Erwan Croze committed
58
            if (Frame.BackStack.Count > 0) {
59 60 61 62 63 64 65 66
                Frame.BackStack.Clear();
            }
        }

        /// <summary>
        /// Method called when the page is displayed.
        /// Searches for a matching contact using the current call address or number and display information if found.
        /// </summary>
Erwan Croze's avatar
Erwan Croze committed
67
        protected override void OnNavigatedTo(NavigationEventArgs nee) {
68 69
            base.OnNavigatedTo(nee);

Erwan Croze's avatar
Erwan Croze committed
70
            if ((nee.Parameter as String).Contains("sip")) {
71
                _callingNumber = (nee.Parameter as String);
Erwan Croze's avatar
Erwan Croze committed
72 73
                if (_callingNumber.StartsWith("sip:")) {
                    // _callingNumber = _callingNumber.Substring(4);
74 75 76 77
                }
                // While we dunno if the number matches a contact one, we consider it won't and we display the phone number as username
                Contact.Text = _callingNumber;

Erwan Croze's avatar
Erwan Croze committed
78
                if (_callingNumber != null && _callingNumber.Length > 0) {
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
                    //ContactManager cm = ContactManager.Instance;
                    //cm.ContactFound += cm_ContactFound;
                    //cm.FindContact(_callingNumber);
                }
            }
        }

        /// <summary>
        /// Callback called when the search on a phone number for a contact has a match
        /// </summary>
      /*  private void cm_ContactFound(object sender, ContactFoundEventArgs e)
        {
            if (e.ContactFound != null)
            {
                Contact.Text = e.ContactFound.DisplayName;
                if (e.PhoneLabel != null)
                {
                    Number.Text = e.PhoneLabel + " : " + e.PhoneNumber;
                }
                else
                {
                    Number.Text = e.PhoneNumber;
                }
            }
        }*/

Erwan Croze's avatar
Erwan Croze committed
105 106
        private void Answer_Click(object sender, RoutedEventArgs e) {
            if (LinphoneManager.Instance.Core.CurrentCall != null) {
107 108 109 110
                List<string> parameters = new List<string>();
                parameters.Add(_callingNumber);
                parameters.Add("incomingCall");
                Frame.Navigate(typeof(Views.InCall), parameters);
Erwan Croze's avatar
Erwan Croze committed
111
            }
112 113
        }

Erwan Croze's avatar
Erwan Croze committed
114
        private void AnswerVideo_Click(object sender, RoutedEventArgs e) {
115 116
        }

Erwan Croze's avatar
Erwan Croze committed
117
        private void Decline_Click(object sender, RoutedEventArgs e) {
118
            LinphoneManager.Instance.EndCurrentCall();
Erwan Croze's avatar
Erwan Croze committed
119
            if (Frame.CanGoBack) {
120 121 122 123 124
                Frame.GoBack();
            }
        }
    }
}