public MainPage(IDeviceDisplay deviceDisplay) { this.deviceDisplay = deviceDisplay; this.InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); this.Appearing += this.OnAppearing; }
public static void SetCurrent(IDeviceDisplay?implementation) { lock (locker) { if (currentImplementation == implementation) { return; } var newImplementation = implementation ?? new DeviceDisplayImplementation(); var oldImplementation = currentImplementation; currentImplementation = newImplementation; if (oldImplementation is not null) { oldImplementation.MainDisplayInfoChanged -= OnMainDisplayInfoChanged; var wasAlwaysOn = oldImplementation.KeepScreenOn; if (wasAlwaysOn) { oldImplementation.KeepScreenOn = false; newImplementation.KeepScreenOn = true; } var wasRunning = MainDisplayInfoChangedInternal != null; if (wasRunning) { oldImplementation.StopScreenMetricsListeners(); newImplementation.StartScreenMetricsListeners(); } } newImplementation.MainDisplayInfoChanged += OnMainDisplayInfoChanged; SetCurrent(newImplementation.GetMainDisplayInfo()); } }
static DeviceDisplay() { currentImplementation = new DeviceDisplayImplementation(); currentImplementation.MainDisplayInfoChanged += OnMainDisplayInfoChanged; }