Example #1
0
        private void ToastRun()
        {
            while (true)
            {
                lock (_lock)
                {
                    if (_toastQueue.IsEmpty)
                    {
                        if (CurrentToast != null)
                        {
                            CurrentToast = null;
                            OnDeactivate();
                        }

                        Monitor.Wait(_lock);
                    }
                }

                ToastData toastData;
                if (_toastQueue.TryDequeue(out toastData))
                {
                    OnActivate();
                    CurrentToast = toastData;
                    Thread.Sleep(Math.Max(toastData.DisplayTime, 2000));
                }
            }
        }
Example #2
0
        public void NotifyDefaultChanged(MMDevice audioDevice)
        {
            var toastData = new ToastData
            {
                ImagePath = "file:///" + ApplicationPath.DefaultImagePath,
                Title     = audioDevice.FriendlyName
            };

            if (Configuration.CustomSound != null && File.Exists(Configuration.CustomSound.FilePath))
            {
                toastData.Silent        = false;
                toastData.SoundFilePath = Configuration.CustomSound.FilePath;
            }

            switch (audioDevice.DataFlow)
            {
            case DataFlow.Render:
                toastData.Line0 = SettingsStrings.tooltipOnHoverOptionPlaybackDevice;
                break;

            case DataFlow.Capture:
                toastData.Line0 = SettingsStrings.tooltipOnHoverOptionRecordingDevice;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(audioDevice.DataFlow), audioDevice.DataFlow, null);
            }
            new ToastManager().ShowNotification(toastData);
        }
Example #3
0
        public void NotifyDefaultChanged(IAudioDevice audioDevice)
        {
            var toastData = new ToastData
            {
                ImagePath = "file:///" + ApplicationPath.DefaultImagePath,
                Title     = audioDevice.FriendlyName
            };

            if ((Configuration.CustomSound != null) && File.Exists(Configuration.CustomSound.FilePath))
            {
                toastData.Silent        = false;
                toastData.SoundFilePath = Configuration.CustomSound.FilePath;
            }

            switch (audioDevice.Type)
            {
            case AudioDeviceType.Playback:
                toastData.Line0 = Notifications.PlaybackChanged;

                break;

            case AudioDeviceType.Recording:
                toastData.Line0 = Notifications.RecordingChanged;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(audioDevice.Type), audioDevice.Type, null);
            }
            new ToastManager().ShowNotification(toastData);
        }
Example #4
0
 public void NewNotification(ToastData data)
 {
     lock (_lock)
     {
         _toastQueue.Enqueue(data);
         Monitor.Pulse(_lock);
     }
 }
Example #5
0
 public void Show(ToastData data)
 {
     if (_view.CheckAccess())
     {
         _viewModel.NewNotification(data);
     }
     else
     {
         _view.Dispatcher.BeginInvoke(new Action <ToastData>(Show), DispatcherPriority.Background, data);
     }
 }
Example #6
0
 public override void onAddCallBack <T>(T data)
 {
     if (data is UIData)
     {
         UIData uiData = data as UIData;
         {
             uiData.toastData.allAddCallBack(this);
             uiData.toastMessageUI.allAddCallBack(this);
         }
         dirty = true;
         return;
     }
     if (data is ToastData)
     {
         ToastData toastData = data as ToastData;
         {
             ToastDataUpdate toastDataUpdate = this.GetComponent <ToastDataUpdate>();
             if (toastDataUpdate != null)
             {
                 toastDataUpdate.setData(toastData);
             }
             else
             {
                 Debug.LogError("toastDataUpdate null");
             }
         }
         dirty = true;
         return;
     }
     if (data is ToastMessageUI.UIData)
     {
         ToastMessageUI.UIData subUIData = data as ToastMessageUI.UIData;
         {
             if (toastMessageUI != null)
             {
                 toastMessageUI.setData(subUIData);
             }
             else
             {
                 Debug.LogError("toastMessageUI null");
             }
         }
         dirty = true;
         return;
     }
     Debug.LogError("Don't process: " + data + "; " + this);
 }
Example #7
0
 public override void refresh()
 {
     if (dirty)
     {
         dirty = false;
         if (this.data != null)
         {
             // Find current show toastMessage
             ToastMessage currentMessage = null;
             {
                 if (this.data.toastData.v != null)
                 {
                     ToastData toastData = this.data.toastData.v;
                     if (toastData.state.v == ToastData.State.Normal)
                     {
                         if (toastData.messages.vs.Count > 0)
                         {
                             currentMessage = toastData.messages.vs[0];
                         }
                         else
                         {
                             Logger.Log("Don't have any message");
                         }
                     }
                 }
                 else
                 {
                     Logger.LogError("toastData null");
                 }
             }
             // Show
             {
                 if (this.data.toastMessageUI.v != null)
                 {
                     ToastMessageUI.UIData toastMessageUI = this.data.toastMessageUI.v;
                     toastMessageUI.toastMessage.v = new ReferenceData <ToastMessage>(currentMessage);
                 }
             }
         }
         else
         {
             Debug.LogError("data null");
         }
     }
 }
