Inheritance: StringElement, IElementSizing
        private static RootElement CreateRootElement()
        {
            using (var bindingSet = new BindingSet<MainViewModel>())
            {
                var root = new RootElement("Main view");
                var section = new Section();
                var element = new MultilineElement(string.Empty);
                bindingSet.Bind(element, () => e => e.Caption)
                    .To(() => (vm, ctx) => vm.ResourceUsageInfo);
                section.Add(element);
                root.Add(section);

                section = new Section("Samples");
                root.Add(section);
                bindingSet.Bind(section, AttachedMemberConstants.ItemsSource).To(() => (vm, ctx) => vm.Items);
                section.SetBindingMemberValue(AttachedMembers.Element.ItemTemplateSelector, ButtonItemTemplate.Instance);
                return root;
            }
        }
        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);
        }
        public override void ViewDidLoad()
        {
            //maybe i don't need this controler at all?!?!

            base.ViewDidLoad ();
            //this.TableView.Source = new DateTableViewSource ();
            var section = new Section ("New Checkpoint:");

            var nameElement = new EntryElement ("name", "Name your checkpoint", "");
            var instructions = new MultilineElement ("specify the time that you expect to complete this checkpoint, each day:");

            var targetElement = new TimeElement ("target", DateTime.Now);

            var aCell = new DatePickerCell(UIDatePickerMode.Time,DateTime.Now)
            {
                Key = "1234",
            };
            aCell.TextLabel.Text = "Date";
            aCell.RightLabelTextAlignment = UITextAlignment.Right;
            aCell.OnItemChanged += (object sender, PickerCellArgs e) => {

                var result = e.Items;
            };

            var saveButton = new StringElement ("save",
                () =>{
                    this.Parent.AddNewCheckPoint(nameElement.Value,targetElement.DateValue.TimeOfDay);
                    this.DismissModalViewController(true);
                }){Alignment=UITextAlignment.Right};

            var cancelButton = new StringElement ("cancel",
                () =>{
                    this.DismissModalViewController(true);
                }){Alignment=UITextAlignment.Right};

            section.AddAll (new Element[]{ nameElement, instructions, targetElement, saveButton,cancelButton });
            this.Root.Add (section);
        }
Esempio n. 4
0
		void Populate (object callbacks, object o, RootElement root)
		{
			MemberInfo last_radio_index = null;
			
			BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance;
			if (Attribute.GetCustomAttribute(o.GetType (), typeof(SkipNonPublicAttribute)) == null)
				flags |= BindingFlags.NonPublic;
			var members = o.GetType ().GetMembers (flags);

			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)
						skip = true;
					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 };
					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;
						
						csection.Add (new RadioElement (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);
		}
