Exemplo n.º 1
0
        private async void PickAContactButton_Click(object sender, RoutedEventArgs e)
        {
            ContactPicker contactPicker = new ContactPicker();
            contactPicker.CommitButtonText = "SelectThis";
           

            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Address);
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
            Contact contact = await contactPicker.PickContactAsync();

            if (contact != null)
            {
                //OutputFields.Visibility = Visibility.Visible;
                //OutputEmpty.Visibility = Visibility.Collapsed;

                txtblock_imePriimek.Text = contact.DisplayName;

                AppendContactFieldValues(OutputEmails, contact.Emails);
                AppendContactFieldValues(OutputPhoneNumbers, contact.Phones);
                AppendContactFieldValues(OutputAddresses, contact.Addresses);

                
                
            }
            else
            {
                //OutputEmpty.Visibility = Visibility.Visible;
                //OutputFields.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 2
0
        static async Task <Contact> PlatformPickContactAsync()
        {
            var contactPicker   = new ContactPicker();
            var contactSelected = await contactPicker.PickContactAsync();

            return(ConvertContact(contactSelected));
        }
Exemplo n.º 3
0
        private async Task<IList<Contact>> SelectContactsAsync( SelectContactInteraction selectContact )
        {
            Contract.Requires( selectContact != null );
            Contract.Ensures( Contract.Result<Task<IList<Contact>>>() != null );

            var commitButtonText = selectContact.DefaultCommand?.Name;
            var dialog = new ContactPicker();

            dialog.DesiredFieldsWithContactFieldType.AddRange( selectContact.DesiredFields );
#if WINDOWS_PHONE_APP
            TryIfImplemented( () => dialog.SelectionMode = selectContact.DesiredFields.Any() ? ContactSelectionMode.Fields : ContactSelectionMode.Contacts );
            TryIfImplemented( () => { if ( !string.IsNullOrEmpty( commitButtonText ) ) dialog.CommitButtonText = commitButtonText; } );
#else
            dialog.SelectionMode = selectContact.DesiredFields.Any() ? ContactSelectionMode.Fields : ContactSelectionMode.Contacts;

            if ( !string.IsNullOrEmpty( commitButtonText ) )
                dialog.CommitButtonText = commitButtonText;
#endif
            if ( selectContact.Multiselect )
                return await dialog.PickContactsAsync();

            var contacts = new List<Contact>();
            var contact = await dialog.PickContactAsync();

            if ( contact != null )
                contacts.Add( contact );

            return contacts;
        }
Exemplo n.º 4
0
        private async void BtnShareMail_Click(object sender, RoutedEventArgs e)
        {
            if (txtNom.Text != "" || txtPrenom.Text != "")
            {
                string        message       = "Bonjour, " + txtNom.Text + " " + txtPrenom.Text + " vous informe de sa participation à GeoDrapeau et que son score est de " + lblScore.Text + " points. \nSi vous pensez faire mieux, venez relever le défi.\n\nL'équipe de GeoDrapeau vous remercie.";
                ContactPicker contactPicker = new ContactPicker();
                Contact       contact       = await contactPicker.PickContactAsync();

                ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

                if (contact != null)
                {
                    Contact real = await contactStore.GetContactAsync(contact.Id);

                    EmailMessage emailMessage = new EmailMessage();
                    emailMessage.To.Add(new EmailRecipient(real.Emails.FirstOrDefault <Windows.ApplicationModel.Contacts.ContactEmail>().Address));
                    emailMessage.Subject = "GeoDrapeau Score" + ApplicationView.GetForCurrentView().Title.ToString().Trim();
                    emailMessage.Body    = message;

                    await EmailManager.ShowComposeNewEmailAsync(emailMessage);
                }
            }
            else
            {
                message();
            }
        }
Exemplo n.º 5
0
        private async void ThirdContactPanel_OnTapped(object sender, TappedRoutedEventArgs e)
        {
            var localsettings   = ApplicationData.Current.LocalSettings;
            var romaingsettings = ApplicationData.Current.RoamingSettings;
            var contactPicker2  = new ContactPicker();

            // Ask the user to pick contact phone numbers.
            contactPicker2.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
            var contacts2 = await contactPicker2.PickContactAsync();

            if (!localsettings.Values.ContainsKey("ThirdContactName"))
            {
                localsettings.Values.Add("ThirdContactName", contacts2.DisplayName);
                localsettings.Values.Add("ThirdContactNumber", contacts2.YomiDisplayName);
                ThirdContactTextBlock.Text = contacts2.DisplayName;
            }
            else
            {
                localsettings.Values.Remove("ThirdContactName");
                localsettings.Values.Remove("ThirdContactNumber");
                localsettings.Values.Add("ThirdContactName", contacts2.DisplayName);
                localsettings.Values.Add("ThirdContactNumber", contacts2.YomiDisplayName);
                ThirdContactTextBlock.Text = contacts2.DisplayName;
            }
        }
Exemplo n.º 6
0
        private async void btnPickContact_Click(object sender, RoutedEventArgs e)
        {
            ContactPicker contactPicker = new ContactPicker();

            // 指定需要选取的联系人的字段
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

            // 启动联系人选取器,以选择一个联系人
            Contact contact = await contactPicker.PickContactAsync();

            if (contact != null)
            {
                lblMsg.Text += string.Format("name:{0}", contact.Name);
                lblMsg.Text += Environment.NewLine;

                foreach (ContactEmail email in contact.Emails)
                {
                    lblMsg.Text += string.Format("email kind:{0}, email address:{1}", email.Kind, email.Address);
                    lblMsg.Text += Environment.NewLine;
                }

                foreach (ContactPhone phone in contact.Phones)
                {
                    lblMsg.Text += string.Format("phone kind:{0}, phone number:{1}, phone description:{2}", phone.Kind, phone.Number, phone.Description);
                    lblMsg.Text += Environment.NewLine;
                }
            }
            else
            {
                lblMsg.Text += "取消了";
                lblMsg.Text += Environment.NewLine;
            }
        }
        private async void SendContactExecute()
        {
            var picker = new ContactPicker();

            picker.SelectionMode = ContactSelectionMode.Fields;
            picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

            var picked = await picker.PickContactAsync();

            if (picked != null)
            {
                Telegram.Td.Api.Contact contact = null;

                var annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                var store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

                if (store != null && annotationStore != null)
                {
                    var full = await store.GetContactAsync(picked.Id);

                    if (full != null)
                    {
                        var annotations = await annotationStore.FindAnnotationsForContactAsync(full);

                        var first = annotations.FirstOrDefault();
                        if (first != null)
                        {
                            var remote = first.RemoteId;
                            if (int.TryParse(remote.Substring(1), out int userId))
                            {
                                var user = ProtoService.GetUser(userId);
                                if (user != null)
                                {
                                    contact = new Telegram.Td.Api.Contact(user.PhoneNumber, user.FirstName, user.LanguageCode, user.Id);
                                }
                            }
                        }

                        //contact = full;
                    }
                }

                if (contact == null)
                {
                    var phone = picked.Phones.FirstOrDefault();
                    if (phone == null)
                    {
                        return;
                    }

                    contact = new Telegram.Td.Api.Contact(phone.Number, picked.FirstName, picked.LastName, 0);
                }

                if (contact != null)
                {
                    await SendContactAsync(contact);
                }
            }
        }
Exemplo n.º 8
0
        private async void Send(object sender, RoutedEventArgs e)
        {
            ContactPicker contactPicker = new ContactPicker();

            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Address);
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
            Contact contact = await contactPicker.PickContactAsync();

            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation =
                Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (contact != null && file != null)
            {
                await  ComposeEmail(contact, "hello", file);
            }
        }
