Exemple #1
0
        public static void AddSeperator(AdaptiveRenderContext context, AdaptiveElement element, Grid uiContainer)
        {
            if (element.Spacing == AdaptiveSpacing.None && !element.Separator)
            {
                return;
            }
            Grid grid = new Grid()
            {
                Style = context.GetStyle("Adaptive.Separator")
            };
            int             spacing   = context.Config.GetSpacing(element.Spacing);
            SeparatorConfig separator = context.Config.Separator;

            grid.Margin = new Thickness(0, (double)((spacing - separator.LineThickness) / 2), 0, 0);
            grid.SetHeight((double)separator.LineThickness);
            if (!string.IsNullOrWhiteSpace(separator.LineColor))
            {
                grid.SetBackgroundColor(separator.LineColor, context);
            }
            uiContainer.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            Grid.SetRow(grid, uiContainer.RowDefinitions.Count - 1);
            uiContainer.Children.Add(grid);
        }
        public static Button CreateActionButton(AdaptiveAction action, AdaptiveRenderContext context)
        {
            //var button = new ContentButton()
            //{
            //    Style = context.GetStyle(string.Format("Adaptive.{0}", action.Type)),
            //    Padding = new Thickness(6, 4, 6, 4),
            //    Content = new Label()
            //    {
            //        Text = action.Title,
            //        FontSize = (double)context.Config.FontSizes.Default,
            //        Style = context.GetStyle("Adaptive.Action.Title")
            //    }
            //};
            var button = new Button()
            {
                //Style = context.GetStyle(string.Format("Adaptive.{0}", action.Type)),
                Text       = action.Title,
                FontSize   = (double)context.Config.FontSizes.Medium,
                FontFamily = "Segoe UI",
            };

            context.GetType().Name.Replace("Action", string.Empty);

            MessagingCenter.Subscribe <Page>(button, "HidePreviousButtons", (sender) =>
            {
                button.IsVisible     = false;
                button.HeightRequest = 0;
                MessagingCenter.Unsubscribe <Page>(button, "HidePreviousButtons");
            });

            return(button);
        }
Exemple #3
0
 public static void SetBackgroundSource(this Grid grid, string url, AdaptiveRenderContext context)
 {
     if (string.IsNullOrWhiteSpace(url))
     {
         return;
     }
     grid.SetBackgroundImage(new Uri(url));
 }
Exemple #4
0
 public static void SetSource(this Image image, string url, AdaptiveRenderContext context)
 {
     if (string.IsNullOrWhiteSpace(url))
     {
         return;
     }
     image.SetSource(new Uri(url));
 }
Exemple #5
0
        public static View RenderSelectAction(this AdaptiveRenderContext context, AdaptiveAction selectAction, View uiElement)
        {
            if (!context.Config.SupportsInteractivity)
            {
                return(uiElement);
            }
            ContentButton button = (ContentButton)context.Render(selectAction);

            button.HorizontalOptions = LayoutOptions.FillAndExpand;
            button.VerticalOptions   = LayoutOptions.FillAndExpand;
            button.BackgroundColor   = Color.Transparent;
            button.Margin            = 0;
            button.Content           = uiElement;
            button.Style             = context.GetStyle("Adaptive.Action.Tap");
            return(button);
        }
Exemple #6
0
        public static View Render(AdaptiveContainer container, AdaptiveRenderContext context)
        {
            ContainerStyleConfig defaultConfig = context.Config.ContainerStyles.Default;
            Grid grid = new Grid()
            {
                Style = context.GetStyle("Adaptive.Container")
            };

            AdaptiveContainerRenderer.AddContainerElements(grid, container.Items, context);
            if (container.SelectAction != null)
            {
                return(context.RenderSelectAction(container.SelectAction, grid));
            }
            Grid grid1 = new Grid()
            {
                BackgroundColor = context.GetColor(defaultConfig.BackgroundColor)
            };

            grid1.Children.Add(grid);
            return(grid1);
        }
