Пример #1
0
 /// <summary>
 /// CapptainPage constructor
 /// </summary>
 public CapptainPageOverlay()
 {
     mNotification = CapptainOverlayNotification.Instance;
     mAnnouncement = CapptainOverlayAnnoucement.Instance;
     mCapptainGrid = new Grid();
 }
Пример #2
0
        /// <summary>
        /// Initialize overlay on the current page
        /// </summary>
        public void InitOverlay()
        {
            /* We have to use RunOnUI to ensure to be in the same thread pool than UI */
      #pragma warning disable 4014
            RunOnUI(() =>
            {
                /* capptainGrid is locked to ensure fast switching between page doesn't crash the app */
                lock (thisLock)
                {
                    mCapptainGrid = new Grid();

                    /* Check if customer have tagged a grid with "capptainGrid" */
                    mCapptainGrid = FindChildControl <Grid>(Window.Current.Content, "CapptainGrid") as Grid;

                    /* Pick the first grid element founded */
                    if (mCapptainGrid == null)
                    {
                        mCapptainGrid = FindChildControl <Grid>(Window.Current.Content, "") as Grid;
                    }

                    /* Take the instance of capptain UI element to add them on capptain grid */
                    mNotification = CapptainOverlayNotification.Instance;
                    mAnnouncement = CapptainOverlayAnnoucement.Instance;

                    /* If we have a grid then insert the overlay in it */
                    if (mCapptainGrid != null)
                    {
                        /* Check that notification is not already set */
                        if (!mCapptainGrid.Children.Contains(mNotification))
                        {
                            /* Add it */
                            try
                            {
                                mCapptainGrid.Children.Add(mNotification);
                            }
                            catch (Exception)
                            {
                                /* Because of threading context we can grab an unexpected error due to webview insertion
                                 * But we have to ensure overlay creation */
                                InitOverlay();
                                return;
                            }


                            /* Set the display_orientation_change event to resize the notification */
                            mNotification.SetHandler();

                            /* Made the first resize to be sure to match the current application size */
                            mNotification.SetWebView();
                        }

                        /* Check an announcement is already set */
                        if (!mCapptainGrid.Children.Contains(mAnnouncement))
                        {
                            /* Add it */
                            try
                            {
                                mCapptainGrid.Children.Add(mAnnouncement);
                            }
                            catch (Exception)
                            {
                                /* Because of threading context we can grab an unexpected error due to webview insertion
                                 * But we have to ensure overlay creation */
                                InitOverlay();
                                return;
                            }

                            /* Set the display_orientation_change event to resize the notification */
                            mAnnouncement.SetHandler();

                            /* Made the first resize to be sure to match the current application size */
                            mAnnouncement.SetWebView();
                        }
                    }
                    else
                    {
                        /* Even if we have locked we ensure that event on overlay are detach  */
                        mNotification.UnsetHandler();
                        mAnnouncement.UnsetHandler();
                        mCapptainGrid = new Grid();

                        /* Run again the init because sometime graphical context isn't set fine */
                        InitOverlay();
                    }
                }
            });
        }