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); }
public void PerformSalesforceOAuthSaml2Grant() { XmlDocument xDoc = new XmlDocument(); xDoc.PreserveWhitespace = true; xDoc.Load("salesforce-oauthsaml2-idp-metadata.xml"); Saml20MetadataDocument idpMetadata = new Saml20MetadataDocument(xDoc); Saml20Authenticator authenticator = new Saml20Authenticator( "Symplified.Auth.iOS.Sample", idpMetadata ); authenticator.Completed += (s, e) => { loginViewController.DismissViewController(true, null); if (!e.IsAuthenticated) { samlLoginStatusStringElement.Caption = "Not authorized"; samlLoginStatusStringElement.GetActiveCell().BackgroundColor = UIColor.Red; } else { SamlAccount authenticatedAccount = (SamlAccount)e.Account; samlLoginStatusStringElement.Caption = authenticatedAccount.Assertion.Subject.Value; samlLoginStatusStringElement.GetActiveCell().BackgroundColor = UIColor.Green; authenticatedAccount.GetBearerAssertionAuthorizationGrant( new Uri("https://login.salesforce.com/services/oauth2/token") ).ContinueWith(t => { if (!t.IsFaulted) { accessTokenStringElement.Caption = t.Result ["access_token"]; scopeStringElement.Caption = t.Result ["scope"]; BeginInvokeOnMainThread(delegate { loginViewController.ReloadData(); ListSalesforceResources(t.Result ["instance_url"], t.Result ["access_token"]); }); } else { Console.WriteLine("error"); } }); } loginViewController.ReloadData(); }; UIViewController vc = authenticator.GetUI(); loginViewController.PresentViewController(vc, true, null); }
void LoginToFacebook(bool allowCancel) { IOAuthClient.IOAuthClient auth = new PlatformOAuthClient(); auth.New(dialog, "temporaryKey", clientId: "App ID from https://developers.facebook.com/apps", scope: "", authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"), redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html")); auth.AllowCancel = allowCancel; // If authorization succeeds or is canceled, .Completed will be fired. auth.Completed += (s, e) => { // We presented the UI, so it's up to us to dismiss it. dialog.DismissViewController(true, null); if (!e.IsAuthenticated) { facebookStatus.Caption = "Not authorized"; dialog.ReloadData(); return; } // Now that we're logged in, make a OAuth2 request to get the user's info. var request = auth.CreateRequest("GET", new Uri("https://graph.facebook.com/me"), null, e.Account); request.GetResponseAsync().ContinueWith(t => { if (t.IsFaulted) { facebookStatus.Caption = "Error: " + t.Exception.InnerException.Message; } else if (t.IsCanceled) { facebookStatus.Caption = "Canceled"; } else { var obj = JsonValue.Parse(t.Result.GetResponseText()); facebookStatus.Caption = "Logged in as " + obj["name"]; } dialog.ReloadData(); }, uiScheduler); }; auth.Start("Facebook login"); }
public void GetLocation() { if (Busy) { return; } Busy = true; Util.RequestLocation(newLocation => { controller.Root = CreateRoot(newLocation.Coordinate.Latitude.ToString(), newLocation.Coordinate.Longitude.ToString()); controller.ReloadData(); Busy = false; }); }
public void ShowMenu() { if (isOpen) { return; } EnsureInvokedOnMainThread(delegate { navigation.ReloadData(); isOpen = true; closeButton.Frame = mainView.Frame; shadowView.Frame = mainView.Frame; if (!HideShadow) { this.View.InsertSubviewBelow(shadowView, mainView); } if (!ShouldStayOpen) { this.View.AddSubview(closeButton); } UIView.BeginAnimations("slideMenu"); UIView.SetAnimationCurve(UIViewAnimationCurve.EaseIn); //UIView.SetAnimationDuration(2); setViewSize(); var frame = mainView.Frame; frame.X = menuWidth; SetLocation(frame); setViewSize(); frame = mainView.Frame; shadowView.Frame = frame; closeButton.Frame = frame; UIView.CommitAnimations(); }); }
void SetCaption(string caption) { BeginInvokeOnMainThread(() => { element.Caption = caption; dvc.ReloadData(); }); }
private void InitializeComponent() { // initialize controls ListName = new EntryElement("Name", "", folderCopy.Name); // set up the item type listpicker ItemTypePicker = new ItemTypePickerElement("Folder Type", folderCopy.ItemTypeID); var root = new RootElement("Folder Properties") { new Section() { ListName, ItemTypePicker } }; // if this isn't a new folder, render the delete button if (folder != null) { var actionButtons = new ButtonListElement() { new Button() { Caption = "Delete", Background = "Images/redbutton.png", Clicked = DeleteButton_Click }, }; actionButtons.Margin = 0f; root.Add(new Section() { actionButtons }); } if (dvc == null) { // create and push the dialog view onto the nav stack dvc = new DialogViewController(UITableViewStyle.Grouped, root); dvc.Title = NSBundle.MainBundle.LocalizedString("Folder Properties", "Folder Properties"); dvc.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate { // save the item and trigger a sync with the service SaveButton_Click(null, null); }); dvc.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, delegate { NavigateBack(); }); dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); controller.PushViewController(dvc, true); } else { // refresh the dialog view controller with the new root var oldroot = dvc.Root; dvc.Root = root; oldroot.Dispose(); dvc.ReloadData(); } }
public override void ViewDidAppear(bool animated) { TraceHelper.AddMessage("Settings: ViewDidAppear"); if (dvc == null) { InitializeComponent(); } else { CreateRoot(); } // set the background dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); dvc.ReloadData(); base.ViewDidAppear(animated); }
void AdvancedConfigDone(DialogViewController dvc) { dvc.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate { // Deactivate editing dvc.ReloadData(); // Switch updated entry elements to StringElements dvc.Root = CreateEditableRoot(dvc.Root, false); dvc.TableView.SetEditing(false, true); AdvancedConfigEdit(dvc); }); }
void AdvancedConfigEdit(DialogViewController dvc) { dvc.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Edit, delegate { // Activate editing // Switch the root to editable elements dvc.Root = CreateEditableRoot(dvc.Root, true); dvc.ReloadData(); // Activate row editing & deleting dvc.TableView.SetEditing(true, true); AdvancedConfigDone(dvc); }); }
void FqlSample() { // query to get all the friends var query = string.Format("SELECT uid,name,pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) ORDER BY name ASC", "me()"); if (isLoggedIn) { _fb.GetTaskAsync("fql", new { q = query }).ContinueWith(t => { if (!t.IsFaulted) { if (t.Exception != null) { new UIAlertView("Couldn't Load Info", "Reason: " + t.Exception.Message, null, "Ok", null).Show(); return; } var result = (IDictionary <string, object>)t.Result; var data = (IList <object>)result["data"]; var count = data.Count; if (dvcController.Root[0].Elements.Count == 3) { InvokeOnMainThread(() => { dvcController.Root[0].Elements.RemoveAt(2); dvcController.ReloadData(); }); } friends = new RootElement(count + " friends"); var section = new Section(); foreach (IDictionary <string, object> friend in data) { section.Add(new StringElement((string)friend["name"])); } friends.Add(section); BeginInvokeOnMainThread(() => { dvcController.Root[0].Add(friends); new UIAlertView("Info", "You have " + count + " friend(s).", null, "Ok", null).Show(); }); } }); } else { new UIAlertView("Not Logged In", "Please Log In First", null, "Ok", null).Show(); } }
void Test() { try { var utils = new StringUtilities(); var up = upper.Caption; var down = lower.Caption; up = NativeCode.TestUpperCase(utils, up); down = NativeCode.TestLowerCase(utils, down); lower.Caption = down; upper.Caption = up; dvc.ReloadData(); } catch (Exception ex) { upper.Caption = "Failed to test managed interop"; lower.Caption = ex.Message; } }
public override void ViewWillDisappear(bool animated) { base.ViewWillDisappear(animated); Util.Defaults.SetInt(playMusic.Value ? 0 : 1, "disableMusic"); Util.Defaults.SetInt(chicken.Value ? 0 : 1, "disableChickens"); Util.Defaults.SetInt(autoFav.Value ? 0 : 1, "disableFavoriteRetweets"); int style = (selfOnRight.Value ? 0 : 1) | (shadows.Value ? 0 : 2); Util.Defaults.SetInt(style, "cellStyle"); TweetCell.CellStyle = style; BaseTimelineViewController.ChickenNoisesEnabled = chicken.Value; Util.Defaults.SetInt(compress.RadioSelected, "sizeCompression"); Util.Defaults.Synchronize(); parent.ReloadData(); }
public void EditPrices(DialogViewController dvc) { if (_tabs.MyNavigationBar.Hidden) { _tabs.MyNavigationBar.Hidden = false; } _tabs.MyNavigationBar.TopItem.SetRightBarButtonItems(new UIBarButtonItem[] { new UIBarButtonItem("Adjust prices", UIBarButtonItemStyle.Bordered, delegate { // Bring the table view up, so that the keyboard does not obscure it MoveViewUp(); // Activate editing // Switch the root to editable elements dvc.Root = CreateEditableRoot(dvc.Root, true); dvc.ReloadData(); // Activate row editing & deleting dvc.TableView.SetEditing(true, true); // disable the toolbar Nav._tabs._payment.DisableToolbar(); EditPricesDone(dvc); }) }, true); _tabs.MyNavigationBar.TopItem.SetLeftBarButtonItems(new UIBarButtonItem[] { }, true); }
void Upload() { TcpListener listener = new TcpListener(new IPEndPoint(IPAddress.Loopback, 0)); listener.Start(); Console.WriteLine("Listening on: {0}", listener.LocalEndpoint); uploader = new NativeUploader(); uploader.UploadStream("http://127.0.0.1:" + ((IPEndPoint)listener.LocalEndpoint).Port.ToString(), 1000, () => { Console.WriteLine("Upload completed."); }); listener.BeginAcceptSocket((IAsyncResult res) => { ThreadPool.QueueUserWorkItem((v) => { using (var socket = listener.EndAcceptSocket(res)) { byte [] buffer = new byte[1024]; int read; // receive headers read = socket.Receive(buffer); BeginInvokeOnMainThread(() => { status.Caption = "Received headers..."; dvc.ReloadData(); }); Console.WriteLine("\n" + System.Text.ASCIIEncoding.ASCII.GetString(buffer, 0, read)); // send 100 Continue socket.Send(System.Text.ASCIIEncoding.ASCII.GetBytes(@"HTTP/1.1 100 Continue\r\n\r\n")); // receive data read = socket.Receive(buffer); BeginInvokeOnMainThread(() => { status.Caption = "Received data"; dvc.ReloadData(); }); Console.WriteLine("\n" + System.Text.ASCIIEncoding.ASCII.GetString(buffer, 0, read)); // send 200 OK socket.Send(System.Text.ASCIIEncoding.ASCII.GetBytes(@"HTTP/1.1 200 OK\r\n\r\n")); } listener.Stop(); }); }, null); }
public VisitDetailsView(VisitDetailsViewController parent) { Parent = parent; BackgroundColor = UIColor.FromRGB(239, 239, 244); addVisitor = new UIButton { Frame = new RectangleF(0, 0, 150, 150), TintColor = UIColor.White, Layer = { CornerRadius = 75, MasksToBounds = true, } }; addVisitor.SetTitle("Add a visitor", UIControlState.Normal); addVisitor.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;; addVisitor.SetImage(Theme.UserImageDefaultLight.Value, UIControlState.Normal); addVisitor.TouchUpInside += (sender, args) => { if (Parent.PickVisitor != null) { Parent.PickVisitor(); } }; AddSubview(addVisitor); addEmployee = new UIButton { Frame = new RectangleF(0, 0, 150, 150), TintColor = UIColor.White, Layer = { CornerRadius = 75, MasksToBounds = true, } }; addEmployee.SetTitle("Add an employee", UIControlState.Normal); addEmployee.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;; addEmployee.SetImage(Theme.UserImageDefaultLight.Value, UIControlState.Normal); addEmployee.TouchUpInside += (sender, args) => { if (Parent.PickEmployee != null) { Parent.PickEmployee(); } }; AddSubview(addEmployee); editButton = new UIButton(new RectangleF(0, 0, 40, 40)); editButton.SetBackgroundImage(UIImage.FromBundle("edit"), UIControlState.Normal); editButton.TouchUpInside += (sender, args) => { var vc = new EditVisitorViewController { Visitor = new VMVisitor { Visitor = visit.Visitor } }; this.Parent.NavigationController.PushViewController(vc, true); }; visitorLabel = new UILabel { Text = "Visitor", Font = UIFont.FromName(font2, 30), TextAlignment = UITextAlignment.Center, AdjustsFontSizeToFitWidth = true, }; visitorLabel.SizeToFit(); AddSubview(visitorLabel); employeeLabel = new UILabel { Text = "Employee", Font = UIFont.FromName(font2, 30), TextAlignment = UITextAlignment.Center, AdjustsFontSizeToFitWidth = true, }; employeeLabel.SizeToFit(); AddSubview(employeeLabel); date = new DateTimeElement("Date", DateTime.Now); comment = new EntryElement("Reason: ", "Reason", ""); comment.Changed += (sender, args) => { Console.WriteLine("Comment"); }; vehicle = new BooleanElement("Vehicle", false); licensePlate = new EntryElement("Lic Plate: ", "License Plate", ""); licensePlate.Changed += (sender, args) => { Console.WriteLine("licensePlate"); }; vehicle.ValueChanged += (sender, args) => { if (vehicle.Value) { if (!section.Elements.Contains(licensePlate)) { section.Add(licensePlate); } datadvc.ReloadData(); } else { licensePlate.FetchValue(); section.Remove(licensePlate); } }; datadvc = new DialogViewController(new RootElement("visit") { (section = new Section { date, comment, vehicle, licensePlate }) }); datadvc.TableView.SectionHeaderHeight = 0; datadvc.TableView.TableHeaderView = null; datadvc.View.BackgroundColor = UIColor.White; datadvc.View.Layer.CornerRadius = 5f; var height = Enumerable.Range(0, datadvc.TableView.Source.RowsInSection(datadvc.TableView, 0)).Sum(x => datadvc.TableView.Source.GetHeightForRow(datadvc.TableView, NSIndexPath.FromRowSection(x, 0))); datadvc.View.Frame = new RectangleF(0, 0, 100, height); AddSubview(datadvc.View); this.Parent.AddChildViewController(datadvc); }
//------------------------------------------------------------------------------ public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { //var store = NSUbiquitousKeyValueStore.DefaultStore; //bool result = store.Synchronize(); Settings.LoadSettings(); Window = new UIWindow(UIScreen.MainScreen.Bounds); var rootElement = new RootElement("Advexp.Settings iCloud sample"); bool boolChangeLock = false; var boolElement = new BooleanElement("bool value", Settings.Bool); boolElement.ValueChanged += (object sender, System.EventArgs e) => { if (!boolChangeLock) { Settings.Bool = boolElement.Value; Settings.SaveSetting(s => Settings.Bool); } }; bool stringChangeLock = false; var stringElement = new EntryElement("string value", "string value", Settings.Text); stringElement.AutocorrectionType = UITextAutocorrectionType.No; stringElement.Changed += (object sender, EventArgs e) => { if (!stringChangeLock) { Settings.Text = stringElement.Value; Settings.SaveSetting(s => Settings.Text); } }; var staticSection = new Section("Static settings") { boolElement, stringElement, }; var iCloudPlugin = Settings.GetPlugin <IiCloudSettingsPlugin>(); var iCloudDynamicSettings = (IDynamicSettingsPlugin)iCloudPlugin; bool checkChangeLock = false; Action <CheckboxElementEx, EventArgs> checkDelegate = (sender, e) => { if (!checkChangeLock) { iCloudDynamicSettings.SetSetting(sender.Caption, sender.Value); iCloudDynamicSettings.SaveSetting(sender.Caption); } }; var value1 = new CheckboxElementEx("value1", iCloudDynamicSettings.GetSetting <bool>("value1", false), checkDelegate); var value2 = new CheckboxElementEx("value2", iCloudDynamicSettings.GetSetting <bool>("value2", false), checkDelegate); var value3 = new CheckboxElementEx("value3", iCloudDynamicSettings.GetSetting <bool>("value3", false), checkDelegate); var value4 = new CheckboxElementEx("value4", iCloudDynamicSettings.GetSetting <bool>("value4", false), checkDelegate); var value5 = new CheckboxElementEx("value5", iCloudDynamicSettings.GetSetting <bool>("value5", false), checkDelegate); var value6 = new CheckboxElementEx("value6", iCloudDynamicSettings.GetSetting <bool>("value6", false), checkDelegate); var dynamicSection = new Section("Dynamic settings") { value1, value2, value3, value4, value5, value6, }; rootElement.Add(staticSection); rootElement.Add(dynamicSection); var rootVC = new DialogViewController(rootElement); var nav = new UINavigationController(rootVC); Window.RootViewController = nav; Window.MakeKeyAndVisible(); m_iCloudNotification = NSNotificationCenter.DefaultCenter.AddObserver( NSUbiquitousKeyValueStore.DidChangeExternallyNotification, notification => { Console.WriteLine("iCloud notification received - iOS"); InvokeOnMainThread(() => { try { boolChangeLock = true; stringChangeLock = true; checkChangeLock = true; var store = NSUbiquitousKeyValueStore.DefaultStore; store.Synchronize(); Settings.LoadSettings(); boolElement.Value = Settings.Bool; stringElement.Value = Settings.Text; value1.Value = iCloudDynamicSettings.GetSetting <bool>("value1", false); value2.Value = iCloudDynamicSettings.GetSetting <bool>("value2", false); value3.Value = iCloudDynamicSettings.GetSetting <bool>("value3", false); value4.Value = iCloudDynamicSettings.GetSetting <bool>("value4", false); value5.Value = iCloudDynamicSettings.GetSetting <bool>("value5", false); value6.Value = iCloudDynamicSettings.GetSetting <bool>("value6", false); } finally { boolChangeLock = false; stringChangeLock = false; checkChangeLock = false; } rootVC.ReloadData(); }); }); return(true); }
public void EditPricesDone(DialogViewController dvc) { if (_tabs.MyNavigationBar.Hidden) { _tabs.MyNavigationBar.Hidden = false; } _tabs.MyNavigationBar.TopItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate { MoveViewDown(); // Deactivate editing dvc.ReloadData(); // Switch updated entry elements to StringElements dvc.Root = CreateEditableRoot(dvc.Root, false); dvc.TableView.SetEditing(false, true); // check the input here bool ok = true; double total = 0; for (int j = 0; j < dvc.Root[0].Count; j++) { double result; StringElement element = (dvc.Root[0].Elements[j] as StringElement); string enteredPrice = element.Value; ok = double.TryParse(enteredPrice, out result); ok = (ok && result > 0); if (!ok) { element.Value = (j > 0)? String.Format("${0:0.00}", mainJob.ChildJobs[j - 1].MoneyToCollect) : String.Format("${0:0.00}", mainJob.MoneyToCollect); // old value, if the input was invalid total += (j > 0)? mainJob.ChildJobs[j - 1].MoneyToCollect : mainJob.MoneyToCollect; TableView.ReloadData(); } else { element.Value = String.Format("${0:0.00}", result); // new entered value, if it's correct // normal or split payment -- does not matter -- we can still assume that every job has at least one payment in their payments list if (j == 0) { mainJob.MoneyToCollect = result; mainJob.Payments[0].Amount = mainJob.MoneyToCollect; total += mainJob.MoneyToCollect; } else { mainJob.ChildJobs[j - 1].MoneyToCollect = result; mainJob.ChildJobs[j - 1].Payments[0].Amount = mainJob.ChildJobs[j - 1].MoneyToCollect; total += mainJob.ChildJobs[j - 1].MoneyToCollect; } } } if (!ok) { var alert = new UIAlertView("Incorrect input value for price ignored", "Please try again", null, "OK"); alert.Show(); } _tabs._payment.SetTotalToCollect(total); if (this._tabs._payment.ContainsInvoicePaymentType(mainJob.Payments)) { _tabs._payment.SetTotalReceived(0); } // else _tabs._payment.SetTotalReceived (total); // --- no need for this, this has been done in SetTotalToCollect() already if (Root[0].Footer != "") { Root[0].Footer = ""; } EditPrices(dvc); // enable the toolbar Nav._tabs._payment.EnableToolbar(); SelectCurrentJobRow(); }); }