Example #1
0
        //  Called in Date Diff, when 'ToDatePicker' is selected'
        void ToValueChanged(object sender, DateTimeValueChangedEventArgs e)
        {
            // do a sanity check to make sure dates are valid here
            DateTime dtFromDate;
            DateTime dtToDate;
            string strDisplayResults = "";
            
            dtFromDate = (DateTime)FromDatePicker.Value;
            dtToDate = (DateTime)ToDatePicker.Value;

            FormatResultsClass frc = new FormatResultsClass();
            frc.FormatDateDiffResults(dtFromDate, dtToDate, out strDisplayResults);// 3 == DATEDIFF
            
            textBlock2.Text = strDisplayResults;
        }
Example #2
0
        // Called for 'DaysSince', when DatePicker is selected.
        void SelectedDateValueChanged(object sender, DateTimeValueChangedEventArgs e)
        {
            if (null == textBlock1)
                return;
            /*
            if (date is changed) && (chkbox is not already selected)
	            do nothing

             * if (date is unchanged and (chkbox is already selected)
	            // do nothing

            if (date is unchanged and (chkbox gets selected)
	            // save date  */

            // get today's date. This is the 'To' date.
            DateTime dtToday = DateTime.Now;

            // get 'from' date
            DateTime dtFromDate = new DateTime();
            dtFromDate = (DateTime)e.NewDateTime;

            string strDisplayResults = "";
            
            FormatResultsClass frc = new FormatResultsClass();
            frc.FormatDaysSinceResults(dtFromDate, dtToday, out strDisplayResults);
            
            textBlock1.Text = strDisplayResults;
            
            (Application.Current as App).gdtSelectedDate = dtFromDate;
            
            // if (date is changed) && (chkbox is already selected)
	        // assume user wants this to be new default selected date
            if ((bool)chkUseSelectedDate.IsChecked)
            {
                SaveSelectedDate();
            }

            // if (date is changed) && (chkbox is already selected)
            // assume user wants this to show on live tile
            if ((bool)chkShowOnLiveTile.IsChecked)
            {
                ShowOnLiveTile();
            }
        } // void SelectedDateValueChanged(object sender, DateTimeValueChangedEventArgs e)
Example #3
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Code to localize the ApplicationBar
            BuildLocalizedApplicationBar();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            if ((Application.Current as App).gbHaveLoadedSavedDate)
                datePicker.Value = (Application.Current as App).gdtSelectedDate;

            string strDisplayResults = "";
            FormatResultsClass frc = new FormatResultsClass();
            if (true == (Application.Current as App).gbSaveDate)
            {
                chkUseSelectedDate.IsChecked = true;
                
                chkShowOnLiveTile.Visibility = Visibility.Visible;
                if (true == (Application.Current as App).gbShowOnTile)
                {
                    chkShowOnLiveTile.IsChecked = true;
                    frc.FormatDaysSinceResults((Application.Current as App).gdtSelectedDate, DateTime.Now, out strDisplayResults);
                    textBlock1.Text = strDisplayResults;
                    SetDynamicTile();
                    StartPeriodicAgent();  //called to refresh the agent on each startup so it doesn't expire (agents expire every 14 days).
                }
                else
                {
                    frc.FormatDaysSinceResults((Application.Current as App).gdtSelectedDate, DateTime.Now, out strDisplayResults);
                    textBlock1.Text = strDisplayResults;
                    SetApplicationTile("");
                }
            }
            else
            {
                frc.FormatDaysSinceResults(DateTime.Now, DateTime.Now, out strDisplayResults);
                textBlock1.Text = strDisplayResults;
                SetApplicationTile(""); // Set up default flip tile (blank)
            }
        }
