protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); #if DEBUG int disposedCount = 0; WeakEventHandler.ObjectDisposedAction = delegate { Toast.MakeText(Application.Context, disposedCount++ + " ObjectDisposed", ToastLength.Short).Show(); }; #endif AppCenter.Start(Secrets.AppCenterAppSecret, typeof(Analytics), typeof(Crashes)); TelemetryExtension.Current = new DroidTelemetryExtension(); #if DEBUG Java.Lang.Thread.DefaultUncaughtExceptionHandler = new MyUncaughtExceptionHandler(); #endif // Color the status bar since the theme color provided in themes.xml seemed to stop taking effect in Android 8.0 if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { this.Window.ClearFlags(WindowManagerFlags.TranslucentStatus); this.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); this.Window.SetStatusBarColor(new Android.Graphics.Color(Android.Support.V4.Content.ContextCompat.GetColor(this, Resource.Color.primaryDark))); } // Register the window _mainAppWindow = new MainAppWindow(); await PowerPlannerDroidApp.Current.RegisterWindowAsync(_mainAppWindow, new NativeDroidAppWindow(this)); HandleIntent(); HandleVersionChange(); }
private void Application_Startup(object sender, StartupEventArgs e) { Settings.SettingsDatabase.Load(); MainAppWindow.Topmost = Settings.SettingsDatabase.AlwaysOnTop; MainAppWindow.Show(); }
private async void RegisterWindow(ShortcutAction?shortcutAction) { this.Window = new UIWindow(UIScreen.MainScreen.Bounds); Window.BackgroundColor = new UIColor(1, 1); Window.TintColor = ColorResources.PowerPlannerAccentBlue; this.Window.RootViewController = UIStoryboard.FromName("LaunchScreen", null).InstantiateInitialViewController(); this.Window.MakeKeyAndVisible(); _mainAppWindow = new MainAppWindow(); await PortableApp.Current.RegisterWindowAsync(_mainAppWindow, new NativeiOSAppWindow(Window)); // Launch the app var mainWindowViewModel = _mainAppWindow.GetViewModel(); if (shortcutAction != null) { HandleShortcutAction(shortcutAction.Value); // We make sure to activate the normal launch, and then later the HandleLaunch kicks in if (!_hasActivatedWindow) { await mainWindowViewModel.HandleNormalLaunchActivation(); } } else { await mainWindowViewModel.HandleNormalLaunchActivation(); } ViewManager.RootViewModel = _mainAppWindow.ViewModel; }
private async void RegisterWindow() { this.Window = new UIWindow(UIScreen.MainScreen.Bounds); Window.BackgroundColor = new UIColor(1, 1); Window.TintColor = ColorResources.PowerPlannerAccentBlue; this.Window.RootViewController = UIStoryboard.FromName("LaunchScreen", null).InstantiateInitialViewController(); this.Window.MakeKeyAndVisible(); _mainAppWindow = new MainAppWindow(); await PortableApp.Current.RegisterWindowAsync(_mainAppWindow, new NativeiOSAppWindow(Window)); // Launch the app await _mainAppWindow.GetViewModel().HandleNormalLaunchActivation(); ViewManager.RootViewModel = _mainAppWindow.ViewModel; }
public async Task LaunchAsync() { MainAppWindow mainAppWindow; // If no windows, need to register window mainAppWindow = PowerPlannerApp.Current.Windows.OfType <MainAppWindow>().FirstOrDefault(); if (mainAppWindow == null) { // This configures the view models, does NOT call Activate yet var nativeWindow = new DummyPowerPlannerWindow(); mainAppWindow = new MainAppWindow(); await PowerPlannerApp.Current.RegisterWindowAsync(mainAppWindow, nativeWindow); if (PowerPlannerApp.Current.Windows.Count > 1) { throw new Exception("There are more than 1 windows registered"); } } }
private void LoginAction() { bool result = RestClient.Instance.MakePostRequest("LogIn", new User() { Login = loginTextBox.Text, Password = pswdTextBox.Password }); if (result) { RestClient.Instance.LoggedUserLogin = loginTextBox.Text; Window mainWindow = new MainAppWindow(); App.Current.MainWindow = mainWindow; mainWindow.Show(); this.Close(); } else { loginTextBox.Clear(); pswdTextBox.Clear(); FailLogIn.Visibility = Visibility.Visible; } }
private static async System.Threading.Tasks.Task HandleArguments(MainAppWindow mainAppWindow, string arguments, LaunchSurface launchContext) { try { MainWindowViewModel viewModel = mainAppWindow.GetViewModel(); var args = ArgumentsHelper.Parse(arguments); Guid desiredLocalAccountId = Guid.Empty; if (args is BaseArgumentsWithAccount) { desiredLocalAccountId = (args as BaseArgumentsWithAccount).LocalAccountId; } else { desiredLocalAccountId = AccountsManager.GetLastLoginLocalId(); } Guid currentLocalAccountId = Guid.Empty; if (viewModel.CurrentAccount != null) { currentLocalAccountId = viewModel.CurrentAccount.LocalAccountId; } // View schedule if (args is ViewScheduleArguments) { TrackLaunch(args, launchContext, "Schedule"); await viewModel.HandleViewScheduleActivation(desiredLocalAccountId); } // View class else if (args is ViewClassArguments) { TrackLaunch(args, launchContext, "Class"); var viewClassArgs = args as ViewClassArguments; await viewModel.HandleViewClassActivation(viewClassArgs.LocalAccountId, viewClassArgs.ItemId); } else if (args is ViewTaskArguments) { TrackLaunch(args, launchContext, "Task"); var viewTaskArgs = args as ViewTaskArguments; await viewModel.HandleViewTaskActivation(viewTaskArgs.LocalAccountId, viewTaskArgs.ItemId); } else if (args is ViewEventArguments) { TrackLaunch(args, launchContext, "Event"); var viewEventArgs = args as ViewEventArguments; await viewModel.HandleViewEventActivation(viewEventArgs.LocalAccountId, viewEventArgs.ItemId); } else if (args is ViewHolidayArguments) { TrackLaunch(args, launchContext, "Holiday"); var viewHolidayArgs = args as ViewHolidayArguments; await viewModel.HandleViewHolidayActivation(viewHolidayArgs.LocalAccountId, viewHolidayArgs.ItemId); } else if (args is QuickAddArguments) { TrackLaunch(args, launchContext, "QuickAdd"); var quickAddArgs = args as QuickAddArguments; await viewModel.HandleQuickAddActivation(quickAddArgs.LocalAccountId); } else if (args is QuickAddTaskToCurrentAccountArguments) { // Jump list was created before we included the launch surface, so we'll manually port it if (launchContext == LaunchSurface.Normal) { launchContext = LaunchSurface.JumpList; } TrackLaunch(args, launchContext, "QuickAddTask"); await viewModel.HandleQuickAddTask(); } else if (args is QuickAddEventToCurrentAccountArguments) { // Jump list was created before we included the launch surface, so we'll manually port it if (launchContext == LaunchSurface.Normal) { launchContext = LaunchSurface.JumpList; } TrackLaunch(args, launchContext, "QuickAddEvent"); await viewModel.HandleQuickAddEvent(); } else { TrackLaunch(args, launchContext, "Launch"); if (viewModel.Content == null) { await viewModel.HandleNormalLaunchActivation(); } } } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } }
protected override async System.Threading.Tasks.Task OnLaunchedOrActivated(IActivatedEventArgs e) { try { #if DEBUG //if (System.Diagnostics.Debugger.IsAttached) //{ // this.DebugSettings.EnableFrameRateCounter = true; //} #endif // Register background tasks if (!_registeredBackgroundTasks) { try { // Make sure none are registered (they should have already been unregistered) UnregisterAllBackgroundTasks(); RegisterInfrequentBackgroundTask(); RegisterRawPushBackgroundTask(); RegisterToastBackgroundTask(); } catch (Exception ex) { if (UWPExceptionHelper.TrackIfRpcServerUnavailable(ex, "RegisterBgTasks")) { } else if (UWPExceptionHelper.TrackIfPathInvalid(ex, "RegisterBgTasks")) { } else { TelemetryExtension.Current?.TrackException(ex); } } _registeredBackgroundTasks = true; } // Wait for initialization to complete, to ensure we don't accidently add multiple windows // Although right now we don't even do any async tasks, so this will be useless await PowerPlannerApp.InitializeTask; MainAppWindow mainAppWindow; // If no windows, need to register window mainAppWindow = PowerPlannerApp.Current.Windows.OfType <MainAppWindow>().FirstOrDefault(); if (mainAppWindow == null) { // This configures the view models, does NOT call Activate yet var nativeWindow = new NativeUwpAppWindow(); mainAppWindow = new MainAppWindow(); await PowerPlannerApp.Current.RegisterWindowAsync(mainAppWindow, nativeWindow); if (PowerPlannerApp.Current.Windows.Count > 1) { throw new Exception("There are more than 1 windows registered"); } } if (e is LaunchActivatedEventArgs) { var launchEventArgs = e as LaunchActivatedEventArgs; var launchContext = !object.Equals(launchEventArgs.TileId, "App") ? LaunchSurface.SecondaryTile : LaunchSurface.Normal; if (launchContext == LaunchSurface.Normal) { // Track whether was launched from primary tile if (ApiInformation.IsPropertyPresent(typeof(LaunchActivatedEventArgs).FullName, nameof(LaunchActivatedEventArgs.TileActivatedInfo))) { if (launchEventArgs.TileActivatedInfo != null) { launchContext = LaunchSurface.PrimaryTile; } } } await HandleArguments(mainAppWindow, launchEventArgs.Arguments, launchContext); } else if (e is ToastNotificationActivatedEventArgs) { var args = e as ToastNotificationActivatedEventArgs; await HandleArguments(mainAppWindow, args.Argument, LaunchSurface.Toast); } else if (e is ProtocolActivatedEventArgs) { var protocolEventArgs = e as ProtocolActivatedEventArgs; if (!string.IsNullOrWhiteSpace(protocolEventArgs.Uri.PathAndQuery) && protocolEventArgs.Uri.PathAndQuery.StartsWith("?")) { await HandleArguments(mainAppWindow, protocolEventArgs.Uri.PathAndQuery.Substring(1), LaunchSurface.Uri); } } else if (e is AppointmentsProviderShowAppointmentDetailsActivatedEventArgs) { // Note that this code is essentially deprecated and doesn't get hit... Uri launch happens instead var showDetailsArgs = e as AppointmentsProviderShowAppointmentDetailsActivatedEventArgs; try { AppointmentsHelper.RoamingIdData data = AppointmentsHelper.RoamingIdData.FromString(showDetailsArgs.RoamingId); string finalArgs = null; switch (data.ItemType) { case ItemType.Schedule: finalArgs = new ViewScheduleArguments() { LocalAccountId = data.LocalAccountId }.SerializeToString(); break; case ItemType.MegaItem: finalArgs = new ViewTaskArguments() { LocalAccountId = data.LocalAccountId, ItemId = data.Identifier }.SerializeToString(); break; } if (finalArgs != null) { await HandleArguments(mainAppWindow, finalArgs, LaunchSurface.Calendar); } } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } } if (mainAppWindow.GetViewModel().Content == null) { await mainAppWindow.GetViewModel().HandleNormalLaunchActivation(); } Window.Current.Activate(); // Listen to window activation changes Window.Current.Activated += Current_Activated; // Set up the default window properties ConfigureWindowProperties(); // Set up the sharing support ConfigureDataTransferManager(); // Display updates HandleVersionChange(); } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } }