Contact.xaml.cs 3.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Media.Imaging;
using Microsoft.Phone;
using System.IO;
using Microsoft.Phone.UserData;
using Linphone.Model;
using Linphone.Controls;

namespace Linphone.Views
{
19 20 21
    /// <summary>
    /// Page displaying contact information + action buttons associated to phone numbers and email addresses.
    /// </summary>
22
    public partial class Contact : BasePage
23 24 25
    {
        private Microsoft.Phone.UserData.Contact contact { get; set; }

26 27 28
        /// <summary>
        /// Public constructor.
        /// </summary>
29 30 31 32 33
        public Contact()
        {
            InitializeComponent();
        }

34 35 36
        /// <summary>
        /// Method called when the page is displayed, fetches and display contact information and create actions.
        /// </summary>
37 38
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
39
            base.OnNavigatedTo(e);
40
            StatusBar = status;
41

42 43 44 45 46
            while (actions.Children.Count > 0)
            {
                actions.Children.RemoveAt(0);
            }

47 48 49 50 51 52 53 54 55 56 57
            contact = ContactManager.Instance.TempContact;
            contactName.Text = contact.DisplayName;

            Stream imgStream = contact.GetPicture();
            if (imgStream != null)
            {
                Image contactPicture = new Image();
                contactPicture.Width = 150;
                contactPicture.Height = 150;
                contactPicture.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                contactPicture.Source = PictureDecoder.DecodeJpeg(imgStream);
58
                contactPicture.Margin = new Thickness(0,0,0,15);
59 60 61 62 63 64 65 66
                actions.Children.Add(contactPicture);
            }

            foreach (ContactPhoneNumber phone in contact.PhoneNumbers)
            {
                ContactAction entry = new ContactAction();
                entry.Action = "/Assets/AppBar/feature.phone.png";
                entry.Label = phone.Kind.ToString();
67 68
                entry.NumberOrAddress = phone.PhoneNumber;
                entry.Click += action_Click_1;
69 70
                actions.Children.Add(entry);
            }
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

            foreach (ContactEmailAddress email in contact.EmailAddresses)
            {
                ContactAction entry = new ContactAction();
                entry.Action = "/Assets/AppBar/feature.phone.png";
                entry.Label = email.Kind.ToString();
                entry.NumberOrAddress = email.EmailAddress;
                entry.Click += action_Click_1;
                actions.Children.Add(entry);
            }
        }

        private void SetAddressGoToDialerAndCall(String address)
        {
            NavigationService.Navigate(new Uri("/Views/Dialer.xaml?sip=" + address, UriKind.RelativeOrAbsolute));
        }

        private void action_Click_1(object sender, EventArgs e)
        {
            String numberOrAddress = (sender as Button).Tag.ToString();
            SetAddressGoToDialerAndCall(numberOrAddress);
92 93 94
        }
    }
}