Exemple #7
0
        public static Label CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context)
        {
            var label1 = new Label()
            {
                Style         = context.GetStyle("Adaptive.TextBlock"),
                LineBreakMode = LineBreakMode.TailTruncation
            };

            switch (textBlock.HorizontalAlignment)
            {
            case AdaptiveHorizontalAlignment.Left:
            {
                label1.HorizontalTextAlignment = TextAlignment.Start;
                break;
            }

            case AdaptiveHorizontalAlignment.Center:
            {
                label1.HorizontalTextAlignment = TextAlignment.Center;
                break;
            }

            case AdaptiveHorizontalAlignment.Right:
            {
                label1.HorizontalTextAlignment = TextAlignment.End;
                break;
            }
            }
            label1.TextColor = context.Resources.TryGetValue <Color>(string.Format("Adaptive.{0}", textBlock.Color));
            if (textBlock.Weight == AdaptiveTextWeight.Bolder)
            {
                label1.FontAttributes = FontAttributes.Bold;
            }
            if (textBlock.Wrap)
            {
                label1.LineBreakMode = LineBreakMode.WordWrap;
            }
            return(label1);
        }
        public static View Render(AdaptiveAction action, AdaptiveRenderContext context)
        {
            if (!context.Config.SupportsInteractivity || !context.ActionHandlers.IsSupported(action.GetType()))
            {
                return(null);
            }
            var button = CreateActionButton(action, context);
            var view   = CreateActionButton(action, context);

            button.Clicked += new EventHandler((object sender, EventArgs e) =>
            {
                bool isInputMissing = false;
                if (context.InputBindings.Count > 0)
                {
                    isInputMissing = true;
                    var dict       = context.UserInputs.AsDictionary();
                    foreach (var binding in dict.Values)
                    {
                        if (!string.IsNullOrWhiteSpace(binding))
                        {
                            isInputMissing = false;
                            break;
                        }
                    }
                }
                if (isInputMissing)
                {
                    var missingInput     = new MissingAdaptiveInput();
                    missingInput.Message = "Select at least one option.";
                    context.InvokeMissingInput(action, new MissingInputEventArgs(missingInput, button));
                }
                else
                {
                    context.InvokeAction(button, new AdaptiveActionEventArgs(action));
                    button.IsEnabled = false;
                }
            });
            return(button);
        }
Exemple #9
0
 public static void SetColor(this Label label, string color, AdaptiveRenderContext context)
 {
     label.TextColor = Color.FromHex(color);
 }
Exemple #10
0
 public static void SetBorderColor(this Button view, string color, AdaptiveRenderContext context)
 {
 }
Exemple #11
0
 public static void SetBackgroundColor(this View view, string color, AdaptiveRenderContext context)
 {
     view.BackgroundColor = Color.FromHex(color);
 }
Exemple #12
0
        public static View Render(AdaptiveTextBlock textBlock, AdaptiveRenderContext context)
        {
            FontColorConfig fontColorConfig;
            var             label = CreateControl(textBlock, context);

            switch (textBlock.Color)
            {
            case AdaptiveTextColor.Default:
            {
                fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Default;
                break;
            }

            case AdaptiveTextColor.Dark:
            {
                fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Dark;
                break;
            }

            case AdaptiveTextColor.Light:
            {
                fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Light;
                break;
            }

            case AdaptiveTextColor.Accent:
            {
                fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Accent;
                break;
            }

            case AdaptiveTextColor.Good:
            {
                fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Good;
                break;
            }

            case AdaptiveTextColor.Warning:
            {
                fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Warning;
                break;
            }

            case AdaptiveTextColor.Attention:
            {
                fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Attention;
                break;
            }

            default:
            {
                goto case AdaptiveTextColor.Default;
            }
            }

            if (!textBlock.IsSubtle)
            {
                label.SetColor(fontColorConfig.Default, context);
            }
            else
            {
                label.SetColor(fontColorConfig.Subtle, context);
            }

            switch (textBlock.Size)
            {
            case AdaptiveTextSize.Default:
            {
                label.FontSize = (double)context.Config.FontSizes.Default;
                break;
            }

            case AdaptiveTextSize.Small:
            {
                label.FontSize = (double)context.Config.FontSizes.Small;
                break;
            }

            case AdaptiveTextSize.Medium:
            {
                label.FontSize = (double)context.Config.FontSizes.Medium;
                break;
            }

            case AdaptiveTextSize.Large:
            {
                label.FontSize = (double)context.Config.FontSizes.Large;
                break;
            }

            case AdaptiveTextSize.ExtraLarge:
            {
                label.FontSize = (double)context.Config.FontSizes.ExtraLarge;
                break;
            }

            default:
            {
                goto case AdaptiveTextSize.Default;
            }
            }

            var text = RendererUtilities.ApplyTextFunctions(textBlock.Text);

            label.FormattedText = text.GetFormattedString(label.FontSize);

            if (textBlock.MaxLines <= 0)
            {
                return(label);
            }
            Grid grid = new Grid();

            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            grid.Children.Add(label);
            return(grid);
        }
