Exemplo n.º 1
0
        /// <summary>
        /// Resolves the image from the given uri. Also handles
        /// caching and resizing... It's a magic function.
        /// </summary>
        /// <param name="url">The URL to the image</param>
        /// <returns>A resized, nice bitmap</returns>
        private AsyncImageLoader ResolveImage(string url)
        {
            if (_cache.ContainsKey(url))
            {
                return(_cache[url]);
            }

            // Resize and assign the bitmap
            using (var client = new HttpClient(new NativeMessageHandler()))
            {
                var loader = new AsyncImageLoader(url);
                loader.Completed = (a) =>
                {
                    var rect = CalculateLargestRect(a.Bitmap);
                    loader.Bitmap = ResizeBitmap(a.Bitmap, rect.Width(), rect.Height());
                    Device.BeginInvokeOnMainThread(() => Invalidate());
                };

                lock (_cache)
                {
                    if (!_cache.ContainsKey(url))
                    {
                        _cache.Add(url, loader);
                    }
                }

                return(loader);
            }
        }
Exemplo n.º 2
0
        public void AsyncImageLoaderAssign()
        {
            tlog.Debug(tag, $"AsyncImageLoaderAssign START");

            using (AsyncImageLoader loader = new AsyncImageLoader())
            {
                var testingTarget = new AsyncImageLoader(loader);
                Assert.IsNotNull(testingTarget, "Can't create success object AsyncImageLoader");
                Assert.IsInstanceOf <AsyncImageLoader>(testingTarget, "Should be an instance of AsyncImageLoader type.");

                try
                {
                    testingTarget.Assign(loader);
                }
                catch (Exception e)
                {
                    tlog.Debug(tag, e.Message.ToString());
                    Assert.Fail("Caught Exception: Failed!");
                }

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"AsyncImageLoaderAssign END (OK)");
        }
