コード例 #1
0
 bool LockInfoChanged(LockScreenSnapshot prev, LockScreenSnapshot cur)
 {
     if (prev == null)
     {
         return(true);
     }
     if (prev.Badges.Count() != cur.Badges.Count())
     {
         return(true);
     }
     else
     {
         for (int i = 0; i < prev.Badges.Count(); i++)
         {
             if (prev.Badges[i].BadgeIconURI != cur.Badges[i].BadgeIconURI)
             {
                 return(true);
             }
             if (prev.Badges[i].BadgeValue != cur.Badges[i].BadgeValue)
             {
                 return(true);
             }
         }
     }
     if (prev.DetailedTexts.Count() != cur.DetailedTexts.Count())
     {
         return(true);
     }
     else
     {
         for (int i = 0; i < prev.DetailedTexts.Count(); i++)
         {
             if (prev.DetailedTexts[i].IsBold != cur.DetailedTexts[i].IsBold)
             {
                 return(true);
             }
             if (prev.DetailedTexts[i].Text != cur.DetailedTexts[i].Text)
             {
                 return(true);
             }
         }
     }
     if ((prev.AlarmIcon.BadgeIcon == null) != (cur.AlarmIcon.BadgeIcon == null))
     {
         return(true);
     }
     // TODO: more
     return(false);
 }
コード例 #2
0
 bool LockInfoChanged(LockScreenSnapshot prev, LockScreenSnapshot cur)
 {
     if (prev == null) return true;
     if (prev.Badges.Count() != cur.Badges.Count())
     {
         return true;
     }
     else
     {
         for (int i = 0; i < prev.Badges.Count(); i++)
         {
             if (prev.Badges[i].BadgeIconURI != cur.Badges[i].BadgeIconURI) return true;
             if (prev.Badges[i].BadgeValue != cur.Badges[i].BadgeValue) return true;
         }
     }
     if (prev.DetailedTexts.Count() != cur.DetailedTexts.Count())
     {
         return true;
     }
     else
     {
         for (int i = 0; i < prev.DetailedTexts.Count(); i++)
         {
             if (prev.DetailedTexts[i].IsBold != cur.DetailedTexts[i].IsBold) return true;
             if (prev.DetailedTexts[i].Text != cur.DetailedTexts[i].Text) return true;
         }
     }
     if((prev.AlarmIcon.BadgeIcon == null) != (cur.AlarmIcon.BadgeIcon == null))
     {
         return true;
     }
     // TODO: more
     return false;
 }
コード例 #3
0
        void timer_Tick(object sender, EventArgs e)
        {
            var cont = Application.Current.Host.Content;
            LockScreenSnapshot newLockInfo = new LockScreenSnapshot((int)Math.Ceiling(cont.ActualWidth * cont.ScaleFactor / 100.0), (int)Math.Ceiling(cont.ActualHeight * cont.ScaleFactor / 100.0));

            if (LockInfoChanged(lockInfo, newLockInfo))
            {
                lockInfo = newLockInfo;
                //Badges
                if (lockInfo.HasTrayBadges)
                {
                    grdBadges.Visibility = System.Windows.Visibility.Visible;
                    for (int i = 0; i < 5; i++)
                    {
                        if (!String.IsNullOrEmpty(lockInfo.Badges[i].BadgeValue))
                        {
                            System.Windows.Media.Imaging.BitmapImage badge = new System.Windows.Media.Imaging.BitmapImage();
                            try
                            {
                                if (lockInfo.Badges[i].BadgeIcon != null)
                                {
                                    badge.SetSource(new MemoryStream(lockInfo.Badges[i].BadgeIcon));
                                }
                                else
                                {
                                    var str = lockInfo.Badges[i].BadgeIconURI.Substring(7);
                                    badge.SetSource(new FileStream(lockInfo.Badges[i].BadgeIconURI.Substring(7), FileMode.Open));
                                }
                            }
                            catch
                            {
                                badge.UriSource = new Uri("ms-appx:///Assets/BadgeLogo.png", UriKind.Absolute);
                            }
                            imgBadges[i].Source     = badge;
                            txtBadges[i].Text       = lockInfo.Badges[i].BadgeValue;
                            imgBadges[i].Visibility = System.Windows.Visibility.Visible;
                            txtBadges[i].Visibility = System.Windows.Visibility.Visible;
                        }
                        else
                        {
                            imgBadges[i].Visibility = System.Windows.Visibility.Collapsed;
                            txtBadges[i].Visibility = System.Windows.Visibility.Collapsed;
                        }
                    }
                }
                else
                {
                    grdBadges.Visibility = System.Windows.Visibility.Collapsed;
                }
                //Detailed texts
                for (int i = 0; i < lockInfo.DetailedTexts.Count(); i++)
                {
                    if (!String.IsNullOrEmpty(lockInfo.DetailedTexts[i].Text))
                    {
                        txtDetailedTexts[i].Text       = lockInfo.DetailedTexts[i].Text;
                        txtDetailedTexts[i].FontWeight = (lockInfo.DetailedTexts[i].IsBold) ? FontWeights.Bold : FontWeights.Normal;
                        txtDetailedTexts[i].Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        txtDetailedTexts[i].Visibility = System.Windows.Visibility.Collapsed;
                    }
                }
            }
            string[] TimeAMPM = DateTime.Now.ToShortTimeString().Split(space, 2, StringSplitOptions.RemoveEmptyEntries);
            HourText.Text  = TimeAMPM[0];
            AMPM.Text      = TimeAMPM.Count() > 1 ? TimeAMPM[1] : "";
            DatePanel.Text = DateTime.Now.ToShortDateString();

            //Alarm
            BitmapImage alarmBadge = new BitmapImage();

            if (lockInfo.AlarmIcon.BadgeIcon != null)
            {
                try
                {
                    alarmBadge.SetSource(new MemoryStream(lockInfo.AlarmIcon.BadgeIcon));
                }
                catch
                {
                    alarmBadge.UriSource = new Uri("ms-appx:///Assets/BadgeLogo.png", UriKind.Absolute);
                }
                AlarmImage.Source = alarmBadge;
            }
            else
            {
                AlarmImage.Source = null;
            }
            FrameworkDispatcher.Update();
        }
