Exemplo n.º 1
0
 public override void HandleWorkoutConfiguration(HKWorkoutConfiguration workoutConfiguration)
 {
     WKInterfaceController.ReloadRootPageControllers(new string[] { nameof(WorkoutInterfaceController) },
                                                     new NSObject[] { workoutConfiguration },
                                                     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);
        }
 partial void TapDoneTapped()
 {
     WKInterfaceController.ReloadRootPageControllers(new string[] { nameof(ConfigurationInterfaceController) },
                                                     null,
                                                     WKPageOrientation.Vertical,
                                                     0);
 }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
        partial void Button1_Activated() => this.PresentTextInputController(new[] { "Yes", "No", "Maybe" }, WKTextInputMode.Plain, delegate(NSArray results) {
            if (results?.Count > 0)
            {
                WKInterfaceController.OpenParentApplication(new NSDictionary("input", results.GetItem <NSObject>(0).ToString()), (replyInfo, error) =>
                {
                    if (error != null)
                    {
                        this.label1.SetText(error.ToString());
                        return;
                    }

                    var result = ((NSString)replyInfo["result"]).ToString();
                    this.label1.SetText(result);
                });
            }
        });
Exemplo n.º 6
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"})");
                }
            });
        }
Exemplo n.º 7
0
		partial void ReplyWithTextInputController (NSObject obj)
		{
			// Using the WKTextInputMode enum, you can specify which aspects of the Text Input Controller are shown when presented.
			PresentTextInputController (new [] { "Yes", "No", "Maybe" }, WKTextInputMode.AllowAnimatedEmoji, delegate(NSArray results) {
				Console.WriteLine ("Text Input Results: {0}", results);

				if (results.GetItem<NSString> (0) != null) {
					// Sends a non-nil result to the parent iOS application.
					bool didOpenParent = WKInterfaceController.OpenParentApplication (new NSDictionary (new NSString ("TextInput"), results.GetItem<NSString> (0)), delegate(NSDictionary replyInfo, NSError error) {
						Console.WriteLine ("Reply Info: {0}", replyInfo);
						Console.WriteLine ("Error: {0}", error != null ? error.LocalizedDescription : "null");
					});

					Console.WriteLine ("Did open parent application? {0}", didOpenParent);
				}
			});
		}
Exemplo n.º 8
0
        void UpdateUserInterface()
        {
            WKInterfaceController.OpenParentApplication(new NSDictionary(), (replyInfo, error) =>
            {
                if (error != null)
                {
                    Console.WriteLine(error);
                    return;
                }

                var events = (NSArray)replyInfo["SessionTitle"];

                MyTable.SetNumberOfRows((nint)events.Count, "default");

                for (int i = 0; i < (int)events.Count; i++)
                {
                    var elementRow = (RowController)MyTable.GetRowController(i);
                    elementRow.MyLabel.SetText(events.GetItem <NSString>((nuint)i));
                }
            });
        }
Exemplo n.º 9
0
        void UpdateUserInterface(NSTimer t)
        {
            WKInterfaceController.OpenParentApplication(new NSDictionary(), (replyInfo, error) => {
                if (error != null)
                {
                    Console.WriteLine(error);
                    return;
                }

                var status    = (CLAuthorizationStatus)((NSNumber)replyInfo["status"]).UInt32Value;
                var longitude = ((NSNumber)replyInfo["lon"]).DoubleValue;
                var latitude  = ((NSNumber)replyInfo["lat"]).DoubleValue;

                Console.WriteLine("authorization status {0}", status);
                switch (status)
                {
                case CLAuthorizationStatus.AuthorizedAlways:
                    SetCooridinate(longitude, latitude);
                    HideWarning();
                    break;

                case CLAuthorizationStatus.NotDetermined:
                    SetNotAvailable();
                    ShowWarning("Launch the iOS app first");
                    break;

                case CLAuthorizationStatus.Denied:
                    SetNotAvailable();
                    ShowWarning("Enable Location Service on iPhone");
                    break;

                default:
                    throw new NotImplementedException();
                }
            });
        }