org.symbian.tools.wrttools/plugin.xml
changeset 389 5a72e60dea8b
parent 388 bd7a2b98ea78
child 390 41fb932132ea
equal deleted inserted replaced
388:bd7a2b98ea78 389:5a72e60dea8b
   967 	}
   967 	}
   968           </content>
   968           </content>
   969        </item>
   969        </item>
   970        <item
   970        <item
   971              class="org.symbian.tools.wrttools.util.SnippetInsertion"
   971              class="org.symbian.tools.wrttools.util.SnippetInsertion"
   972              description="Function that processes notifications from the sensors"
   972              description="Use this code to track acceleration, orientation or rotation changes"
   973              id="org.symbian.tools.wrttools.contacts"
       
   974              label="Sensor callback">
       
   975           <content>
       
   976 // This function can be passed as callback to 
       
   977 // sensors.ISensor.RegisterForNotification method
       
   978 function sensorCallback(transactionId, code, result) {
       
   979 	if (result.ErrorCode == 0) {
       
   980 		// TODO Process notification
       
   981 		var dataType = result.ReturnValue.DataType; // One of: "AxisData", "DoubleTappingData", "OrientationData" or "RotationData"
       
   982 		// var xAxis = result.ReturnValue.XAxisData; // Accelerometer
       
   983 		// var yAxis = result.ReturnValue.YAxisData; // Accelerometer
       
   984 		// var zAxis = result.ReturnValue.ZAxisData; // Accelerometer
       
   985 		// var direction = result.ReturnValue.DeviceDirection; // Accelerometer double tapping
       
   986 		// var orientation = result.ReturnValue.DeviceOrientation; // Orientation
       
   987 		// var xRotation = result.ReturnValue.XRotation; // Rotation
       
   988 		// var yRotation = result.ReturnValue.YRotation; // Rotation
       
   989 		// var zRotation = result.ReturnValue.ZRotation; // Rotation
       
   990 	} else {
       
   991 		var errorCode = result.ErrorCode;
       
   992 		var errorMessage = result.ErrorMessage;
       
   993 		// TODO Handle error
       
   994 	}
       
   995 }
       
   996          </content>
       
   997        </item>
       
   998        <item
       
   999              class="org.symbian.tools.wrttools.util.SnippetInsertion"
       
  1000              description="Use this method to track acceleration, orientation or rotation changes"
       
  1001              id="org.symbian.tools.wrttools.contacts"
   973              id="org.symbian.tools.wrttools.contacts"
  1002              label="Watch sensor notifications">
   974              label="Watch sensor notifications">
  1003           <content>
   975           <content>
  1004 // Call this function to add a callback that will be notified of orientation changes
   976 // Call this function to add a callback that will be notified of orientation changes
  1005 function watchSensorNotifications(sensorCallback) {
   977 function watchSensorNotifications() {
  1006 	var sensors = device.getServiceObject("Service.Sensor", "ISensor");
   978 	var sensors = device.getServiceObject("Service.Sensor", "ISensor");
  1007 	var SensorParams = {
   979 	var SensorParams = {
  1008 		SearchCriterion : "Orientation" // TODO Possible values (one of):
   980 		SearchCriterion : "Orientation" // TODO Possible values (one of):
  1009 			// SearchCriterion : "All"
   981 			// SearchCriterion : "All"
  1010 			// SearchCriterion : "AccelerometerAxis"
   982 			// SearchCriterion : "AccelerometerAxis"
  1017 		var errorCode = result.ErrorCode;
   989 		var errorCode = result.ErrorCode;
  1018 		var errorMessage = result.ErrorMessage;
   990 		var errorMessage = result.ErrorMessage;
  1019 		// TODO Handle error
   991 		// TODO Handle error
  1020 		return null;
   992 		return null;
  1021 	}
   993 	}
  1022     // TODO Function named "orientationCallback" will be called when device orientation changes. This function should be created. 
   994     // TODO Function named "sensorCallback" will be called when device orientation changes. This function should be created. 
  1023 	var result2 = sensors.ISensor.RegisterForNotification(
   995 	var result2 = sensors.ISensor.RegisterForNotification(
  1024 			{ ChannelInfoMap : result.ReturnValue[0], 
   996 			{ ChannelInfoMap : result.ReturnValue[0], 
  1025 				ListeningType : "ChannelData" }, sensorCallback);
   997 				ListeningType : "ChannelData" }, sensorCallback);
  1026 	if (result.ErrorCode == 0) {
   998 	if (result.ErrorCode == 0) {
  1027 		var transactionId = result.TransactionID;
   999 		var transactionId = result.TransactionID;
  1032 		var errorMessage = result.ErrorMessage;
  1004 		var errorMessage = result.ErrorMessage;
  1033 		// TODO Handle error
  1005 		// TODO Handle error
  1034 		return null;
  1006 		return null;
  1035 	}
  1007 	}
  1036 }
  1008 }
       
  1009 
       
  1010 // This function can be passed as callback to 
       
  1011 // sensors.ISensor.RegisterForNotification method
       
  1012 function sensorCallback(transactionId, code, result) {
       
  1013 	if (result.ErrorCode == 0) {
       
  1014 		// TODO Process notification
       
  1015 		var dataType = result.ReturnValue.DataType; // One of: "AxisData", "DoubleTappingData", "OrientationData" or "RotationData"
       
  1016 		var orientation = result.ReturnValue.DeviceOrientation; // Orientation
       
  1017 		// var xAxis = result.ReturnValue.XAxisData; // Accelerometer
       
  1018 		// var yAxis = result.ReturnValue.YAxisData; // Accelerometer
       
  1019 		// var zAxis = result.ReturnValue.ZAxisData; // Accelerometer
       
  1020 		// var direction = result.ReturnValue.DeviceDirection; // Accelerometer double tapping
       
  1021 		// var xRotation = result.ReturnValue.XRotation; // Rotation
       
  1022 		// var yRotation = result.ReturnValue.YRotation; // Rotation
       
  1023 		// var zRotation = result.ReturnValue.ZRotation; // Rotation
       
  1024 	} else {
       
  1025 		var errorCode = result.ErrorCode;
       
  1026 		var errorMessage = result.ErrorMessage;
       
  1027 		// TODO Handle error
       
  1028 	}
       
  1029 }
       
  1030 
  1037          </content>
  1031          </content>
  1038        </item>
  1032        </item>
  1039     </category>
  1033     </category>
  1040     <category
  1034     <category
  1041           description="Snippets using PhoneGap APIs"
  1035           description="Snippets using PhoneGap APIs"