Exemple #13
0
        public static View Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            object list;
            string str = input.Value;

            if (str != null)
            {
                list = (
                    from p in str.Split(new char[] { ',' })
                    select p.Trim() into s
                    where !string.IsNullOrEmpty(s)
                    select s).ToList <string>();
            }
            else
            {
                list = null;
            }
            if (list == null)
            {
                list = new List <string>();
            }
            List <string> strs        = (List <string>)list;
            StackLayout   stackLayout = new StackLayout();

            stackLayout.Orientation = StackOrientation.Vertical;
            foreach (AdaptiveChoice choice in input.Choices)
            {
                if (input.IsMultiSelect)
                {
                    var checkBox = new CheckBox()
                    {
                        Text           = choice.Title,
                        IsChecked      = strs.Contains(choice.Value),
                        BindingContext = choice,
                        Style          = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox")
                    };
                    stackLayout.Children.Add(checkBox);


                    checkBox.CheckUnCheckAction = new Action <CheckBox>((c) =>
                    {
                        if (CheckBoxUpdating)
                        {
                            return;
                        }
                        CheckBoxUpdating = true;

                        if (c.Text == "All")
                        {
                            stackLayout.Children.ForEach((i) => (i as CheckBox).IsChecked = c.IsChecked);
                        }
                        else if (c.IsChecked)
                        {
                            CheckBox allCheckBox = null;
                            var isChecked        = true;
                            foreach (var i in stackLayout.Children)
                            {
                                var box = i as CheckBox;
                                if (box.Text == "All")
                                {
                                    allCheckBox = box;
                                }
                                else if (!box.IsChecked)
                                {
                                    isChecked = false;
                                    break;
                                }
                            }
                            if (allCheckBox != null && isChecked)
                            {
                                allCheckBox.IsChecked = true;
                            }
                        }
                        else
                        {
                            foreach (var i in stackLayout.Children)
                            {
                                var box = i as CheckBox;
                                if (box.Text == "All")
                                {
                                    box.IsChecked = false;
                                    break;
                                }
                            }
                        }
                        CheckBoxUpdating = false;
                    });
                }
            }

            context.HideIcon = true;
            context.InputBindings.Add(input.Id, new Func <string>(() =>
            {
                if (input.IsMultiSelect)
                {
                    string value = string.Empty;
                    foreach (var item in stackLayout.Children)
                    {
                        AdaptiveChoice dataContext = item.BindingContext as AdaptiveChoice;
                        var isChecked = (item as CheckBox).IsChecked;
                        if (!isChecked)//(isChecked.GetValueOrDefault() ? !isChecked.HasValue : true))
                        {
                            continue;
                        }
                        value = string.Concat(value, (value == string.Empty ? "" : ";"), dataContext.Value);
                    }
                    return(value);
                }
                return(string.Empty);
            }));

            return(stackLayout);
        }
Exemple #14
0
        public static void AddContainerElements(Grid uiContainer, IList <AdaptiveElement> elements, AdaptiveRenderContext context)
        {
            foreach (AdaptiveElement element in elements)
            {
                View view = context.Render(element);
                if (view == null)
                {
                    continue;
                }
                if (element.Separator && uiContainer.Children.Count > 0)
                {
                    AddSeperator(context, element, uiContainer);
                }
                else if (uiContainer.Children.Count > 0)
                {
                    double spacing = context.Config.GetSpacing(element.Spacing);

                    if (element is AdaptiveTextBlock)
                    {
                        spacing = spacing + (spacing / 2);
                    }
                    else
                    {
                        spacing = spacing / 2;
                    }

                    view.Margin = new Thickness(0, spacing, 0, 0);
                }
                uiContainer.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                Grid.SetRow(view, uiContainer.RowDefinitions.Count - 1);
                uiContainer.Children.Add(view);
            }
        }