Example #4
0
        } // void OnImageOpened(object sender, RoutedEventArgs e)


        // Only called if they've selected to Show On Live Tile
        // Updates the text on the live tile
        public static void UpdateLiveTile()
        {
            ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();
            if (tile != null)
            {
                FormatResultsClass frc = new FormatResultsClass();

                FlipTileData flipTile = new FlipTileData();
                flipTile.Title = AppResources.AppTitle;
                flipTile.BackTitle = AppResources.AppTitle;

                flipTile.BackContent = " ";
                flipTile.WideBackContent = " ";

                String strBackContent = "";
                frc.FormatLiveTileText((Application.Current as App).gdtSelectedDate, DateTime.Now, out strBackContent );

                //Medium size Tile 336x336 px
                //Create image for BackBackgroundImage in IsoStore
                frc.RenderText(strBackContent, c_n336, c_n336, 28, "BackBackgroundImage");

                flipTile.BackBackgroundImage = new Uri(@"isostore:/Shared/ShellContent/BackBackgroundImage.jpg", UriKind.Absolute); //Generated image for Back Background 336x336
                flipTile.BackgroundImage = new Uri("/Content/MediumBlankTileImage336x336.png", UriKind.Relative); //Default image for Background Image Medium Tile 336x336 px
                //End Medium size Tile 336x336 px

                //Wide size Tile 691x336 px
                //flipTile.WideBackgroundImage = new Uri("/Content/WideBlankTileIcon691x336.png", UriKind.Relative); // Default image for Background Image Wide Tile 691x336 px
                flipTile.WideBackgroundImage = new Uri("/Content/WideBackBackgroundTileIcon691x336WithGlow.png", UriKind.Relative); // Default image for Background Image Wide Tile 691x336 px

                //Create image for WideBackBackgroundImage in IsoStore
                frc.RenderText(strBackContent, 691, c_n336, 40, "WideBackBackgroundImage");
                flipTile.WideBackBackgroundImage = new Uri(@"isostore:/Shared/ShellContent/WideBackBackgroundImage.jpg", UriKind.Absolute);
                
                //End Wide size Tile 691x336 px

                //Update Live Tile
                tile.Update(flipTile);
            }
        } // public static void UpdateLiveTile(string info)
Example #5
0
        // Called when BitMapImage loads the image
        void OnImageOpened(object sender, RoutedEventArgs e)
        {
            String strBackContent = "";

            // Only called if they've selected to Show On Live Tile
            if ((Application.Current as App).gbShowOnTile)
            {
                FormatResultsClass frc = new FormatResultsClass();
                frc.FormatLiveTileText((Application.Current as App).gdtSelectedDate, DateTime.Now, out strBackContent ); 
            }

            BitmapImage bm = (BitmapImage)sender;

            var img = new Image { Source = bm };

            WriteableBitmap wbm = new WriteableBitmap( bm );
            var tt = new TranslateTransform();
            tt.X = c_n336;
            tt.Y = c_n336;

            /*
            Next, we create the UI Elements that we want to push into our WriteableBitmap using the Render method.  
            We will need to format our Tile to our liking.  
            We will also need to add our image to our bitmap and position it properly.  
            In order to do that, we will need to use Transforms.  
            I’m lazy and uncreative, so I will use a TranslateTransform, but the idea is the same even if you use a MatrixTransform.             
            */
            var tbText = new TextBlock();
            tbText.Height = c_n336;
            tbText.Width = c_n336;
            tbText.Foreground = new SolidColorBrush(Colors.White);
            tbText.FontFamily = new FontFamily("Arial Narrow");
            tbText.FontSize = 30;
            tbText.TextWrapping = TextWrapping.Wrap;
            tbText.Text = strBackContent;
            tbText.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            tbText.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            
            
            wbm.Render(img, tt);
            wbm.Render(tbText, null);
            wbm.Invalidate();

            /*
            Next is a little bit of complexity with IsolatedStorage.  
            In addition to providing local storage for our application, on the Phone, 
            IsolatedStorage has some shared areas.  
            Specifically, the Shared/ShellContent section.  
            We need to store our Bitmap in this area in order to be used by a Tile.             * 
            */
            var filename = "/Shared/ShellContent/testtile.jpg";
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var st = new IsolatedStorageFileStream(filename,
                                                               System.IO.FileMode.Create,
                                                               System.IO.FileAccess.Write,
                                                               store))
                {
                    wbm.SaveJpeg(st, c_n336, c_n336, 0, 100);
                }
            }

            // Application Tile is always the first Tile, even if it is not pinned to Start.
            ShellTile TileToFind = ShellTile.ActiveTiles.First();

            // Application should always be found
            if (null != TileToFind)
            {
                // set the properties to update for the Application Tile
                // Empty strings for the text values and URIs will result in the property being cleared.
                /*StandardTileData NewTileData = new StandardTileData
                {
                    BackBackgroundImage = new Uri("isostore:" + filename, UriKind.Absolute)
                };*/

                FlipTileData NewTileData = new FlipTileData
                {
                    BackBackgroundImage = new Uri("isostore:" + filename, UriKind.Absolute),
                };


                // Update the Application Tile
                TileToFind.Update(NewTileData);
            }
        } // void OnImageOpened(object sender, RoutedEventArgs e)