Esempio n. 5
0
		//
		// Creates one of the various StringElement classes, based on the
		// properties set.   It tries to load the most memory efficient one
		// StringElement, if not, it fallsback to MultilineStringElement or
		// StyledStringElement
		//
		static Element LoadString (JsonObject json, object data)
		{
			string value = null;
			string caption = value;
			string background = null;
			NSAction ontap = null;
			NSAction onaccessorytap = null;
			int? lines = null;
			UITableViewCellAccessory? accessory = null;
			UILineBreakMode? linebreakmode = null;
			UITextAlignment? alignment = null;
			UIColor textcolor = null, detailcolor = null;
			UIFont font = null;
			UIFont detailfont = null;
			UITableViewCellStyle style = UITableViewCellStyle.Value1;

			foreach (var kv in json){
				string kvalue = (string) kv.Value;
				switch (kv.Key){
				case "caption":
					caption = kvalue;
					break;
				case "value":
					value = kvalue;
					break;
				case "background":	
					background = kvalue;
					break;
				case "style":
					style = ToCellStyle (kvalue);
					break;
				case "ontap": case "onaccessorytap":
					string sontap = kvalue;
					int p = sontap.LastIndexOf ('.');
					if (p == -1)
						break;
					NSAction d = delegate {
						string cname = sontap.Substring (0, p);
						string mname = sontap.Substring (p+1);
						foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()){
							Type type = a.GetType (cname);
						
							if (type != null){
								var mi = type.GetMethod (mname, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
								if (mi != null)
									mi.Invoke (null, new object [] { data });
								break;
							}
						}
					};
					if (kv.Key == "ontap")
						ontap = d;
					else
						onaccessorytap = d;
					break;
				case "lines":
					int res;
					if (int.TryParse (kvalue, out res))
						lines = res;
					break;
				case "accessory":
					accessory = ToAccessory (kvalue);
					break;
				case "textcolor":
					textcolor = ParseColor (kvalue);
					break;
				case "linebreak":
					linebreakmode = ToLinebreakMode (kvalue);
					break;
				case "font":
					font = ToFont (kvalue);
					break;
				case "subtitle":
					value = kvalue;
					style = UITableViewCellStyle.Subtitle;
					break;
				case "detailfont":
					detailfont = ToFont (kvalue);
					break;
				case "alignment":
					alignment = ToAlignment (kvalue);
					break;
				case "detailcolor":
					detailcolor = ParseColor (kvalue);
					break;
				case "type":
					break;
				default:
					Console.WriteLine ("Unknown attribute: '{0}'", kv.Key);
					break;
				}
			}
			if (caption == null)
				caption = "";
			if (font != null || style != UITableViewCellStyle.Value1 || detailfont != null || linebreakmode.HasValue || textcolor != null || accessory.HasValue || onaccessorytap != null || background != null || detailcolor != null){
				StyledStringElement styled;
				
				if (lines.HasValue){
					styled = new StyledMultilineElement (caption, value, style);
					styled.Lines = lines.Value;
				} else {
					styled = new StyledStringElement (caption, value, style);
				}
				if (ontap != null)
					styled.Tapped += ontap;
				if (onaccessorytap != null)
					styled.AccessoryTapped += onaccessorytap;
				if (font != null)
					styled.Font = font;
				if (detailfont != null)
					styled.SubtitleFont = detailfont;
				if (detailcolor != null)
					styled.DetailColor = detailcolor;
				if (textcolor != null)
					styled.TextColor = textcolor;
				if (accessory.HasValue)
					styled.Accessory = accessory.Value;
				if (linebreakmode.HasValue)
					styled.LineBreakMode = linebreakmode.Value;
				if (background != null){
					if (background.Length > 1 && background [0] == '#')
						styled.BackgroundColor = ParseColor (background);
					else
						styled.BackgroundUri = new Uri (background);
				}
				if (alignment.HasValue)
					styled.Alignment = alignment.Value;
				return styled;
			} else {
				StringElement se;
				if (lines == 0)
					se = new MultilineElement (caption, value);
				else
					se = new StringElement (caption, value);
				if (alignment.HasValue)
					se.Alignment = alignment.Value;
				if (ontap != null)
					se.Tapped += ontap;
				return se;
			}
		}
Esempio n. 6
0
		void Credits ()
		{
			var title = new MultilineElement ("Touch.Unit Runner\nCopyright 2011-2012 Xamarin Inc.\nAll rights reserved.");
			title.Alignment = UITextAlignment.Center;
			
			var root = new RootElement ("Credits") {
				new Section () { title },
				new Section () {
					new HtmlElement ("About Xamarin", "http://www.xamarin.com"),
					new HtmlElement ("About MonoTouch", "http://ios.xamarin.com"),
					new HtmlElement ("About MonoTouch.Dialog", "https://github.com/migueldeicaza/MonoTouch.Dialog"),
					new HtmlElement ("About NUnitLite", "http://www.nunitlite.org"),
					new HtmlElement ("About Font Awesome", "http://fortawesome.github.com/Font-Awesome")
				}
			};
				
			var dv = new DialogViewController (root, true) { Autorotate = true };
			NavigationController.PushViewController (dv, true);				
		}