Exemplo n.º 9
0
        private async void pickContactsBt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                cp = new ContactPicker();
                cp.SelectionMode = ContactSelectionMode.Fields;
                cp.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
                var contact = await cp.PickContactAsync();

                Country selectedCountry = ((WithdrawalViewModel)DataContext).SelectedCountry;
                bool    validationResult;
                if (contact == null)
                {
                    validationResult = Helper.ValidateContactInfo("", "", out ((WithdrawalViewModel)DataContext).contactNumberWellFormatted, ref selectedCountry, ref ((WithdrawalViewModel)DataContext).isToResetCountry, ref ((WithdrawalViewModel)DataContext).validateContactInfoAgain);
                    ((WithdrawalViewModel)DataContext).SelectedCountry = selectedCountry;
                    ((WithdrawalViewModel)DataContext).updateUserInterfaceBasedOnBasedOnValidationResult("", "", validationResult);
                }
                else
                {
                    validationResult = Helper.ValidateContactInfo(contact.DisplayName, contact.Phones.FirstOrDefault().Number, out ((WithdrawalViewModel)DataContext).contactNumberWellFormatted, ref selectedCountry, ref ((WithdrawalViewModel)DataContext).isToResetCountry, ref ((WithdrawalViewModel)DataContext).validateContactInfoAgain);
                    ((WithdrawalViewModel)DataContext).SelectedCountry = selectedCountry;
                    ((WithdrawalViewModel)DataContext).updateUserInterfaceBasedOnBasedOnValidationResult(contact.DisplayName, contact.Phones.FirstOrDefault().Number, validationResult);

                    contactNumberBackup = contact.Phones.FirstOrDefault().Number;
                    ButtonOk.Focus(FocusState.Programmatic);
                }
            }
            catch (Exception) { }

            HelperWindows.LoseFocus(sender);
        }