Example #6
0
        protected override void OnInvoke(ScheduledTask task)
        {
            // NOTE: determine if this needs to run.
            // maybe save the "number of days" in isostorage and check it to see if it has changed?

            IsolatedStorageSettings settings     = IsolatedStorageSettings.ApplicationSettings;
            DateTime dtDaysSinceDate             = DateTime.Now;
            bool     bWasSaveSelectedDateChecked = false;

            // only load a 'selected' date if gbSaveDate == true
            if (!settings.TryGetValue <bool>("saveSelectedDateIsChecked", out bWasSaveSelectedDateChecked))
            {
                NotifyComplete();
                return;
            }

            if (!settings.TryGetValue <DateTime>("selectdate", out dtDaysSinceDate))
            {
                NotifyComplete();
                return;
            }

            // We'll be using UIElements and WriteableBitmaps to build an image so we have to call BeginInvoke
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // If the agent crashes twice WP7 will shut us down so let make sure if there's an error we catch it
                try
                {
                    ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();
                    if (tile != null)
                    {
                        FormatResultsClass frc = new FormatResultsClass();

                        FlipTileData flipTile = new FlipTileData();
                        flipTile.Title        = LiveTileScheduledTaskAgentResources.AppTitle;
                        flipTile.BackTitle    = LiveTileScheduledTaskAgentResources.AppTitle;

                        flipTile.BackContent     = " ";
                        flipTile.WideBackContent = " ";

                        String strBackContent = "";
                        frc.FormatLiveTileText(dtDaysSinceDate, DateTime.Now, out strBackContent);

                        //Medium size Tile 336x336 px
                        //Create image for BackBackgroundImage in IsoStore
                        frc.RenderText(strBackContent, c_n336, c_n336, 28, "BackBackgroundImage");

                        flipTile.BackBackgroundImage = new Uri(@"isostore:/Shared/ShellContent/BackBackgroundImage.jpg", UriKind.Absolute); //Generated image for Back Background 336x336
                        flipTile.BackgroundImage     = new Uri("/Content/MediumBlankTileImage336x336.png", UriKind.Relative);               //Default image for Background Image Medium Tile 336x336 px
                        //End Medium size Tile 336x336 px

                        //Wide size Tile 691x336 px
                        //flipTile.WideBackgroundImage = new Uri("/Content/WideBlankTileIcon691x336.png", UriKind.Relative); // Default image for Background Image Wide Tile 691x336 px
                        flipTile.WideBackgroundImage = new Uri("/Content/WideBackBackgroundTileIcon691x336WithGlow.png", UriKind.Relative); // Default image for Background Image Wide Tile 691x336 px

                        //Crete image for WideBackBackgroundImage in IsoStore
                        frc.RenderText(strBackContent, 691, c_n336, 40, "WideBackBackgroundImage");
                        flipTile.WideBackBackgroundImage = new Uri(@"isostore:/Shared/ShellContent/WideBackBackgroundImage.jpg", UriKind.Absolute);

                        //End Wide size Tile 691x336 px

                        //Update Live Tile
                        tile.Update(flipTile);
                    }
                } // try

                // catch
                catch (Exception e)
                {
                    //MessageBox.Show( e.ToString() );
                }
                finally
                {
                    NotifyComplete();
                } // finally
            }); //Deployment.Current.Dispatcher.BeginInvoke(() =>
        }         // OnInvoke(ScheduledTask task)