Esempio n. 7
0
		private void BuildElementPropertyMap()
		{
			_ElementPropertyMap = new Dictionary<Type, Func<MemberInfo, string, object, List<Binding>, Element>>();
			_ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
	
				var buttonAttribute = member.GetCustomAttribute<ButtonAttribute>();
				if (buttonAttribute != null)
				{	
					element = new ButtonElement(caption)
					{
						BackgroundColor = buttonAttribute.BackgroundColor,
						TextColor = buttonAttribute.TextColor,
						Command = GetCommandForMember(dataContext, member)
					};
				}

				return element;
			});

			_ElementPropertyMap.Add(typeof(CLLocationCoordinate2D), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
		
				var mapAttribute = member.GetCustomAttribute<MapAttribute>();
				var location = (CLLocationCoordinate2D)GetValue(member, dataContext);
				if (mapAttribute != null)
					element = new MapElement(mapAttribute.Caption, mapAttribute.Value, location);

				return element;
			});

			_ElementPropertyMap.Add(typeof(string), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
	
				var passwordAttribute = member.GetCustomAttribute<PasswordAttribute>();
				var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
				var multilineAttribute = member.GetCustomAttribute<MultilineAttribute>();
				var htmlAttribute = member.GetCustomAttribute<HtmlAttribute>();
				var alignmentAttribute = member.GetCustomAttribute<AlignmentAttribute>();
		
				if (passwordAttribute != null)
					element = new EntryElement(caption, passwordAttribute.Placeholder, true);
				else if (entryAttribute != null)
					element = new EntryElement(caption, entryAttribute.Placeholder) { KeyboardType = entryAttribute.KeyboardType };
				else if (multilineAttribute != null)
					element = new MultilineElement(caption);
				else if (htmlAttribute != null)
				{
					SetDefaultConverter(member, "Value", new UriConverter(), bindings);
					element = new HtmlElement(caption);
				}
				else
				{
					var selement = new StringElement(caption, (string)GetValue(member, dataContext));
					
					if (alignmentAttribute != null)
						selement.Alignment = alignmentAttribute.Alignment;
					
					element = selement;
				}

				var tappable = element as ITappable;
				if (tappable != null)
					((ITappable)element).Command = GetCommandForMember(dataContext, member);
				
				return element;
			});

			_ElementPropertyMap.Add(typeof(float), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
				var rangeAttribute = member.GetCustomAttribute<RangeAttribute>();
				if (rangeAttribute != null)
				{
					var floatElement = new FloatElement() {  };
					floatElement.Caption = caption;
					element = floatElement;
					
					floatElement.MinValue = rangeAttribute.Low;
					floatElement.MaxValue = rangeAttribute.High;
					floatElement.ShowCaption = rangeAttribute.ShowCaption;
				}
				else 
				{		
					var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
					var placeholder = "";
					var keyboardType = UIKeyboardType.NumberPad;

					if(entryAttribute != null)
					{
						placeholder = entryAttribute.Placeholder;
						if(entryAttribute.KeyboardType != UIKeyboardType.Default)
							keyboardType = entryAttribute.KeyboardType;
					}

					element = new EntryElement(caption, placeholder, "") { KeyboardType = keyboardType };
				}

				return element;
			});
			
			_ElementPropertyMap.Add(typeof(Uri), (member, caption, dataContext, bindings)=>
			{
				return new HtmlElement(caption, (Uri)GetValue(member, dataContext));  
			});

			_ElementPropertyMap.Add(typeof(bool), (member, caption, dataContext, bindings)=>
			{
				Element element = null;

				var checkboxAttribute = member.GetCustomAttribute<CheckboxAttribute>();
				if (checkboxAttribute != null)
				    element = new CheckboxElement(caption) {  };
				else
					element = new BooleanElement(caption) {  };

				return element;
			});

			_ElementPropertyMap.Add(typeof(DateTime), (member, caption, dataContext, bindings)=>
			{
				Element element = null;

				var dateAttribute = member.GetCustomAttribute<DateAttribute>();
				var timeAttribute = member.GetCustomAttribute<TimeAttribute>();

				if(dateAttribute != null)
					element = new DateElement(caption);
				else if (timeAttribute != null)
					element = new TimeElement(caption);
				else
					element = new DateTimeElement(caption);
				
				return element;
			});

			_ElementPropertyMap.Add(typeof(UIImage),(member, caption, dataContext, bindings)=>
			{
				return new ImageElement();
			});

			_ElementPropertyMap.Add(typeof(int), (member, caption, dataContext, bindings)=>
			{
				return new StringElement(caption) { Value = GetValue(member, dataContext).ToString() };
			});
		}
		public RootElement getUI(MovieEntry entry){
		
			NSUrl url = new NSUrl(entry.MovieThumbnail);
			NSData data = NSData.FromUrl(url);
			UIImage MovieThumb = new UIImage (data);

			UIImage Rotten = UIImage.FromBundle ("rotten.png");
			UIImage Fresh = UIImage.FromBundle ("fresh.png");
			UIImage DontKnow = UIImage.FromBundle ("QuestionMark.png");

			System.Drawing.SizeF size = new System.Drawing.SizeF ();
			size.Height = 3;
			size.Width = 3;
			Rotten.Scale (size);
			Fresh.Scale (size);
			DontKnow.Scale (size);

			String Director_String=""; 
			String Genre_String = "";
			foreach(var directors in entry.Directors){

				Director_String = Director_String +  +directors+" " ;
			}

			foreach (var genre in entry.Genres) {
			
				Genre_String = Genre_String +genre+" ";
			}

			var Actor_Section = new Section ("Actors");

			Console.WriteLine ("CompleteCast count"+entry.CompleteCast.Count);
			Console.WriteLine ("Abridged Cast Count" + entry.AbridgedCast.Count);

			foreach (var actor in entry.AbridgedCast) {

				var elem = new StyledStringElement (actor.Name , actor.Charachter, UITableViewCellStyle.Subtitle);
				Actor_Section.Add (elem);
				
			}

			var Reviews_Section = new Section ("Reviews");

			foreach (var review in entry.ListOfCritics.Critic_Info) {
				BadgeElement elem = null;
				if(review.FreshOrRotten==true){
					elem = new BadgeElement (Fresh, review.NameOfCritic+", "+review.MediaSourceOfCritc+Environment.NewLine+Environment.NewLine+review.BriefCriticReview);
					elem.LineBreakMode = UILineBreakMode.WordWrap;
					elem.Lines = 0;
					elem.Font = UIFont.FromName ("AmericanTypeWriter", 8f);
				}else if(review.FreshOrRotten==false){
					elem = new BadgeElement (Rotten, review.NameOfCritic+", "+review.MediaSourceOfCritc+Environment.NewLine+Environment.NewLine+review.BriefCriticReview);
					elem.LineBreakMode = UILineBreakMode.WordWrap;
					elem.Lines = 0;
					elem.Font = UIFont.FromName ("AmericanTypeWriter", 8f);
				}else{
					elem = new BadgeElement (DontKnow, review.NameOfCritic+", "+review.MediaSourceOfCritc+Environment.NewLine+Environment.NewLine+review.BriefCriticReview);
					elem.LineBreakMode = UILineBreakMode.WordWrap;
					elem.Lines = 0;
					elem.Font = UIFont.FromName ("AmericanTypeWriter", 8f);
				}

				Reviews_Section.Add (elem);
			}

			var Movie_Title = new Section (entry.MovieTitle);

			var Movie_Title_Element = new BadgeElement(MovieThumb,entry.OverallCriticScore +"% Of Critics liked it." + Environment.NewLine + entry.AbridgedCast [0].Name + ", " + entry.AbridgedCast [1].Name + Environment.NewLine + entry.MPAA_Rating + ", " + entry.Runtime + Environment.NewLine + entry.TheatreReleaseDate);

			Movie_Title_Element.Font = UIFont.FromName ("AmericanTypeWriter", 10f);
			Movie_Title_Element.LineBreakMode = UILineBreakMode.WordWrap;
			Movie_Title_Element.Lines = 0;

			Movie_Title.Add (Movie_Title_Element);

			var Movie_Info_Section = new Section ("Movie Details");
			var DirectorElem = new StyledStringElement("Director Names: ",Director_String,UITableViewCellStyle.Subtitle);
			var RatingElem = new StyledStringElement ("Rated: ", entry.MPAA_Rating, UITableViewCellStyle.Subtitle);
			var RunningElem = new StyledStringElement ("Running Time: ", entry.Runtime, UITableViewCellStyle.Subtitle);
			var GenreElem = new StyledStringElement ("Genre: ", Genre_String, UITableViewCellStyle.Subtitle);
			var TheatreReleaseElem = new StyledStringElement ("Theatre Release Date: ", entry.TheatreReleaseDate, UITableViewCellStyle.Subtitle);


			Movie_Info_Section.Add (DirectorElem);
			Movie_Info_Section.Add (RatingElem);
			Movie_Info_Section.Add (RunningElem);
			Movie_Info_Section.Add (GenreElem);
			Movie_Info_Section.Add (TheatreReleaseElem);

			var Synopsis_Sec = new Section ("Synopsis");

			var SysnopsisElem = new MultilineElement ("Synopsis", entry.Synopsis);

			Synopsis_Sec.Add (SysnopsisElem);

			var Links_Section = new Section ("Links");
			var Root_Element = new RootElement ("MOVIE DETAILS");

			Root_Element.Add (Movie_Title);
			Root_Element.Add (Movie_Info_Section);
	
			Root_Element.Add (Actor_Section);

			Root_Element.Add (Reviews_Section);

			return Root_Element;
		}
