Exemple #1
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            var root = new RootElement("Xamarin.Social Sample");

            var section = new Section("Services");

            var facebookButton = new StringElement("Share with Facebook");

            facebookButton.Tapped += delegate { Share(Facebook, facebookButton); };
            section.Add(facebookButton);

            var twitterButton = new StringElement("Share with Twitter");

            twitterButton.Tapped += delegate { Share(Twitter, twitterButton); };
            section.Add(twitterButton);

            var twitter5Button = new StringElement("Share with built-in Twitter");

            twitter5Button.Tapped += delegate { Share(Twitter5, twitter5Button); };
            section.Add(twitter5Button);

            var flickr = new StringElement("Share with Flickr");

            flickr.Tapped += () => {
                var picker = new MediaPicker();                 // Set breakpoint here
                picker.PickPhotoAsync().ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    var item = new Item("I'm sharing great things using Xamarin!")
                    {
                        Images = new[] { new ImageData(t.Result.Path) }
                    };

                    Console.WriteLine("Picked image {0}", t.Result.Path);

                    UIViewController viewController = Flickr.GetShareUI(item, shareResult =>
                    {
                        dialog.DismissViewController(true, null);
                        flickr.GetActiveCell().TextLabel.Text = "Flickr shared: " + shareResult;
                    });

                    dialog.PresentViewController(viewController, true, null);
                }, TaskScheduler.FromCurrentSynchronizationContext());
            };
            section.Add(flickr);
            root.Add(section);

            dialog = new DialogViewController(root);

            window = new UIWindow(UIScreen.MainScreen.Bounds);
            window.RootViewController = new UINavigationController(dialog);
            window.MakeKeyAndVisible();

            return(true);
        }
Exemple #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            Button flickrButton = FindViewById <Button> (Resource.Id.Flickr);

            flickrButton.Click += (sender, args) =>
            {
                var picker = new MediaPicker(this);
                picker.PickPhotoAsync().ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    var item = new Item("I'm sharing great things using Xamarin!")
                    {
                        Images = new[] { new ImageData(t.Result.Path) }
                    };

                    Intent intent = Flickr.GetShareUI(this, item, shareResult => {
                        flickrButton.Text = "Flickr shared: " + shareResult;
                    });

                    StartActivity(intent);
                }, TaskScheduler.FromCurrentSynchronizationContext());
            };

            Button facebookButton = FindViewById <Button>(Resource.Id.Facebook);

            facebookButton.Click += (sender, args) => Share(Facebook, facebookButton);

            Button twitterButton = FindViewById <Button> (Resource.Id.Twitter);

            twitterButton.Click += (sender, args) => Share(Twitter, twitterButton);
        }