Inheritance: NSObject
Exemplo n.º 1
0
		public BindingContext(UIView view, string title, Theme currentTheme)
		{
			if (view == null)
				throw new ArgumentNullException("view");
			
			var parser = new ViewParser();

			parser.Parse(view, title, currentTheme);
			Root = parser.Root;

			var viewContext = view as IBindingContext;
			if (viewContext != null)
			{
				viewContext.BindingContext = this;
				var dataContext = view as IDataContext;
				if (dataContext != null)
				{
					var vmContext = dataContext.DataContext as IBindingContext;
					if (vmContext != null)
					{
						vmContext.BindingContext = this;
					}
				}
			}
		}
		private void CreateTableView(object view, MemberInfo member, Theme theme)
		{
			Theme = Theme.CreateTheme(theme);
			var themeable = view as IThemeable;
			if (themeable != null)
			{
				var themeAttribute = view.GetType().GetCustomAttribute<ThemeAttribute>();
				if (themeAttribute != null)
				{
					var viewTheme = Theme.CreateTheme(themeAttribute.ThemeType);
					themeable.Theme = viewTheme;
					var newTheme = Theme.CreateTheme(viewTheme);

					Theme = newTheme;
					themeable.Theme = Theme;
				}
			}

			using(var parser = new ViewParser())
			{
				var source = parser.Parse(this, view, member);
				
				var tableViewStyle = Theme.TableViewStyle;
				var tableStyle = source as ITableViewStyle;
				if (tableStyle != null)
				{
					tableViewStyle = tableStyle.TableViewStyle;
				}
				
				if (source != null)
				{
					_TableView = MakeTableView(UIScreen.MainScreen.Bounds, tableViewStyle);
					_TableView.Source = source;
					
					TableView = _TableView;
					DisableScrolling = view.GetType().GetCustomAttribute<DisableScrollingAttribute>() != null;
				}
			}
		}
		public DialogViewController(string title, object view, MemberInfo member, Theme theme, bool pushing) : base(UITableViewStyle.Grouped)
		{
			Title = title;
			SetPushing(pushing);
			
			CreateTableView(view, member, theme);	
		}
		public void ResetTheme(Theme newTheme)
		{
			this.Theme.MergeTheme(newTheme);

			var source = TableView.Source as BaseDialogViewSource;

			foreach(var cell in TableView.VisibleCells)
			{
				var listCell = cell as ComposableViewListCell;
				if (listCell != null)
				{
					listCell.Theme.MergeTheme(newTheme);
				}
			}

			foreach (var section in source.Sections.Values)
			{
				foreach (var viewList in section.Views.Values)
				{
					foreach (var view in viewList)
					{
						var themeable = view as IThemeable;
						if (themeable != null)
						{
							themeable.Theme.MergeTheme(Theme);	
						}
					}
				}
			}

			ReloadData();
		}
		private void CreateTableView(object view, Theme theme)
		{
			CreateTableView(view, null, theme);
		}
