public Add ( IEnumerable |
||
elements | IEnumerable |
/// An enumerable list that can be produced by something like: /// from x in ... select (Element) new MyElement (...) /// |
return | int |
/// <summary> /// Invoked when it comes time to set the root so the child classes can create their own menus /// </summary> private void OnCreateMenu(RootElement root) { var addGistSection = new Section(); root.Add(addGistSection); addGistSection.Add(new MenuElement("New Gist", () => { var gistController = new CreateGistController(); gistController.Created = (id) => { NavigationController.PushViewController(new GistInfoController(id), true); }; var navController = new UINavigationController(gistController); PresentViewController(navController, true, null); }, Images.Buttons.NewGist)); var gistMenuSection = new Section() { HeaderView = new MenuSectionView("Gists") }; root.Add(gistMenuSection); gistMenuSection.Add(new MenuElement("My Gists", () => NavigationController.PushViewController(new MyGistsController(), true), Images.Buttons.MyGists)); gistMenuSection.Add(new MenuElement("Starred", () => NavigationController.PushViewController(new StarredGistsController(), true), Images.Buttons.Star2)); gistMenuSection.Add(new MenuElement("Public", () => NavigationController.PushViewController(new PublicGistsController(), true), Images.Buttons.Public)); // var labelSection = new Section() { HeaderView = new MenuSectionView("Tags") }; // root.Add(labelSection); // labelSection.Add(new MenuElement("Add New Tag", () => { }, null)); var moreSection = new Section() { HeaderView = new MenuSectionView("Info") }; root.Add(moreSection); moreSection.Add(new MenuElement("About", () => NavigationController.PushViewController(new AboutController(), true), Images.Buttons.Info)); moreSection.Add(new MenuElement("Feedback & Support", () => { var config = UserVoice.UVConfig.Create("http://gistacular.uservoice.com", "lYY6AwnzrNKjHIkiiYbbqA", "9iLse96r8yki4ZKknfHKBlWcbZAH9g8yQWb9fuG4"); UserVoice.UserVoice.PresentUserVoiceInterface(this, config); }, Images.Buttons.Feedback)); moreSection.Add(new MenuElement("Logout", Logout, Images.Buttons.Logout)); }
public override bool FinishedLaunching (UIApplication app, NSDictionary options) { window = new UIWindow (UIScreen.MainScreen.Bounds); var what = new EntryElement ("What ?", "e.g. pizza", String.Empty); var where = new EntryElement ("Where ?", "here", String.Empty); var section = new Section (); if (CLLocationManager.LocationServicesEnabled) { lm = new CLLocationManager (); lm.LocationsUpdated += delegate (object sender, CLLocationsUpdatedEventArgs e) { lm.StopUpdatingLocation (); here = e.Locations [e.Locations.Length - 1]; var coord = here.Coordinate; where.Value = String.Format ("{0:F4}, {1:F4}", coord.Longitude, coord.Latitude); }; section.Add (new StringElement ("Get Current Location", delegate { lm.StartUpdatingLocation (); })); } section.Add (new StringElement ("Search...", async delegate { await SearchAsync (what.Value, where.Value); })); var root = new RootElement ("MapKit Search Sample") { new Section ("MapKit Search Sample") { what, where }, section }; window.RootViewController = new UINavigationController (new DialogViewController (root, true)); window.MakeKeyAndVisible (); return true; }
private void Initialize() { var loginWithWidgetBtn = new StyledStringElement ("Login with Widget", this.LoginWithWidgetButtonClick) { Alignment = UITextAlignment.Center }; var loginWithConnectionBtn = new StyledStringElement ("Login with Google", this.LoginWithConnectionButtonClick) { Alignment = UITextAlignment.Center }; var loginBtn = new StyledStringElement ("Login", this.LoginWithUsernamePassword) { Alignment = UITextAlignment.Center }; this.resultElement = new StyledMultilineElement (string.Empty, string.Empty, UITableViewCellStyle.Subtitle); var login1 = new Section ("Login"); login1.Add (loginWithWidgetBtn); login1.Add (loginWithConnectionBtn); var login2 = new Section ("Login with user/password"); login2.Add (this.userNameElement = new EntryElement ("User", string.Empty, string.Empty)); login2.Add (this.passwordElement = new EntryElement ("Password", string.Empty, string.Empty, true)); login2.Add (loginBtn); var result = new Section ("Result"); result.Add(this.resultElement); this.Root.Add (new Section[] { login1, login2, result }); }
public void DemoLoadMore () { Section loadMore = new Section(); loadMore.Add(new StringElement("Element 1")); loadMore.Add(new StringElement("Element 2")); loadMore.Add(new StringElement("Element 3")); loadMore.Add (new LoadMoreElement("Load More Elements...", "Loading Elements...", lme => { // Launch a thread to do some work ThreadPool.QueueUserWorkItem (delegate { // We just wait for 2 seconds. System.Threading.Thread.Sleep(2000); // Now make sure we invoke on the main thread the updates navigation.BeginInvokeOnMainThread(delegate { lme.Animating = false; loadMore.Insert(loadMore.Count - 1, new StringElement("Element " + (loadMore.Count + 1)), new StringElement("Element " + (loadMore.Count + 2)), new StringElement("Element " + (loadMore.Count + 3))); }); }); }, UIFont.BoldSystemFontOfSize(14.0f), UIColor.Blue)); var root = new RootElement("Load More") { loadMore }; var dvc = new DialogViewController (root, true); navigation.PushViewController (dvc, true); }
private Section BuildListing(string basePath) { Section sect = new Section(); foreach(string dir in Directory.GetDirectories(basePath)) { string strDir = dir; string strDirDisplay = strDir.Replace(basePath,""); if(strDirDisplay[0] == '/') strDirDisplay = strDirDisplay.Remove(0,1); ImageStringElement element = new ImageStringElement (strDirDisplay, imgFolder); element.Tapped += delegate { ShowDirectoryTree(strDir, true); }; sect.Add(element); } foreach(string fil in Directory.GetFiles(basePath)) { string strFil = fil; string strFilDisplay = strFil.Replace(basePath,""); if(strFilDisplay[0] == '/') strFilDisplay = strFilDisplay.Remove(0,1); ImageStringElement element = new ImageStringElement (strFilDisplay, imgFile); element.Tapped += delegate { Utilities.UnsuccessfulMessage("File: " + strFil + " tapped"); }; sect.Add(element); } return sect; }
public ProvisioningDialog() : base(UITableViewStyle.Grouped, null) { Root = new RootElement ("GhostPractice Mobile"); var topSec = new Section ("Welcome"); topSec.Add (new StringElement ("Please enter activation code")); activation = new EntryElement ("Code", "Activation Code", "999998-zcrdbrkqwogh"); topSec.Add (activation); var submit = new StringElement ("Send Code"); submit.Alignment = UITextAlignment.Center; submit.Tapped += delegate { if (activation.Value == null || activation.Value == string.Empty) { new UIAlertView ("Device Activation", "Please enter activation code", null, "OK", null).Show (); return; } if (!isBusy) { getAsyncAppAndPlatform (); } else { Wait (); } }; topSec.Add (submit); Root.Add (topSec); UIImage img = UIImage.FromFile ("Images/launch_small.png"); UIImageView v = new UIImageView (new RectangleF (0, 0, 480, 600)); v.Image = img; Root.Add (new Section (v)); }
// This method is invoked when the application has loaded its UI and its ready to run public override bool FinishedLaunching(UIApplication app, NSDictionary options) { load(); string[] s; mainMenu = new Section("Blogs", "Click for a new Account"); for(int i = 0; i < titles.Count; i++){ s = titles.ElementAt(i); var a = new Account( s[0], s[1], s[2] ); accounts.Add( a ); a.SetDelegate(this); mainMenu.Add( a.GetRoot() ); } var nb = new StringElement("new Account", NewBlog); nb.Alignment = UITextAlignment.Center; mainMenu.Add( nb ); var dv = new ExtDialogViewController ( new RootElement("Blogs"){ mainMenu } ) { Autorotate = true, DisableUpsideDown = true }; window.AddSubview (navigation.View); navigation.PushViewController (dv, true); window.MakeKeyAndVisible (); return true; }
private void CreateTable() { var application = Mvx.Resolve<IApplicationService>(); var vm = (SettingsViewModel)ViewModel; var currentAccount = application.Account; var accountSection = new Section("Account"); accountSection.Add(new TrueFalseElement("Save Credentials".t(), !currentAccount.DontRemember, e => { currentAccount.DontRemember = !e.Value; application.Accounts.Update(currentAccount); })); var showOrganizationsInEvents = new TrueFalseElement("Show Organizations in Events".t(), currentAccount.ShowOrganizationsInEvents, e => { currentAccount.ShowOrganizationsInEvents = e.Value; application.Accounts.Update(currentAccount); }); var showOrganizations = new TrueFalseElement("List Organizations in Menu".t(), currentAccount.ExpandOrganizations, e => { currentAccount.ExpandOrganizations = e.Value; application.Accounts.Update(currentAccount); }); var repoDescriptions = new TrueFalseElement("Show Repo Descriptions".t(), currentAccount.ShowRepositoryDescriptionInList, e => { currentAccount.ShowRepositoryDescriptionInList = e.Value; application.Accounts.Update(currentAccount); }); var startupView = new StyledStringElement("Startup View", vm.DefaultStartupViewName, MonoTouch.UIKit.UITableViewCellStyle.Value1) { Accessory = MonoTouch.UIKit.UITableViewCellAccessory.DisclosureIndicator, }; startupView.Tapped += () => vm.GoToDefaultStartupViewCommand.Execute(null); if (vm.PushNotificationsActivated) accountSection.Add(new TrueFalseElement("Push Notifications".t(), vm.PushNotificationsEnabled, e => vm.PushNotificationsEnabled = e.Value)); var totalCacheSizeMB = vm.CacheSize.ToString("0.##"); var deleteCache = new StyledStringElement("Delete Cache".t(), string.Format("{0} MB", totalCacheSizeMB), MonoTouch.UIKit.UITableViewCellStyle.Value1); deleteCache.Tapped += () => { vm.DeleteAllCacheCommand.Execute(null); deleteCache.Value = string.Format("{0} MB", 0); ReloadData(); }; var usage = new TrueFalseElement("Send Anonymous Usage".t(), vm.AnalyticsEnabled, e => vm.AnalyticsEnabled = e.Value); //Assign the root var root = new RootElement(Title); root.Add(accountSection); root.Add(new Section("Appearance") { showOrganizationsInEvents, showOrganizations, repoDescriptions, startupView }); root.Add(new Section ("Internal") { deleteCache, usage }); Root = root; }
public override void ViewDidLoad() { base.ViewDidLoad (); var section = new Section (); section.Add (CreateMemoriesScreen ()); section.Add (CreateUpdateScreen ()); Root.Add (section); }
public AddEditContactScreen(UINavigationController nav) : base(UITableViewStyle.Grouped, null, true) { _rootContainerNavigationController = nav; // Navigation NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (sender, args) => { NavigationController.DismissViewController(true, null); }); NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, DoneButtonClicked); NavigationItem.Title = "New Contact"; Root = new RootElement(""); // Photo _photoSection = new Section(); _photoBadge = new BadgeElement(UIImage.FromBundle("Images/UnknownIcon.jpg"), "Add Photo"); _photoBadge.Tapped += PhotoBadgeTapped; _photoSection.Add(_photoBadge); Root.Add(_photoSection); // Name _nameSection = new Section(); var firstName = new EntryElement(null, "First", null); var middleName = new EntryElement(null, "Middle", null); var lastName = new EntryElement(null, "Last", null); var org = new EntryElement(null, "Organization", null); _nameSection.Add(firstName); _nameSection.Add(middleName); _nameSection.Add(lastName); _nameSection.Add(org); Root.Add(_nameSection); // Phone numbers _phoneSection = new Section("Phone Numbers"); Root.Add(_phoneSection); var phoneLoadMore = new LoadMoreElement("Add More Phone Numbers", "Loading...", PhoneLoadMoreTapped); _phoneSection.Add(phoneLoadMore); // Emails _emailSection = new Section("Emails"); Root.Add(_emailSection); var emailLoadMore = new LoadMoreElement("Add More Emails", "Loading...", EmailLoadMoreTapped); _emailSection.Add(emailLoadMore); // Urls _urlSection = new Section("Urls"); Root.Add(_urlSection); var urlLoadMore = new LoadMoreElement("Add More Urls", "Loading...", UrlLoadMoreTapped); _urlSection.Add(urlLoadMore); // IMs _instantMsgSection = new Section("Instant Messages"); Root.Add(_instantMsgSection); var instantMsgLoadMore = new LoadMoreElement("Add More Instant Messages", "Loading...", InstantMsgLoadMoreTapped); _instantMsgSection.Add(instantMsgLoadMore); }
public FieldImage(string farmName,int farmID,FlyoutNavigationController fnc,SelectField sf) : base(UITableViewStyle.Grouped, null) { Root = new RootElement (null) {}; this.Pushing = true; var section = new Section () {}; var totalRainGuage = new StringElement ("Total Raid Guage(mm): " + DBConnection.getRain (farmID),()=>{}); var rainGuage=new EntryElement ("New Rain Guage(mm): ",null," "); rainGuage.KeyboardType = UIKeyboardType.NumbersAndPunctuation; var update=new StringElement("Add",()=>{ try{ DBConnection.updateRain(farmID,Int32.Parse(rainGuage.Value)); } catch(Exception e){ new UIAlertView ("Error", "Wrong input format!", null, "Continue").Show (); return; } UIAlertView alert = new UIAlertView (); alert.Title = "Success"; alert.Message = "Your Data Has Been Saved"; alert.AddButton("OK"); alert.Show(); }); var showDetail=new StringElement("Show Rain Guage Detail",()=>{ RainDetail rd=new RainDetail(farmID,farmName); sf.NavigationController.PushViewController(rd,true); }); section.Add (totalRainGuage); section.Add (rainGuage); section.Add (update); section.Add (showDetail); Root.Add (section); var section2 = new Section () { }; var farmImg=UIImage.FromFile ("img/"+farmName+".jpg"); if(farmImg==null) farmImg=UIImage.FromFile ("Icon.png"); var imageView = new UIImageView (farmImg); if(farmImg==null) farmImg=UIImage.FromFile ("Icon.png"); var scrollView=new UIScrollView ( new RectangleF(0,0,fnc.View.Frame.Width-20,250) ); scrollView.ContentSize = imageView.Image.Size; scrollView.AddSubview (imageView); scrollView.MaximumZoomScale = 3f; scrollView.MinimumZoomScale = .1f; scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => { return imageView; }; var imageElement=new UIViewElement(null,scrollView,false); section2.Add(imageElement); Root.Add (section2); }
public SelectFarm() : base(UITableViewStyle.Grouped, null) { Root = new RootElement (null){}; this.Pushing=true; //farm section var farms = DBConnection.getAllFarms(); int farmNumber=farms.Count(); var section = new Section ("Farms:"){}; foreach(Farm farm in farms){ int farmID = farm.farmID; string farmName = farm.farmName; int fieldNumber = DBConnection.getAllFields(farmID).Count (); var farmImg=UIImage.FromFile ("img/"+farmName+".jpg"); if(farmImg==null) farmImg=UIImage.FromFile ("Icon.png"); var theFarm=new BadgeElement(farmImg,farmName+" "+fieldNumber+" fields",()=>{ Console.WriteLine("Farm Name is: "+farmName); var field=new SelectField(farmName,farmID,fieldNumber); this.NavigationController.PushViewController(field,true); }); section.Add(theFarm); } Root.Add(section); //grain section var section2 = new Section ("Grain Inventory:"){}; var grin1 = new StringElement ("Bin (1-15)", () => { var selectBin=new SelectBin(1); this.NavigationController.PushViewController(selectBin,true); }); var grin2 = new StringElement ("Bin(16-30)", () => { var selectBin=new SelectBin(16); this.NavigationController.PushViewController(selectBin,true); }); var grin3 = new StringElement ("Bin(31-45)", () => { var selectBin=new SelectBin(31); this.NavigationController.PushViewController(selectBin,true); }); var grin4 = new StringElement ("Bin(46-60)", () => { var selectBin=new SelectBin(46); this.NavigationController.PushViewController(selectBin,true); }); var grin5 = new StringElement ("Bin(61-75)", () => { var selectBin=new SelectBin(61); this.NavigationController.PushViewController(selectBin,true); }); section2.Add (grin1); section2.Add (grin2); section2.Add (grin3); section2.Add (grin4); section2.Add (grin5); Root.Add (section2); }
public void buildFeeTargetReport() { Root = new RootElement ("Practice Fee Target Progress"); Stripper.SetReportHeader (Root, "Practice Fee Target Progress", null, contentWidth); PracticeTotals totals = this.report.practiceTotals; var totSection = new Section (""); var tot1 = new BigFinanceElement ("Invoiced MTD Total: ", totals.invoicedMTDTotal); totSection.Add (tot1); Root.Add (totSection); //Fee Target Progress: The Invoiced Debits MTD field display the invoiced YTD value if (totals.recordedMTD != null) { var mtdSection = new Section ("Recorded MTD"); mtdSection.Add (getElement (totals.recordedMTD.achieved, "Achieved: ")); mtdSection.Add (getElement (totals.recordedMTD.estimatedTarget, "Estimated Target: ")); mtdSection.Add (getElement (totals.recordedMTD.invoicedDebits, "Invoiced: ")); mtdSection.Add (getElement (totals.recordedMTD.unbilled, "Unbilled: ")); mtdSection.Add (getElement (totals.recordedMTD.total, "Total: ")); Root.Add (mtdSection); } if (totals.recordedYTD != null) { var mtdSection = new Section ("Recorded YTD"); mtdSection.Add (getElement (totals.recordedYTD.achieved, "Achieved: ")); mtdSection.Add (getElement (totals.recordedYTD.estimatedTarget, "Estimated Target: ")); mtdSection.Add (getElement (totals.recordedYTD.invoiced, "Invoiced: ")); mtdSection.Add (getElement (totals.recordedYTD.unbilled, "Unbilled: ")); mtdSection.Add (getElement (totals.recordedYTD.total, "Total: ")); Root.Add (mtdSection); } if (totals.matterActivity != null) { var matterActivitySection = new Section ("Matter Activity"); var tot2 = new NumberElement (totals.matterActivity.active, "Active Matters: "); matterActivitySection.Add (tot2); var tot3 = new NumberElement (totals.matterActivity.deactivated, "Deactivated Matters: "); matterActivitySection.Add (tot3); var tot4 = new NumberElement (totals.matterActivity.newWork, "New Work: "); matterActivitySection.Add (tot4); var tot5 = new NumberElement (totals.matterActivity.noActivity, "No Activity: "); matterActivitySection.Add (tot5); var tot6 = new StringElement ("No Activity Duration: " + totals.matterActivity.noActivityDuration); matterActivitySection.Add (tot6); Root.Add (matterActivitySection); } // if (totals.matterBalances != null) { var matterBalancesSection = new Section ("Matter Balances"); matterBalancesSection.Add (getElement (totals.matterBalances.business, "Business: ")); matterBalancesSection.Add (getElement (totals.matterBalances.unbilled, "Unbilled: ")); matterBalancesSection.Add (getElement (totals.matterBalances.trust, "Trust Balance: ")); matterBalancesSection.Add (getElement (totals.matterBalances.investment, "Investments: ")); Root.Add (matterBalancesSection); } }
private Element Generate(StudentGuideModel item) { var root=new RootElement(item.Title); var section=new Section(item.Title); root.Add (section); if (item.Phone!="") { var phoneStyle = new StyledStringElement("Contact Number",item.Phone) { BackgroundColor=UIColor.FromRGB(71,165,209), TextColor=UIColor.White, DetailColor=UIColor.White, }; phoneStyle.Tapped+= delegate { UIAlertView popup = new UIAlertView("Alert","Do you wish to send a text or diall a number?",null,"Cancel","Text","Call"); popup.Show(); popup.Dismissed += delegate(object sender, UIButtonEventArgs e) { if (e.ButtonIndex==1) { MFMessageComposeViewController msg = new MFMessageComposeViewController(); msg.Recipients=new string[] {item.Phone}; this.NavigationController.PresentViewController(msg,true,null); } else if (e.ButtonIndex==2) { AppDelegate.getControl.calling(item.Phone); }; }; }; section.Add(phoneStyle); }; if (item.Email!="") { var style = new StyledStringElement("Contact Email",item.Email) { BackgroundColor=UIColor.FromRGB(71,165,209), TextColor=UIColor.White, DetailColor=UIColor.White, }; style.Tapped += delegate { MFMailComposeViewController email = new MFMailComposeViewController(); email.SetToRecipients(new string[] {item.Email}); this.NavigationController.PresentViewController(email,true,null); }; section.Add (style); } if (item.Address!="") { section.Add(new StyledMultilineElement(item.Address) { BackgroundColor=UIColor.FromRGB(71,165,209), TextColor=UIColor.White, DetailColor=UIColor.White, }); } if (item.Description!="") { section.Add (new StyledMultilineElement(item.Description) { BackgroundColor=UIColor.FromRGB(71,165,209), TextColor=UIColor.White, DetailColor=UIColor.White, Alignment=UITextAlignment.Center, }); } return root; }
public void buildReport() { Root = new RootElement (""); var v = new UIView (); v.Frame = new RectangleF (10, 10, 600, 10); var dummy = new Section (v); Root.Add (dummy); var headerLabel = new UILabel (new RectangleF (10, 10, 800, 48)) { Font = UIFont.BoldSystemFontOfSize (18), BackgroundColor = ColorHelper.GetGPPurple (), TextAlignment = UITextAlignment.Center, TextColor = UIColor.White, Text = "Owner Matter Analysis" }; var view = new UIViewBordered (); view.Frame = new RectangleF (10, 10, 800, 48); view.Add (headerLabel); Root.Add (new Section (view)); //NumberFormatInfo nfi = new CultureInfo ("en-US", false).NumberFormat; for (int i = 0; i < report.branches.Count; i++) { Branch branch = report.branches [i]; Section s = new Section (branch.name); Root.Add (s); for (int j = 0; j < branch.owners.Count; j++) { Owner o = branch.owners [j]; Section seco = new Section (o.name); var recMTD = new TitleElement ("Matter Activity"); seco.Add (recMTD); seco.Add (new NumberElement (o.matterActivity.active, "Active: ")); seco.Add (new NumberElement (o.matterActivity.deactivated, "Deactivated: ")); seco.Add (new NumberElement (o.matterActivity.newWork, "New Work: ")); seco.Add (new NumberElement (o.matterActivity.workedOn, "Worked On: ")); seco.Add (new NumberElement (o.matterActivity.noActivity, "No Activity: ")); seco.Add (new StringElement ("No Activity Duration: " + o.matterActivity.noActivityDuration)); // var recYTD = new TitleElement ("Matter Balances"); seco.Add (recYTD); seco.Add (getElement (o.matterBalances.business, S.GetText (S.BUSINESS) + ": ")); seco.Add (getElement (o.matterBalances.trust, S.GetText (S.TRUST) + ": ")); seco.Add (getElement (o.matterBalances.investment, S.GetText (S.INVESTMENTS) + ": ")); seco.Add (getElement (o.matterBalances.unbilled, "Unbilled: ")); seco.Add (getElement (o.matterBalances.pendingDisbursements, "Pending Disb: ")); Root.Add (seco); } } for (var i = 0; i < 10; i++) { Root.Add (new Section (" ")); } }
private RootElement buildRootMenu() { menu = new RootElement ("Recorded Media"); moviesElement = buildMoviesElement(); imagesElement = buildImagesElement(); Section rootSection = new Section("File Types"); rootSection.Add((Element)moviesElement); rootSection.Add((Element)imagesElement); menu.Add(rootSection); return menu; }
protected override void CreateMenuRoot() { var root = new RootElement(Application.Account.Username); root.Add(new Section() { new MenuElement("Profile".t(), () => NavPush(new ProfileViewController(Application.Account.Username) { Title = "Profile".t() }), Images.Buttons.Person), }); var eventsSection = new Section() { HeaderView = new MenuSectionView("Events".t()) }; eventsSection.Add(new MenuElement(Application.Account.Username, () => NavPush(new EventsViewController(Application.Account.Username)), Images.Buttons.Event)); if (Application.Account.Teams != null && !Application.Account.DontShowTeamEvents) Application.Account.Teams.ForEach(team => eventsSection.Add(new MenuElement(team, () => NavPush(new EventsViewController(team)), Images.Buttons.Event))); root.Add(eventsSection); var repoSection = new Section() { HeaderView = new MenuSectionView("Repositories".t()) }; repoSection.Add(new MenuElement("Owned".t(), () => NavPush(new RepositoriesViewController(Application.Account.Username) { Title = "Owned".t() }), Images.Repo)); repoSection.Add(new MenuElement("Following".t(), () => NavPush(new FollowingRepositoriesViewController()), Images.RepoFollow)); repoSection.Add(new MenuElement("Explore".t(), () => NavPush(new ExploreRepositoriesViewController()), Images.Buttons.Explore)); root.Add(repoSection); var pinnedRepos = Application.Account.GetPinnedRepositories(); if (pinnedRepos.Count > 0) { var pinnedRepoSection = new Section() { HeaderView = new MenuSectionView("Favorite Repositories".t()) }; pinnedRepos.ForEach(x => pinnedRepoSection.Add(new MenuElement(x.Name, () => NavPush(new RepositoryInfoViewController(x.Owner, x.Slug, x.Name)), Images.Repo) { ImageUri = new System.Uri(x.ImageUri) })); root.Add(pinnedRepoSection); } var groupsTeamsSection = new Section() { HeaderView = new MenuSectionView("Collaborations".t()) }; if (Application.Account.DontExpandTeamsAndGroups) { groupsTeamsSection.Add(new MenuElement("Groups".t(), () => NavPush(new GroupViewController(Application.Account.Username)), Images.Buttons.Group)); groupsTeamsSection.Add(new MenuElement("Teams".t(), () => NavPush(new TeamViewController()), Images.Team)); } else { if (Application.Account.Groups != null) Application.Account.Groups.ForEach(x => groupsTeamsSection.Add(new MenuElement(x.Name, () => NavPush(new GroupMembersViewController(Application.Account.Username, x.Slug, x.Members) { Title = x.Name }), Images.Buttons.Group))); if (Application.Account.Teams != null) Application.Account.Teams.ForEach(x => groupsTeamsSection.Add(new MenuElement(x, () => NavPush(new ProfileViewController(x)), Images.Team))); } //There should be atleast 1 thing... if (groupsTeamsSection.Elements.Count > 0) root.Add(groupsTeamsSection); var infoSection = new Section() { HeaderView = new MenuSectionView("Info & Preferences".t()) }; root.Add(infoSection); infoSection.Add(new MenuElement("Settings".t(), () => NavPush(new SettingsViewController()), Images.Buttons.Cog)); infoSection.Add(new MenuElement("About".t(), () => NavPush(new AboutController()), Images.Buttons.Info)); infoSection.Add(new MenuElement("Feedback & Support".t(), PresentUserVoice, Images.Buttons.Flag)); infoSection.Add(new MenuElement("Accounts".t(), () => ProfileButtonClicked(this, System.EventArgs.Empty), Images.Buttons.User)); Root = root; }
public Login() : base(UITableViewStyle.Grouped, null) { Root = new RootElement ("Login") {}; var input = new Section(){}; var userName=new EntryElement ("User Name", "Enter your user name",null); var password = new EntryElement ("Password", "Enter your password", null, true); input.Add (userName); input.Add (password); Root.Add (input); var submit = new Section () { }; var btnSubmit=new StringElement("Submit",()=>{ Console.WriteLine("user name is: "+userName.Value); Console.WriteLine("password is: "+password.Value); var pass=DBConnection.isUser(userName.Value,password.Value);//change this and use userName.Vale... if(pass){ // download templates, before go to another screen var webRequest = WebRequestManager.getWebRequestManager(); webRequest.downloadSeedTemplate(); webRequest.downloadChemicalTemplate(); webRequest.downloadUsers(); webRequest.downloadFarms(); // var farm=new SelectFarm(); this.NavigationController.PushViewController(farm,true); } else{ new UIAlertView ("Error", "Wrong UserName or Password!", null, "Continue").Show (); } }); submit.Add (btnSubmit); Root.Add (submit); /* //code to add user var addUser=new Section(){}; var btnAddUser=new StringElement("Adduser",()=>{ Console.WriteLine("Add user name: "+userName.Value); Console.WriteLine("The password is: "+password.Value); DBConnection.insertUser(userName.Value,password.Value); }); addUser.Add(btnAddUser); Root.Add(addUser); //end of code for add user */ }
public static Section[] CreateTaskDetailSections(Task task) { List<Section> sections = new List<Section>(); // additional info var detailSection = new Section(); sections.Add(detailSection); string dateValue = task.Date.ToShortTimeString(); detailSection.Add(new StringElement("Date", dateValue)); detailSection.Add(new StyledMultilineElement("Description", task.Description)); return sections.ToArray(); }
protected void UpdateView() { var root = new RootElement(Title) { UnevenRows = true }; var section = new Section(); root.Add(section); var desc = new MultilinedElement("Description") { Value = ViewModel.Description }; desc.Tapped += ChangeDescription; section.Add(desc); var pub = new TrueFalseElement("Public", ViewModel.Public, (e) => ViewModel.Public = e.Value); section.Add(pub); var fileSection = new Section(); root.Add(fileSection); foreach (var file in ViewModel.Files.Keys) { var key = file; if (string.IsNullOrEmpty(ViewModel.Files[file])) continue; var size = System.Text.Encoding.UTF8.GetByteCount(ViewModel.Files[file]); var el = new StyledStringElement(file, size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator }; el.Tapped += () => { if (!ViewModel.Files.ContainsKey(key)) return; var createController = new ModifyGistFileController(key, ViewModel.Files[key]); createController.Save = (name, content) => { if (string.IsNullOrEmpty(name)) throw new InvalidOperationException("Please enter a name for the file"); //If different name & exists somewhere else if (!name.Equals(key) && ViewModel.Files.ContainsKey(name)) throw new InvalidOperationException("A filename by that type already exists"); ViewModel.Files.Remove(key); ViewModel.Files[name] = content; ViewModel.Files = ViewModel.Files; // Trigger refresh }; NavigationController.PushViewController(createController, true); }; fileSection.Add(el); } fileSection.Add(new StyledStringElement("Add New File", AddFile)); Root = root; }
public TestViewController (TestMethod test, string log) : base (UITableViewStyle.Grouped, null, pushing: true) { var section = new Section(); if (!String.IsNullOrWhiteSpace (test.Description)) section.Add (new StyledMultilineElement ("Description:", test.Description)); section.Add (new StyledMultilineElement ("Output:", log, UITableViewCellStyle.Subtitle)); Root = new RootElement (test.Name) { section }; }
public void buildReport() { Root = new RootElement (""); var v = new UIView (); v.Frame = new RectangleF (10, 10, 600, 10); var dummy = new Section (v); Root.Add (dummy); var headerLabel = new UILabel (new RectangleF (10, 10, 800, 48)) { Font = UIFont.BoldSystemFontOfSize (18), BackgroundColor = ColorHelper.GetGPPurple (), TextAlignment = UITextAlignment.Center, TextColor = UIColor.White, Text = "Branch Fee Target Progress" }; var view = new UIViewBordered (); view.Frame = new RectangleF (10, 20, 800, 48); view.Add (headerLabel); Root.Add (new Section (view)); for (int i = 0; i < report.branches.Count; i++) { Branch branch = report.branches [i]; Section s = new Section (branch.name); var t2 = new BigFinanceElement ("Invoiced MTD Total: ", branch.branchTotals.InvoicedMTDTotal); s.Add (t2); // Section s2 = new Section (branch.name + " Recorded MTD"); s2.Add (getElement (branch.branchTotals.recordedMTD.achieved, "Achieved: ")); s2.Add (getElement (branch.branchTotals.recordedMTD.estimatedTarget, "Estimated Target: ")); s2.Add (getElement (branch.branchTotals.recordedMTD.invoicedDebits, "Invoiced Debits: ")); s2.Add (getElement (branch.branchTotals.recordedMTD.unbilled, "Unbilled: ")); s2.Add (getElement (branch.branchTotals.recordedMTD.total, "Total: ")); // Section s21 = new Section (branch.name + " Recorded YTD"); s21.Add (getElement (branch.branchTotals.recordedYTD.achieved, "Achieved: ")); s21.Add (getElement (branch.branchTotals.recordedYTD.estimatedTarget, "Estimated Target: ")); s21.Add (getElement (branch.branchTotals.recordedYTD.invoiced, "Invoiced: ")); s21.Add (getElement (branch.branchTotals.recordedYTD.unbilled, "Unbilled: ")); s21.Add (getElement (branch.branchTotals.recordedYTD.total, "Total: ")); Root.Add (s); Root.Add (s2); Root.Add (s21); } for (var i = 0; i < 10; i++) { Root.Add (new Section (" ")); } }
public SelectBin(int startBin) : base(UITableViewStyle.Grouped, null) { this.Pushing = true; Root = new RootElement ("Bin "+startBin+" - "+(startBin+14)) {}; //var bins = DBConnection.getBins(startBin); var section = new Section () { }; for(int i=0;i<15;i++){ var newBinID=startBin+i; var theBinElem=new StringElement("Bin "+newBinID,()=>{ Console.WriteLine("BinID is"+ newBinID); var theBin=new ModifyBin(newBinID); this.NavigationController.PushViewController(theBin,true); }); section.Add(theBinElem); } /* foreach(Bin bin in bins){ var newBinID=bin.binID; var theBinElem=new StringElement("Bin "+newBinID,()=>{ Console.WriteLine("BinID is"+ newBinID); var theBin=new ModifyBin(newBinID); this.NavigationController.PushViewController(theBin,true); }); section.Add(theBinElem); } */ Root.Add(section); }
public EnumChoiceElement <T> CreateEnumElement <T>(string title, T value) where T : struct, IConvertible { var element = new EnumChoiceElement <T>(title, value); element.Tapped += () => { var ctrl = new DialogViewController(new RootElement(title), true); ctrl.Title = title; ctrl.Style = MonoTouch.UIKit.UITableViewStyle.Grouped; var sec = new MonoTouch.Dialog.Section(); foreach (var x in System.Enum.GetValues(typeof(T)).Cast <System.Enum>()) { sec.Add(new MonoTouch.Dialog.StyledStringElement(x.Description(), () => { element.Value = (T)Enum.ToObject(typeof(T), x); NavigationController.PopViewControllerAnimated(true); }) { Accessory = object.Equals(x, element.Value) ? MonoTouch.UIKit.UITableViewCellAccessory.Checkmark : MonoTouch.UIKit.UITableViewCellAccessory.None }); } ctrl.Root = new MonoTouch.Dialog.RootElement(title) { sec }; NavigationController.PushViewController(ctrl, true); }; return(element); }
public async override void ViewDidLoad () { base.ViewDidLoad (); // Open the folder for reading await Folder.OpenAsync (FolderAccess.ReadOnly); // Get the message summaries var summaries = await Folder.FetchAsync (0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.Envelope | MessageSummaryItems.InternalDate); var sectionMessages = new Section (); // Loop through all the message summaries foreach (var s in summaries) { // Add an item to the UI section/list sectionMessages.Add (new MessageElement (async (viewController, tableView, indexPath) => { // When a message is selected, fetch the actual message by UID var msg = await Folder.GetMessageAsync (summaries [indexPath.Row].UniqueId.Value); // Show the message details view controller viewMessageViewController = new MessageViewController (msg); NavigationController.PushViewController (viewMessageViewController, true); }) { Sender = s.Envelope.Sender.ToString (), Subject = s.Envelope.Subject, Body = "", Date = s.Envelope.Date.Value.LocalDateTime, NewFlag = false, MessageCount = 0, }); } Root.Clear (); Root.Add (sectionMessages); }
private void FoundResults(ParseObject[] array, NSError error) { var easySection = new Section("Easy"); var mediumSection = new Section("Medium"); var hardSection = new Section("Hard"); var objects = array.Select(x=> x.ToObject<GameScore>()).OrderByDescending(x=> x.Score).ToList(); foreach(var score in objects) { var element = new StringElement(score.Player,score.Score.ToString("#,###")); switch(score.Dificulty) { case GameDificulty.Easy: easySection.Add(element); break; case GameDificulty.Medium: mediumSection.Add(element); break; case GameDificulty.Hard: hardSection.Add (element); break; } } Root = new RootElement("High Scores") { easySection, mediumSection, hardSection, }; }
// Creates the dynamic content from the twitter results RootElement CreateDynamicContent (XDocument doc) { var users = doc.XPathSelectElements ("./statuses/status/user").ToArray (); var texts = doc.XPathSelectElements ("./statuses/status/text").Select (x=>x.Value).ToArray (); var people = doc.XPathSelectElements ("./statuses/status/user/name").Select (x=>x.Value).ToArray (); var section = new Section (); var root = new RootElement ("Tweets") { section }; for (int i = 0; i < people.Length; i++){ var line = new RootElement (people [i]) { new Section ("Profile"){ new StringElement ("Screen name", users [i].XPathSelectElement ("./screen_name").Value), new StringElement ("Name", people [i]), new StringElement ("oFllowers:", users [i].XPathSelectElement ("./followers_count").Value) }, new Section ("Tweet"){ new StringElement (texts [i]) } }; section.Add (line); } return root; }
private void LoadTable() { var imageCount = Data.Database.Main.Table<ProjectImage>().Count(); var allPatternsButton = new StyledElement("All UI Images", imageCount.ToString(), UITableViewCellStyle.Value1); if (imageCount > 0) { allPatternsButton.Accessory = UITableViewCellAccessory.DisclosureIndicator; allPatternsButton.Tapped += () => NavigationController.PushViewController(new LocalViewPatternsViewController() { Title = "All" }, true); } var section = new Section("Albums"); var projects = Data.Database.Main.Table<Project>(); foreach (var p in projects) { var project = p; var element = new ProjectElement(project); if (Data.Database.Main.Table<ProjectImage>().Where(a => a.ProjectId == project.Id).Count() > 0) { element.Accessory = UITableViewCellAccessory.DisclosureIndicator; element.Tapped += () => { NavigationController.PushViewController(new LocalViewPatternsViewController(project.Id) { Title = project.Name }, true); }; } section.Add(element); } var root = new RootElement(Title) { new Section() { allPatternsButton }, section }; Root = root; }
public void DemoHeadersFooters () { var section = new Section () { HeaderView = new UIImageView (UIImage.FromFile ("caltemplate.png")), #if !__TVOS__ FooterView = new UISwitch (new RectangleF (0, 0, 80, 30)), #endif // !__TVOS__ }; // Fill in some data var linqRoot = new RootElement ("LINQ source"){ from x in new string [] { "one", "two", "three" } select new Section (x) { from y in "Hello:World".Split (':') select (Element) new StringElement (y) } }; section.Add (new RootElement ("Desert", new RadioGroup ("desert", 0)){ new Section () { new RadioElement ("Ice Cream", "desert"), new RadioElement ("Milkshake", "desert"), new RadioElement ("Chocolate Cake", "desert") }, }); var root = new RootElement ("Headers and Footers") { section, new Section () { linqRoot } }; var dvc = new DialogViewController (root, true); navigation.PushViewController (dvc, true); }
public TankMix_History_Fill(List<Fill> Fills,int F) : base(UITableViewStyle.Grouped, null) { this.Pushing = true; Root = new RootElement ("Fills"); var Section = new Section (); for(int i=1; i<=F; i++) { var btn = new StringElement ("Fill "+i, string.Empty); btn.Tapped += () => { //this.NavigationController.PushViewController(new TankMix_CalculationCreateFill (Convert.ToInt32(btn.Caption.Split(' ')[1]),Fills,F),true); var index = Convert.ToInt32(btn.Caption.Split(' ')[1])-1; try{ this.NavigationController.PushViewController(new TankMix_CalculationCreateNewFill(Fills[index],index+1),true); }catch{ new UIAlertView ("Error", "This fill has no data !", null, "Continue").Show (); } }; Section.Add (btn); } Root.Add (Section); }
protected override void AddElementsInCaseOfEmptyList(MonoTouch.Dialog.Section items) { if (!supplier.CredentialsStorage.IsLoggedIn) { base.AddElementsInCaseOfEmptyList(items); return; } var createTemplateSuggestion = new MultilineElement("Sources was't found. Tap to create source spreadsheet at your Google Drive "); createTemplateSuggestion.Tapped += () => { this.ExecuteAsync(supplier.CreateTemplate, () => { PopulateSources(); var dialod = new UIAlertView("Done", "Spreadsheet with name MemorizeIt was created at your Google Drive", null, "I got it!", null); dialod.Show(); }); }; items.Add(createTemplateSuggestion); }
void Populate(JsonValue json, RootElement root, JsonValue data) { if (json.ContainsKey("title")) { root.Caption = json["title"]; } JsonValue jsonRoot = null; try { jsonRoot = json["root"]; } catch (Exception) { Console.WriteLine("Bad JSON: could not find the root element - " + json.ToString()); return; } foreach (JsonObject section in jsonRoot) { var sec = new Section(section.s("caption"), section.s("footer")); if (section.ContainsKey("elements")) { foreach (JsonObject elem in section["elements"]) { var dataForElement = data; var bindExpression = elem.s("bind"); if (bindExpression != null) { try { if (data != null && data.JsonType == JsonType.Object) { var bind = elem.s("bind"); if (data != null && !string.IsNullOrEmpty(bind) && data.ContainsKey(bind)) { dataForElement = data[bind]; } } else if (bindExpression.StartsWith("#")) { dataForElement = _controller.GetValue(bindExpression.Replace("#", "")); } } catch (Exception) { Console.WriteLine("Exception when binding element " + elem.ToString()); } } _parseElement(elem, sec, dataForElement); } } else if (section.ContainsKey("iterate") && data != null) { string iterationname = section["iterate"]; string emptyMessage = section.ContainsKey("empty") ? section["empty"].CleanString() : "Empty"; var iterationdata = string.IsNullOrEmpty(iterationname) ? (JsonArray)data : (JsonArray)data[iterationname]; var template = (JsonObject)section["template"]; var items = iterationdata.ToList(); if (items.Count > 0) { foreach (JsonValue v in items) { _parseElement(template, sec, v); } } else { sec.Add(new EmptyListElement(emptyMessage)); } } else if (section.ContainsKey("iterateproperties") && data != null) { string iterationname = section["iterateproperties"]; string emptyMessage = section.ContainsKey("empty") ? section["empty"].CleanString() : "Empty"; var iterationdata = string.IsNullOrEmpty(iterationname) ? (JsonObject)data : (JsonObject)data[iterationname]; var template = (JsonObject)section["template"]; var items = iterationdata.Keys; if (items.Count > 0) { foreach (string v in items) { var obj = new JsonObject(); obj.Add(v, iterationdata[v]); _parseElement(template, sec, obj); } } else { sec.Add(new EmptyListElement(emptyMessage)); } } root.Add(sec); } }
private Element GetElementForMember(object dataContext, MemberInfo member) { string caption = null; Element element = null; var bindings = new List <Binding>(); var captionAttribute = member.GetCustomAttribute <CaptionAttribute>(); var orderAttribute = member.GetCustomAttribute <OrderAttribute>(); var bindAttributes = member.GetCustomAttributes(typeof(BindAttribute), false); var popOnSelectionAttribute = member.GetCustomAttribute <PopOnSelectionAttribute>(); // var memberDataContext = GetDataContextForMember(dataContext, ref member); var memberDataContext = dataContext; if (captionAttribute != null) { caption = captionAttribute.Caption; } else { caption = MakeCaption(member.Name); } Type memberType = GetTypeForMember(member); if (!(member is MethodInfo)) { foreach (BindAttribute bindAttribute in bindAttributes) { bindings.Add(bindAttribute.Binding); } var valueBinding = bindings.Where((b) => b.TargetPath == "Value").FirstOrDefault() != null; if (!valueBinding) { bindings.Add(new Binding(member.Name, null)); } foreach (var binding in bindings) { if (string.IsNullOrEmpty(binding.SourcePath)) { binding.SourcePath = member.Name; } // else { var sourceDataContext = memberDataContext; var sourceProperty = sourceDataContext.GetType().GetNestedProperty(ref sourceDataContext, binding.SourcePath, true); if (sourceProperty == null) { sourceDataContext = dataContext; sourceProperty = sourceDataContext.GetType().GetNestedProperty(ref sourceDataContext, binding.SourcePath, true); } binding.Source = sourceDataContext; } } } if (_ElementPropertyMap.ContainsKey(memberType)) { element = _ElementPropertyMap[memberType](member, caption, dataContext, bindings); } else if (memberType.IsEnum) { SetDefaultConverter(member, "Value", new EnumConverter() { PropertyType = memberType }, bindings); var csection = new Section(); var currentValue = GetValue(member, memberDataContext); int index = 0; int selected = 0; var pop = popOnSelectionAttribute != null; foreach (Enum value in Enum.GetValues(memberType)) { if (currentValue == value) { selected = index; } csection.Add(new RadioElement(value.GetDescription(), pop) { Index = index, Value = false }); index++; } element = new RootElement <int>(caption, new RadioGroup(memberType.FullName, selected)) { csection }; element.Caption = caption; ((IRoot)element).Group = new RadioGroup(memberType.FullName, selected) { EnumType = memberType }; ((IRoot)element).CellStyle = UITableViewCellStyle.Value1; } else if (typeof(EnumCollection).IsAssignableFrom(memberType)) { SetDefaultConverter(member, "Value", new EnumItemsConverter(), bindings); var csection = new Section() { IsMultiselect = true }; var collection = GetValue(member, memberDataContext); if (collection == null) { var collectionType = typeof(EnumCollection <>); var enumType = memberType.GetGenericArguments()[0]; Type[] generic = { enumType }; collection = Activator.CreateInstance(collectionType.MakeGenericType(generic)); (member as PropertyInfo).SetValue(memberDataContext, collection, new object[] {}); } var index = 0; var items = (EnumCollection)collection; foreach (var item in items.AllValues) { csection.Add(new CheckboxElement(item.Description, item.IsChecked, item.GroupName) { Index = index }); index++; } element = new RootElement <int>(caption) { csection }; ((IRoot)element).CellStyle = GetCellStyle(member, UITableViewCellStyle.Value1); } else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(memberType)) { SetDefaultConverter(member, "Value", new EnumerableConverter(), bindings); ListBoxElement listBox = new ListBoxElement(); int index = 0; Type viewType = memberType.GetGenericArguments()[0]; var rootAttribute = member.GetCustomAttribute <RootAttribute>(); var items = (IEnumerable)GetValue(member, memberDataContext); foreach (var e in items) { Element newElement = null; newElement = CreateGenericRoot(viewType, null, e); if (rootAttribute != null) { ((IRoot)newElement).ElementType = rootAttribute.DataTemplateType; } ((IRoot)newElement).ToolbarButtons = CheckForToolbarItems(e); ((IRoot)newElement).NavbarButtons = CheckForNavbarItems(e); listBox.Add(newElement); index++; } element = CreateGenericRoot(memberType, listBox, null); element.Caption = caption; ((IRoot)element).CellStyle = GetCellStyle(member, UITableViewCellStyle.Default); } else { var nested = GetValue(member, memberDataContext); if (nested != null) { var newRoot = CreateGenericRoot(memberType, null, nested); newRoot.Caption = caption; ((IRoot)newRoot).CellStyle = GetCellStyle(member, UITableViewCellStyle.Default); ((IRoot)newRoot).ToolbarButtons = CheckForToolbarItems(nested); ((IRoot)newRoot).NavbarButtons = CheckForNavbarItems(nested); element = newRoot; } } if (orderAttribute != null && element != null) { element.Order = orderAttribute.Order; } var bindable = element as IBindable; if (bindable != null && bindings.Count != 0) { foreach (Binding binding in bindings) { if (binding.TargetPath == null) { binding.TargetPath = "Value"; } BindingOperations.SetBinding(bindable, binding.TargetPath, binding); } } return(element); }
void LoadSectionElements(Section section, JsonArray array, object data) { if (array == null) { return; } for (int i = 0; i < array.Count; i++) { Element element = null; try { var json = array [i] as JsonObject; if (json == null) { continue; } var type = GetString(json, "type"); switch (type) { case "bool": case "boolean": element = LoadBoolean(json); break; case "entry": case "password": element = LoadEntry(json, type == "password"); break; case "string": element = LoadString(json, data); break; case "root": element = FromJson(this, json, data); break; case "radio": element = LoadRadio(json, data); break; case "checkbox": element = LoadCheckbox(json, data); break; case "datetime": case "date": case "time": element = LoadDateTime(json, type); break; case "html": element = LoadHtmlElement(json); break; default: Error("json element at {0} contain an unknown type `{1}', json {2}", i, type, json); break; } if (element != null) { var id = GetString(json, "id"); if (id != null) { AddMapping(id, element); } } } catch (Exception e) { Console.WriteLine("Error processing Json {0}, exception {1}", array, e); } if (element != null) { section.Add(element); } } }
void Populate(object callbacks, object o, RootElement root) { MemberInfo last_radio_index = null; var members = o.GetType().GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); Section section = null; foreach (var mi in members) { Type mType = GetTypeForMember(mi); if (mType == null) { continue; } string caption = null; object [] attrs = mi.GetCustomAttributes(false); bool skip = false; foreach (var attr in attrs) { if (attr is SkipAttribute || attr is System.Runtime.CompilerServices.CompilerGeneratedAttribute) { skip = true; } else if (attr is CaptionAttribute) { caption = ((CaptionAttribute)attr).Caption; } else if (attr is SectionAttribute) { if (section != null) { root.Add(section); } var sa = attr as SectionAttribute; section = new Section(sa.Caption, sa.Footer); } } if (skip) { continue; } if (caption == null) { caption = MakeCaption(mi.Name); } if (section == null) { section = new Section(); } Element element = null; if (mType == typeof(string)) { PasswordAttribute pa = null; AlignmentAttribute align = null; EntryAttribute ea = null; object html = null; NSAction invoke = null; bool multi = false; foreach (object attr in attrs) { if (attr is PasswordAttribute) { pa = attr as PasswordAttribute; } else if (attr is EntryAttribute) { ea = attr as EntryAttribute; } else if (attr is MultilineAttribute) { multi = true; } else if (attr is HtmlAttribute) { html = attr; } else if (attr is AlignmentAttribute) { align = attr as AlignmentAttribute; } if (attr is OnTapAttribute) { string mname = ((OnTapAttribute)attr).Method; if (callbacks == null) { throw new Exception("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor"); } var method = callbacks.GetType().GetMethod(mname); if (method == null) { throw new Exception("Did not find method " + mname); } invoke = delegate { method.Invoke(method.IsStatic ? null : callbacks, new object [0]); }; } } string value = (string)GetValue(mi, o); if (pa != null) { element = new EntryElement(caption, pa.Placeholder, value, true); } else if (ea != null) { element = new EntryElement(caption, ea.Placeholder, value) { KeyboardType = ea.KeyboardType, AutocapitalizationType = ea.AutocapitalizationType, AutocorrectionType = ea.AutocorrectionType, ClearButtonMode = ea.ClearButtonMode } } ; else if (multi) { element = new MultilineElement(caption, value); } else if (html != null) { element = new HtmlElement(caption, value); } else { var selement = new StringElement(caption, value); element = selement; if (align != null) { selement.Alignment = align.Alignment; } } if (invoke != null) { ((StringElement)element).Tapped += invoke; } } else if (mType == typeof(float)) { var floatElement = new FloatElement(null, null, (float)GetValue(mi, o)); floatElement.Caption = caption; element = floatElement; foreach (object attr in attrs) { if (attr is RangeAttribute) { var ra = attr as RangeAttribute; floatElement.MinValue = ra.Low; floatElement.MaxValue = ra.High; floatElement.ShowCaption = ra.ShowCaption; } } } else if (mType == typeof(bool)) { bool checkbox = false; foreach (object attr in attrs) { if (attr is CheckboxAttribute) { checkbox = true; } } if (checkbox) { element = new CheckboxElement(caption, (bool)GetValue(mi, o)); } else { element = new BooleanElement(caption, (bool)GetValue(mi, o)); } } else if (mType == typeof(DateTime)) { var dateTime = (DateTime)GetValue(mi, o); bool asDate = false, asTime = false; foreach (object attr in attrs) { if (attr is DateAttribute) { asDate = true; } else if (attr is TimeAttribute) { asTime = true; } } if (asDate) { element = new DateElement(caption, dateTime); } else if (asTime) { element = new TimeElement(caption, dateTime); } else { element = new DateTimeElement(caption, dateTime); } } else if (mType.IsEnum) { var csection = new Section(); ulong evalue = Convert.ToUInt64(GetValue(mi, o), null); int idx = 0; int selected = 0; foreach (var fi in mType.GetFields(BindingFlags.Public | BindingFlags.Static)) { ulong v = Convert.ToUInt64(GetValue(fi, null)); if (v == evalue) { selected = idx; } CaptionAttribute ca = Attribute.GetCustomAttribute(fi, typeof(CaptionAttribute)) as CaptionAttribute; csection.Add(new RadioElement(ca != null ? ca.Caption : MakeCaption(fi.Name))); idx++; } element = new RootElement(caption, new RadioGroup(null, selected)) { csection }; } else if (mType == typeof(UIImage)) { element = new ImageElement((UIImage)GetValue(mi, o)); } else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(mType)) { var csection = new Section(); int count = 0; if (last_radio_index == null) { throw new Exception("IEnumerable found, but no previous int found"); } foreach (var e in (IEnumerable)GetValue(mi, o)) { csection.Add(new RadioElement(e.ToString())); count++; } int selected = (int)GetValue(last_radio_index, o); if (selected >= count || selected < 0) { selected = 0; } element = new RootElement(caption, new MemberRadioGroup(null, selected, last_radio_index)) { csection }; last_radio_index = null; } else if (typeof(int) == mType) { foreach (object attr in attrs) { if (attr is RadioSelectionAttribute) { last_radio_index = mi; break; } } } else { var nested = GetValue(mi, o); if (nested != null) { var newRoot = new RootElement(caption); Populate(callbacks, nested, newRoot); element = newRoot; } } if (element == null) { continue; } section.Add(element); mappings [element] = new MemberAndInstance(mi, o); } root.Add(section); }
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; }