예제 #1
0
        internal static void BindObject(NotificationEventArgs eventargs)
        {
            string text;
            int    max;
            bool   isExisted = false;
            SafeAppControlHandle appcontrol = null;
            Bundle bundle;

            NotificationEventArgs.ReplyActionArgs  reply  = new NotificationEventArgs.ReplyActionArgs();
            NotificationEventArgs.ButtonActionArgs button = new NotificationEventArgs.ButtonActionArgs();
            string replyKey = "__PARENT_INDEX__";

            Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.TextInputButton, out text);
            if (string.IsNullOrEmpty(text) == false)
            {
                isExisted        = true;
                button.ImagePath = text;
            }

            Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.InputButton, out text);
            if (string.IsNullOrEmpty(text) == false)
            {
                isExisted   = true;
                button.Text = text;
            }

            Interop.NotificationEventListener.GetEventHandler(eventargs.Handle, (int)ClickEventType.InputButton, out appcontrol);

            if (appcontrol != null && appcontrol.IsInvalid == false)
            {
                button.Action = new AppControl(appcontrol);
                isExisted     = true;
            }

            reply.Button = button;

            Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.PlaceHolder, out text);

            if (string.IsNullOrEmpty(text) == false)
            {
                isExisted             = true;
                reply.PlaceHolderText = text;
            }

            Interop.NotificationEventListener.GetPlaceHolderLength(eventargs.Handle, out max);
            reply.ReplyMax = max;
            if (max > 0)
            {
                isExisted = true;
            }

            if (eventargs.ExtraData.TryGetValue(replyKey, out bundle))
            {
                if (bundle.Contains(replyKey))
                {
                    string parentIndex;
                    if (bundle.TryGetItem(replyKey, out parentIndex))
                    {
                        try
                        {
                            reply.ParentIndex = (ButtonIndex)int.Parse(parentIndex);
                            isExisted         = true;
                        }
                        catch (Exception ex)
                        {
                            Log.Error(LogTag, "unable to get ParentIndex " + ex.Message);
                        }
                    }
                }
            }

            if (isExisted)
            {
                NotificationEventArgs.ActiveStyleArgs activeStyle = eventargs.Style["Active"] as NotificationEventArgs.ActiveStyleArgs;
                if (activeStyle != null)
                {
                    activeStyle.Reply = reply;
                }
            }
        }
        internal static void BindObject(NotificationEventArgs eventargs)
        {
            bool   autoRemove;
            string path;
            int    styleList;
            int    timeout;
            SafeAppControlHandle appcontrol = null;

            Interop.NotificationEventListener.GetStyleList(eventargs.Handle, out styleList);

            if ((styleList & (int)NotificationDisplayApplist.Active) != 0)
            {
                NotificationEventArgs.ActiveStyleArgs activeStyle = new NotificationEventArgs.ActiveStyleArgs();
                eventargs.Style.Add(activeStyle.Key, activeStyle);

                for (int i = (int)ClickEventType.FirstButton; i <= (int)ClickEventType.ThirdButton; i++)
                {
                    NotificationButtonActionArgBinder.BindObject(eventargs, i);
                }

                Interop.NotificationEventListener.GetAutoRemove(eventargs.Handle, out autoRemove);
                activeStyle.IsAutoRemove = autoRemove;

                Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Background, out path);
                activeStyle.BackgroundImage = path;

                int index;
                Interop.NotificationEventListener.GetDefaultButton(eventargs.Handle, out index);
                activeStyle.DefaultButton = (ButtonIndex)(index - 1);

                Interop.NotificationEventListener.GetHideTimeout(eventargs.Handle, out timeout);
                activeStyle.HideTimeout = timeout;

                try
                {
                    Interop.NotificationEventListener.GetDeleteTimeout(eventargs.Handle, out timeout);
                }
                catch (TypeLoadException)
                {
                    //To support in API version 3.0
                    timeout = 60;
                }
                activeStyle.DeleteTimeout = timeout;

                appcontrol = null;
                Interop.NotificationEventListener.GetExtensionAction(eventargs.Handle, UserEventType.HiddenByUser, out appcontrol);
                if (appcontrol != null && appcontrol.IsInvalid == false)
                {
                    activeStyle.HiddenByUserAction = new AppControl(appcontrol);
                }

                appcontrol = null;
                Interop.NotificationEventListener.GetExtensionAction(eventargs.Handle, UserEventType.HiddenByTimeout, out appcontrol);
                if (appcontrol != null && appcontrol.IsInvalid == false)
                {
                    activeStyle.HiddenByTimeoutAction = new AppControl(appcontrol);
                }

                appcontrol = null;
                Interop.NotificationEventListener.GetExtensionAction(eventargs.Handle, UserEventType.HiddenByExternal, out appcontrol);
                if (appcontrol != null && appcontrol.IsInvalid == false)
                {
                    activeStyle.HiddenByExternalAction = new AppControl(appcontrol);
                }

                NotificationReplyActionArgBinder.BindObject(eventargs);
            }

            if ((styleList & (int)NotificationDisplayApplist.Lock) != 0)
            {
                NotificationEventArgs.LockStyleArgs lockStyle = new NotificationEventArgs.LockStyleArgs();
                eventargs.Style.Add(lockStyle.Key, lockStyle);

                Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Lockscreen, out path);
                lockStyle.IconPath = path;

                Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.ThumbnailLockscreen, out path);
                lockStyle.Thumbnail = path;
            }

            if ((styleList & (int)NotificationDisplayApplist.Ticker) != 0 || (styleList & (int)NotificationDisplayApplist.Indicator) != 0)
            {
                NotificationEventArgs.IndicatorStyleArgs indicatorStyle = new NotificationEventArgs.IndicatorStyleArgs();
                eventargs.Style.Add(indicatorStyle.Key, indicatorStyle);

                Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Indicator, out path);
                indicatorStyle.IconPath = path;

                Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.FirstMainText, out path);
                indicatorStyle.SubText = path;
            }
        }