示例#1
0
    static AwarenessFence CreateExercisingWithHeadphonesFence()
    {
        // DetectedActivityFence will fire when it detects the user performing the specified
        // activity.  In this case it's walking.
        var walkingFence = DetectedActivityFence.During(DetectedActivityFence.ActivityType.Walking);

        // There are lots of cases where it's handy for the device to know if headphones have been
        // plugged in or unplugged.  For instance, if a music app detected your headphones fell out
        // when you were in a library, it'd be pretty considerate of the app to pause itself before
        // the user got in trouble.
        var headphoneFence = HeadphoneFence.During(HeadphoneState.PluggedIn);

#pragma warning disable 0219
        // Combines multiple fences into a compound fence.  While the first two fences trigger
        // individually, this fence will only trigger its callback when all of its member fences
        // hit a true state.
        var notWalkingWithHeadphones = AwarenessFence.And(AwarenessFence.Not(walkingFence), headphoneFence);
#pragma warning restore 0219

        // We can even nest compound fences.  Using both "and" and "or" compound fences, this
        // compound fence will determine when the user has headphones in and is engaging in at least
        // one form of exercise.
        // The below breaks down to "(headphones plugged in) AND (walking OR running OR bicycling)"
        var exercisingWithHeadphonesFence = AwarenessFence.And(
            headphoneFence,
            AwarenessFence.Or(
                walkingFence,
                DetectedActivityFence.During(DetectedActivityFence.ActivityType.Running),
                DetectedActivityFence.During(DetectedActivityFence.ActivityType.OnBicycle)));

        return(exercisingWithHeadphonesFence);
    }
示例#2
0
 static AwarenessFence CreateHeadphonesFence()
 {
     // Will trigger when headphones are connected or disconnected
     return(AwarenessFence.Or(HeadphoneFence.During(HeadphoneState.PluggedIn), HeadphoneFence.PluggingIn(), HeadphoneFence.Unplugging()));
 }