Esempio n. 9
0
        private Element CreateElement(ApiNode element, ApiNode parentNode)
        {
            string childType = parentNode["childType"];
            string childAction = parentNode["childAction"];

            // if there is an item call for the api, build the url here
            if (parentNode.ApiItemUrl != null)
                element.ApiUrl = String.Format(parentNode.ApiItemUrl, element.Id);

            // copy parent values to the children
            if (parentNode["contentNode"] != null)
                element["contentNode"] = parentNode["contentNode"];

            if (parentNode["bannerImgUrl"] != null)
                element["bannerImgUrl"] = parentNode["bannerImgUrl"];

            Func<ApiNode, UIViewController> selectedAction = null;

            if (element.Title.Contains("&#039;"))
                element.Title = element.Title.Replace("&#039;","'");

            switch(childAction)
            {
                case "video":
                    selectedAction = ApiVideoElement.VideoSelected;
                    break;
                case "audio":
                    selectedAction = ApiVideoElement.AudioSelected;
                    break;
                default:
                    selectedAction = ApiVideoElement.HtmlSelected;
                    break;
            }

            switch (childType)
            {
                case "detailedImage":

                    return new DetailedImageElement(element, selectedAction);

                case "htmlContent":

                    // try to combine date and reference for a description
                    if(element.Description == null)
                        element.Description = String.Format("{0}\n{1}", element["date"], element["reference"]);

                    if(element["bannerImgUrl"] != null)
                        return new ApiBannerElement(element, selectedAction);

                    return new ApiDetailElement(element, selectedAction);

                default:
                    var strElement = new MultilineElement(element.Title, element["description"]);

                    //strElement.
                    return strElement;
            }
        }
