Beispiel #1
0
        public static UIImage BuildCroppedGalleryBackground(float left, float width, int index, bool landscape)
        {
            var key = "gallery_background_" + left + "_" + landscape + "_" + width;            // + "_" + index;

            return(ImageCache.Get(key, () =>
            {
                var image0 = ImageFactory.BuildGalleryBackground(landscape);
                var image1 = ImageHelper.Crop(image0, new RectangleF(left, 0, width, landscape ? image0.Size.Width : image0.Size.Height));
                image0.Dispose();
                return image1;
            }));
        }
Beispiel #2
0
        private void SetFlipPieceThumbnail()
        {
            var z = ImageCache.Get("flip_thumbnail_" + _series.Title + "_" + _page, () =>
            {
                var thumb0 = ImageFactory.LoadRoundedThumbnail(_series.Pieces[_page]);
                var thumb1 = ImageHelper.ImageToFitSize(thumb0, _listViewImageSize);
                thumb0.Dispose();
                return(thumb1);
            });

            _buttonGalleryThumb.Image.Dispose();
            _buttonGalleryThumb.Image = null;
            _buttonGalleryThumb.Image = z;
        }
Beispiel #3
0
 public override void ReceiveMemoryWarning(UIApplication application)
 {
     ImageCache.Clear();
 }
Beispiel #4
0
        public static GalleryImageView BuildGalleryPage(Piece piece, int index, int total, out RectangleF canvasFrame)
        {
            float width;
            float height;
            float gutter;

            GetGalleryArea(out width, out height, out gutter);

            // Background width is 1280
            var     backgroundImage = BuildGalleryBackground(Util.IsLandscape());
            UIImage background      = GetSeamlessBackgroundSlice(index, backgroundImage);
            var     imageView       = new GalleryImageView(background);   // UIImageView

            background.Dispose();
            backgroundImage.Dispose();

            // Add canvas
            UIImage canvas     = ImageCache.Get(GetImageKey(piece, width * 2, height * 2), () => GenerateGalleryPiece(piece, width * 2, height * 2));
            var     canvasView = new UIImageView(canvas);

            canvasView.Center = new PointF(width / 2, (height / 2) - gutter);
            canvasView.Layer.MasksToBounds = false;
            var canvasViewFrame = canvasView.Frame;

            canvasFrame = canvasViewFrame;

            // Add reflection
            float reflectionY = GetReflectionY();
            var   reflection  = GetOrGenerateReflection(piece, canvasViewFrame, canvas, reflectionY);

            canvas.Dispose();

            var reflectionFrame = new RectangleF(canvasViewFrame.X, reflectionY, reflection.Size.Width, reflection.Size.Height);
            var reflectionView  = new UIImageView(reflection);

            reflectionView.Frame         = reflectionFrame;
            reflectionView.Layer.Opacity = 0.30f;
            reflection.Dispose();

            // Add shadow
            var shadowY    = canvasViewFrame.Y + canvasViewFrame.Height - 10;
            var shadowView = new UIImageView(_shadowMask);

            shadowView.Frame = new RectangleF(canvasViewFrame.X, shadowY, canvasViewFrame.Width, _shadowMask.Size.Height);
            var shadowLeftView = new UIImageView(_shadowLeft);

            shadowLeftView.Frame = new RectangleF(canvasViewFrame.X - 3, canvasViewFrame.Y, 3, canvasViewFrame.Height);
            var shadowRightView = new UIImageView(_shadowRight);

            shadowRightView.Frame = new RectangleF(canvasViewFrame.X + canvasViewFrame.Width, canvasViewFrame.Y, 3, canvasViewFrame.Height);
            var shadowTopView = new UIImageView(_shadowTop);

            shadowTopView.Frame = new RectangleF(canvasViewFrame.X, canvasViewFrame.Y, canvasViewFrame.Width, _shadowTop.Size.Height);

            // Add image layers together
            imageView.AddSubview(shadowView);
            imageView.AddSubview(shadowLeftView);
            imageView.AddSubview(shadowRightView);
            imageView.AddSubview(canvasView);
            imageView.AddSubview(shadowTopView);
            imageView.AddSubview(reflectionView);

            var lighting     = BuildLighting();
            var lightingView = new LightImageView(lighting);

            lighting.Dispose();
            imageView.AddSubview(lightingView);
            imageView.Lights = lightingView;
            return(imageView);
        }
Beispiel #5
0
        public static UIImage LoadRoundedThumbnail(Piece piece)
        {
            var s = DimensionSet.ListThumbnailSquare;

            return(ImageCache.Get(GetImageKey(piece, s, s), () => GeneratePieceThumbnail(piece, s, s)));
        }
Beispiel #6
0
 public static UIImage LoadMapThumbnail(Piece piece)
 {
     return(ImageCache.Get(GetImageKey(piece, 27, 28), () => GeneratePieceThumbnail(piece, 27, 28)));
 }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            // http://stackoverflow.com/questions/7436870/resizing-monotouch-dialog-styledmultilineelement-after-an-async-call
            // NameResolutionFailure on device...
            Util.PushNetworkActive();

            if (_bio.UpdateImage)
            {
                _view.ShowActivity();
            }

            if (!_fetching)
            {
                _fetching = true;
                ThreadPool.QueueUserWorkItem(s =>
                {
                    try
                    {
                        var client = new WebClient();
                        var json   = client.DownloadString(string.Format("https://api.twitter.com/users/show/{0}.json?include_entities=1", _bio.Twitter));
                        var user   = JsonParser.FromJson(json);
                        client.Dispose();

                        // http://a2.twimg.com/profile_images/1558350756/image.jpg
                        // http://a2.twimg.com/profile_images/1558350756/image_normal.jpg
                        //var url = user["profile_image_url"].ToString().Replace("_normal", "_reasonably_small"); // Gets the 128px version
                        var url = user["profile_image_url"].ToString().Replace("_normal", "");                         // Gets the full version

                        // Sometimes Twitter does not return the inline status (this is obviously a bug)
                        string tweet;
                        if (!user.ContainsKey("status"))
                        {
                            tweet = "...";
                        }
                        else
                        {
                            tweet = ((IDictionary <string, object>)user["status"])["text"].ToString();
                        }

                        UIImage image = null;

                        // Update twitter image on disk
                        if (_bio.UpdateImage)
                        {
                            NSUrl imageUrl   = NSUrl.FromString(url);
                            NSData imageData = NSData.FromUrl(imageUrl);

                            image = UIImage.LoadFromData(imageData);
                            image = ImageHelper.RoundAndSquare(image, 14);

                            ImageCache.StoreAs("latest_twitter", image);
                            imageData.Dispose();
                        }
                        else
                        {
                            image = _view.GetDefaultBioImage();
                        }

                        InvokeOnMainThread(() =>
                        {
                            Util.PopNetworkActive();
                            _bio.Image = image;
                            _main.Remove(_tweetBox);
                            CreateTweetView(tweet);
                            _main.Add(_tweetBox);
                            _view.AddOrUpdateBio(_bio);

                            image.Dispose();
                            this.View.SetNeedsDisplay();
                        });
                    }
                    catch
                    {
                    }
                    finally
                    {
                        InvokeOnMainThread(() =>
                        {
                            _view.HideActivity();
                            _fetching = false;
                        });
                    }
                });
            }
        }