Пример #1
0
        public void LoginToSymplifiedToken()
        {
            SymplifiedAuthenticator authenticator = new SymplifiedAuthenticator(
                new Uri("https://idp.symplified.net"),
                new Uri("https://idp.symplified.net/portal/mobile/applications.html")
                );

            authenticator.Completed += (s, e) =>
            {
                loginViewController.DismissViewController(true, null);

                if (!e.IsAuthenticated)
                {
                    tokenLoginStatusStringElement.Caption = "Not authorized";
                }
                else
                {
                    tokenLoginStatusStringElement.Caption = "Authorized";
                    tokenLoginStatusStringElement.GetActiveCell().BackgroundColor = UIColor.Green;
                }

                loginViewController.ReloadData();
            };

            vc = authenticator.GetUI();
            loginViewController.PresentViewController(vc, true, null);
        }
Пример #2
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);
        }
Пример #3
0
        private void Share(Service service, StringElement button)
        {
            Item item = new Item {
                Text  = "I'm sharing great things using Xamarin!",
                Links = new List <Uri> {
                    new Uri("http://xamarin.com"),
                },
            };

            UIViewController vc = service.GetShareUI(item, shareResult => {
                dialog.DismissViewController(true, null);

                button.GetActiveCell().TextLabel.Text = service.Title + " shared: " + shareResult;
            });

            dialog.PresentViewController(vc, true, null);
        }
Пример #4
0
        public SettingsViewController() : base(UITableViewStyle.Grouped, null)
        {
            var testButton = new SimpleButton {
                Title      = "Test Connection",
                TitleColor = UIColor.Black,
                Tapped     = async(t) => {
                    View.DismissKeyboard();
                    var f = t.Frame;
                    t.Title = "Testing...";
                    t.Title = string.Format("Test Connection: {0}", await WebService.Main.Test());
                    t.Frame = f;
                }
            };

            this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, (s, e) => save());
            Root = new RootElement("Settings")
            {
                new Section("Server Settings")
                {
                    new EntryElement("Server", "http://10.0.1.2/api/", Settings.Shared.ServerUrl)
                    {
                        ShouldAutoCorrect = false,
                        ValueUpdated      = (v) => {
                            Settings.Shared.ServerUrl = v;
                        },
                    },
                    new EntryElement("Test Server", "http://10.0.1.2/api/", Settings.Shared.TestServerUrl)
                    {
                        ShouldAutoCorrect = false,
                        ValueUpdated      = (v) => {
                            Settings.Shared.TestServerUrl = v;
                        },
                    },
                    new UIViewElement("", testButton, false),
                },
                new Section("iPad Settings")
                {
                    new BooleanElement("Test Mode", Settings.Shared.TestMode)
                    {
                        ValueUpdated = (v) => {
                            Settings.Shared.TestMode = v;
                        }
                    },
                    new EntryElement("Register Id", "1", Settings.Shared.RegisterId.ToString())
                    {
                        ShouldAutoCorrect = false,
                        ValueUpdated      = (v) => {
                            try {
                                Settings.Shared.RegisterId = int.Parse(v);
                            } catch (Exception ex) {
                                Console.WriteLine(ex);
                                new SimpleAlertView("Invalid Register ID", "The Register ID must be a number").Show();
                            }
                        },
                    },
                },
                new Section("Payment Settings")
                {
                    (processorType = new StringElement("Credit Card Processor", Settings.Shared.CreditCardProcessor.ToString(), () => {
                        //
                        var sheet = new SimpleActionSheet();
                        Enum.GetValues(typeof(CreditCardProcessorType)).Cast <CreditCardProcessorType>().ToList().ForEach(x => sheet.Add(x.ToString(), Color.LightBlue, () => {
                            if (x == CreditCardProcessorType.Paypal)
                            {
                                //check if paypal is installed
                            }
                            processorType.Value = x.ToString();
                            Settings.Shared.CreditCardProcessor = x;
                            processorType.Reload();
                            UpdatePaymentDetails();
                        }));
                        sheet.ShowFrom(processorType.GetActiveCell().Bounds, processorType.GetActiveCell(), true);
                    })),
                },
                new Section()
                {
                    new StringElement("Version", NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString()),
                    new StringElement("Check for updates", () => Updater.Shared.Update()),
                }
            };
            UpdatePaymentDetails();
        }
        private void DownloadRoutesDb()
        {
            var webClient = new WebClient();

            webClient.DownloadProgressChanged += (s, e) => {
                InvokeOnMainThread(delegate {
                    _stringDownload.GetActiveCell().TextLabel.Text = string.Format("Downloading... ({0}%)", e.ProgressPercentage);
                    _stringDownload.GetActiveCell().SetNeedsLayout();
                });
            };

            webClient.DownloadDataCompleted += (s, e) => {
                if (e.Result == null)
                {
                    InvokeOnMainThread(delegate {
                        new UIAlertView("Error", "File could not be downloaded", null, "OK", null).Show();
                    });
                }
                else
                {
                    try
                    {
                        var bytes = e.Result;                         // get the downloaded data

                        FileStream   fstream      = new FileStream(localPathUnzg, FileMode.Create);
                        MemoryStream stream       = new MemoryStream(bytes);
                        GZipStream   uncompressed = new GZipStream(stream, CompressionMode.Decompress);
                        uncompressed.CopyTo(fstream);

                        uncompressed.Flush();
                        uncompressed.Close();

                        stream.Dispose();
                        fstream.Dispose();
                    }
                    catch
                    {
                        InvokeOnMainThread(delegate {
                            new UIAlertView("Error", "File could not be downloaded", null, "OK", null).Show();
                        });
                    }

                    InvokeOnMainThread(delegate {
                        new UIAlertView("Done", "File downloaded and saved", null, "OK", null).Show();
                    });
                }

                InvokeOnMainThread(delegate {
                    string fileDownloaded = string.Empty;
                    if (File.Exists(localPathUnzg))
                    {
                        FileInfo fi    = new FileInfo(localPathUnzg);
                        fileDownloaded = string.Format(" ({0})", fi.CreationTime);
                    }

                    _stringDownload.GetActiveCell().TextLabel.Text = "Download" + fileDownloaded;
                    _stringDownload.GetActiveCell().SetNeedsLayout();
                });
            };

            var url = new Uri(@"http://www.virtualradarserver.co.uk/Files/StandingData.sqb.gz");

            webClient.DownloadDataAsync(url);
        }