Example #8
0
        // Update is called once per frame
        void Update()
        {
            if (!BlueprintReality.Utility.ScreenUtility.AreAllScenesLoaded())
            {
                return;
            }
            Instance.timeElapsed += Time.deltaTime;
            if (currentToast != null)
            {
                if (Instance.timeElapsed >= currentToast.duration + TIME_TWEEN)
                {
                    Instance.timeElapsed = 0f;
                    GameObject.Destroy(Instance.popupWindow.gameObject);
                    Instance.popupWindow = null;
                    currentToast         = null;
                }
                else
                {
                    if (Instance.timeElapsed < TIME_TWEEN)
                    {
                        PopupAlphaTween(Instance.timeElapsed, 0f, 1f);   // fade in
                    }
                    else if (timeElapsed >= currentToast.duration)
                    {
                        PopupAlphaTween(Instance.timeElapsed - currentToast.duration, 1f, 0f);   // fade out
                    }
                }
            }
            else if (Instance.toasts.Count > 0 && Instance.timeElapsed >= TIME_BETWEEN_TOASTS)
            {
                Instance.timeElapsed = 0f;
                currentToast         = Instance.toasts[0];
                Instance.toasts.RemoveAt(0);

                string titleText   = currentToast.locTitle;
                string contentText = string.IsNullOrEmpty(currentToast.plainMsg) ? currentToast.locMsg : currentToast.plainMsg;
                bool   contentLoc  = string.IsNullOrEmpty(currentToast.plainMsg);
                bool   titleLoc    = true;

                CreatePopup(titleText, titleLoc, contentText, contentLoc, 0f);
            }
        }
Example #9
0
        private void ShowToast(ITracer tracer, NamedPipeMessages.Notification.Request request)
        {
            ToastData toastData = new ToastData();

            toastData.Visual = new VisualData();

            BindingData binding = new BindingData();

            toastData.Visual.Binding = binding;

            binding.Template = "ToastGeneric";
            binding.Items    = new XmlList <BindingItem>();
            binding.Items.Add(new BindingItem.TextData(request.Title));
            binding.Items.AddRange(request.Message.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(t => new BindingItem.TextData(t)));

            XmlDocument toastXml = new XmlDocument();

            using (StringWriter stringWriter = new StringWriter())
                using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings {
                    OmitXmlDeclaration = true
                }))
                {
                    XmlSerializer           serializer = new XmlSerializer(toastData.GetType());
                    XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                    namespaces.Add(string.Empty, string.Empty);

                    serializer.Serialize(xmlWriter, toastData, namespaces);

                    toastXml.LoadXml(stringWriter.ToString());
                }

            ToastNotification toastNotification = new ToastNotification(toastXml);

            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(ServiceAppId);

            toastNotifier.Show(toastNotification);
        }
Example #10
0
 /// <summary>
 /// Show a toast notification with the given data
 /// </summary>
 /// <param name="data"></param>
 public void ShowNotification(ToastData data)
 {
     var notification = data.BuildNotification();
     ToastNotificationManager.CreateToastNotifier(APP_ID).Show(notification);
 }
Example #11
0
        public override void OnShow(object param)
        {
            // Log.Debug($"Toast OnShow");
            if (null != param)
            {
                string mContent = param as string;
                if (null != mContent)
                {
                    if (mContent == LanguageMgr.mInstance.GetLanguageForKey("error105"))
                    {
                        return;
                    }
                    GameObject mGameObject = GameObject.Instantiate(transToast.gameObject);
                    mGameObject.transform.SetParent(rc.transform);
                    mGameObject.transform.localPosition = Vector3.zero;
                    mGameObject.transform.localRotation = Quaternion.identity;
                    mGameObject.transform.localScale    = Vector3.one;
                    ToastData mToastData = new ToastData();
                    mToastData.gameObject       = mGameObject;
                    mToastData.textContent      = mGameObject.transform.Find("Text_Toast").GetComponent <Text>();
                    mToastData.imageContent     = mGameObject.transform.Find("Image_Toast").GetComponent <Image>();
                    mToastData.state            = 1;
                    mToastData.textContent.text = mContent;
                    RectTransform mRectTransform     = mToastData.imageContent.transform as RectTransform;
                    RectTransform mTextRectTransform = mToastData.textContent.transform as RectTransform;
                    if (null != mRectTransform)
                    {
                        // float mWidth = getFontlen(mToastData.textContent);
                        float mWidth = mToastData.textContent.preferredWidth;
                        if (mWidth < 1000)
                        {
                            mRectTransform.sizeDelta     = new Vector2(mWidth + 80, 100);
                            mTextRectTransform.sizeDelta = new Vector2(mWidth, 100);
                        }
                        else
                        {
                            mRectTransform.sizeDelta     = new Vector2(1080, 150);
                            mTextRectTransform.sizeDelta = new Vector2(1000, 150);
                        }
                    }


                    float deltaY = (rc.transform.childCount - 2) * 150f;

                    mToastData.gameObject.transform.localPosition = new Vector3(0, -deltaY, 0);

                    mToastData.gameObject.SetActive(true);
                    mToastData.imageContent.color = new Color(1, 1, 1, 1);
                    mToastData.textContent.color  = new Color(1, 1, 1, 1);
                    Sequence mSequence = DOTween.Sequence();
                    mSequence.Append(mToastData.gameObject.transform.DOLocalMoveY(250f - deltaY, 1f).SetEase(Ease.OutQuart));
                    mSequence.AppendInterval(1f);
                    mSequence.Append(mToastData.imageContent.DOFade(0, 0.3f));
                    mSequence.Join(mToastData.textContent.DOFade(0, 0.3f));
                    // mSequence.AppendCallback(() =>
                    // {
                    //     mToastData.state = 0;
                    //     mToastData.gameObject.SetActive(false);
                    //     GameObject.Destroy(mToastData.gameObject);
                    //     mToastData = null;
                    //     CheckPos();
                    // });
                    mSequence.OnComplete(() =>
                    {
                        mToastData.state = 0;
                        mToastData.gameObject.SetActive(false);
                        GameObject.Destroy(mToastData.gameObject);
                        mToastData = null;
                        CheckPos();
                    });
                }
            }
        }