Exemplo n.º 10
0
        private async void ContactPickerBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            if (args.ChosenSuggestion == null)
            {
                var picker = new ContactPicker();
                picker.CommitButtonText = "Select";
                picker.SelectionMode    = ContactSelectionMode.Fields;
                picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

                var result = await picker.PickContactAsync();

                if (result != null)
                {
                    if (string.IsNullOrEmpty(ContactPickerBox.Text))
                    {
                        ContactPickerBox.Text = result.Phones.First().Number;
                    }
                    else
                    {
                        ContactPickerBox.Text += "; " + result.Phones.First().Number;
                    }
                    ContactPickerBox.Focus(FocusState.Pointer);
                }
            }
        }
Exemplo n.º 11
0
        private async void SendContactExecute()
        {
            var picker = new ContactPicker();

            picker.SelectionMode = ContactSelectionMode.Fields;
            picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

            var contact = await picker.PickContactAsync();

            if (contact != null)
            {
                TLUser user = null;

                var annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                var store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

                if (store != null && annotationStore != null)
                {
                    var full = await store.GetContactAsync(contact.Id);

                    if (full != null)
                    {
                        var annotations = await annotationStore.FindAnnotationsForContactAsync(full);

                        var first = annotations.FirstOrDefault();
                        if (first != null)
                        {
                            var remote = first.RemoteId;
                            if (int.TryParse(remote.Substring(1), out int userId))
                            {
                                user = CacheService.GetUser(userId) as TLUser;
                            }
                        }

                        //contact = full;
                    }
                }

                if (user == null)
                {
                    var phone = contact.Phones.FirstOrDefault();
                    if (phone == null)
                    {
                        return;
                    }

                    user           = new TLUser();
                    user.FirstName = contact.FirstName;
                    user.LastName  = contact.LastName;
                    user.Phone     = phone.Number;
                }

                if (user != null)
                {
                    await SendContactAsync(user);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Handles the click event for the button that allows selection of a contact to be used for procotol activation.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private async void HandleProtocolActivationContactSelection(Object sender, RoutedEventArgs e)
        {
            var contactPicker = new ContactPicker();

            _selectedContact = await contactPicker.PickContactAsync();

            UpdateProtocolLauncherControls();
        }
Exemplo n.º 13
0
        private async void btnPickContact_Click(object sender, RoutedEventArgs e)
        {
            ContactPicker contactPicker = new ContactPicker();

            // 指定需要选取的联系人的字段
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

            // 启动联系人选取器,以选择一个联系人
            Contact contact = await contactPicker.PickContactAsync();

            if (contact != null)
            {
                lblMsg.Text += string.Format("name:{0}", contact.Name);
                lblMsg.Text += Environment.NewLine;
                lblMsg.Text += string.Format("id:{0}", contact.Id);
                lblMsg.Text += Environment.NewLine;

                foreach (ContactEmail email in contact.Emails)
                {
                    lblMsg.Text += string.Format("email kind:{0}, email address:{1}", email.Kind, email.Address);
                    lblMsg.Text += Environment.NewLine;
                }

                foreach (ContactPhone phone in contact.Phones)
                {
                    lblMsg.Text += string.Format("phone kind:{0}, phone number:{1}, phone description:{2}", phone.Kind, phone.Number, phone.Description);
                    lblMsg.Text += Environment.NewLine;
                }


                ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

                // 通过 ContactStore 和联系人 id 可以获取到联系人的完整信息(需要配置 <Capability Name = "contacts" />)
                Contact realContact = await contactStore.GetContactAsync(contact.Id);

                // 通过 ContactStore 也是可以拿到全部联系人信息的,这部分知识点以后再写
                // IReadOnlyList<Contact> contacts = await contactStore.FindContactsAsync();

                // 显示联系人的图片(只通过 ContactPicker 是获取不到的)
                IRandomAccessStreamReference imageStreamRef = realContact.SmallDisplayPicture;
                if (imageStreamRef != null)
                {
                    IRandomAccessStream imageStream = await imageStreamRef.OpenReadAsync();

                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(imageStream);
                    imgThumbnail.Source = bitmapImage;
                }
            }
            else
            {
                lblMsg.Text += "取消了";
                lblMsg.Text += Environment.NewLine;
            }
        }
Exemplo n.º 14
0
        public async Task <Contact> PickContactEmail()
        {
            ContactPicker contactPicker = new ContactPicker();

            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);

            var contact = await contactPicker.PickContactAsync();

            return(contact);
        }
        private async void PickContactEmail()
        {
            ClearOutputs();

            // Ask the user to pick a contact email address.
            var contactPicker = new ContactPicker();

            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);

            Contact contact = await contactPicker.PickContactAsync();

            ReportContactResult(contact);
        }
        private async void PickContactPhone()
        {
            ClearOutputs();

            // Ask the user to pick a contact phone number.
            var contactPicker = new ContactPicker();

            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

            Contact contact = await contactPicker.PickContactAsync();

            ReportContactResult(contact);
        }
Exemplo n.º 17
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var contactPicker = new ContactPicker();
                contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

                Contact contact = await contactPicker.PickContactAsync();

                string sms = string.Format("I need your help, The coordinates of my location are:- " + "Latitude:{0}  Longitude:{1}", MyMap.Center.Position.Latitude, MyMap.Center.Position.Longitude);
                ComposeSMS(contact, sms);
            }
            catch { }
        }
Exemplo n.º 18
0
        private async void selectContact_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var contactPicker = new ContactPicker();

            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

            contact = await contactPicker.PickContactAsync();

            if (contact != null)
            {
                ClientName.Text  = contact.DisplayName;
                PhoneNumber.Text = contact.Phones[0].Number;
            }
        }
Exemplo n.º 19
0
        private async void ComposeEmail()
        {
            var contactPicker = new ContactPicker();

            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
            Contact recipent = await contactPicker.PickContactAsync();

            if (recipent != null)
            {
                this.AppendContactFieldValues(recipent.Emails);
            }
            else
            {
            }
        }
Exemplo n.º 20
0
        private async void SendSMSButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            ContactPicker contactPicker = new ContactPicker();
            Contact       contact       = await contactPicker.PickContactAsync();

            // You need to add required capabilities in your App manifest file for access contact list.
            ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

            if (contact != null)
            {
                // Get Selected Contact
                Contact realContact = await contactStore.GetContactAsync(contact.Id);

                SendSMS(realContact, "This is test SMS.");
            }
        }
Exemplo n.º 21
0
 public void openContactSelection(ContactFieldType?fieldType, IPromise promise)
 {
     try {
         this.RunOnDispatcher(async() => {
             try {
                 var contactPicker = new ContactPicker();
                 if (fieldType != null)
                 {
                     contactPicker.SelectionMode = ContactSelectionMode.Fields;
                     contactPicker.DesiredFieldsWithContactFieldType.Add(fieldType.Value);
                 }
                 Contact contact = await contactPicker.PickContactAsync();
                 promise.Resolve(contact == null ? null : new {
                     recordId   = contact.Id,
                     name       = contact.Name,
                     givenName  = contact.FirstName,
                     middleName = contact.MiddleName,
                     familyName = contact.LastName,
                     phones     = contact.Phones?.Select(x => new {
                         number = x.Number,
                         type   = x.Kind.ToString(),
                     }),
                     emails = contact.Emails?.Select(x => new {
                         address = x.Address,
                         type    = x.Kind.ToString(),
                     }),
                     postalAddresses = contact.Addresses?.Select(x => new {
                         street         = x.StreetAddress,
                         city           = x.Locality,
                         state          = x.Region,
                         postalCode     = x.PostalCode,
                         isoCountryCode = CountryHelper.TryGetTwoLetterISORegionName(x.Country),
                     }),
                 });
             }
             catch (Exception ex) {
                 promise.Reject(ex);
             }
         });
     }
     catch (Exception ex) {
         promise.Reject(ex);
     }
 }
