123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- /*
- * Copyright © 2011-2012 Nokia Corporation. All rights reserved.
- * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
- * Other product and company names mentioned herein may be trademarks
- * or trade names of their respective owners.
- * See LICENSE.TXT for license information.
- */
- using System;
- using System.Windows;
- using System.Windows.Navigation;
- using Microsoft.Phone.Controls;
- using Microsoft.Phone.Shell;
- using RSSReader.Model;
- namespace RSSReader
- {
- /// <summary>
- /// Application instance
- /// </summary>
- public partial class App : Application
- {
- /// <summary>
- /// Const used to signal when no selection has been made in for example a listbox
- /// </summary>
- public static readonly int NO_SELECTION = -1;
- /// <summary>
- /// True if upon deactivation application was tombstoned, false otherwise
- /// </summary>
- public static bool WasTombstoned { get; private set; }
- /// <summary>
- /// Provides easy access to the root frame of the Phone Application.
- /// </summary>
- /// <returns>The root frame of the Phone Application.</returns>
- public PhoneApplicationFrame RootFrame { get; private set; }
- /// <summary>
- /// Constructor for the Application object.
- /// </summary>
- public App()
- {
- WasTombstoned = false;
- // Global handler for uncaught exceptions.
- UnhandledException += Application_UnhandledException;
- // Show graphics profiling information while debugging.
- if (System.Diagnostics.Debugger.IsAttached)
- {
- // Display the current frame rate counters.
- //Application.Current.Host.Settings.EnableFrameRateCounter = true;
- // Show the areas of the app that are being redrawn in each frame.
- //Application.Current.Host.Settings.EnableRedrawRegions = true;
- // Enable non-production analysis visualization mode,
- // which shows areas of a page that are being GPU accelerated with a colored overlay.
- //Application.Current.Host.Settings.EnableCacheVisualization = true;
- }
- // Standard Silverlight initialization
- InitializeComponent();
- // Phone-specific initialization
- InitializePhoneApplication();
- }
- // Code to execute when the application is launching (eg, from Start)
- // This code will not execute when the application is reactivated
- private void Application_Launching(object sender, LaunchingEventArgs e)
- {
- RSSService.InitializeFeeds();
- }
- // Code to execute when the application is activated (brought to foreground)
- // This code will not execute when the application is first launched
- private void Application_Activated(object sender, ActivatedEventArgs e)
- {
- WasTombstoned = !e.IsApplicationInstancePreserved;
- // If we were tombstoned, load feeds
- if (WasTombstoned)
- {
- RSSService.InitializeFeeds();
- }
- }
- // Code to execute when the application is deactivated (sent to background)
- // This code will not execute when the application is closing
- private void Application_Deactivated(object sender, DeactivatedEventArgs e)
- {
- RSSService.PersistCache();
- }
- // Code to execute when the application is closing (eg, user hit Back)
- // This code will not execute when the application is deactivated
- private void Application_Closing(object sender, ClosingEventArgs e)
- {
- RSSService.PersistCache();
- }
- // Code to execute if a navigation fails
- private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
- {
- if (System.Diagnostics.Debugger.IsAttached)
- {
- // A navigation has failed; break into the debugger
- System.Diagnostics.Debugger.Break();
- }
- }
- // Code to execute on Unhandled Exceptions
- private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
- {
- if (System.Diagnostics.Debugger.IsAttached)
- {
- // An unhandled exception has occurred; break into the debugger
- App.Log(e.ExceptionObject.Message);
- System.Diagnostics.Debugger.Break();
- }
- }
- #region Phone application initialization
- // Avoid double-initialization
- private bool phoneApplicationInitialized = false;
- // Do not add any additional code to this method
- private void InitializePhoneApplication()
- {
- if (phoneApplicationInitialized)
- return;
- // Create the frame but don't set it as RootVisual yet; this allows the splash
- // screen to remain active until the application is ready to render.
- RootFrame = new PhoneApplicationFrame();
- RootFrame.Navigated += CompleteInitializePhoneApplication;
- // Handle navigation failures
- RootFrame.NavigationFailed += RootFrame_NavigationFailed;
- // Ensure we don't initialize again
- phoneApplicationInitialized = true;
- }
- // Do not add any additional code to this method
- private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
- {
- // Set the root visual to allow the application to render
- if (RootVisual != RootFrame)
- RootVisual = RootFrame;
- // Remove this handler since it is no longer needed
- RootFrame.Navigated -= CompleteInitializePhoneApplication;
- }
- #endregion
- public static void Log(String message)
- {
- System.Diagnostics.Debug.WriteLine("[RSSREADER] " + message);
- }
- }
- }
|