Exemple #15
0
        public static void AddActions(Grid uiContainer, IList <AdaptiveAction> actions, AdaptiveRenderContext context)
        {
            if (!context.Config.SupportsInteractivity)
            {
                return;
            }

            ActionsConfig         actionsConfig = context.Config.Actions;
            int                   maxActions    = actionsConfig.MaxActions;
            List <AdaptiveAction> list          = actions.Take <AdaptiveAction>(maxActions).ToList <AdaptiveAction>();

            if (!list.Any <AdaptiveAction>())
            {
                return;
            }

            var flexLayout = new FlexLayout()
            {
                JustifyContent = FlexJustify.SpaceEvenly
            };

            if (actionsConfig.ActionsOrientation != ActionsOrientation.Horizontal)
            {
                flexLayout.Direction = FlexDirection.Row;
            }
            else
            {
                flexLayout.Direction = FlexDirection.Column;
            }

            flexLayout.AlignItems = FlexAlignItems.Center;
            flexLayout.Style      = context.GetStyle("Adaptive.Actions");
            flexLayout.Margin     = new Thickness(0, (double)((actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal ? context.Config.GetSpacing(actionsConfig.Spacing) : context.Config.GetSpacing(actionsConfig.Spacing) - actionsConfig.ButtonSpacing)), 0, 0);
            uiContainer.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });

            Grid.SetRow(flexLayout, uiContainer.RowDefinitions.Count - 1);
            uiContainer.Children.Add(flexLayout);
            bool actionMode = actionsConfig.ShowCard.ActionMode == ShowCardActionMode.Inline;

            if (actionMode)
            {
                if (list.Any <AdaptiveAction>((AdaptiveAction a) => a is AdaptiveShowCardAction))
                {
                    uiContainer.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = GridLength.Auto
                    });
                }
            }
            int         num   = 0;
            List <View> views = new List <View>();

            foreach (AdaptiveAction adaptiveAction in list)
            {
                var button = (Button)context.Render(adaptiveAction);
                if (actionsConfig.ActionsOrientation != ActionsOrientation.Horizontal)
                {
                    button.Margin = new Thickness(0, (double)actionsConfig.ButtonSpacing, 0, 0);
                }
                else if (flexLayout.Children.Count > 0)
                {
                    button.Margin = new Thickness((double)actionsConfig.ButtonSpacing, 0, 0, 0);
                }
                if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal)
                {
                    int num1 = num;
                    num = num1 + 1;
                    Grid.SetColumn(button, num1);
                }
                flexLayout.Children.Add(button);
                AdaptiveShowCardAction adaptiveShowCardAction  = adaptiveAction as AdaptiveShowCardAction;
                AdaptiveShowCardAction adaptiveShowCardAction1 = adaptiveShowCardAction;
                if (adaptiveShowCardAction == null || !actionMode)
                {
                    continue;
                }
                var grid = new Grid()
                {
                    Style          = context.GetStyle("Adaptive.Actions.ShowCard"),
                    BindingContext = adaptiveShowCardAction1,
                    Margin         = new Thickness(0, (double)actionsConfig.ShowCard.InlineTopMargin, 0, 0),
                    IsVisible      = false
                };

                var showCardGrid = (Grid)context.Render(adaptiveShowCardAction1.Card);
                showCardGrid.BackgroundColor    = Color.Transparent;
                showCardGrid.BindingContext     = adaptiveShowCardAction1;
                showCardGrid.Children[0].Margin = new Thickness(0);

                grid.Children.Add(showCardGrid);
                views.Add(grid);
                Grid.SetRow(grid, uiContainer.RowDefinitions.Count - 1);
                uiContainer.Children.Add(grid);

                button.Clicked += new EventHandler((object sender, EventArgs e) =>
                {
                    foreach (var actionBarCard in views)
                    {
                        actionBarCard.IsVisible = false;
                    }
                    if (!grid.IsVisible)
                    {
                        grid.IsVisible = true;
                    }
                });
            }
        }
Exemple #16
0
        public static void SetImageProperties(this Image imageview, AdaptiveImage image, AdaptiveRenderContext context)
        {
            switch (image.Size)
            {
            case AdaptiveImageSize.Auto:
            case AdaptiveImageSize.Stretch:
            {
                imageview.VerticalOptions   = LayoutOptions.FillAndExpand;
                imageview.HorizontalOptions = LayoutOptions.FillAndExpand;
                return;
            }

            case AdaptiveImageSize.Small:
            {
                imageview.WidthRequest  = (double)context.Config.ImageSizes.Small;
                imageview.HeightRequest = (double)context.Config.ImageSizes.Small;
                return;
            }

            case AdaptiveImageSize.Medium:
            {
                imageview.WidthRequest  = (double)context.Config.ImageSizes.Medium;
                imageview.HeightRequest = (double)context.Config.ImageSizes.Medium;
                return;
            }

            case AdaptiveImageSize.Large:
            {
                imageview.WidthRequest  = (double)context.Config.ImageSizes.Large;
                imageview.HeightRequest = (double)context.Config.ImageSizes.Large;
                return;
            }

            default:
            {
                return;
            }
            }
        }