Пример #1
0
 public override void HandleWorkoutConfiguration(HKWorkoutConfiguration workoutConfiguration)
 {
     WKInterfaceController.ReloadRootPageControllers(new string[] { nameof(WorkoutInterfaceController) },
                                                     new NSObject[] { workoutConfiguration },
                                                     WKPageOrientation.Vertical,
                                                     0);
 }
 partial void TapDoneTapped()
 {
     WKInterfaceController.ReloadRootPageControllers(new string[] { nameof(ConfigurationInterfaceController) },
                                                     null,
                                                     WKPageOrientation.Vertical,
                                                     0);
 }
        /// <summary>
        /// Load paged-based UI. If a current context is specified, use the timed color it provided.
        /// </summary>
        private void ReloadRootController(CommandStatus currentContext = null)
        {
            var commands = Enum.GetValues(typeof(Command)).Cast <Command>();
            var contexts = new List <CommandStatus>();

            foreach (var aCommand in commands)
            {
                var commandStatus = new CommandStatus(aCommand, Phrase.Finished);

                if (currentContext != null && aCommand == currentContext.Command)
                {
                    commandStatus.Phrase     = currentContext.Phrase;
                    commandStatus.TimedColor = currentContext.TimedColor;
                }

                contexts.Add(commandStatus);
            }

            var names = new string[contexts.Count];

            for (int i = 0; i < contexts.Count; i++)
            {
                names[i] = nameof(MainInterfaceController);
            }

            WKInterfaceController.ReloadRootPageControllers(names, contexts.ToArray(), WKPageOrientation.Horizontal, 0);
        }
Пример #4
0
        partial void DidTapStartButton()
        {
            // Create workout configuration
            var workoutConfiguration = new HKWorkoutConfiguration
            {
                ActivityType = this.selectedActivityType.Map(),
                LocationType = this.selectedLocationType.Map()
            };

            // Pass configuration to next interface controller
            WKInterfaceController.ReloadRootPageControllers(new[] { nameof(WorkoutInterfaceController) },
                                                            new[] { workoutConfiguration },
                                                            WKPageOrientation.Vertical,
                                                            0);
        }
Пример #5
0
        private void AddSamples(HKWorkout workout, NSDate startDate, NSDate endDate)
        {
            // Create energy and distance sample
            var totalEnergyBurnedSample = HKQuantitySample.FromType(HKQuantityType.Create(HKQuantityTypeIdentifier.ActiveEnergyBurned),
                                                                    this.TotalBurningEnergyQuantity(),
                                                                    startDate,
                                                                    endDate);

            var totalDistanceSample = HKQuantitySample.FromType(HKQuantityType.Create(HKQuantityTypeIdentifier.DistanceWalkingRunning),
                                                                this.TotalDistanceQuantity(),
                                                                startDate,
                                                                endDate);

            // add samples to workout
            this.healthStore.AddSamples(new HKSample[] { totalEnergyBurnedSample, totalDistanceSample }, workout, (isSuccess, error) =>
            {
                if (isSuccess)
                {
                    DispatchQueue.MainQueue.DispatchAsync(() =>
                    {
                        WKInterfaceController.ReloadRootPageControllers(new string[] { nameof(SummaryInterfaceController) },
                                                                        new NSObject[] { workout },
                                                                        WKPageOrientation.Vertical,
                                                                        0);
                    });
                }
                else
                {
                    Console.WriteLine($"Adding workout subsamples failed with error: ({error?.Description ?? "unknown"})");
                }
            });

            // finish the route with a syn identifier so we can easily update the route later
            var objects = new NSObject[] { new NSString(new NSUuid().AsString()), NSNumber.FromInt32(1) };
            var keys    = new NSString[] { HKMetadataKey.SyncIdentifier, HKMetadataKey.SyncVersion };

            var dictionary = NSDictionary.FromObjectsAndKeys(objects, keys);
            var metadata   = new HKMetadata(dictionary);

            this.workoutRouteBuilder?.FinishRoute(workout, metadata, (workoutRoute, error) =>
            {
                if (workoutRoute == null)
                {
                    Console.WriteLine($"Finishing route failed with error: ({error?.Description ?? "unknown"})");
                }
            });
        }