Exemplo n.º 22
0
        public async Task <Contact> PromptUserForContactAsync()
        {
            // Open the prompt
            var contactPicker = new ContactPicker()
            {
                SelectionMode = ContactSelectionMode.Contacts
            };

            Contact contact = await contactPicker.PickContactAsync();

            if (contact != null)
            {
                // Fetch all the details
                ContactStore contactStore = await PromptForPermissionsAsync();

                contact = await contactStore.GetContactAsync(contact.Id);
            }

            return(contact);
        }
Exemplo n.º 23
0
        static async Task <Contact> PlatformPickContactAsync()
        {
            var contactPicker = new ContactPicker();

            try
            {
                var contactSelected = await contactPicker.PickContactAsync();

                if (contactSelected == null)
                {
                    return(null);
                }

                var phones = new List <ContactPhone>();
                var emails = new List <ContactEmail>();

                foreach (var item in contactSelected.Phones)
                {
                    phones.Add(new ContactPhone(item.Number, GetPhoneContactType(item.Kind)));
                }

                phones = phones.Distinct().ToList();

                foreach (var item in contactSelected.Emails)
                {
                    emails.Add(new ContactEmail(item.Address, GetEmailContactType(item.Kind)));
                }

                emails = emails.Distinct().ToList();

                return(new Contact(
                           contactSelected.Name,
                           phones,
                           emails,
                           ContactType.Unknown));
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Launches a picker which allows the user to choose a contact
        /// </summary>
        /// <param name="response">Contains the chosen contact or null if nothing was selected</param>
        public static void PickContact(Action <WSAContact> response)
        {
#if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0)
            UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
            {
                ContactPicker contactPicker = new ContactPicker();

                contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
                contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
                contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Address);

                Contact contact = await contactPicker.PickContactAsync();

                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    if (response != null)
                    {
                        response(contact != null ? MapContactToWSAContact(contact) : null);
                    }
                }, true);
            }, false);
#endif
        }
