| 1 | using System; |
| 2 | using System.Diagnostics; |
| 3 | using System.Resources; |
| 4 | using System.Windows; |
| 5 | using System.Windows.Markup; |
| 6 | using System.Windows.Navigation; |
| 7 | using Microsoft.Phone.Controls; |
| 8 | using Microsoft.Phone.Shell; |
| 9 | |
| 10 | namespace PjsuaCLI.UI |
| 11 | { |
| 12 | public partial class App : Application |
| 13 | { |
| 14 | /// <summary> |
| 15 | /// Provides easy access to the root frame of the Phone Application. |
| 16 | /// </summary> |
| 17 | /// <returns>The root frame of the Phone Application.</returns> |
| 18 | public static PhoneApplicationFrame RootFrame { get; private set; } |
| 19 | |
| 20 | /// <summary> |
| 21 | /// Constructor for the Application object. |
| 22 | /// </summary> |
| 23 | public App() |
| 24 | { |
| 25 | // Global handler for uncaught exceptions. |
| 26 | UnhandledException += Application_UnhandledException; |
| 27 | |
| 28 | // Standard XAML initialization |
| 29 | InitializeComponent(); |
| 30 | |
| 31 | // Phone-specific initialization |
| 32 | InitializePhoneApplication(); |
| 33 | |
| 34 | // Language display initialization |
| 35 | InitializeLanguage(); |
| 36 | |
| 37 | // Show graphics profiling information while debugging. |
| 38 | if (Debugger.IsAttached) |
| 39 | { |
| 40 | // Display the current frame rate counters. |
| 41 | Application.Current.Host.Settings.EnableFrameRateCounter = true; |
| 42 | |
| 43 | // Show the areas of the app that are being redrawn in each frame. |
| 44 | //Application.Current.Host.Settings.EnableRedrawRegions = true; |
| 45 | |
| 46 | // Enable non-production analysis visualization mode, |
| 47 | // which shows areas of a page that are handed off to GPU with a colored overlay. |
| 48 | //Application.Current.Host.Settings.EnableCacheVisualization = true; |
| 49 | |
| 50 | // Prevent the screen from turning off while under the debugger by disabling |
| 51 | // the application's idle detection. |
| 52 | // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run |
| 53 | // and consume battery power when the user is not using the phone. |
| 54 | PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | |
| 59 | // Code to execute when the application is launching (eg, from Start) |
| 60 | // This code will not execute when the application is reactivated |
| 61 | private void Application_Launching(object sender, LaunchingEventArgs e) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | // Code to execute when the application is activated (brought to foreground) |
| 66 | // This code will not execute when the application is first launched |
| 67 | private void Application_Activated(object sender, ActivatedEventArgs e) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | // Code to execute when the application is deactivated (sent to background) |
| 72 | // This code will not execute when the application is closing |
| 73 | private void Application_Deactivated(object sender, DeactivatedEventArgs e) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | // Code to execute when the application is closing (eg, user hit Back) |
| 78 | // This code will not execute when the application is deactivated |
| 79 | private void Application_Closing(object sender, ClosingEventArgs e) |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | // Code to execute if a navigation fails |
| 84 | private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) |
| 85 | { |
| 86 | if (Debugger.IsAttached) |
| 87 | { |
| 88 | // A navigation has failed; break into the debugger |
| 89 | Debugger.Break(); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Code to execute on Unhandled Exceptions |
| 94 | private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) |
| 95 | { |
| 96 | if (Debugger.IsAttached) |
| 97 | { |
| 98 | // An unhandled exception has occurred; break into the debugger |
| 99 | Debugger.Break(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | #region Phone application initialization |
| 104 | |
| 105 | // Avoid double-initialization |
| 106 | private bool phoneApplicationInitialized = false; |
| 107 | |
| 108 | // Do not add any additional code to this method |
| 109 | private void InitializePhoneApplication() |
| 110 | { |
| 111 | if (phoneApplicationInitialized) |
| 112 | return; |
| 113 | |
| 114 | // Create the frame but don't set it as RootVisual yet; this allows the splash |
| 115 | // screen to remain active until the application is ready to render. |
| 116 | RootFrame = new PhoneApplicationFrame(); |
| 117 | RootFrame.Navigated += CompleteInitializePhoneApplication; |
| 118 | |
| 119 | // Handle navigation failures |
| 120 | RootFrame.NavigationFailed += RootFrame_NavigationFailed; |
| 121 | |
| 122 | // Handle reset requests for clearing the backstack |
| 123 | RootFrame.Navigated += CheckForResetNavigation; |
| 124 | |
| 125 | // Ensure we don't initialize again |
| 126 | phoneApplicationInitialized = true; |
| 127 | } |
| 128 | |
| 129 | // Do not add any additional code to this method |
| 130 | private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e) |
| 131 | { |
| 132 | // Set the root visual to allow the application to render |
| 133 | if (RootVisual != RootFrame) |
| 134 | RootVisual = RootFrame; |
| 135 | |
| 136 | // Remove this handler since it is no longer needed |
| 137 | RootFrame.Navigated -= CompleteInitializePhoneApplication; |
| 138 | } |
| 139 | |
| 140 | private void CheckForResetNavigation(object sender, NavigationEventArgs e) |
| 141 | { |
| 142 | // If the app has received a 'reset' navigation, then we need to check |
| 143 | // on the next navigation to see if the page stack should be reset |
| 144 | if (e.NavigationMode == NavigationMode.Reset) |
| 145 | RootFrame.Navigated += ClearBackStackAfterReset; |
| 146 | } |
| 147 | |
| 148 | private void ClearBackStackAfterReset(object sender, NavigationEventArgs e) |
| 149 | { |
| 150 | // Unregister the event so it doesn't get called again |
| 151 | RootFrame.Navigated -= ClearBackStackAfterReset; |
| 152 | |
| 153 | // Only clear the stack for 'new' (forward) and 'refresh' navigations |
| 154 | if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh) |
| 155 | return; |
| 156 | |
| 157 | // For UI consistency, clear the entire page stack |
| 158 | while (RootFrame.RemoveBackEntry() != null) |
| 159 | { |
| 160 | ; // do nothing |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | #endregion |
| 165 | |
| 166 | // Initialize the app's font and flow direction as defined in its localized resource strings. |
| 167 | // |
| 168 | // To ensure that the font of your application is aligned with its supported languages and that the |
| 169 | // FlowDirection for each of those languages follows its traditional direction, ResourceLanguage |
| 170 | // and ResourceFlowDirection should be initialized in each resx file to match these values with that |
| 171 | // file's culture. For example: |
| 172 | // |
| 173 | // AppResources.es-ES.resx |
| 174 | // ResourceLanguage's value should be "es-ES" |
| 175 | // ResourceFlowDirection's value should be "LeftToRight" |
| 176 | // |
| 177 | // AppResources.ar-SA.resx |
| 178 | // ResourceLanguage's value should be "ar-SA" |
| 179 | // ResourceFlowDirection's value should be "RightToLeft" |
| 180 | // |
| 181 | // For more info on localizing Windows Phone apps see http://go.microsoft.com/fwlink/?LinkId=262072. |
| 182 | // |
| 183 | private void InitializeLanguage() |
| 184 | { |
| 185 | } |
| 186 | } |
| 187 | } |