Bug 3019 - Register orientation callback problems
authorEugene Ostroukhov <eugeneo@symbian.org>
Thu, 17 Jun 2010 11:17:33 -0700
changeset 386 7d0a718a6346
parent 385 9bf326e3aeb9
child 387 53123b7b800d
Bug 3019 - Register orientation callback problems
org.symbian.tools.wrttools/plugin.xml
--- a/org.symbian.tools.wrttools/plugin.xml	Wed Jun 16 17:56:07 2010 -0700
+++ b/org.symbian.tools.wrttools/plugin.xml	Thu Jun 17 11:17:33 2010 -0700
@@ -919,53 +919,6 @@
        </item>
        <item
              class="org.symbian.tools.wrttools.util.SnippetInsertion"
-             description="Sends SMS message"
-             id="org.symbian.tools.wrttools.contacts"
-             label="Send SMS message">
-          <content>
-var phoneNumber = "+6505551214";
-	var text = "Sent from WRT application";
-	var messaging = device.getServiceObject("Service.Messaging", "IMessaging");
-	var result = messaging.IMessaging.Send({ MessageType : "SMS", To : phoneNumber, BodyText : text });
-	if (result.ErrorCode != null) {
-		var errorCode = result.ErrorCode;
-		var errorMessage = result.ErrorMessage;
-		// TODO Cannot send SMS message
-	}
-          </content>
-       </item>
-       <item
-             class="org.symbian.tools.wrttools.util.SnippetInsertion"
-             description="Adds callback that will be notified of orientation chnages"
-             id="org.symbian.tools.wrttools.contacts"
-             label="Register orientation callback">
-          <content>
-var sensors = device.getServiceObject("Service.Sensor", "ISensor");
-	var SensorParams = {
-		SearchCriterion : "Orientation"
-	};
-	var result = sensors.ISensor.FindSensorChannel(SensorParams);
-
-	if (result.ErrorCode == 0) {
-	    // TODO Function named "orientationCallback" will be called when device orientation changes. This function should be created. 
-		var result2 = sensors.ISensor.RegisterForNotification({ ChannelInfoMap : result.ReturnValue[0], ListeningType : "ChannelData" }, orientationCallback);
-		if (result.ErrorCode == 0) {
-			var transactionId = result.TransactionID;
-			// TODO Use this transaction ID to cancel notifications when watching orientation is no longer needed
-		} else {
-			var errorCode = result.ErrorCode;
-			var errorMessage = result.ErrorMessage;
-			// TODO Handle error
-		}
-	} else {
-		var errorCode = result.ErrorCode;
-		var errorMessage = result.ErrorMessage;
-		// TODO Handle error
-	}
-         </content>
-       </item>
-       <item
-             class="org.symbian.tools.wrttools.util.SnippetInsertion"
              description="This function can be used as a callback in GetLocation and Trace calls to location service."
              id="org.symbian.tools.wrttools.location"
              label="Location callback">
@@ -999,23 +952,41 @@
        </item>
        <item
              class="org.symbian.tools.wrttools.util.SnippetInsertion"
-             description="Function that processes notifications from the orientation sensor"
+             description="Sends SMS message"
              id="org.symbian.tools.wrttools.contacts"
-             label="Orientation callback">
+             label="Send SMS message">
           <content>
-// This function can be passed as callback to locationService.ILocation.GetLocation 
-// or locationService.ILocation.Trace method
-function orientationCallback(transactionId, code, result) {
+var phoneNumber = "+6505551214";
+	var text = "Sent from WRT application";
+	var messaging = device.getServiceObject("Service.Messaging", "IMessaging");
+	var result = messaging.IMessaging.Send({ MessageType : "SMS", To : phoneNumber, BodyText : text });
+	if (result.ErrorCode != null) {
+		var errorCode = result.ErrorCode;
+		var errorMessage = result.ErrorMessage;
+		// TODO Cannot send SMS message
+	}
+          </content>
+       </item>
+       <item
+             class="org.symbian.tools.wrttools.util.SnippetInsertion"
+             description="Function that processes notifications from the sensors"
+             id="org.symbian.tools.wrttools.contacts"
+             label="Sensor callback">
+          <content>
+// This function can be passed as callback to 
+// sensors.ISensor.RegisterForNotification method
+function sensorCallback(transactionId, code, result) {
 	if (result.ErrorCode == 0) {
-		var orientation = result.ReturnValue.DeviceOrientation;
-		// TODO Possible values:
-		// "Undefined"
-		// "DisplayUp"
-		// "DisplayDown"
-		// "DisplayLeftUp"
-		// "DisplayRightUp"
-		// "DisplayUpwards"
-		// "DisplayDownwards"
+		// TODO Process notification
+		var dataType = result.ReturnValue.DataType; // One of: "AxisData", "DoubleTappingData", "OrientationData" or "RotationData"
+		// var xAxis = result.ReturnValue.XAxisData; // Accelerometer
+		// var yAxis = result.ReturnValue.YAxisData; // Accelerometer
+		// var zAxis = result.ReturnValue.ZAxisData; // Accelerometer
+		// var direction = result.ReturnValue.DeviceDirection; // Accelerometer double tapping
+		// var orientation = result.ReturnValue.DeviceOrientation; // Orientation
+		// var xRotation = result.ReturnValue.XRotation; // Rotation
+		// var yRotation = result.ReturnValue.YRotation; // Rotation
+		// var zRotation = result.ReturnValue.ZRotation; // Rotation
 	} else {
 		var errorCode = result.ErrorCode;
 		var errorMessage = result.ErrorMessage;
@@ -1024,6 +995,47 @@
 }
          </content>
        </item>
+       <item
+             class="org.symbian.tools.wrttools.util.SnippetInsertion"
+             description="Use this method to track acceleration, orientation or rotation changes"
+             id="org.symbian.tools.wrttools.contacts"
+             label="Watch sensor notifications">
+          <content>
+// Call this function to add a callback that will be notified of orientation changes
+function watchSensorNotifications(sensorCallback) {
+	var sensors = device.getServiceObject("Service.Sensor", "ISensor");
+	var SensorParams = {
+		SearchCriterion : "Orientation" // TODO Possible values (one of):
+			// SearchCriterion : "All"
+			// SearchCriterion : "AccelerometerAxis"
+			// SearchCriterion : "AccelerometerDoubleTapping"
+			// SearchCriterion : "Rotation"
+	};
+	var result = sensors.ISensor.FindSensorChannel(SensorParams);
+
+	if (result.ErrorCode != 0) {
+		var errorCode = result.ErrorCode;
+		var errorMessage = result.ErrorMessage;
+		// TODO Handle error
+		return null;
+	}
+    // TODO Function named "orientationCallback" will be called when device orientation changes. This function should be created. 
+	var result2 = sensors.ISensor.RegisterForNotification(
+			{ ChannelInfoMap : result.ReturnValue[0], 
+				ListeningType : "ChannelData" }, sensorCallback);
+	if (result.ErrorCode == 0) {
+		var transactionId = result.TransactionID;
+		// TODO Use this transaction ID to cancel notifications when watching orientation is no longer needed
+		return transactionId;
+	} else {
+		var errorCode = result.ErrorCode;
+		var errorMessage = result.ErrorMessage;
+		// TODO Handle error
+		return null;
+	}
+}
+         </content>
+       </item>
     </category>
     <category
           description="Snippets using PhoneGap APIs"