コード例 #4
0
        void timer_Tick(object sender, EventArgs e)
        {
            var cont = Application.Current.Host.Content;
            LockScreenSnapshot newLockInfo = new LockScreenSnapshot((int)Math.Ceiling(cont.ActualWidth * cont.ScaleFactor / 100.0), (int)Math.Ceiling(cont.ActualHeight * cont.ScaleFactor / 100.0));
            if (LockInfoChanged(lockInfo, newLockInfo))
            {
                lockInfo = newLockInfo;
                //Badges
                if (lockInfo.HasTrayBadges)
                {
                    grdBadges.Visibility = System.Windows.Visibility.Visible;
                    for (int i = 0; i < 5; i++)
                    {
                        if (!String.IsNullOrEmpty(lockInfo.Badges[i].BadgeValue))
                        {
                            System.Windows.Media.Imaging.BitmapImage badge = new System.Windows.Media.Imaging.BitmapImage();
                            try
                            {
                                if (lockInfo.Badges[i].BadgeIcon != null)
                                {
                                    badge.SetSource(new MemoryStream(lockInfo.Badges[i].BadgeIcon));
                                }
                                else
                                {
                                    var str = lockInfo.Badges[i].BadgeIconURI.Substring(7);
                                    badge.SetSource(new FileStream(lockInfo.Badges[i].BadgeIconURI.Substring(7), FileMode.Open));
                                }
                            }
                            catch
                            {
                                badge.UriSource = new Uri("ms-appx:///Assets/BadgeLogo.png", UriKind.Absolute);
                            }
                            imgBadges[i].Source = badge;
                            txtBadges[i].Text = lockInfo.Badges[i].BadgeValue;
                            imgBadges[i].Visibility = System.Windows.Visibility.Visible;
                            txtBadges[i].Visibility = System.Windows.Visibility.Visible;
                        }
                        else
                        {
                            imgBadges[i].Visibility = System.Windows.Visibility.Collapsed;
                            txtBadges[i].Visibility = System.Windows.Visibility.Collapsed;
                        }
                    }
                }
                else
                {
                    grdBadges.Visibility = System.Windows.Visibility.Collapsed;
                }
                //Detailed texts
                for (int i = 0; i < lockInfo.DetailedTexts.Count(); i++)
                {
                    if (!String.IsNullOrEmpty(lockInfo.DetailedTexts[i].Text))
                    {
                        txtDetailedTexts[i].Text = lockInfo.DetailedTexts[i].Text;
                        txtDetailedTexts[i].FontWeight = (lockInfo.DetailedTexts[i].IsBold) ? FontWeights.Bold : FontWeights.Normal;
                        txtDetailedTexts[i].Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        txtDetailedTexts[i].Visibility = System.Windows.Visibility.Collapsed;
                    }
                }
            }
            string[] TimeAMPM = DateTime.Now.ToShortTimeString().Split(space, 2, StringSplitOptions.RemoveEmptyEntries);
            HourText.Text = TimeAMPM[0];
            AMPM.Text = TimeAMPM.Count() > 1 ? TimeAMPM[1] : "";
            DatePanel.Text = DateTime.Now.ToShortDateString();

            //Alarm
            BitmapImage alarmBadge = new BitmapImage();
            if (lockInfo.AlarmIcon.BadgeIcon != null)
            {
                try
                {
                    alarmBadge.SetSource(new MemoryStream(lockInfo.AlarmIcon.BadgeIcon));
                }
                catch
                {
                    alarmBadge.UriSource = new Uri("ms-appx:///Assets/BadgeLogo.png", UriKind.Absolute);
                }
                AlarmImage.Source = alarmBadge;
            }
            else
            {
                AlarmImage.Source = null;
            }
            FrameworkDispatcher.Update();
        }