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); }
static AwarenessFence CreateSunriseOrSunsetFence() { return(AwarenessFence.Or( TimeFence.AroundTimeInstant(TimeFence.TimeInstant.Sunrise, -HourInMillis, HourInMillis), TimeFence.AroundTimeInstant(TimeFence.TimeInstant.Sunset, -HourInMillis, HourInMillis) )); }
static AwarenessFence CreateLocationFence() { return(AwarenessFence.Or( LocationFence.Entering(0, 0, 1000), LocationFence.Exiting(0, 0, 1000), LocationFence.In(0, 0, 1000, 100) )); }
static AwarenessFence CreateBeaconFence() { var beaconTypes = new List <BeaconState.TypeFilter> { BeaconState.TypeFilter.With("awareness-api-1534415879510", "string") }; var found = BeaconFence.Found(beaconTypes); var near = BeaconFence.Near(beaconTypes); var lost = BeaconFence.Lost(beaconTypes); return(AwarenessFence.Or(found, near, lost)); }
static AwarenessFence CreateAnyTimeIntervalFence() { return(AwarenessFence.Or( TimeFence.InTimeInterval(TimeFence.TimeInterval.Weekday), TimeFence.InTimeInterval(TimeFence.TimeInterval.Weekend), TimeFence.InTimeInterval(TimeFence.TimeInterval.Holiday), TimeFence.InTimeInterval(TimeFence.TimeInterval.Morning), TimeFence.InTimeInterval(TimeFence.TimeInterval.Afternoon), TimeFence.InTimeInterval(TimeFence.TimeInterval.Evening), TimeFence.InTimeInterval(TimeFence.TimeInterval.Night) )); }
static AwarenessFence CreateHeadphonesFence() { // Will trigger when headphones are connected or disconnected return(AwarenessFence.Or(HeadphoneFence.During(HeadphoneState.PluggedIn), HeadphoneFence.PluggingIn(), HeadphoneFence.Unplugging())); }