Exemplo n.º 6
0
		public void MergeTheme(Theme theme)
		{
			if (theme != null)
			{	
				Name = theme.Name;

				if (theme.CellStyle != UITableViewCellStyle.Default && CellStyle != theme.CellStyle)
					CellStyle = theme.CellStyle;

				if (theme.CellHeight != 0 && CellHeight != theme.CellHeight)
					CellHeight = theme.CellHeight;

				if (theme.Accessory != Accessory)
					Accessory = theme.Accessory;
				
//				if (theme.CellImageIcon != null)
//					CellImageIcon = theme.CellImageIcon;
//				
//				if (theme.CellImageIconUri != null)
//					CellImageIconUri = theme.CellImageIconUri;
				
				if (theme.CellBackgroundColor != null)
					CellBackgroundColor = theme.CellBackgroundColor;
				
				if (theme.CellBackgroundUri != null)
					CellBackgroundUri = theme.CellBackgroundUri;
				
				if (theme.CellBackgroundImage != null)
					CellBackgroundImage = theme.CellBackgroundImage;

				
				if (theme.TextFont != null)
					TextFont = theme.TextFont;
				
				if (theme.TextColor != null)
					TextColor = theme.TextColor;
				
				if (theme.TextShadowOffset != SizeF.Empty)
					TextShadowOffset = theme.TextShadowOffset;
				
				if (theme.TextShadowColor != null)
					TextShadowColor = theme.TextShadowColor;
				
				if (theme.TextHighlightColor != null)
					TextHighlightColor = theme.TextHighlightColor;
				
				TextAlignment = theme.TextAlignment;

				
				if (theme.DetailTextFont != null)
					DetailTextFont = theme.DetailTextFont;
				
				if (theme.DetailTextColor != null)
					DetailTextColor = theme.DetailTextColor;
				
				if (theme.DetailTextShadowOffset != SizeF.Empty)
					DetailTextShadowOffset = theme.DetailTextShadowOffset;
				
				if (theme.DetailTextShadowColor != null)
					DetailTextShadowColor = theme.DetailTextShadowColor;
				
				if (theme.DetailTextHighlightColor != null)
					DetailTextHighlightColor = theme.DetailTextHighlightColor;
				
				DetailTextAlignment = theme.DetailTextAlignment;

				
				if (theme.PlaceholderColor != null)
					PlaceholderColor = theme.PlaceholderColor;
				
				if (theme.PlaceholderAlignment != UITextAlignment.Right)
					PlaceholderAlignment = theme.PlaceholderAlignment;

				if (theme.SeparatorColor != null)
					SeparatorColor = theme.SeparatorColor;

				if (theme.SeparatorStyle.HasValue)
					SeparatorStyle = theme.SeparatorStyle;

				if (theme.TableViewStyle.HasValue)
					TableViewStyle = theme.TableViewStyle;				

				if (theme.BarStyle.HasValue)
					BarStyle = theme.BarStyle;

				if (theme.BarTintColor != null)
					BarTintColor = theme.BarTintColor;
		
				if (theme.BarImage != null)
					BarImage = theme.BarImage;
		
				if (theme.BarTranslucent)
					BarTranslucent = theme.BarTranslucent;

			
				HeaderTextAlignment = theme.HeaderTextAlignment;
				
				if (theme.HeaderTextFont != null)
					HeaderTextFont = theme.HeaderTextFont;
				
				if (theme.HeaderTextColor != null)
					HeaderTextColor = theme.HeaderTextColor;
				
				if (theme.HeaderTextShadowOffset != SizeF.Empty)
					HeaderTextShadowOffset = theme.HeaderTextShadowOffset;
				
				if (theme.HeaderTextShadowColor != null)
					HeaderTextShadowColor = theme.HeaderTextShadowColor;
				
				if (theme.HeaderBackgroundColor != null)
					HeaderBackgroundColor = theme.HeaderBackgroundColor;
				

				FooterTextAlignment = theme.FooterTextAlignment;
				
				if (theme.FooterTextFont != null)
					FooterTextFont = theme.FooterTextFont;
				
				if (theme.FooterTextColor != null)
					FooterTextColor = theme.FooterTextColor;
				
				if (theme.FooterTextShadowOffset != SizeF.Empty)
					FooterTextShadowOffset = theme.FooterTextShadowOffset;
				
				if (theme.FooterTextShadowColor != null)
					FooterTextShadowColor = theme.FooterTextShadowColor;
			
				if (theme.FooterBackgroundColor != null)
					FooterBackgroundColor = theme.FooterBackgroundColor;
			

				if (theme.DrawElementViewAction != null)
				{
					DrawElementViewAction = theme.DrawElementViewAction;
				}

				if (theme.BackgroundColor != null)
					BackgroundColor = theme.BackgroundColor;
				
				if (theme.BackgroundUri != null)
					BackgroundUri = theme.BackgroundUri;
				
				if (theme.BackgroundImage != null)
					BackgroundImage = theme.BackgroundImage;
			}
		}
Exemplo n.º 7
0
		public static void ApplyElementTheme(Theme theme, IThemeable element, MemberInfo member)
		{
			if (theme != null)
			{
				var newTheme = Theme.CreateTheme(theme);
				newTheme.MergeTheme(element.Theme);
				
				element.Theme = newTheme;
			}
			
			if (member != null)
				ApplyMemberTheme(member, element);
			
			var root = element as IRoot;
			if (root != null)
			{
				foreach (var s in root.Sections)
					foreach (var e in s.Elements)
						ApplyElementTheme(element.Theme, e, null);
			}
			
			var section = element as ISection;
			if (section != null)
			{
				foreach (var e in section.Elements)
					ApplyElementTheme(element.Theme, e, null);
			}
		}
		public ComposableViewListCell(UITableViewCellStyle style, NSString reuseIdentifier, NSIndexPath indexPath, IList<Type> viewTypes, ListSource listSource) : base(style, reuseIdentifier)
		{
			Style = style;
			IndexPath = indexPath;
			ListSource = listSource;
			
			if (!ListSource.RowHeights.ContainsKey(ListSource.BaseIndexPath))
			{
				ListSource.RowHeights.Add(ListSource.BaseIndexPath, ListSource.Controller.TableView.RowHeight);
			}

			_CompositeView = new UIView(Bounds);
			
			Theme = Theme.CreateTheme(listSource.Controller.Theme);

			if (ViewList == null)
				CreateViewList(viewTypes);			

			AddSubview(_CompositeView);
		}
Exemplo n.º 9
0
		public static Theme CreateTheme(Theme theme)
		{
			var newTheme = new Theme();

			newTheme.MergeTheme(theme);

			return newTheme;
		}
		protected void CreateViewList(IList<Type> viewTypes)
		{
			var frame = new RectangleF(0, 0, ContentView.Bounds.Width, ContentView.Bounds.Height);
			
			if (ViewList != null)
			{
				foreach(var view in ViewList)
				{
					view.Dispose();
				}

				ViewList.Clear();
				ViewList = null;
			}
			
			ViewList = new List<UIView>();

			if (viewTypes != null)
			{
				foreach (var viewType in viewTypes)
				{
					if (viewType == null) continue;

					UIView view = null;
					var hasFrameCtor = viewType.GetConstructor(new Type[] { typeof(RectangleF) }) != null;
					if (hasFrameCtor)
					{
						view = Activator.CreateInstance(viewType, new object[] { frame }) as UIView;
						
						if (ListSource.RowHeights[ListSource.BaseIndexPath] != view.Frame.Height)
						{
							if (ListSource.RowHeights.ContainsKey(IndexPath))
							{
								ListSource.RowHeights[IndexPath] = view.Frame.Height;
							}
							else
							{
								ListSource.RowHeights.Add(IndexPath, view.Frame.Height);
							}
						}
					}
					else
					{
						view = Activator.CreateInstance(viewType) as UIView;
					}
					
					var dc = view as IDataContext<object>;
					if (dc != null)
					{
						var item = ListSource.GetSectionData(0)[IndexPath.Row];
						dc.DataContext = item;
					}

					var initializeCell = view as IInitializeCell;
					if (initializeCell != null)
					{	
						initializeCell.Cell = this;
						initializeCell.Controller = ListSource.Controller;

						var newCellStyle = initializeCell.CellStyle;
						if (newCellStyle != Style)
						{
							Style = newCellStyle;
							break;
						}
					}
					
					var themeable = view as IThemeable;
					if (themeable != null)
					{
						if (themeable.Theme == null)
						{
							var theme = view.GetType().GetCustomAttribute<ThemeAttribute>();
							if (theme != null)
							{
								var cellViewTheme = Theme.CreateTheme(theme.ThemeType);
								if (cellViewTheme != null)
								{
									if (Theme != null)
									{
										Theme.MergeTheme(cellViewTheme);
									}
									else
									{
										Theme = cellViewTheme;
									}

									themeable.Theme = Theme;
								}
							}
						}
						
						themeable.InitializeTheme(this);
					}

					var cellContent = view as ICellContent;
					if (cellContent != null)
					{
						if (cellContent.CellContentView != null)
						{
							_CompositeView.AddSubview(cellContent.CellContentView);
						}
					}
					
					ViewList.Add(view);
				}
			}
		}
Exemplo n.º 11
0
		public void MergeTheme(Theme theme)
		{
			if (theme != null)
			{	
				Name = theme.Name;

				if (theme.CellHeight != 0 && CellHeight != theme.CellHeight)
				{
					CellHeight = theme.CellHeight;
				}
				
				if (theme.CellBackgroundColor != null)
				{
					CellBackgroundColor = theme.CellBackgroundColor.Clone();
				}
				
				if (theme.CellBackgroundUri != null)
				{
					CellBackgroundUri = theme.CellBackgroundUri;
				}
				
				if (theme.CellBackgroundImage != null)
				{
					CellBackgroundImage = theme.CellBackgroundImage;
				}

				
				if (theme.TextFont != null)
				{
					TextFont = theme.TextFont.Clone();
				}
				

				if (theme.TextColor != null)
				{
					TextColor = theme.TextColor.Clone();
				}
				
				if (theme.TextShadowOffset != SizeF.Empty)
				{
					TextShadowOffset = theme.TextShadowOffset;
				}
				
				if (theme.TextShadowColor != null)
				{
					TextShadowColor = theme.TextShadowColor.Clone();
				}
				
				if (theme.TextHighlightColor != null)
				{
					TextHighlightColor = theme.TextHighlightColor.Clone();
				}
				
				TextAlignment = theme.TextAlignment;

				
				if (theme.DetailTextFont != null)
				{
					DetailTextFont = theme.DetailTextFont.Clone();
				}
				

				if (theme.DetailTextColor != null)
				{
					DetailTextColor = theme.DetailTextColor.Clone();
				}

				if (theme.DetailTextShadowOffset != SizeF.Empty)
				{
					DetailTextShadowOffset = theme.DetailTextShadowOffset;
				}
				
				if (theme.DetailTextShadowColor != null)
				{
					DetailTextShadowColor = theme.DetailTextShadowColor.Clone();
				}
				
				if (theme.DetailTextHighlightColor != null)
				{
					DetailTextHighlightColor = theme.DetailTextHighlightColor.Clone();
				}
				
				DetailTextAlignment = theme.DetailTextAlignment;

				
				if (theme.PlaceholderColor != null)
				{
					PlaceholderColor = theme.PlaceholderColor.Clone();
				}
				
				if (theme.PlaceholderAlignment != UITextAlignment.Right)
				{
					PlaceholderAlignment = theme.PlaceholderAlignment;
				}

				if (theme.SeparatorColor != null)
				{
					SeparatorColor = theme.SeparatorColor.Clone();
				}

				if (theme.SeparatorStyle.HasValue)
				{
					SeparatorStyle = theme.SeparatorStyle;
				}

				TableViewStyle = theme.TableViewStyle;				

				if (theme.BarStyle.HasValue)
				{
					BarStyle = theme.BarStyle;
				}

				if (theme.BarTintColor != null)
				{
					BarTintColor = theme.BarTintColor.Clone();
				}
		
				if (theme.BarImage != null)
				{
					BarImage = theme.BarImage;
				}
		
				if (theme.BarTranslucent)
				{
					BarTranslucent = theme.BarTranslucent;
				}

			
				HeaderTextAlignment = theme.HeaderTextAlignment;
				
				if (theme.HeaderTextFont != null)
				{
					HeaderTextFont = theme.HeaderTextFont.Clone();
				}
				
				if (theme.HeaderTextColor != null)
				{
					HeaderTextColor = theme.HeaderTextColor.Clone();
				}
				
				if (theme.HeaderTextBackgroundColor != null)
				{
					HeaderTextBackgroundColor = theme.HeaderTextBackgroundColor.Clone();
				}

				if (theme.HeaderTextShadowOffset != SizeF.Empty)
				{
					HeaderTextShadowOffset = theme.HeaderTextShadowOffset;
				}
				
				if (theme.HeaderTextShadowColor != null)
				{
					HeaderTextShadowColor = theme.HeaderTextShadowColor.Clone();
				}
				
				if (theme.HeaderBackgroundColor != null)
				{
					HeaderBackgroundColor = theme.HeaderBackgroundColor.Clone();
				}
				

				FooterTextAlignment = theme.FooterTextAlignment;
				
				if (theme.FooterTextFont != null)
				{
					FooterTextFont = theme.FooterTextFont.Clone();
				}
				
				if (theme.FooterTextColor != null)
				{
					FooterTextColor = theme.FooterTextColor.Clone();
				}
				
				if (theme.FooterTextBackgroundColor != null)
				{
					FooterTextBackgroundColor = theme.FooterTextBackgroundColor.Clone();
				}

				if (theme.FooterTextShadowOffset != SizeF.Empty)
				{
					FooterTextShadowOffset = theme.FooterTextShadowOffset;
				}
				
				if (theme.FooterTextShadowColor != null)
				{
					FooterTextShadowColor = theme.FooterTextShadowColor.Clone();
				}
			
				if (theme.FooterBackgroundColor != null)
				{
					FooterBackgroundColor = theme.FooterBackgroundColor.Clone();
				}
			

				if (theme.DrawCellViewAction != null)
				{
					DrawCellViewAction = theme.DrawCellViewAction;
				}

				if (theme.BackgroundColor != null)
				{
					BackgroundColor = theme.BackgroundColor.Clone();
				}
				
				if (theme.BackgroundUri != null)
				{
					BackgroundUri = theme.BackgroundUri;
				}
				
				if (theme.BackgroundImage != null)
				{
					BackgroundImage = theme.BackgroundImage;
				}
			}
		}
Exemplo n.º 12
0
		public static Theme CreateTheme()
		{
			var newTheme = new Theme();
			return newTheme;
		}
Exemplo n.º 13
0
		public static Theme CreateTheme(Theme theme)
		{
			var newTheme = CreateTheme();

			newTheme.MergeTheme(theme);
			if (theme != null)
			{
				theme.Dispose();
			}

			return newTheme;
		}
        protected virtual UITableViewCell NewCell(NSString cellId, NSIndexPath indexPath)
        {
            var cellStyle = UITableViewCellStyle.Default;
            var cell      = new UITableViewCell(cellStyle, cellId)
            {
            };

            var views   = new List <UIView>();
            var section = Sections[indexPath.Section];

            var key = cellId.ToString();

            if (section.ViewTypes != null && section.ViewTypes.ContainsKey(key))
            {
                var viewTypes = section.ViewTypes[key];
                if (viewTypes != null)
                {
                    var memberData = GetMemberData(indexPath);

                    foreach (var viewType in viewTypes)
                    {
                        UIView view         = null;
                        var    hasFrameCtor = viewType.GetConstructor(new Type[] { typeof(RectangleF) }) != null;
                        if (hasFrameCtor)
                        {
                            view = Activator.CreateInstance(viewType, new object[] { cell.ContentView.Bounds }) as UIView;
                        }
                        else
                        {
                            view = Activator.CreateInstance(viewType) as UIView;
                        }

                        var memberAttributes = memberData.Member.GetCustomAttributes(false);

                        foreach (var memberAttribute in memberAttributes)
                        {
                            var hasCellViewTemplate = view as ICellViewTemplate;
                            var cellViewTemplate    = memberAttribute as CellViewTemplate;
                            if (hasCellViewTemplate != null && cellViewTemplate != null && hasCellViewTemplate.GetType() == cellViewTemplate.CellViewType)
                            {
                                hasCellViewTemplate.CellViewTemplate = cellViewTemplate;
                            }

                            var viewTheme = view as IThemeable;
                            if (viewTheme != null)
                            {
                                var memberTheme = memberAttribute as CellViewTemplate;
                                if (memberTheme != null && memberTheme.Theme != null)
                                {
                                    viewTheme.Theme = Theme.CreateTheme(memberTheme.Theme);
                                }
                            }

                            var navigable = view as INavigable;
                            if (navigable != null)
                            {
                                var memberNavigable = memberAttribute as INavigable;
                                if (memberNavigable != null)
                                {
                                    navigable.NavigateToViewType = memberNavigable.NavigateToViewType;
                                    navigable.IsModal            = memberNavigable.IsModal;
                                    navigable.TransitionStyle    = memberNavigable.TransitionStyle;
                                }
                            }

                            var caption = view as ICaption;
                            if (caption != null)
                            {
                                var memberCaption = memberAttribute as ICaption;
                                if (memberCaption != null && !string.IsNullOrEmpty(memberCaption.Caption))
                                {
                                    caption.Caption = memberCaption.Caption;
                                }
                            }
                        }

                        var commandButton = view as ICommandButton;
                        if (commandButton != null && !string.IsNullOrEmpty(commandButton.CommandMemberName))
                        {
                            var commandMember = GetMemberFromView(commandButton.CommandMemberName);
                            if (commandMember != null)
                            {
                                commandButton.Command = commandMember.GetValue(memberData.Source) as ICommand;
                            }
                        }

                        var dc = view as IDataContext <MemberData>;
                        if (dc != null)
                        {
                            dc.DataContext = memberData;
                        }

                        var initializeCell = view as IInitializeCell;
                        if (initializeCell != null)
                        {
                            var newCellStyle = initializeCell.CellStyle;
                            if (newCellStyle != cellStyle)
                            {
                                // recreate cell with new style
                                cell = new UITableViewCell(newCellStyle, cellId)
                                {
                                };
                            }

                            initializeCell.Cell       = cell;
                            initializeCell.Controller = Controller;
                        }

                        var themeable = view as IThemeable;
                        if (themeable != null)
                        {
                            var theme = Theme.CreateTheme(Controller.Theme);

                            var themeAttribute = viewType.GetCustomAttribute <ThemeAttribute>();
                            if (themeAttribute != null)
                            {
                                var viewTypeTheme = Theme.CreateTheme(themeAttribute.ThemeType);
                                theme.MergeTheme(viewTypeTheme);
                            }

                            themeAttribute = memberData.Member.GetCustomAttribute <ThemeAttribute>();
                            if (themeAttribute != null)
                            {
                                var memberTheme = Theme.CreateTheme(themeAttribute.ThemeType);
                                theme.MergeTheme(memberTheme);
                            }

                            themeable.Theme      = theme;
                            themeable.Theme.Cell = cell;
                        }

                        var initalizable = view as IInitializable;
                        if (initalizable != null)
                        {
                            initalizable.Initialize();
                        }

                        views.Add(view);
                    }
                }
            }

            cell.TextLabel.Text            = Caption;
            cell.TextLabel.BackgroundColor = UIColor.Clear;

            if (cell.DetailTextLabel != null)
            {
                cell.DetailTextLabel.BackgroundColor = UIColor.Clear;
            }

            var selectable = this as ISelectable;

            cell.SelectionStyle = selectable != null ? UITableViewCellSelectionStyle.Blue : UITableViewCellSelectionStyle.Blue;

            if (views.Count > 0)
            {
                cell.ContentView.AutosizesSubviews = true;
            }

            section.Views.Add(cell, views);
            var resizedRows = false;

            foreach (var view in views)
            {
                var accessoryView = view as IAccessoryView;
                if (accessoryView != null)
                {
                    view.Tag = 1;
                    view.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleLeftMargin;
                    cell.AccessoryView    = view;
                }
                else
                {
                    var contentView = view as ICellContent;
                    if (contentView != null)
                    {
                        view.Tag = 1;
                        view.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleLeftMargin;
                        cell.ContentView.Add(view);
                    }
                }

                var sizeable = view as ISizeable;
                if (sizeable != null)
                {
                    var rowHeight = sizeable.GetRowHeight();

                    if (RowHeights.ContainsKey(indexPath))
                    {
                        if (RowHeights[indexPath] != rowHeight)
                        {
                            RowHeights[indexPath] = rowHeight;
                            resizedRows           = true;
                        }
                    }
                    else
                    {
                        RowHeights.Add(indexPath, rowHeight);
                        resizedRows = true;
                    }
                }
            }

            if (resizedRows)
            {
                new Wait(TimeSpan.FromMilliseconds(0), () =>
                {
                    Controller.TableView.BeginUpdates();
                    Controller.TableView.EndUpdates();
                });
            }

            return(cell);
        }