コード例 #1
0
        async void btnAuthenticate_Click(object sender, EventArgs e)
        {
            Button btnSender = sender as Button;

            if (btnSender.Text == "Sign In")
            {
                btnSender.Enabled = false;
                await Office365Service.EnsureClientCreated(this);

                myContacts = await Office365Service.GetMyContacts();

                myContactsAdapter.AddAll(myContacts);
                myContactsAdapter.NotifyDataSetChanged();
                btnSender.Text    = "Sign Out";
                btnSender.Enabled = true;;
            }
            else
            {
                myContacts.Clear();
                myContactsAdapter.Clear();
                myContactsAdapter.NotifyDataSetChanged();
                Office365Service.SignOut(this);
                btnSender.Text = "Sign In";
            }
        }
コード例 #2
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            MyContact myContactItem = this.GetItem(position);

            View row = convertView;

            if (row == null)
            {
                row = LayoutInflater.FromContext(this.Context).Inflate(Resource.Layout.ContactListItem, parent, false);
            }

            var contactNameElement = row.FindViewById <TextView>(Resource.Id.ContactName);

            contactNameElement.Text = myContactItem.Name;

            var contactEmailElement = row.FindViewById <TextView>(Resource.Id.ContactEmail);

            contactEmailElement.Text = myContactItem.Email;

            Task.Run(async() =>
            {
                Bitmap bitmap = null;

                var contactPictureElement = row.FindViewById <ImageView>(Resource.Id.ContactPicture);

                byte[] bytesContactPicture = await Office365Service.GetContactPicture(myContactItem.Id);

                if (bytesContactPicture.Length > 0)
                {
                    bitmap = await BitmapFactory.DecodeByteArrayAsync(bytesContactPicture, 0, bytesContactPicture.Length);

                    SetBitmapSafe(bitmap, contactPictureElement);
                }
                else
                {
                    var galUser = await Office365Service.GetUser(myContactItem.Email);

                    try
                    {
                        if (galUser != null)
                        {
                            using (var stream = (await galUser.ThumbnailPhoto.DownloadAsync()).Stream)
                            {
                                bitmap = await BitmapFactory.DecodeStreamAsync(stream);

                                SetBitmapSafe(bitmap, contactPictureElement);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            });

            return(row);
        }