Exemplo n.º 25
0
        private async void EditContactButtonHandler(object parameter)
        {
            var applicationData = ApplicationData.Current;
            var localsettings   = applicationData.LocalSettings;

            switch (int.Parse(parameter.ToString()))
            {
            case 1:
                var contactPicker = new ContactPicker();
                // Ask the user to pick contact phone numbers.
                contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
                var contacts = await contactPicker.PickContactAsync();

                if (!localsettings.Values.ContainsKey("FirstContactName"))
                {
                    localsettings.Values.Add("FirstContactName", contacts.DisplayName);
                    localsettings.Values.Add("FirstContactNumber", contacts.YomiDisplayName);

                    FirstContactName = contacts.DisplayName;
                    RaisePropertyChanged(() => FirstContactName);
                }
                else
                {
                    localsettings.Values.Remove("FirstContactName");
                    localsettings.Values.Remove("FirstContactNumber");
                    localsettings.Values.Add("FirstContactName", contacts.DisplayName);
                    localsettings.Values.Add("FirstContactNumber", contacts.YomiDisplayName);
                    FirstContactName = contacts.DisplayName;
                    RaisePropertyChanged(() => FirstContactName);
                }
                break;

            case 2:
                var contactPicker1 = new ContactPicker();
                // Ask the user to pick contact phone numbers.
                contactPicker1.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
                var contacts1 = await contactPicker1.PickContactAsync();

                if (!localsettings.Values.ContainsKey("SecondContactName"))
                {
                    localsettings.Values.Add("SecondContactName", contacts1.DisplayName);
                    localsettings.Values.Add("SecondContactNumber", contacts1.YomiDisplayName);
                    SecondContactName = contacts1.DisplayName;
                    RaisePropertyChanged(() => SecondContactName);
                }
                else
                {
                    localsettings.Values.Remove("SecondContactName");
                    localsettings.Values.Remove("SecondContactNumber");
                    localsettings.Values.Add("SecondContactName", contacts1.DisplayName);
                    localsettings.Values.Add("SecondContactNumber", contacts1.YomiDisplayName);
                    SecondContactName = contacts1.DisplayName;
                    RaisePropertyChanged(() => SecondContactName);
                }
                break;

            case 3:
                var contactPicker2 = new ContactPicker();
                // Ask the user to pick contact phone numbers.
                contactPicker2.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
                var contacts2 = await contactPicker2.PickContactAsync();

                if (!localsettings.Values.ContainsKey("ThirdContactName"))
                {
                    localsettings.Values.Add("ThirdContactName", contacts2.DisplayName);
                    localsettings.Values.Add("ThirdContactNumber", contacts2.YomiDisplayName);
                    ThirdContactName = contacts2.DisplayName;
                    RaisePropertyChanged(() => ThirdContactName);
                }
                else
                {
                    localsettings.Values.Remove("ThirdContactName");
                    localsettings.Values.Remove("ThirdContactNumber");
                    localsettings.Values.Add("ThirdContactName", contacts2.DisplayName);
                    localsettings.Values.Add("ThirdContactNumber", contacts2.YomiDisplayName);
                    ThirdContactName = contacts2.DisplayName;
                    RaisePropertyChanged(() => ThirdContactName);
                }
                break;

            case 4:

                IsMessageBoxDisabled      = true;
                MessageEditIconVisibility = Visibility.Visible;
                MessageSaveIconVisibility = Visibility.Collapsed;
                RaisePropertyChanged(() => MessageEditIconVisibility);
                RaisePropertyChanged(() => MessageSaveIconVisibility);
                RaisePropertyChanged(() => IsMessageBoxDisabled);
                var localData = ApplicationData.Current.LocalSettings;
                var roamData  = ApplicationData.Current.RoamingSettings;
                if (!localData.Values.ContainsKey("MessageToSend") && !roamData.Values.ContainsKey("MessageToSend"))
                {
                    localData.Values.Add("MessageToSend", MessageBox);
                    roamData.Values.Add("MessageToSend", MessageBox);
                }
                else
                {
                    localData.Values.Remove("MessageToSend");
                    roamData.Values.Remove("MessageToSend");
                    localData.Values.Add("MessageToSend", MessageBox);
                    roamData.Values.Add("MessageToSend", MessageBox);
                }

                break;

            case 5:
                IsMessageBoxDisabled      = false;
                MessageEditIconVisibility = Visibility.Collapsed;
                MessageSaveIconVisibility = Visibility.Visible;
                RaisePropertyChanged(() => MessageEditIconVisibility);
                RaisePropertyChanged(() => MessageSaveIconVisibility);
                RaisePropertyChanged(() => IsMessageBoxDisabled);
                break;

            default:
                Debug.WriteLine("Default Case Hit!");
                break;
            }
        }
        async private void selectContact_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ContactPicker contactPicker = new ContactPicker();
                contactPicker.CommitButtonText = "Select";
                contactPicker.SelectionMode    = ContactSelectionMode.Contacts;
                Contact tmp = await contactPicker.PickContactAsync();

                if (tmp == null)
                {
                    status.Log(LocalizableStrings.CONTACTS_NO_CONTACT_SELECTED);
                    return;
                }
                status.Log(LocalizableStrings.CONTACTS_CONTACT_SELECTED);

                ContactStore store = await ContactManager.RequestStoreAsync();

                // BUG on Desktop tmp.Id is an empty string.
                Debug.WriteLine(tmp.Id);
                if (string.IsNullOrEmpty(tmp.Id))
                {
                    status.Log(LocalizableStrings.CONTACTS_NO_CONTACT_DETAILS);
                    return;
                }

                Contact contact = await store.GetContactAsync(tmp.Id);

                if (contact == null)
                {
                    status.Log(LocalizableStrings.CONTACTS_NO_CONTACT_DETAILS);
                    return;
                }
                status.Log(LocalizableStrings.CONTACTS_CONTACT_DETAILS_FOUND);

                BitmapImage bitmap = null;
                if (contact.Thumbnail != null)
                {
                    IRandomAccessStreamWithContentType stream = await contact.Thumbnail.OpenReadAsync();

                    if (stream != null && stream.Size > 0)
                    {
                        bitmap = new BitmapImage();
                        bitmap.SetSource(stream);
                    }
                }
                thumbnail.Source = bitmap;

                string name = contact.DisplayName;
                if (!string.IsNullOrEmpty(name))
                {
                    contactName.Text = name;
                }

                ContactEmail email = contact.Emails.FirstOrDefault();
                if (email != null)
                {
                    contactEmail.Text = email.Address;
                }

                ContactPhone phone = contact.Phones.FirstOrDefault();
                if (phone != null)
                {
                    contactPhone.Text = phone.Number;
                }

                ContactAddress address = contact.Addresses.FirstOrDefault();
                if (address != null)
                {
                    contactAddress.Text = address.StreetAddress;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                status.Log(ex.Message);
            }
        }