Exemplo n.º 3
0
 public AsyncImageLoader(AsyncImageLoader handle) : this(NDalicPINVOKE.new_AsyncImageLoader__SWIG_1(AsyncImageLoader.getCPtr(handle)), true)
 {
     if (NDalicPINVOKE.SWIGPendingException.Pending)
     {
         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Exemplo n.º 4
0
 public AsyncImageLoader(AsyncImageLoader handle) : this(Interop.AsyncImageLoader.NewAsyncImageLoader(AsyncImageLoader.getCPtr(handle)), true)
 {
     if (NDalicPINVOKE.SWIGPendingException.Pending)
     {
         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Exemplo n.º 5
0
        private void EnsureAllBackdropsAreLoaded()
        {
            if (backdropImages == null)
            {
                backdropImages = new List <AsyncImageLoader>();

                // we need to do this on the thread pool ...
                Async.Queue(() =>
                {
                    foreach (var image in baseItem.BackdropImages)
                    {
                        // this is really subtle, we need to capture the image otherwise they will all be the same
                        var captureImage  = image;
                        var backdropImage = new AsyncImageLoader(
                            () => captureImage,
                            null,
                            () => this.FirePropertiesChanged("BackdropImages", "BackdropImage"));

                        lock (backdropImages)
                        {
                            backdropImages.Add(backdropImage);
                            // trigger a load
                            var ignore = backdropImage.Image;
                        }
                    }
                });
            }
        }
Exemplo n.º 6
0
 private void getFirstBackdropImage()
 {
     backdropImage = new AsyncImageLoader(
         () => baseItem.PrimaryBackdropImage,
         null,
         () => this.FirePropertiesChanged("BackdropImage"));
     backdropImage.LowPriority = true;
 }
Exemplo n.º 7
0
        private void InitializeImages()
        {
            if (this.Element.Source == null)
            {
                return;
            }

            if (!this.Element.Source.Any())
            {
                // TODO Add a placeholder bitmap for empty ones?
                _leftBitmap   = null;
                _rightBitmap  = null;
                _centerBitmap = null;

                _currentImageUrl = null;
                return;
            }

            if (_currentImageUrl == null)
            {
                _currentImageUrl = this.Element.Source.First();
            }

            var index = this.Element.Source.IndexOf(_currentImageUrl);

            if (index > 0)
            {
                _leftBitmap = ResolveImage(this.Element.Source[index - 1]);
            }
            else
            {
                _leftBitmap = null;
            }

            if (index < this.Element.Source.Count() - 1)
            {
                _rightBitmap = ResolveImage(this.Element.Source[index + 1]);
            }
            else
            {
                _rightBitmap = null;
            }

            _centerBitmap = ResolveImage(_currentImageUrl);
            Invalidate();

            this.Element.SelectedIndex = index;
            this.Element.SelectedUrl   = _currentImageUrl;

            if (index > (this.Element.Source.Count - 1) - this.Element.NearEndThreshold && this.Element.IsNearEnd != null)
            {
                if (this.Element.IsNearEnd.CanExecute(null))
                {
                    this.Element.IsNearEnd.Execute(null);
                }
            }
        }
Exemplo n.º 8
0
        public AsyncImageLoader Assign(AsyncImageLoader handle)
        {
            AsyncImageLoader ret = new AsyncImageLoader(Interop.AsyncImageLoader.Assign(SwigCPtr, AsyncImageLoader.getCPtr(handle)), false);

            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 9
0
        public static AsyncImageLoader DownCast(BaseHandle handle)
        {
            AsyncImageLoader ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as AsyncImageLoader;

            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 10
0
 private void EnsureArtImageIsSet()
 {
     if (artImage == null)
     {
         artImage = new AsyncImageLoader(
             () => baseItem.ArtImage,
             DefaultImage,
             ArtImageChanged);
         var ignore = artImage.Image;
     }
 }
Exemplo n.º 11
0
 private void EnsureSecondaryImageIsSet()
 {
     if (secondaryImage == null)
     {
         secondaryImage = new AsyncImageLoader(
             () => baseItem.SecondaryImage,
             DefaultImage,
             SecondaryImageChanged);
         var ignore = secondaryImage.Image;
     }
 }
Exemplo n.º 12
0
 private void EnsureThumbnailImageIsSet()
 {
     if (thumbnailImage == null)
     {
         thumbnailImage = new AsyncImageLoader(
             () => baseItem.ThumbnailImage,
             DefaultImage,
             ThumbnailImageChanged);
         var ignore = thumbnailImage.Image;
     }
 }
Exemplo n.º 13
0
 private void EnsureDiscImageIsSet()
 {
     if (discImage == null)
     {
         discImage = new AsyncImageLoader(
             () => baseItem.DiscImage,
             DefaultImage,
             DiscImageChanged);
         var ignore = discImage.Image;
     }
 }
Exemplo n.º 14
0
 private void EnsureLogoImageIsSet()
 {
     if (logoImage == null)
     {
         logoImage = new AsyncImageLoader(
             () => baseItem.LogoImage,
             DefaultImage,
             LogoImageChanged);
         var ignore = logoImage.Image;
     }
 }
Exemplo n.º 15
0
 private void EnsurePrimaryImageIsSet()
 {
     if (primaryImage == null)
     {
         primaryImage = new AsyncImageLoader(
             () => baseItem.PrimaryImage,
             DefaultImage,
             PrimaryImageChanged);
         var ignore = primaryImage.Image;
     }
 }
Exemplo n.º 16
0
    public void FillUserProfile(User userData)
    {
        if (!gameObject.activeSelf)
        {
            return;
        }

        _usernameText.text = userData.username;

        AsyncImageLoader.RequestImage(userData.pictureUrl, _profileImage);
        AsyncImageLoader.RequestImage(userData.clubPictureUrl, _clubImage);
    }
Exemplo n.º 17
0
        public void AsyncImageLoaderConstructor()
        {
            tlog.Debug(tag, $"AsyncImageLoaderConstructor START");

            var testingTarget = new AsyncImageLoader();

            Assert.IsNotNull(testingTarget, "Can't create success object AsyncImageLoader");
            Assert.IsInstanceOf <AsyncImageLoader>(testingTarget, "Should be an instance of AsyncImageLoader type.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"AsyncImageLoaderConstructor END (OK)");
        }
Exemplo n.º 18
0
    public void FillUserProfile(User userData, bool allowEdit)
    {
        if (!gameObject.activeSelf)
        {
            return;
        }

        _usernameInputField.text = userData.username;

        AsyncImageLoader.RequestImage(userData.pictureUrl, _profileImage);
        AsyncImageLoader.RequestImage(userData.clubPictureUrl, _clubImage);

        _changeUsernameButton.gameObject.SetActive(allowEdit);
    }
Exemplo n.º 19
0
    public void Initialize(int index, object data)
    {
        _index = index;

        var cardData = (CardItemData)data;

        _cardId        = cardData.UserId;
        _nameText.text = cardData.Name;
        AsyncImageLoader.RequestImage(cardData.AvatarUrl, _avatarImage);
        AsyncImageLoader.RequestImage(cardData.ClubLogoUrl, _clubImage);

        OnSelected    = new Action <string>(cardData.OnSelected);
        OnLongPressed = new Action <int, string>(cardData.OnLongPressed);
    }
Exemplo n.º 20
0
        private void LoadSmallPrimaryImage()
        {
            float aspect           = primaryImage.Size.Height / (float)primaryImage.Size.Width;
            float constraintAspect = aspect;

            if (preferredImageSmallSize.Height > 0 && preferredImageSmallSize.Width > 0)
            {
                constraintAspect = preferredImageSmallSize.Height / (float)preferredImageSmallSize.Width;
            }

            primaryImageSmall = new AsyncImageLoader(
                () => baseItem.PrimaryImage,
                DefaultImage,
                PrimaryImageChanged);

            if (aspect == constraintAspect)
            {
                smallImageIsDistorted = false;
            }
            else
            {
                smallImageIsDistorted = Math.Abs(aspect - constraintAspect) < Config.Instance.MaximumAspectRatioDistortion;
            }

            if (smallImageIsDistorted)
            {
                primaryImageSmall.Size = preferredImageSmallSize;
            }
            else
            {
                int width  = preferredImageSmallSize.Width;
                int height = preferredImageSmallSize.Height;

                if (aspect > constraintAspect || width <= 0)
                {
                    width = (int)((float)height / aspect);
                }
                else
                {
                    height = (int)((float)width * aspect);
                }

                primaryImageSmall.Size = new Size(width, height);
            }

            FirePropertyChanged("SmallImageIsDistorted");
        }
Exemplo n.º 21
0
        public void AsyncImageLoaderLoadWithDimensions()
        {
            tlog.Debug(tag, $"AsyncImageLoaderLoadWithDimensions START");

            using (AsyncImageLoader loader = new AsyncImageLoader())
            {
                try
                {
                    loader.Load(url, new Uint16Pair(100, 80));
                }
                catch (Exception e)
                {
                    tlog.Debug(tag, e.Message.ToString());
                    Assert.Fail("Caught Exception: Failed!");
                }
            }

            tlog.Debug(tag, $"AsyncImageLoaderLoadWithDimensions END (OK)");
        }
Exemplo n.º 22
0
        public void AsyncImageLoaderDownCast()
        {
            tlog.Debug(tag, $"AsyncImageLoaderDownCast START");

            using (AsyncImageLoader loader = new AsyncImageLoader())
            {
                try
                {
                    AsyncImageLoader.DownCast(loader);
                }
                catch (Exception e)
                {
                    tlog.Debug(tag, e.Message.ToString());
                    Assert.Fail("Caught Exception: Failed!");
                }
            }

            tlog.Debug(tag, $"AsyncImageLoaderDownCast END (OK)");
        }
Exemplo n.º 23
0
        public void AsyncImageLoaderLoadWithFittingMode()
        {
            tlog.Debug(tag, $"AsyncImageLoaderLoadWithFittingMode START");

            using (AsyncImageLoader loader = new AsyncImageLoader())
            {
                try
                {
                    loader.Load(url, new Uint16Pair(100, 80), FittingModeType.Center, SamplingModeType.Linear, false);
                }
                catch (Exception e)
                {
                    tlog.Debug(tag, e.Message.ToString());
                    Assert.Fail("Caught Exception: Failed!");
                }
            }

            tlog.Debug(tag, $"AsyncImageLoaderLoadWithFittingMode END (OK)");
        }
Exemplo n.º 24
0
        public void AsyncImageLoaderImageLoadedSignal()
        {
            tlog.Debug(tag, $"AsyncImageLoaderImageLoadedSignal START");

            using (AsyncImageLoader loader = new AsyncImageLoader())
            {
                try
                {
                    loader.ImageLoadedSignal();
                }
                catch (Exception e)
                {
                    tlog.Debug(tag, e.Message.ToString());
                    Assert.Fail("Caught Exception: Failed!");
                }
            }

            tlog.Debug(tag, $"AsyncImageLoaderImageLoadedSignal END (OK)");
        }
Exemplo n.º 25
0
 private void getRandomBackdropImage()
 {
     if (Config.Instance.RotateBackdrops && baseItem.BackdropImages.Count > 1)
     {
         //start the rotation so we don't get the first one twice
         GetNextBackDropImage();
     }
     else
     {
         //just a single one required
         if (baseItem.BackdropImages.Count > 0)
         {
             backdropImageIndex = randomizer.Next(baseItem.BackdropImages.Count);
             backdropImage      = new AsyncImageLoader(
                 () => baseItem.BackdropImages[backdropImageIndex],
                 null,
                 () => this.FirePropertyChanged("BackdropImage"));
             backdropImage.LowPriority = true;
         }
     }
 }
Exemplo n.º 26
0
        public void GetNextBackDropImage()
        {
            backdropImageIndex++;
            EnsureAllBackdropsAreLoaded();
            var images = new List <AsyncImageLoader>();

            lock (backdropImages)
            {
                images.AddRange(backdropImages);
            }

            if (images != null && images.Count > 0)
            {
                backdropImageIndex = backdropImageIndex % images.Count;
                if (images[backdropImageIndex].Image != null)
                {
                    backdropImage = images[backdropImageIndex];
                    FirePropertyChanged("BackdropImage");
                }
            }
        }
Exemplo n.º 27
0
        public void GetNextBackDropImage()
        {
            if (!Config.Instance.RotateBackdrops)
            {
                return;                                   // only do this if we want to rotate
            }
            EnsureAllBackdropsAreLoaded();
            var images = new List <AsyncImageLoader>();

            lock (backdropImages)
            {
                images.AddRange(backdropImages);
            }

            if (images != null && images.Count > 1)
            {
                if (Config.Instance.RandomizeBackdrops)
                {
                    int lastOne = backdropImageIndex;
                    while (backdropImageIndex == lastOne)
                    {
                        backdropImageIndex = randomizer.Next(images.Count);
                    }
                }
                else
                {
                    backdropImageIndex++;
                    backdropImageIndex = backdropImageIndex % images.Count;
                }
                if (images[backdropImageIndex].Image != null)
                {
                    backdropImage = images[backdropImageIndex];
                    FirePropertyChanged("BackdropImage");
                }
            }
        }
Exemplo n.º 28
0
    protected void loadRoom(MatrixRoom room)
    {
        this.currentRoom = room;

        foreach (var widget in chatBox.Children)
        {
            chatBox.Remove(widget);
        }

        foreach (var message in room.Messages)
        {
            Widget messageContents = null;
            if (message.msgtype == "m.text")
            {
                messageContents = new Label(message.body);
                ((Label)messageContents).Justify = Justification.Left;
            }
            if (message.msgtype == "m.image")
            {
                messageContents = new VBox();
                var imageLabel = new Label(message.body);
                imageLabel.Justify = Justification.Left;

                var loader        = new AsyncImageLoader((MMessageImage)message, this.client);
                var imageContents = loader.GetImageWidget(250, 200);

                ((VBox)messageContents).PackStart(imageLabel);
                ((VBox)messageContents).PackStart(imageContents);
            }
            if (messageContents != null)
            {
                var    messageContainer = new HBox();
                string senderName;

                senderName = this.users [message.sender].displayname;
                if (senderName == null)
                {
                    senderName = message.sender;
                }

                var alignmentBox = new Gtk.Alignment(0, -1, 0, 0);
                if (this.avatars.ContainsKey(message.sender))
                {
                    var senderIcon = new System.Drawing.Bitmap(this.avatars [message.sender]);
                    alignmentBox.Add(new Gtk.Image(Utils.bitmapToPixbuf(senderIcon)));
                }
                else
                {
                    var senderIcon = AvatarGenerator.createRoomAvatar(senderName);
                    alignmentBox.Add(new Gtk.Image(senderIcon));
                }
                messageContainer.PackStart(alignmentBox, false, false, 6);

                messageContainer.PackStart(messageContents, false, false, 6);
                chatBox.PackStart(messageContainer, false, false, 0);
            }

            Console.WriteLine(message.msgtype);
        }
        chatBox.ShowAll();
    }
Exemplo n.º 29
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AsyncImageLoader obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }