<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -31,6 +31,9 @@
     NSDictionary *settings;
     NSMutableDictionary *commandObjects;
     NSURL *invokedURL;
+
+	UIAcceleration *lastAccel;
+	NSInteger accelCount;
 }
 
 @property (nonatomic, retain) UIWindow *window;
@@ -45,6 +48,7 @@
 - (void) javascriptAlert:(NSString*)text;
 - (BOOL) execute:(InvokedUrlCommand*)command;
 - (NSString*) appURLScheme;
+- (BOOL)getAccelerationDelta:(UIAcceleration*)accel aboveThreshold:(double)threshold;
 
 + (NSDictionary*)getBundlePlist:(NSString *)plistName;
 </diff>
      <filename>iphone/Classes/PhoneGapDelegate.h</filename>
    </modified>
    <modified>
      <diff>@@ -73,6 +73,7 @@
 #endif
     NSNumber *useLocation          = [settings objectForKey:@&quot;UseLocation&quot;];
     NSNumber *useAccelerometer     = [settings objectForKey:@&quot;EnableAcceleration&quot;];
+    NSNumber *useAccelerometerGestures = [settings objectForKey:@&quot;EnableAccelerationGestures&quot;];
     NSNumber *autoRotate           = [settings objectForKey:@&quot;AutoRotate&quot;];
     NSString *startOrientation     = [settings objectForKey:@&quot;StartOrientation&quot;];
     NSString *rotateOrientation    = [settings objectForKey:@&quot;RotateOrientation&quot;];
@@ -87,8 +88,8 @@
 
 	webView.delegate = self;
 
-	if ([useAccelerometer boolValue]) {
-        [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0/40.0];
+	if ([useAccelerometer boolValue] || [useAccelerometerGestures boolValue]) {
+        [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0/5.0];
         [[UIAccelerometer sharedAccelerometer] setDelegate:self];
     }
 
@@ -404,10 +405,65 @@
  * Sends Accel Data back to the Device.
  */
 - (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
-	NSString * jsCallBack = nil;
-	jsCallBack = [[NSString alloc] initWithFormat:@&quot;var _accel={x:%f,y:%f,z:%f};&quot;, acceleration.x, acceleration.y, acceleration.z];
-	[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
-    [jsCallBack release];
+	if ([[settings objectForKey:@&quot;EnableAccelerationGestures&quot;] boolValue]) {
+		if ([self getAccelerationDelta:acceleration aboveThreshold:1.0])
+			accelCount += 10;
+		else if ([self getAccelerationDelta:acceleration aboveThreshold:0.8])
+			accelCount += 8;
+		else if ([self getAccelerationDelta:acceleration aboveThreshold:0.5])
+			accelCount += 5;
+		else if ([self getAccelerationDelta:acceleration aboveThreshold:0.2])
+			accelCount++;
+		else if (accelCount &gt; 0)
+			accelCount--;
+		
+		if (lastAccel != nil)
+			[lastAccel release];
+		lastAccel = acceleration;
+		[lastAccel retain];
+		
+		if (accelCount &gt; 10) {
+			[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:
+															 @&quot;(function(){ &quot;
+															 &quot;var e = document.createEvent('Events'); &quot;
+															 &quot;e.initEvent('accelerometerShake', 'false', 'false'); &quot;
+															 &quot;e.strength = %d; &quot;
+															 &quot;document.dispatchEvent(e); &quot;
+															 &quot;})()&quot;,
+															 accelCount]];
+			accelCount = 0;
+		}
+	}
+	
+	if ([[settings objectForKey:@&quot;EnableAcceleration&quot;] boolValue]) {
+		NSString *js = [[NSString alloc] initWithFormat:@&quot;var _accel = { x: %f, y: %f, z: %f };\n&quot;
+						&quot;(function(){ &quot;
+						&quot;var e = document.createEvent('Events'); &quot;
+						&quot;e.initEvent('accelerometerUpdated', 'false', 'false'); &quot;
+						&quot;e.x = _accel.x; &quot;
+						&quot;e.y = _accel.y; &quot;
+						&quot;e.z = _accel.z; &quot;
+						&quot;document.dispatchEvent(e); &quot;
+						&quot;})()&quot;,
+						acceleration.x, acceleration.y, acceleration.z];
+		//NSLog(@&quot;accel: %@&quot;, js);
+		[webView stringByEvaluatingJavaScriptFromString:js];
+		[js release];
+	}
+}
+
+- (BOOL)getAccelerationDelta:(UIAcceleration *)accel aboveThreshold:(double)threshold
+{
+	if (lastAccel == nil)
+		return NO;
+	
+	double deltaX = (double)lastAccel.x - (double)accel.x;
+	double deltaY = (double)lastAccel.y - (double)accel.y;
+	double deltaZ = (double)lastAccel.z - (double)accel.z;
+	
+	return (deltaX &gt; threshold &amp;&amp; deltaY &gt; threshold) ||
+	(deltaX &gt; threshold &amp;&amp; deltaZ &gt; threshold) ||
+	(deltaY &gt; threshold &amp;&amp; deltaZ &gt; threshold);
 }
 
 - (void)dealloc</diff>
      <filename>iphone/Classes/PhoneGapDelegate.m</filename>
    </modified>
    <modified>
      <diff>@@ -9,6 +9,8 @@
 	&lt;key&gt;EnableLocation&lt;/key&gt;
 	&lt;true/&gt;
 	&lt;key&gt;EnableAcceleration&lt;/key&gt;
+	&lt;false/&gt;
+	&lt;key&gt;EnableAccelerationGestures&lt;/key&gt;
 	&lt;true/&gt;
 	&lt;key&gt;AutoRotate&lt;/key&gt;
 	&lt;true/&gt;</diff>
      <filename>iphone/PhoneGap.plist</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2aa71cf15d1a51a0f4ebb742603034e8dd3b3101</id>
    </parent>
  </parents>
  <author>
    <name>Michael Nachbaur</name>
    <email>nachbaur@nacho-3.local</email>
  </author>
  <url>http://github.com/NachoMan/phonegap/commit/bf4361bb27e04020e16ad484be18d523ed4f6037</url>
  <id>bf4361bb27e04020e16ad484be18d523ed4f6037</id>
  <committed-date>2009-10-18T16:36:02-07:00</committed-date>
  <authored-date>2009-10-18T16:36:02-07:00</authored-date>
  <message>Added native accelerometer gestures; initially just 'Shake'</message>
  <tree>ec3aaf8ff7c0406cb42fedd5c48952c8169f6658</tree>
  <committer>
    <name>Michael Nachbaur</name>
    <email>nachbaur@nacho-3.local</email>
  </committer>
</commit>
