DownloadImage() public static method

public static DownloadImage ( string imageUrl ) : Task
imageUrl string
return Task
Beispiel #1
0
        private async void Prueba(string url)
        {
            var downloadedImage = await ImageService.DownloadImage(url);

            Stream stream = new MemoryStream(downloadedImage);

            Myfoto.Source = ImageSource.FromStream(() => new MemoryStream(downloadedImage));

            // DependencyService.Get<IFileService>().SavePicture((Preferences.Get("UserID", 0)).ToString() + ".jpg", stream);
        }
Beispiel #2
0
        // GET: SongsInfo
        public async Task <ActionResult> Index()
        {
            var songsInfo = new SongsInfo();
            var table     = TableStorageService.ConnectToTable(Constants.CurrentSongTableName);
            var queryCS   = await table.ExecuteQuerySegmentedAsync(new TableQuery <AzureTableSong>(), null);

            songsInfo.CurrentSong = queryCS.Results.FirstOrDefault();

            var bytes = await ImageService.DownloadImage(songsInfo.CurrentSong.OriginalGame);

            if (bytes == null)
            {
                bytes = await ImageService.DownloadImage(Constants.DefaultBlobImage);
            }

            songsInfo.GamePicture = bytes;

            var songs = await TableStorageService.RetrieveAllEntities <AzureTableSong>(Constants.QueueTableName);

            songsInfo.SongsQueue = songs.OrderBy(x => x.Position);
            return(View(songsInfo));
        }
Beispiel #3
0
        public void LoginFacebook()
        {
            var activity = this as Activity;

            var auth = new OAuth2Authenticator(
                clientId: "159718315402370",
                scope: "",
                authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth"),
                redirectUrl: new Uri("http://www.facebook/com/connect/login_sucess.html"));

            auth.Completed += async(sender, eventArgs) =>
            {
                if (eventArgs.IsAuthenticated)
                {
                    var accessToken = eventArgs.Account.Properties["access_token"].ToString();
                    var expiresIn   = Convert.ToDouble(eventArgs.Account.Properties["expires_in"]);
                    var expiryDate  = DateTime.Now + TimeSpan.FromSeconds(expiresIn);

                    var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=name,picture"), null, eventArgs.Account);
                    ///https://graph.facebook.com/me?fields=email,first_name,last_name,gender,picture
                    var response = await request.GetResponseAsync();

                    var obj = JObject.Parse(response.GetResponseText());

                    Intent intent = new Intent(this, typeof(Perfil));
                    intent.PutExtra("ID", obj["id"].ToString());
                    intent.PutExtra("Nome", obj["name"].ToString());
                    ImageService.SaveToDisk("imagemFacebook", await ImageService.DownloadImage("https://graph.facebook.com/" + obj["id"].ToString() + "/picture?type=large"));
                    StartActivity(intent);
                }
                else
                {
                    Console.WriteLine("Usuário cancelou");
                }
            };

            activity.StartActivity(auth.GetUI(activity));
        }
        public async Task <bool> Init(Label[] counters, BoxView[] bars, Grid barChart)
        {
            try
            {
                // Icon
                var currentIconPath = await AccountService.GetSummonerIcon();

                string fileName = currentIconPath.Substring(currentIconPath.LastIndexOf('/') + 1);
                Xamarin.Forms.ImageSource cachedIcon = ImageService.GetFromDisk(fileName);

                if (cachedIcon != null)
                {
                    SummonerIcon = cachedIcon;
                }
                else
                {
                    var downloadedIcon = await ImageService.DownloadImage(currentIconPath);

                    ImageService.SaveToDisk(fileName, downloadedIcon);
                    SummonerIcon = ImageService.GetFromDisk(fileName);
                }

                MatchList = await MatchService.GetTotalMatches(10, "SOLODUO");

                TotalGamesPlayed = MatchList.totalGames;

                InitGraph(counters, bars, barChart);

                return(true);
            }
            catch (Exception e)
            {
                // TBD
                return(false);
            }
        }
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var item = this[position];

            var view = convertView ?? _activity.LayoutInflater.Inflate(Resource.Layout.MessagingListRowLayout, null);

            // if message another user ?
            var rightAlignment = (item.User.Equals(_userName));

            // Layout parameters for complete message widget
            var wholeMessageLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

            // Layout parameters for name text
            var userNameLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

            // Layout parameters for timestamp text
            var userTimestampLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

            // Layouts
            var mainLayout         = view.FindViewById <LinearLayout>(Resource.Id.MessagingListRow_MainLayout);
            var bubbleTextLayout   = view.FindViewById <LinearLayout>(Resource.Id.MessagingListRow_BubbleTextLayout);
            var bubbleImageLayout  = view.FindViewById <RelativeLayout>(Resource.Id.MessagingListRow_BubbleImageLayout);
            var wholeMessageLayout = view.FindViewById <LinearLayout>(Resource.Id.MessagingListRow_WholeMessageLayout);
            var messageImageView   = view.FindViewById <ImageView>(Resource.Id.MessagingListRow_MessageImage);

            if (rightAlignment)
            {
                wholeMessageLayoutParams.Gravity = GravityFlags.Right;
                mainLayout.SetPadding(DpToPx(40), 0, DpToPx(10), 0);
                bubbleTextLayout.SetBackgroundResource(Resource.Drawable.chat_bubble_right);
                userNameLayoutParams.Gravity      = GravityFlags.Right;
                userTimestampLayoutParams.Gravity = GravityFlags.Right;
            }
            else
            {
                wholeMessageLayoutParams.Gravity = GravityFlags.Left;
                mainLayout.SetPadding(DpToPx(10), 0, DpToPx(40), 0);
                bubbleTextLayout.SetBackgroundResource(Resource.Drawable.chat_bubble_left);
                userNameLayoutParams.Gravity      = GravityFlags.Left;
                userTimestampLayoutParams.Gravity = GravityFlags.Left;
            }

            wholeMessageLayout.LayoutParameters = wholeMessageLayoutParams;
            bubbleImageLayout.LayoutParameters  = wholeMessageLayoutParams;

            // Message timestamp
            var messageTimeStamp = view.FindViewById <TextView>(Resource.Id.MessagingListRow_MessageTimeStampText);

            messageTimeStamp.Text = item.Created;
            messageTimeStamp.SetTextColor(_activity.Resources.GetColor((rightAlignment) ? Resource.Color.messagelistrow_bubble_datetime_right : Resource.Color.messagelistrow_bubble_datetime_left));
            messageTimeStamp.LayoutParameters = userTimestampLayoutParams;

            // Message user name
            var userName = view.FindViewById <TextView>(Resource.Id.MessagingListRow_UserName);

            userName.Text             = item.User;
            userName.LayoutParameters = userNameLayoutParams;
            if (rightAlignment)
            {
                userName.SetPadding(0, 0, DpToPx(5), DpToPx(2));
            }
            else
            {
                userName.SetPadding(DpToPx(6), 0, 0, DpToPx(2));
            }

            // Message text
            var messageText = view.FindViewById <TextView>(Resource.Id.MessagingListRow_MessageText);

            messageText.Text = item.Message;
            messageText.SetTextColor(_activity.Resources.GetColor((rightAlignment) ? Resource.Color.messagelistrow_bubble_text_right : Resource.Color.messagelistrow_bubble_text_left));

            // show or hide text/image
            if (string.IsNullOrEmpty(item.AttachmentUrl))
            {
                bubbleTextLayout.Visibility  = ViewStates.Visible;
                bubbleImageLayout.Visibility = ViewStates.Gone;
            }
            else
            {
                // Layout parameters for timestamp text
                var imageTimestampLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
                imageTimestampLayoutParams.AddRule((rightAlignment) ? LayoutRules.AlignRight : LayoutRules.AlignLeft, messageImageView.Id);
                imageTimestampLayoutParams.AddRule(LayoutRules.CenterInParent);
                imageTimestampLayoutParams.AddRule(LayoutRules.AlignBottom, messageImageView.Id);

                var imageMessageTimeStamp = view.FindViewById <TextView>(Resource.Id.MessagingListRow_MessageTimeStampImage);
                imageMessageTimeStamp.LayoutParameters = imageTimestampLayoutParams;
                if (rightAlignment)
                {
                    imageMessageTimeStamp.SetPadding(0, 0, DpToPx(20), DpToPx(8));
                }
                else
                {
                    imageMessageTimeStamp.SetPadding(DpToPx(20), 0, 0, DpToPx(10));
                }

                bubbleTextLayout.Visibility  = ViewStates.Gone;
                bubbleImageLayout.Visibility = ViewStates.Visible;

                if (!string.IsNullOrEmpty(item.AttachmentUrl))
                {
                    // try load image from cache
                    var image = _imagesService.TryGetImage(item.AttachmentUrl, true);

                    if (image != null)
                    {
                        // generate and show message image
                        GenerateMessageImage(image, messageImageView, rightAlignment);

                        imageMessageTimeStamp.Text = item.Created;
                    }
                    else
                    {
                        // set 'downloading' icon
                        messageImageView.SetImageResource(Resource.Drawable.ic_missing_image);


                        // starts loading image in background
                        _imagesService.DownloadImage(item.AttachmentUrl, -1);       // additional data are not used now
                    }
                }
            }

            return(view);
        }