public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add);
            NavigationItem.RightBarButtonItem.Clicked += delegate { UploadPicture(); };

            _uploader = new PhotoUploader();
            _listener = new PhotoListener();

            _listener.NewPhotosReceived += (sender, urls) =>
            {
                InvokeOnMainThread(() =>
                {
                    foreach (var url in urls)
                    {
                        _imageSection.Add(
                            new ImageStringElement(DateTime.Now.ToString(), 
                                                   UIImage.LoadFromData(NSData.FromUrl(new NSUrl(url))))
                        );
                    }
                });
            };

            _listener.StartListening();
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.Main);
            Button button = FindViewById<Button> (Resource.Id.myButton);
            imageView = FindViewById<SmartImageView> (Resource.Id.image);
            imageView.SetImageUrl ("http://cdn1.xamarin.com/webimages/images/index/icon-cross-platform.png");

            _uploader = new PhotoUploader ();
            _listener = new PhotoListener ();

            _listener.NewPhotosReceived += (sender, urls) =>
            {
                RunOnUiThread(() =>
                              {
                    foreach (var url in urls)
                    {
                        imageView.SetImageUrl(url);
                        var toast = Toast.MakeText(BaseContext,"New Image: "+url.ToString(),ToastLength.Long);
                        toast.Show();
                    }
                });
            };

            _listener.StartListening ();

            button.Click += delegate {
                UploadPicture();
            };
        }
Exemplo n.º 3
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.myButton);

            button.Click += delegate
            {
                var imageIntent = new Intent();
                imageIntent.SetType("image/*");
                imageIntent.SetAction(Intent.ActionGetContent);
                StartActivityForResult(
                    Intent.CreateChooser(imageIntent, "Select photo"), 0);
            };


            _uploader = new PhotoUploader();
            _listener = new PhotoListener();

            _listener.NewPhotosReceived += (sender, urls) =>
            {
                ThreadPool.QueueUserWorkItem(o =>
                {
                    foreach (var url in urls)
                    {
                        /*// Replace this iOS code
                        _imageSection.Add(
                            new ImageStringElement(DateTime.Now.ToString(),
                                                   UIImage.LoadFromData(NSData.FromUrl(new NSUrl(url))))
                        );

                        // With this, but tailored to load from URL and replace ImageView with http://android-er.blogspot.com/2010/06/listview-with-icon.html
                        _imageSection =
                            FindViewById<ImageView>(Resource.Id.myImageView);
                        _imageSection.SetImageURI(data.Data);
                        */

                    }
                });
            };

            await _listener.StartListening();
        }
Exemplo n.º 4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

            button.Click += async (sender, args) =>
            {
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    Toast.MakeText(this, "No camera available :(.", ToastLength.Short);
                    return;
                }

                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "RealTimeGallery",
                    Name = $"{DateTime.Now.ToString("yyyyMMdd-HHmmss")}.jpg"
                });

                if (file == null)
                    return;

                using (var memoryStream = new MemoryStream())
                using (var fileStream = file.GetStream())
                {
                    try
                    {
                        await fileStream.CopyToAsync(memoryStream);

                        var photoUploader = new PhotoUploader();
                        await photoUploader.UploadPhoto(memoryStream.GetBuffer(), ".jpg");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Toast.MakeText(this, "Something went wrong while uploading picture.", ToastLength.Long);
                    }
                }

                Toast.MakeText(this, "Picture uploaded.", ToastLength.Short);
            };
        }