Example #12
0
 public override void onRemoveCallBack <T>(T data, bool isHide)
 {
     if (data is UIData)
     {
         UIData uiData = data as UIData;
         {
             uiData.toastData.allRemoveCallBack(this);
             uiData.toastMessageUI.allRemoveCallBack(this);
         }
         this.setDataNull(uiData);
         return;
     }
     if (data is ToastData)
     {
         ToastData toastData = data as ToastData;
         {
             ToastDataUpdate toastDataUpdate = this.GetComponent <ToastDataUpdate>();
             if (toastDataUpdate != null)
             {
                 if (toastDataUpdate.data == toastData)
                 {
                     toastDataUpdate.setData(null);
                 }
                 else
                 {
                     Debug.LogError("why different");
                 }
             }
             else
             {
                 Debug.LogError("toastDataUpdate null");
             }
         }
         return;
     }
     if (data is ToastMessageUI.UIData)
     {
         ToastMessageUI.UIData subUIData = data as ToastMessageUI.UIData;
         {
             if (toastMessageUI != null)
             {
                 if (toastMessageUI.data == subUIData)
                 {
                     toastMessageUI.setData(null);
                 }
                 else
                 {
                     Debug.LogError("why different");
                 }
             }
             else
             {
                 Debug.LogError("toastMessageUI null");
             }
         }
         // Remove child
         {
             if (subUIData.toastMessage.v.data != null)
             {
                 subUIData.toastMessage.v = new ReferenceData <ToastMessage>(null);
             }
         }
         return;
     }
     Debug.LogError("Don't process: " + data + "; " + this);
 }
Example #13
0
        public void Notify(string title, string message, string actionButtonTitle, string callbackArgs)
        {
            // Reference: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/adaptive-interactive-toasts
            ToastData toastData = new ToastData();

            toastData.Visual = new VisualData();

            BindingData binding = new BindingData();

            toastData.Visual.Binding = binding;

            // ToastGeneric- Our toast contains VFSForGit icon and text
            binding.Template = "ToastGeneric";
            binding.Items    = new XmlList <BindingItem>();
            binding.Items.Add(new BindingItem.TextData(title));
            binding.Items.Add(new BindingItem.TextData(message));

            string logo = "file:///" + Path.Combine(ProcessHelper.GetCurrentProcessLocation(), ScalarIconName);

            binding.Items.Add(new BindingItem.ImageData()
            {
                Source    = logo,
                Placement = "appLogoOverride",
                HintCrop  = "circle"
            });

            if (!string.IsNullOrEmpty(actionButtonTitle))
            {
                ActionsData actionsData = new ActionsData();
                actionsData.Actions = new XmlList <ActionItem>();
                actionsData.Actions.Add(new ActionItem()
                {
                    Content        = actionButtonTitle,
                    Arguments      = string.IsNullOrEmpty(callbackArgs) ? string.Empty : callbackArgs,
                    ActivationType = "background"
                });

                toastData.Actions = actionsData;
            }

            XmlDocument toastXml = new XmlDocument();

            using (StringWriter stringWriter = new StringWriter())
                using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings {
                    OmitXmlDeclaration = true
                }))
                {
                    XmlSerializer           serializer = new XmlSerializer(toastData.GetType());
                    XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                    namespaces.Add(string.Empty, string.Empty);

                    serializer.Serialize(xmlWriter, toastData, namespaces);

                    toastXml.LoadXml(stringWriter.ToString());
                }

            ToastNotification toastNotification = new ToastNotification(toastXml);

            toastNotification.Activated += this.ToastActivated;
            toastNotification.Dismissed += this.ToastDismissed;
            toastNotification.Failed    += this.ToastFailed;

            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(ServiceAppId);

            toastNotifier.Show(toastNotification);
        }