Exemplo n.º 1
0
        public ItemView(OpenFlowView container, RectangleF bounds) : base(bounds)
        {
            this.container = container;

            Opaque = true;
            //BackgroundColor = null;

            ImageView = new UIImageView(bounds)
            {
                Opaque = true
            };
            AddSubview(ImageView);
        }
Exemplo n.º 2
0
        public ItemView(OpenFlowView container, RectangleF bounds)
            : base(bounds)
        {
            this.container = container;

            Opaque = true;
            //BackgroundColor = null;

            ImageView = new UIImageView (bounds) {
                Opaque = true
            };
            AddSubview (ImageView);
        }
        void IOpenFlowDataSource.RequestImage(OpenFlowView view, int index)
        {
            NSAction task;

            if (flickr == null){
                task = delegate {
                    var img = UIImage.FromFile ("images/" + index + ".jpg");
                    InvokeOnMainThread (delegate {
                        flowView [index] = img;
                    });
                };
            } else {
                task = delegate {
                    Network = true;
                    var data = NSData.FromUrl (new NSUrl (photos [index].SmallUrl));
                    var image = UIImage.LoadFromData (data);
                    Network = false;

                    if (image != null){
                        InvokeOnMainThread (delegate {
                            image = PrepareFlickrPhoto (image, CalculateSizeForCroppingBox (image, 255, 255));

                            flowView [index] = image;
                        });
                    }
                };
            }
            lock (tasks){
                tasks.Enqueue (task);
            }
            signal.Set ();
        }
        void Initialize()
        {
            flowView = new OpenFlowView (UIScreen.MainScreen.Bounds, this);
            View = flowView;

            using (var alertView = new UIAlertView ("OpenFlowSharp Demo Data Source",
                "Would you like to download images from Flickr or use 30 sample images included with this project?",
                null, "Flickr",
                "Samples (all at once)",
                "Samples (using threads)")){
                alertView.Dismissed += delegate(object sender, UIButtonEventArgs e) {
                    switch (e.ButtonIndex){
                    // Flickr
                    case 0:
                        flickr = new Flickr (apiKey, sharedSecret);
                        tasks.Enqueue (delegate {
                            try {
                                Network = true;
                                photos = flickr.InterestingnessGetList ();
                                Network = false;
                                InvokeOnMainThread (delegate {
                                    flowView.NumberOfImages = photos.Count;
                                });
                            } catch {
                                InvokeOnMainThread (delegate {
                                    using (var alert = new UIAlertView ("Error", "While accessing Flickr", null, "Ok")){
                                        alert.Show ();
                                    }
                                });
                            }
                        });
                        break;

                        // Load images on demand on a worker thread
                    case 2:
                        flowView.NumberOfImages = 30;
                        break;

                        // Sync case, load all images at startup
                    case 1:
                        LoadAllImages ();
                        return;
                    }

                    // Start our thread queue system
                    new Thread (Worker).Start ();
                    signal.Set ();
                };
                alertView.Show ();
            }
        }