CreateTheme() public static method

public static CreateTheme ( ) : Theme
return Theme
Exemplo n.º 1
0
        private static DialogViewController CreateDialogViewController(object view, bool isModal, bool pushing)
        {
            Theme theme = null;

            if (CurrentDialogViewController != null)
            {
                theme = CurrentDialogViewController.Theme;
                theme = Theme.CreateTheme(theme);
                theme.TableViewStyle = UITableViewStyle.Grouped;
            }

            string title      = null;
            var    hasCaption = view as ICaption;

            if (hasCaption != null)
            {
                title = hasCaption.Caption;
            }

            if (string.IsNullOrEmpty(title))
            {
                title = MonoMobileApplication.Title;
            }

            var dvc = new DialogViewController(title, view, theme, pushing)
            {
                Autorotate = true, IsModal = isModal
            };

            return(dvc);
        }
        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 UITableViewSource ParseView(DialogViewController controller, object view)
        {
            var members = view.GetType().GetMembers(false);

            var sections     = new SortedList <int, Section>();
            var memberLists  = new SortedList <int, SortedList <int, MemberData> >();
            var sectionIndex = 0;
            var memberOrder  = 0;

            foreach (var member in members)
            {
                var attributes = member.GetCustomAttributes(false);

                var memberData = new MemberData(view, member)
                {
                    Section = sectionIndex
                };

                var defaultValueAttribute = member.GetCustomAttribute <DefaultValueAttribute>();
                if (defaultValueAttribute != null)
                {
                    memberData.Value = defaultValueAttribute.Value;
                }

                var pullToRefreshAttribute = member.GetCustomAttribute <PullToRefreshAttribute>();
                if (pullToRefreshAttribute != null)
                {
                    ((DialogViewController)controller).PullToRefreshCommand = GetCommandForMember(view, member);
                    ((DialogViewController)controller).RefreshKey           = pullToRefreshAttribute.SettingsKey;
                    ((DialogViewController)controller).EnablePullToRefresh  = true;
                }

                var toolbarButtonAttribute = member.GetCustomAttribute <ToolbarButtonAttribute>();
                var navbarButtonAttribute  = member.GetCustomAttribute <NavbarButtonAttribute>();
                var skipAttribute          = member.GetCustomAttribute <SkipAttribute>();

                if (skipAttribute != null ||
                    toolbarButtonAttribute != null ||
                    navbarButtonAttribute != null ||
                    pullToRefreshAttribute != null ||
                    (attributes.Length == 0 && typeof(MethodInfo) == memberData.Type))
                {
                    memberData.Dispose();
                    continue;
                }

                var themeAttribute = member.GetCustomAttribute <ThemeAttribute>();
                if (themeAttribute != null)
                {
                    var theme = Theme.CreateTheme(themeAttribute.ThemeType);
                    if (theme != null && theme.CellHeight > 0)
                    {
                        memberData.RowHeight = theme.CellHeight;
                        theme.Dispose();
                    }
                }
                else
                {
                    var themeable = view as IThemeable;
                    if (themeable != null && themeable.Theme != null && themeable.Theme.CellHeight > 0)
                    {
                        memberData.RowHeight = themeable.Theme.CellHeight;
                    }
                }

                var rowHeightAttribute = member.GetCustomAttribute <RowHeightAttribute>();
                if (rowHeightAttribute != null)
                {
                    memberData.RowHeight = rowHeightAttribute.RowHeight;
                }

                var listAttribute = member.GetCustomAttribute <ListAttribute>();
                var isList        = (listAttribute != null && listAttribute.DisplayMode == DisplayMode.List) &&
                                    !typeof(string).IsAssignableFrom(memberData.Type) &&
                                    (typeof(IEnumerable).IsAssignableFrom(memberData.Type) ||
                                     typeof(Enum).IsAssignableFrom(memberData.Type));

                var orderAttribute = member.GetCustomAttribute <OrderAttribute>();
                if (orderAttribute != null)
                {
                    // make sure assigned order is an even number to fit in between the default order
                    // allowing the values int.MinValue and int.MaxValue for the first and Last positions
                    memberData.Order = orderAttribute.Order > int.MaxValue / 2 ? int.MaxValue : orderAttribute.Order * 2;
                }
                else
                {
                    // make sure all default memberOrder is odd;
                    memberOrder      = memberOrder + (memberOrder % 2) + 1;
                    memberData.Order = memberOrder;
                }

                var sectionAttribute = member.GetCustomAttribute <SectionAttribute>();
                if (sectionAttribute != null || isList)
                {
                    if (sections.Count > 0)
                    {
                        sectionIndex++;
                    }

                    memberData.Section = sectionIndex;

                    if (sectionAttribute != null && orderAttribute != null)
                    {
                        memberData.Section = orderAttribute.Order == 0 ? sectionIndex : orderAttribute.Order;
                    }
                    else
                    {
                        memberData.Section = sectionIndex;
                    }
                }

                var viewTypes = GetViewTypes(memberData);

                if (!sections.ContainsKey(memberData.Section))
                {
                    var section = CreateSection(controller, memberData, viewTypes);
                    sections.Add(memberData.Section, section);
                }
                else
                {
                    if (viewTypes != null)
                    {
                        IList <Type> list = null;
                        var          key  = memberData.Id.ToString();

                        var viewTypesList = sections[memberData.Section].ViewTypes;
                        if (viewTypesList.ContainsKey(key))
                        {
                            list = viewTypesList[key];
                        }
                        else
                        {
                            list = new List <Type>();
                            viewTypesList.Add(key, list);
                        }

                        foreach (var viewType in viewTypes)
                        {
                            if (!list.Contains(viewType))
                            {
                                list.Add(viewType);
                            }
                        }
                    }
                }

                if (memberLists.ContainsKey(memberData.Section))
                {
                    memberLists[memberData.Section].Add(memberData.Order, memberData);
                }
                else
                {
                    var sortedList = new SortedList <int, MemberData>();
                    sortedList.Add(memberData.Order, memberData);
                    memberLists.Add(memberData.Section, sortedList);
                }
            }

            foreach (var kvp in memberLists)
            {
                var listSources = new SortedList <int, ListSource>();

                var index = 0;
                var list  = kvp.Value.Values.ToList();
                list.ForEach(data => data.Order = index++);

                foreach (var memberData in list)
                {
                    var viewTypes = GetViewTypes(memberData);

                    if ((!typeof(string).IsAssignableFrom(memberData.Type) && typeof(IEnumerable).IsAssignableFrom(memberData.Type)) || typeof(Enum).IsAssignableFrom(memberData.Type))
                    {
                        var listSource = ParseList(controller, memberData, viewTypes) as ListSource;

                        listSource.MemberData        = memberData;
                        listSource.Sections[0].Index = memberData.Section;

                        listSources.Add(memberData.Order, listSource);
                    }
                    else
                    {
                        listSources.Add(memberData.Order, null);
                    }

                    sections[memberData.Section].ListSources = listSources;
                    sections[memberData.Section].Index       = memberData.Section;

                    var lastListSource = listSources.Values.Last();
                    if (lastListSource != null)
                    {
                        memberData.DataContextBinder = new DataContextBinder(controller, lastListSource.Sections[0]);
                    }
                }

                sections[kvp.Key].DataContext = list;
            }

            var keyIndex    = 0;
            var sectionList = sections.Select(kvp => kvp.Value).ToDictionary((value) => keyIndex++);

            // If there is only one list property return the ListSource rather than create a ViewSource
            if (sectionList.Count == 1 && sectionList[0].DataContext.Count == 1 && sectionList[0].ListSources[0] != null && !sectionList[0].ListSources[0].IsRootCell)
            {
                sectionList[0].ListSources[0].TableViewStyle = UITableViewStyle.Plain;
                return(sectionList[0].ListSources[0]);
            }

            var source = new ViewSource(controller)
            {
                Sections = sectionList
            };

            return(source);
        }
        private static void Startup()
        {
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var assembly in assemblies)
            {
                var types = assembly.GetTypes();
                foreach (var type in types)
                {
                    var initialize = type.GetCustomAttribute <InitializeAttribute>();
                    if (initialize != null)
                    {
                        var initializeMethod = type.GetMethod("Initialize");
                        if (initializeMethod != null)
                        {
                            initializeMethod.Invoke(type, null);
                        }
                    }
                }
            }

            MonoMobileApplication.Views = new List <object>();
            foreach (var viewType in MonoMobileApplication.ViewTypes)
            {
                var view = Activator.CreateInstance(viewType);
                MonoMobileApplication.Views.Add(view);
            }

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

            foreach (var view in MonoMobileApplication.Views)
            {
                MonoMobileApplication.DialogViewControllers.Add(new DialogViewController(MonoMobileApplication.Title, view, Theme.CreateTheme(), true)
                {
                    Autorotate = true
                });
            }

            MonoMobileApplication.NavigationController.ViewControllers = MonoMobileApplication.DialogViewControllers.ToArray();

            UIView.BeginAnimations("fadeIn");
            UIView.SetAnimationDuration(0.3f);
            MonoMobileApplication.NavigationController.View.Alpha = 1.0f;
            UIView.CommitAnimations();
        }
Exemplo n.º 5
0
        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);
        }