Exemplo n.º 27
0
        private async void SendContactExecute()
        {
            var picker = new ContactPicker();
            //picker.SelectionMode = ContactSelectionMode.Fields;
            //picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Address);
            //picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.ConnectedServiceAccount);
            //picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
            //picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.ImportantDate);
            //picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.JobInfo);
            //picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Notes);
            //picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
            //picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.SignificantOther);
            //picker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Website);

            var picked = await picker.PickContactAsync();

            if (picked != null)
            {
                Telegram.Td.Api.Contact contact = null;
                string vcard = string.Empty;

                var annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                var store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

                if (store != null && annotationStore != null)
                {
                    var full = await store.GetContactAsync(picked.Id);

                    if (full != null)
                    {
                        var annotations = await annotationStore.FindAnnotationsForContactAsync(full);

                        //var vcardStream = await ContactManager.ConvertContactToVCardAsync(full, 2000);
                        //using (var stream = await vcardStream.OpenReadAsync())
                        //{
                        //    using (var dataReader = new DataReader(stream.GetInputStreamAt(0)))
                        //    {
                        //        await dataReader.LoadAsync((uint)stream.Size);
                        //        vcard = dataReader.ReadString(dataReader.UnconsumedBufferLength);
                        //    }
                        //}

                        var first = annotations.FirstOrDefault();
                        if (first != null)
                        {
                            var remote = first.RemoteId;
                            if (int.TryParse(remote.Substring(1), out int userId))
                            {
                                var user = ProtoService.GetUser(userId);
                                if (user != null)
                                {
                                    contact = new Telegram.Td.Api.Contact(user.PhoneNumber, user.FirstName, user.LastName, vcard, user.Id);
                                }
                            }
                        }

                        //contact = full;

                        if (contact == null)
                        {
                            var phone = full.Phones.FirstOrDefault();
                            if (phone == null)
                            {
                                return;
                            }

                            contact = new Telegram.Td.Api.Contact(phone.Number, picked.FirstName, picked.LastName, vcard, 0);
                        }
                    }
                }

                if (contact != null)
                {
                    await SendContactAsync(contact);
                }
            }
        }
Exemplo n.º 28
0
        internal async void PickButton_Click(object sender, RoutedEventArgs e)
        {
            if (UIEnabled)
            {
                UIEnabled = false;
                ContactPicker contactPicker = new ContactPicker();
                contactPicker.SelectionMode = ContactSelectionMode.Fields;
                contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
                var contact = await contactPicker.PickContactAsync();

                if (contact != null)
                {
                    // The contact we just got doesn't contain the contact picture so we need to fetch it
                    // see https://stackoverflow.com/questions/33401625/cant-get-contact-profile-images-in-uwp
                    ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

                    // If we do not have access to contacts the ContactStore will be null, we can still use the contact the user
                    // seleceted however
                    if (contactStore != null)
                    {
                        Contact realContact = await contactStore.GetContactAsync(contact.Id);

                        if (realContact.SourceDisplayPicture != null)
                        {
                            using (var stream = await realContact.SourceDisplayPicture.OpenReadAsync())
                            {
                                BitmapImage bitmapImage = new BitmapImage();
                                await bitmapImage.SetSourceAsync(stream);

                                ContactPhoto = bitmapImage;
                            }
                        }
                        else
                        {
                            ContactPhoto = null;
                        }
                    }
                    ContactName = contact.Name;
                    if (contact.Phones.Count > 0)
                    {
                        var originalNumber = contact.Phones[0].Number;
                        if (originalNumber[0] != '+')
                        {
                            // need a better way of determining the "default" country code here
                            var formattedPhoneNumber = PhoneNumberFormatter.FormatE164("1", originalNumber);
                            if (string.IsNullOrEmpty(formattedPhoneNumber))
                            {
                                ContactNumber = originalNumber;
                                MessageDialog message = new MessageDialog("Please format the number in E.164 format.", "Could not format number");
                                await message.ShowAsync();
                            }
                            else
                            {
                                ContactNumber = formattedPhoneNumber;
                            }
                        }
                    }
                }
                UIEnabled = true;
            }
        }