Esempio n. 10
0
		void Populate (object callbacks, object o, RootElement root)
		{
			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);
				foreach (var attr in attrs){
					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 (caption == null)
					caption = MakeCaption (mi.Name);
				
				if (section == null)
					section = new Section ();
				
				Element element = null;
				if (mType == typeof (string)){
					PasswordAttribute pa = null;
					EntryAttribute ea = 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;
						
						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);
					else if (multi)
						element = new MultilineElement (caption, value);
					else
						element = new StringElement (caption, value);
					
					if (invoke != null)
						((StringElement) element).Tapped += invoke;
				} else if (mType == typeof (float)){
					var floatElement = new FloatElement (null, null, (float) GetValue (mi, o));
					element = floatElement;
					
					foreach (object attr in attrs){
						if (attr is RangeAttribute){
							var ra = attr as RangeAttribute;
							floatElement.MinValue = ra.Low;
							floatElement.MaxValue = ra.High;
						}
					}
				} 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;
						
						csection.Add (new RadioElement (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 {
					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);
		}
Esempio n. 11
0
        //
        // Creates one of the various StringElement classes, based on the
        // properties set.   It tries to load the most memory efficient one
        // StringElement, if not, it fallsback to MultilineStringElement or
        // StyledStringElement
        //
        static Element LoadString(JsonObject json, object data)
        {
            string   value = null;
            string   caption = value;
            string   background = null;
            NSAction ontap = null;
            NSAction onaccessorytap = null;
            int?     lines = null;
            UITableViewCellAccessory?accessory = null;
            UILineBreakMode?         linebreakmode = null;
            UITextAlignment?         alignment = null;
            UIColor textcolor = null, detailcolor = null;
            UIFont  font = null;
            UIFont  detailfont         = null;
            UITableViewCellStyle style = UITableViewCellStyle.Value1;

            foreach (var kv in json)
            {
                string kvalue = (string)kv.Value;
                switch (kv.Key)
                {
                case "caption":
                    caption = kvalue;
                    break;

                case "value":
                    value = kvalue;
                    break;

                case "background":
                    background = kvalue;
                    break;

                case "style":
                    style = ToCellStyle(kvalue);
                    break;

                case "ontap":
                case "onaccessorytap":
                    string sontap = kvalue;
                    int    p      = sontap.LastIndexOf('.');
                    if (p == -1)
                    {
                        break;
                    }
                    NSAction d = delegate {
                        string cname = sontap.Substring(0, p);
                        string mname = sontap.Substring(p + 1);
                        foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
                        {
                            Type type = a.GetType(cname);

                            if (type != null)
                            {
                                var mi = type.GetMethod(mname, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                                if (mi != null)
                                {
                                    mi.Invoke(null, new object [] { data });
                                }
                                break;
                            }
                        }
                    };
                    if (kv.Key == "ontap")
                    {
                        ontap = d;
                    }
                    else
                    {
                        onaccessorytap = d;
                    }
                    break;

                case "lines":
                    int res;
                    if (int.TryParse(kvalue, out res))
                    {
                        lines = res;
                    }
                    break;

                case "accessory":
                    accessory = ToAccessory(kvalue);
                    break;

                case "textcolor":
                    textcolor = ParseColor(kvalue);
                    break;

                case "linebreak":
                    linebreakmode = ToLinebreakMode(kvalue);
                    break;

                case "font":
                    font = ToFont(kvalue);
                    break;

                case "subtitle":
                    value = kvalue;
                    style = UITableViewCellStyle.Subtitle;
                    break;

                case "detailfont":
                    detailfont = ToFont(kvalue);
                    break;

                case "alignment":
                    alignment = ToAlignment(kvalue);
                    break;

                case "detailcolor":
                    detailcolor = ParseColor(kvalue);
                    break;

                case "type":
                    break;

                default:
                    Console.WriteLine("Unknown attribute: '{0}'", kv.Key);
                    break;
                }
            }
            if (caption == null)
            {
                caption = "";
            }
            if (font != null || style != UITableViewCellStyle.Value1 || detailfont != null || linebreakmode.HasValue || textcolor != null || accessory.HasValue || onaccessorytap != null || background != null || detailcolor != null)
            {
                StyledStringElement styled;

                if (lines.HasValue)
                {
                    styled       = new StyledMultilineElement(caption, value, style);
                    styled.Lines = lines.Value;
                }
                else
                {
                    styled = new StyledStringElement(caption, value, style);
                }
                if (ontap != null)
                {
                    styled.Tapped += ontap;
                }
                if (onaccessorytap != null)
                {
                    styled.AccessoryTapped += onaccessorytap;
                }
                if (font != null)
                {
                    styled.Font = font;
                }
                if (detailfont != null)
                {
                    styled.SubtitleFont = detailfont;
                }
                if (detailcolor != null)
                {
                    styled.DetailColor = detailcolor;
                }
                if (textcolor != null)
                {
                    styled.TextColor = textcolor;
                }
                if (accessory.HasValue)
                {
                    styled.Accessory = accessory.Value;
                }
                if (linebreakmode.HasValue)
                {
                    styled.LineBreakMode = linebreakmode.Value;
                }
                if (background != null)
                {
                    if (background.Length > 1 && background [0] == '#')
                    {
                        styled.BackgroundColor = ParseColor(background);
                    }
                    else
                    {
                        styled.BackgroundUri = new Uri(background);
                    }
                }
                if (alignment.HasValue)
                {
                    styled.Alignment = alignment.Value;
                }
                return(styled);
            }
            else
            {
                StringElement se;
                if (lines == 0)
                {
                    se = new MultilineElement(caption, value);
                }
                else
                {
                    se = new StringElement(caption, value);
                }
                if (alignment.HasValue)
                {
                    se.Alignment = alignment.Value;
                }
                if (ontap != null)
                {
                    se.Tapped += ontap;
                }
                return(se);
            }
        }
Esempio n. 12
0
        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 ConfigScreenDVC()
            : base(UITableViewStyle.Grouped, null)
        {
            MyRootElement configRoot = new MyRootElement("Configuration") { };

            Section weightSection = new Section("Weight Options") {};

            MyRootElement weightOptions = new MyRootElement ("Units", new RadioGroup ("units", 0)) {
                new Section () { }

            };

            MyRadioElement lbs = new MyRadioElement ("pounds");

            lbs.OnSelected += delegate(object sender, EventArgs e) {
                //Settings.DefaultUnits = 0;
                //Settings.Write();
            };

            MyRadioElement kgs = new MyRadioElement ("kilograms");

            kgs.OnSelected += delegate(object sender, EventArgs e) {
                //Settings.DefaultUnits = 1;
                //Settings.Write();
            };

            weightOptions[0].Add(lbs);
            weightOptions[0].Add(kgs);

            weightSection.Add(weightOptions);

            configRoot.Add(weightSection);

            Section aboutSection = new Section("About") { };

            StyledStringElement pennyFarthing = new StyledStringElement("Penny Farthing Apps", "website");
            //facebookPageBE.Font = UIFont.FromName ("HelveticaNeue-Bold", 17f);
            pennyFarthing.Image = UIImage.FromBundle("icons/contactHP");
            pennyFarthing.Tapped += delegate() {
                UIApplication.SharedApplication.OpenUrl(NSUrl.FromString("http://pennyfarthingapps.com"));
            };

            MyRootElement contactUsRoot = new MyRootElement("Contact Us");

            Section contactUsSect = new Section("Contact");

            StyledStringElement facebookPageBE = new StyledStringElement("Our Facebook Page");
            //facebookPageBE.Font = UIFont.FromName ("HelveticaNeue-Bold", 17f);
            facebookPageBE.Image = UIImage.FromBundle("icons/contactFb");

            facebookPageBE.Tapped += delegate() {
                if(UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString("fb://profile/439101479483557"))) {
                    UIApplication.SharedApplication.OpenUrl(NSUrl.FromString("fb://profile/439101479483557"));
                } else {
                    UIApplication.SharedApplication.OpenUrl(NSUrl.FromString("http://penfarapps.com/RxuFzI"));
                }
            };

            StyledStringElement twitterBE = new StyledStringElement("On Twitter");
            twitterBE.Image = UIImage.FromBundle("icons/contactTw");
            twitterBE.Tapped += delegate() {
                ShowTwitterView();
            };

            StyledStringElement emailSupBE = new StyledStringElement("Email Support");
            emailSupBE.Image = UIImage.FromBundle("icons/contactEm");
            emailSupBE.Tapped += delegate() {
                ShowEmailView();
            };

            contactUsSect.Add(emailSupBE);
            contactUsSect.Add(facebookPageBE);
            contactUsSect.Add(twitterBE);

            contactUsRoot.Add(contactUsSect);

            aboutSection.Add(pennyFarthing);
            aboutSection.Add(contactUsRoot);

            configRoot.Add(aboutSection);

            // TODO: change to JSON from website
            Section	ourAppsSection = new Section("Check out Our Apps");
            StyledStringElement myWODTimeBadge = new StyledStringElement("My WOD Time", "Crossfit Timer");
            myWODTimeBadge.Image = UIImage.FromBundle("icons/myWODTime");
            myWODTimeBadge.Tapped += delegate() {
                UIApplication.SharedApplication.OpenUrl(NSUrl.FromString("itms://itunes.apple.com/us/app/my-wod-time/id568915915?mt=8&uo=4"));
            };

            ourAppsSection.Add(myWODTimeBadge);
            configRoot.Add(ourAppsSection);

            Section legalSect = new Section("Disclaimer") { };

            MultilineElement disclaimerLines = new MultilineElement("Please consult a physician before starting any exercise program. Always use a spotter, and pick up your weights!");

            legalSect.Add(disclaimerLines);

            configRoot.Add(legalSect);

            Root = configRoot;
        }