public static void Add(MultiPlatformApplication.Controls.CtrlContentPage contentPage, View view, PopupType type)
        {
            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => Add(contentPage, view, type));
                return;
            }

            if (contentPage == null)
            {
                contentPage = GetCurrentContentPage();
            }

            if (contentPage != null)
            {
                if (!String.IsNullOrEmpty(view.AutomationId))
                {
                    if (!contentPage.PopupExists(view.AutomationId))
                    {
                        contentPage.AddViewAsPopupInternal(view);
                        SetType(view, type);
                    }
                }
            }
        }
        public static void AddBasicActivityActivatorUsingDefaultSettings(MultiPlatformApplication.Controls.CtrlContentPage contentPage, String automationId)
        {
            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => AddBasicActivityActivatorUsingDefaultSettings(contentPage, automationId));
                return;
            }

            Color backColor   = Helper.GetResourceDictionaryById <Color>("ColorEntryBackground");
            Color color       = Helper.GetResourceDictionaryById <Color>("ColorMain");
            Color borderColor = Helper.GetResourceDictionaryById <Color>("ColorEntryPlaceHolder");

            String colorHex = borderColor.ToHex();

            colorHex = "#7F" + colorHex.Substring(3);
            Color obfuscationColor = Color.FromHex(colorHex);

            if (automationId == DEFAULT_ACTIVITY_INDICATOR_AUTOMATION_ID)
            {
                SetDefaultBasicActivityActivator(obfuscationColor, 80, 10, 2, borderColor, backColor, 50, color, true);
            }
            else
            {
                AddBasicActivityActivator(contentPage, automationId, obfuscationColor, 80, 10, 2, borderColor, backColor, 50, color, true);
            }
        }
        public static void AddBasicDisconnexionInformationUsingDefaultSettings(MultiPlatformApplication.Controls.CtrlContentPage contentPage, String automationId)
        {
            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => AddBasicDisconnexionInformationUsingDefaultSettings(contentPage, automationId));
                return;
            }

            Color backColor   = Color.Black;
            Color color       = Color.White;
            Color borderColor = Color.White;

            String colorHex = Helper.GetResourceDictionaryById <Color>("ColorMainOnOver").ToHex();

            colorHex = "#7F" + colorHex.Substring(3);
            Color obfuscationColor = Color.FromHex(colorHex);

            if (automationId == DEFAULT_DISCONNECTION_INFORMATION_AUTOMATION_ID)
            {
                SetDefaultBasicDisconnexionInformation(obfuscationColor, 300, 10, 2, borderColor, backColor, 50, color, true);
            }
            else
            {
                AddBasicDisconnexionInformation(contentPage, automationId, obfuscationColor, 360, 10, 2, borderColor, backColor, 50, color, true);
            }
        }
 public static void Remove(MultiPlatformApplication.Controls.CtrlContentPage contentPage, View view)
 {
     // NECESSARY TO BE ON MAIN THREAD
     if (!MainThread.IsMainThread)
     {
         MainThread.BeginInvokeOnMainThread(() => Remove(contentPage, view));
         return;
     }
     contentPage.RemoveViewAsPopupInternal(view);
 }
        private static void HideInternal(String popupAutomationId)
        {
            if (String.IsNullOrEmpty(popupAutomationId))
            {
                return;
            }

            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => HideInternal(popupAutomationId));
                return;
            }

            // If we add a known activity indicator, remove it from the list
            if (activityIndicatorList.ContainsKey(popupAutomationId))
            {
                activityIndicatorList.Remove(popupAutomationId);
            }


            MultiPlatformApplication.Controls.CtrlContentPage contentPage = GetCurrentContentPage();
            View view = GetView(popupAutomationId, contentPage);

            if (view != null)
            {
                if (view.IsVisible)
                {
                    Boolean needToHide = true;

                    if (popupAutomationId == previousContextMenuActionDisplayed?.PopupAutomationId)
                    {
                        if (previousContextMenuActionDisplayed.Date != DateTime.MinValue)
                        {
                            TimeSpan duration = DateTime.UtcNow - previousContextMenuActionDisplayed.Date;
                            needToHide = (duration.TotalMilliseconds > 100);
                        }
                        else
                        {
                            needToHide = false;
                        }
                    }

                    if (needToHide)
                    {
                        view.IsVisible = false;
                        //contentPage.GetRelativeLayout().LowerChild(view);
                    }
                }
                else
                {
                }
            }
        }
        public static void SetDefaultBasicDisconnexionInformation(Color obfuscationColor, double squareSize, float squareCornerRadius, double squareCornerSize, Color squareCornerColor, Color squareBackgroundColor, double indicatorSize, Color indicatorColor, Boolean useDeviceActivityIndicator)
        {
            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => SetDefaultBasicDisconnexionInformation(obfuscationColor, squareSize, squareCornerRadius, squareCornerSize, squareCornerColor, squareBackgroundColor, indicatorSize, indicatorColor, useDeviceActivityIndicator));
                return;
            }

            MultiPlatformApplication.Controls.CtrlContentPage contentPage = GetCurrentContentPage();

            if (contentPage != null)
            {
                View popupView = contentPage?.GetPopup(DEFAULT_DISCONNECTION_INFORMATION_AUTOMATION_ID);
                if (popupView == null)
                {
                    AddBasicDisconnexionInformation(contentPage, DEFAULT_DISCONNECTION_INFORMATION_AUTOMATION_ID, obfuscationColor, squareSize, squareCornerRadius, squareCornerSize, squareCornerColor, squareBackgroundColor, indicatorSize, indicatorColor, useDeviceActivityIndicator);
                }
                else
                {
                    if (popupView is ContentView contentView)
                    {
                        popupView.BackgroundColor = obfuscationColor;

                        if (contentView.Content is Frame frame1)
                        {
                            frame1.HeightRequest   = squareSize;
                            frame1.WidthRequest    = squareSize;
                            frame1.CornerRadius    = squareCornerRadius;
                            frame1.BackgroundColor = squareCornerColor;

                            if (frame1.Content is Frame frame2)
                            {
                                frame2.WidthRequest    = squareSize - squareCornerSize;
                                frame2.HeightRequest   = squareSize - squareCornerSize;
                                frame2.CornerRadius    = squareCornerRadius;
                                frame2.BackgroundColor = squareBackgroundColor;

                                // Recreate Content
                                frame2.Content = CreateActivityIndicatorContent(indicatorSize, indicatorColor, useDeviceActivityIndicator);

                                if (useDeviceActivityIndicator)
                                {
                                    frame2.Content.SetBinding(ActivityIndicator.IsRunningProperty, new Binding("IsVisible", source: popupView));
                                }
                            }
                        }
                    }
                }
            }
        }
        public static void Remove(MultiPlatformApplication.Controls.CtrlContentPage contentPage, String automationId)
        {
            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => Remove(contentPage, automationId));
                return;
            }

            View view = GetView(automationId, contentPage);

            if (view != null)
            {
                contentPage.RemoveViewAsPopupInternal(view);
            }
        }
        public static void ShowDefaultActivityIndicator(String linkedToAutomationId = null)
        {
            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => ShowDefaultActivityIndicator(linkedToAutomationId));
                return;
            }

            MultiPlatformApplication.Controls.CtrlContentPage contentPage = GetCurrentContentPage();

            if (contentPage?.PopupExists(DEFAULT_ACTIVITY_INDICATOR_AUTOMATION_ID) != true)
            {
                AddBasicActivityActivatorUsingDefaultSettings(null, DEFAULT_ACTIVITY_INDICATOR_AUTOMATION_ID);
            }

            Show(DEFAULT_ACTIVITY_INDICATOR_AUTOMATION_ID, linkedToAutomationId, LayoutAlignment.Center, false, LayoutAlignment.Center, false, new Point(), -1);
        }
        public static void ShowDefaultDisconnectionInformation(String linkedToAutomationId = null)
        {
            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => ShowDefaultDisconnectionInformation(linkedToAutomationId));
                return;
            }

            MultiPlatformApplication.Controls.CtrlContentPage contentPage = GetCurrentContentPage();

            String id = DEFAULT_DISCONNECTION_INFORMATION_AUTOMATION_ID;

            if (contentPage?.PopupExists(id) != true)
            {
                AddBasicDisconnexionInformationUsingDefaultSettings(null, id);
            }

            Show(id, linkedToAutomationId, LayoutAlignment.Center, false, LayoutAlignment.Center, false, new Point(), -1);
        }
        public static void AddBasicDisconnexionInformation(MultiPlatformApplication.Controls.CtrlContentPage contentPage, String automationId, Color obfuscationColor, double width, float cornerRadius, double cornerSize, Color squareCornerColor, Color squareBackgroundColor, double indicatorSize, Color indicatorColor, Boolean useDeviceActivityIndicator)
        {
            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => AddBasicActivityActivator(contentPage, automationId, obfuscationColor, width, cornerRadius, cornerSize, squareCornerColor, squareBackgroundColor, indicatorSize, indicatorColor, useDeviceActivityIndicator));
                return;
            }

            if (contentPage == null)
            {
                contentPage = GetCurrentContentPage();
            }

            if (contentPage?.PopupExists(automationId) == true)
            {
                return;
            }

            if (String.IsNullOrEmpty(automationId))
            {
                return;
            }

            ContentView contentView = new ContentView
            {
                AutomationId = automationId,
                IsVisible    = false,

                Margin          = 0,
                Padding         = 0,
                BackgroundColor = obfuscationColor
            };



            // Create Frame which contains the activity indicator
            Frame frame1 = new Frame
            {
                Margin    = 0,
                Padding   = 0,
                HasShadow = false,

                WidthRequest  = width,
                HeightRequest = indicatorSize + cornerSize,

                CornerRadius    = cornerRadius,
                BackgroundColor = squareCornerColor,

                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center
            };

            // Set frame1 as the content of the contentView
            contentView.Content = frame1;

            // Create Frame which contains the label and the activity indicator
            Frame frame2 = new Frame
            {
                Margin    = 0,
                Padding   = 0,
                HasShadow = false,

                WidthRequest  = width - cornerSize,
                HeightRequest = indicatorSize,

                CornerRadius    = cornerRadius,
                BackgroundColor = squareBackgroundColor,

                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center
            };

            // Set frame2 as the content of the frame1
            frame1.Content = frame2;

            StackLayout stackLayout = new StackLayout
            {
                Margin            = 0,
                Padding           = 0,
                Orientation       = StackOrientation.Horizontal,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center
            };

            frame2.Content = stackLayout;

            Color backColor   = Helper.GetResourceDictionaryById <Color>("ColorEntryBackground");
            Color color       = Helper.GetResourceDictionaryById <Color>("ColorMain");
            Color borderColor = Helper.GetResourceDictionaryById <Color>("ColorEntryPlaceHolder");

            Label label = new Label
            {
                Margin  = new Thickness(0, 0, 20, 0),
                Padding = 0,

                Text      = Helper.SdkWrapper.GetLabel("noNetwork").Replace("<br/>", "\r\n"),
                TextColor = indicatorColor,

                MaxLines = 2,

                FontSize       = Helper.GetResourceDictionaryById <double>("FontSizeMicro"),
                FontAttributes = FontAttributes.None,

                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalTextAlignment = TextAlignment.Center,

                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
            };

            stackLayout.Children.Add(label);

            // Create activity indicator
            View activityIndicator = CreateActivityIndicatorContent(indicatorSize, indicatorColor, useDeviceActivityIndicator);

            if (useDeviceActivityIndicator)
            {
                activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, new Binding("IsVisible", source: contentView));
            }

            // Set the activityIndicator as content of the frame
            stackLayout.Children.Add(activityIndicator);

            contentPage.AddViewAsPopupInternal(contentView);
            SetType(contentView, PopupType.Information);
        }
        public static void AddBasicActivityActivator(MultiPlatformApplication.Controls.CtrlContentPage contentPage, String automationId, Color obfuscationColor, double squareSize, float squareCornerRadius, double squareCornerSize, Color squareCornerColor, Color squareBackgroundColor, double indicatorSize, Color indicatorColor, Boolean useDeviceActivityIndicator)
        {
            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => AddBasicActivityActivator(contentPage, automationId, obfuscationColor, squareSize, squareCornerRadius, squareCornerSize, squareCornerColor, squareBackgroundColor, indicatorSize, indicatorColor, useDeviceActivityIndicator));
                return;
            }

            if (contentPage == null)
            {
                contentPage = GetCurrentContentPage();
            }

            if (contentPage?.PopupExists(automationId) == true)
            {
                return;
            }

            if (String.IsNullOrEmpty(automationId))
            {
                return;
            }

            ContentView contentView = new ContentView
            {
                AutomationId = automationId,
                IsVisible    = false,

                Margin          = 0,
                Padding         = 0,
                BackgroundColor = obfuscationColor
            };

            // Create Frame which contains the activity indicator
            Frame frame1 = new Frame
            {
                Margin    = 0,
                Padding   = 0,
                HasShadow = false,

                WidthRequest  = squareSize,
                HeightRequest = squareSize,

                CornerRadius    = squareCornerRadius,
                BackgroundColor = squareCornerColor,

                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center
            };

            // Set frame content
            contentView.Content = frame1;

            // Create Frame which contains the activity indicator
            Frame frame2 = new Frame
            {
                Margin    = 0,
                Padding   = 0,
                HasShadow = false,

                WidthRequest  = squareSize - squareCornerSize,
                HeightRequest = squareSize - squareCornerSize,

                CornerRadius    = squareCornerRadius,
                BackgroundColor = squareBackgroundColor,

                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center
            };

            frame1.Content = frame2;

            // Create activity indicator
            View activityIndicator = CreateActivityIndicatorContent(indicatorSize, indicatorColor, useDeviceActivityIndicator);

            if (useDeviceActivityIndicator)
            {
                activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, new Binding("IsVisible", source: contentView));
            }

            // Set the activityIndicator as content of the frame
            frame2.Content = activityIndicator;

            contentPage.AddViewAsPopupInternal(contentView);
            SetType(contentView, PopupType.ActivityIndicator);
        }
        private static void ProcessPositionAndShowPopup(PopupAction newPopupAction)
        {
            if (newPopupAction == null)
            {
                return;
            }

            // NECESSARY TO BE ON MAIN THREAD
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => ProcessPositionAndShowPopup(newPopupAction));
                return;
            }

            // Get ContentPage
            MultiPlatformApplication.Controls.CtrlContentPage contentPage = GetCurrentContentPage();

            // Get the View of the popup
            View view = GetView(newPopupAction.PopupAutomationId, contentPage);

            if (view == null)
            {
                return;
            }

            // Get Rect of the linked element (if any)
            if (!String.IsNullOrEmpty(newPopupAction.LinkedToAutomationId))
            {
                newPopupAction.Rect = GetRectOfView(contentPage, newPopupAction.LinkedToAutomationId);
            }

            // If no Rect is defined, we use the Content Page Bounds
            if (newPopupAction.Rect.IsEmpty)
            {
                newPopupAction.Rect = contentPage.Bounds;
            }

            if (popupAction.PopupType != PopupType.ContextMenu)
            {
                if (String.IsNullOrEmpty(newPopupAction.LinkedToAutomationId))
                {
                    // Set X and Y Constraints
                    RelativeLayout.SetXConstraint(view, Constraint.Constant(0));
                    RelativeLayout.SetYConstraint(view, Constraint.Constant(0));

                    // Set Width and HeightConstraints
                    RelativeLayout.SetWidthConstraint(view, Constraint.RelativeToParent((rl) => { return(rl.Width); }));
                    RelativeLayout.SetHeightConstraint(view, Constraint.RelativeToParent((rl) => { return(rl.Height); }));
                }
                else
                {
                    Rect rect = GetRectOfView(newPopupAction.LinkedToAutomationId);

                    // Set X and Y Constraints
                    RelativeLayout.SetXConstraint(view, Constraint.Constant(rect.X));
                    RelativeLayout.SetYConstraint(view, Constraint.Constant(rect.Y));

                    // Set Width and HeightConstraints
                    RelativeLayout.SetWidthConstraint(view, Constraint.Constant(rect.Width));
                    RelativeLayout.SetHeightConstraint(view, Constraint.Constant(rect.Height));

                    // Add to the list of Activity Indicator
                    if (!activityIndicatorList.ContainsKey(popupAction.PopupAutomationId))
                    {
                        activityIndicatorList.Add(popupAction.PopupAutomationId, popupAction);
                    }
                }

                if (popupAction.PopupType == PopupType.Information)
                {
                    // We display an Information popup. Do we have to hide it after a delay ?
                    if (newPopupAction.Delay > 0)
                    {
                        Device.StartTimer(TimeSpan.FromMilliseconds(newPopupAction.Delay), () =>
                        {
                            HideInternal(newPopupAction.PopupAutomationId); return(false);
                        });
                    }
                }

                // Show popup
                view.IsVisible = true;
                contentPage.GetRelativeLayout().RaiseChild(view);
            }
            else
            {
                // Calculate the new position of the Popup
                double X = 0, Y = 0;

                X = GetXPosition(contentPage, view, newPopupAction.HorizontalLayoutAlignment, newPopupAction.Rect, newPopupAction.OutsideRectHorizontally, popupAction.Translation.X);
                Y = GetYPosition(contentPage, view, newPopupAction.VerticalLayoutAlignment, newPopupAction.Rect, newPopupAction.OutsideRectVertically, popupAction.Translation.Y);

                // Are we dealing with a Context Menu ?
                if (newPopupAction.PopupType == PopupType.ContextMenu)
                {
                    // Hide previous context menu - if any (only one can be display in same time)
                    HideInternal(previousContextMenuActionDisplayed?.PopupAutomationId);

                    // Store context menu
                    previousContextMenuActionDisplayed = newPopupAction;
                }

                // Set X and Y Constraints
                RelativeLayout.SetXConstraint(view, Constraint.RelativeToParent((rl) => X));
                RelativeLayout.SetYConstraint(view, Constraint.RelativeToParent((rl) => Y));

                // Show popup
                view.IsVisible = true;
                contentPage.GetRelativeLayout().RaiseChild(view);
            }
        }