Created
January 18, 2013 15:35
-
-
Save prashantvc/4565376 to your computer and use it in GitHub Desktop.
Periodically checks if app is idle for particular interval. (MonoTouch)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ActiveWindows:UIWindow | |
{ | |
NSTimer idleTimter; | |
double idleTimeInterval; | |
public MyWindows (RectangleF frame):base(frame) | |
{ | |
idleTimeInterval = 10; //Change the idle time | |
idleTimter = | |
NSTimer.CreateScheduledTimer (idleTimeInterval, WindowIdleNotification); | |
} | |
public override void SendEvent (UIEvent evt) | |
{ | |
base.SendEvent (evt); | |
var allTouches = evt.AllTouches; | |
if (allTouches.Count > 0) { | |
var touch = allTouches.AnyObject as UITouch; | |
var phase = touch.Phase; | |
if (phase == UITouchPhase.Began || phase == UITouchPhase.Ended) { | |
if (!idleTimter.IsValid) { | |
WindowActiveNotification (); | |
} else { | |
idleTimter.Invalidate (); | |
} | |
if (idleTimeInterval != 0) { | |
idleTimter = | |
NSTimer.CreateScheduledTimer (idleTimeInterval, WindowIdleNotification); | |
} | |
} | |
} | |
} | |
void WindowActiveNotification () | |
{ | |
Console.WriteLine ("Active"); | |
} | |
void WindowIdleNotification () | |
{ | |
Console.WriteLine ("Idle"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment