public async Task InitializeAsync()
        {
            _hinge = await HingeAngleSensor.GetDefaultAsync();

            if (_hinge != null)
            {
                SensorStatus = "HingeAngleSensor created";
            }
            else
            {
                SensorStatus = "HingeAngleSensor not available on this device";
            }
        }
Exemple #2
0
        public async Task InitializeAsync()
        {
            //Asynchronously retrieves the default hinge angle sensor.
            hinge = await HingeAngleSensor.GetDefaultAsync();

            if (hinge != null)
            {
                SensorStatus.Content = "HingeAngleSensor created";

                //Listener for the HingeAngleSensor ReadingChanged event.
                hinge.ReadingChanged += HingeAngleSensor_ReadingChanged;
            }
            else
            {
                SensorStatus.Content = "HingeAngleSensor not available on this device";
                AngleValue.Content   = "Angle value: Not available";
            }
        }
Exemple #3
0
            public async Task InitializeAsync()
            {
                _hinge = await HingeAngleSensor.GetDefaultAsync();

                if (_hinge != null)
                {
                    SensorStatus = "HingeAngleSensor created";
                }
                else
                {
                    SensorStatus = "HingeAngleSensor not available on this device";
                }
                Disposables.Add(Disposable.Create(() =>
                {
                    if (_hinge != null)
                    {
                        _hinge.ReadingChanged -= HingeAngleSensor_ReadingChanged;
                    }
                }));
            }
Exemple #4
0
        private async void HingeAngleSensor_ReadingChanged(HingeAngleSensor sender, HingeAngleSensorReadingChangedEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var angleValue = args.Reading.AngleInDegrees;

                AngleValue.Content = "Angle value: " + angleValue.ToString();

                //Making sure we are not moving again the cars if we are keeping the same angle
                if (angleValue != previousAngle)
                {
                    previousAngle = angleValue;

                    // When the dual-screen device is half-opened
                    if (angleValue == 180)
                    {
                        //Making sure the SketchCar is not bouncing and rotating wheels.
                        CarStoryboard.Stop();

                        // Making sure the scene animation is paused at the same time if it was already started.
                        if (isSceneAnimationStarted)
                        {
                            SceneStoryboard.Pause();
                        }

                        // Move the lower cars along the x-axis in the middle of the screen and keeping the same upper y-axis.
                        dragLowerTranslation.X = (MainRoot.ActualWidth / 2) - (MainRoot.ActualWidth *leftSideThresholdRatio) - 100;
                        dragLowerTranslation.Y = dragUpperTranslation.Y;

                        // Keep the upper rectangle at the same position as the lower rectangle.
                        dragUpperTranslation.X = dragLowerTranslation.X;
                    }
                    // When the dual-screen device is fully opened, meaning that both screens are facing aware from each other.
                    else if (angleValue == 360)
                    {
                        // Move the lower cars along the x-axis on the right side of the screen and keeping the same upper y-axis.
                        dragLowerTranslation.X = MainRoot.ActualWidth *rightSideThresholdRatio;
                        dragLowerTranslation.Y = dragUpperTranslation.Y;

                        // Keep the upper rectangle at the same position as the lower rectangle.
                        dragUpperTranslation.X = dragLowerTranslation.X;
                        dragUpperTranslation.Y = dragLowerTranslation.Y;

                        // Making sure the SketchCar bouncing and rotating wheels animations begin for
                        // the first time or correctly being stopped and begin again if already started.
                        if (isCarAnimationStarted)
                        {
                            CarStoryboard.Stop();
                            CarStoryboard.Begin();
                        }
                        else
                        {
                            CarStoryboard.Begin();
                            isCarAnimationStarted = true;
                        }

                        // Making sure the scene animation begin for the first time or resume if paused.
                        if (isSceneAnimationStarted)
                        {
                            SceneStoryboard.Resume();
                        }
                        else
                        {
                            SceneStoryboard.Begin();
                            isSceneAnimationStarted = true;
                        }
                    }
                }
            });
        }
        public MainPage()
        {
            InitializeComponent();

            //ApplicationView.PreferredLaunchViewSize = new Size(1440, 936);
            //ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;

            CustomizeTitleBar();
            void CustomizeTitleBar()
            {
                var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;

                // Draw into the title bar.
                coreTitleBar.ExtendViewIntoTitleBar = true;
                DraggableAppTitleBarArea.Height     = coreTitleBar.Height;

                // Set a draggable region.
                Window.Current.SetTitleBar(DraggableAppTitleBarArea);

                coreTitleBar.LayoutMetricsChanged += (s, args) =>
                {
                    DraggableAppTitleBarArea.Height = s.Height;
                };

                coreTitleBar.IsVisibleChanged += (s, args) =>
                {
                    DraggableAppTitleBarArea.Visibility = s.IsVisible ? Visibility.Visible : Visibility.Collapsed;
                };

                // Remove the solid-colored backgrounds behind the caption controls and system back button.
                var viewTitleBar = ApplicationView.GetForCurrentView().TitleBar;

                viewTitleBar.ButtonBackgroundColor         = Colors.Transparent;
                viewTitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
                viewTitleBar.ButtonForegroundColor         = Color.FromArgb(255, 4, 119, 191);
            }

            ConnectedAnimationService.GetForCurrentView().DefaultDuration = TimeSpan.FromMilliseconds(400);

            if (MainNav.MenuItems[0] is WinUI.NavigationViewItemBase item)
            {
                MainNav.SelectedItem = item;
                NavigateToPage(item.Tag);
            }

            Window.Current.SizeChanged += async(s, e) =>
            {
                await Task.Delay(1200);

                var isSpanned = ApplicationView.GetForCurrentView().ViewMode == ApplicationViewMode.Spanning;
                if (isSpanned)
                {
                    Logo.GoToDualScreenState();
                }
                else
                {
                    Logo.GoToSingleScreenState();
                }
            };

            Loaded += async(s, e) =>
            {
                var titleBarHeight = CoreApplication.GetCurrentView().TitleBar.Height;
                MainNav.Padding = new Thickness(0, titleBarHeight, 0, 0);

                Logo.Start();

                _sensor = await HingeAngleSensor.GetDefaultAsync();

                if (_sensor != null)
                {
                    _sensor.ReportThresholdInDegrees = _sensor.MinReportThresholdInDegrees;

                    _sensor.ReadingChanged += OnSensorReadingChanged;
                    var current = (await _sensor.GetCurrentReadingAsync()).AngleInDegrees;
                }

                async void OnSensorReadingChanged(HingeAngleSensor sender, HingeAngleSensorReadingChangedEventArgs args)
                {
                    // Event is invoked from a different thread.
                    await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                    {
                        double angle = 0.0;

                        if (args.Reading.AngleInDegrees <= 180)
                        {
                            angle = args.Reading.AngleInDegrees / 2 - 90;
                        }
                        else
                        {
                            angle = (args.Reading.AngleInDegrees - 180) * 2;
                        }

                        Logo.SetAngle(angle);
                    });
                }
            };
        }