Esempio n. 1
0
		void AddSection ()
		{
			var section = new Section () {
				new StringElement ("Demo Section Added")
			};
			
			demoRoot.Insert (demoRoot.Count, section);
		}
Esempio n. 2
0
		public void DemoAddRemove ()
		{
			rnd = new Random ();
			var section = new Section (null, "Elements are added randomly") {
				new StringElement ("Add elements", AddElements),
				new StringElement ("Add, with no animation", AddNoAnimation),
				new StringElement ("Remove top element", RemoveElements),
				new StringElement ("Add Section", AddSection),
				new StringElement ("Remove Section", RemoveSection)
			};
			region = new Section ();
			
			demoRoot = new RootElement ("Add/Remove Demo") { section, region };
			var dvc = new DialogViewController (demoRoot, true);
			navigation.PushViewController (dvc, true);
		}
Esempio n. 3
0
		public void DemoLoadMore () 
		{
			Section loadMore = new Section();
			
			var s = new StyledStringElement ("Hola") {
				BackgroundUri = new Uri ("http://www.google.com/images/logos/ps_logo2.png")
				//BackgroundColor = UIColor.Red
			};
			loadMore.Add (s);
			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);
		}
Esempio n. 4
0
		public void PerformFilter (string text)
		{
			if (originalSections == null)
				return;
			
			OnSearchTextChanged (text);
			
			var newSections = new List<Section> ();
			
			for (int sidx = 0; sidx < originalSections.Length; sidx++){
				Section newSection = null;
				var section = originalSections [sidx];
				Element [] elements = originalElements [sidx];
				
				for (int eidx = 0; eidx < elements.Length; eidx++){
					if (elements [eidx].Matches (text)){
						if (newSection == null){
							newSection = new Section (section.Header, section.Footer){
								FooterView = section.FooterView,
								HeaderView = section.HeaderView
							};
							newSections.Add (newSection);
						}
						newSection.Add (elements [eidx]);
					}
				}
			}
			
			Root.Sections = newSections;
			
			ReloadData ();
		}
Esempio n. 5
0
		public void DemoEditing () 
		{
			var editingSection = new Section ("To-do list") {
				new StringElement ("Donate to non-profit"),
				new StringElement ("Read new Chomsky book"),
				new StringElement ("Practice guitar"),
				new StringElement ("Watch Howard Zinn Documentary")
			};
				
			var root = new RootElement("Edit Support") {
				editingSection
			};
			var dvc = new EditingDialog (root, true);
			ConfigEdit (dvc);
			
			navigation.PushViewController (dvc, true);
		}
Esempio n. 6
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 };
					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);
		}
Esempio n. 7
0
		public void DemoDate ()
		{
			if (badgeImage == null)
				badgeImage = UIImage.FromFile ("jakub-calendar.png");
			
			var badgeSection = new Section ("Basic Badge Properties"){
				new BadgeElement (badgeImage, "New Movie Day") {
					Font = UIFont.FromName ("Helvetica", 36f)
				},
				new BadgeElement (badgeImage, "Valentine's Day"),
				
				new BadgeElement (badgeImage, longString) {
					Lines = 3,
					Font = UIFont.FromName ("Helvetica", 12f)
				}
			};
			
			//
			// Use the MakeCalendarBadge API
			//
			var font = UIFont.FromName ("Helvetica", 14f);
			var dates = new string [][] {
				new string [] { "January", "1", "Hangover day" },
				new string [] { "February", "14", "Valentine's Day" },
 				new string [] { "March", "3", "Third day of March" },
				new string [] { "March", "31", "Prank Preparation day" },
				new string [] { "April", "1", "Pranks" },
			};
			var calendarSection = new Section ("Date sample");
			foreach (string [] date in dates) {
				calendarSection.Add (new BadgeElement (BadgeElement.MakeCalendarBadge (badgeImage, date [0], date [1]), date [2]){
					Font = font
				});
			}
			
			UIImage favorite = UIImage.FromFile ("favorite.png");
			UIImage favorited = UIImage.FromFile ("favorited.png");
			
			var imageSection = new Section ("Image Booleans"){
				new BooleanImageElement ("Gone with the Wind", true, favorited, favorite),
				new BooleanImageElement ("Policy Academy 38", false, favorited, favorite),
			};
			
#warning Message Section removed
            /*
             
			var messageSection = new Section ("Message Elements"){
				new MessageElement (msgSelected) { 
					Sender = "Miguel de Icaza ([email protected])", 
					Subject = "Re: [Gtk-sharp-list] Glib Timeout and other ways to handle idle",
					Body = "Please bring friends, but make sure that you also bring eggs and bacon as we are running short of those for the coctails tonight",
					Date = DateTime.Now - TimeSpan.FromHours (23),
					NewFlag = true,
					MessageCount = 0
				},
				new MessageElement (msgSelected) { 
					Sender = "Nat Friedman ([email protected])", 
					Subject = "Pictures from Vietnam",
					Body = "Hey dude, here are the pictures that I promised from Vietnam",
					Date = new DateTime (2010, 10, 20),
					NewFlag = false,
					MessageCount = 2
				}
			};
			*/
			var entrySection = new Section ("Keyboard styles for entry"){
				new EntryElement ("Number ", "Some cute number", "1.2") { KeyboardType = UIKeyboardType.NumberPad },
				new EntryElement ("Email ", "", null) { KeyboardType = UIKeyboardType.EmailAddress },
				new EntryElement ("Url ", "", null) { KeyboardType = UIKeyboardType.Url },
				new EntryElement ("Phone ", "", "1.2") { KeyboardType = UIKeyboardType.PhonePad },
			};
			
			var root = new RootElement ("Assorted Elements") {
				imageSection,
				//messageSection,
				entrySection,
				calendarSection,
				badgeSection,
			};
			var dvc = new DialogViewController (root, true);
			dvc.Style = UITableViewStyle.Plain;
			
			navigation.PushViewController (dvc, true);
		}