You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by be...@apache.org on 2013/05/25 02:15:39 UTC

[17/21] wp7 commit: removed accelerometer plugin dependencies

removed accelerometer plugin dependencies


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp7/commit/b4bacc04
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp7/tree/b4bacc04
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp7/diff/b4bacc04

Branch: refs/heads/3.0.0
Commit: b4bacc04a3d8f545753968529d6faea8b9cc218d
Parents: 8d0ae97
Author: Benn Mapes <be...@gmail.com>
Authored: Fri May 17 15:15:18 2013 -0700
Committer: Benn Mapes <be...@gmail.com>
Committed: Fri May 24 16:54:18 2013 -0700

----------------------------------------------------------------------
 templates/standalone/CordovaAppProj.csproj         |    1 -
 templates/standalone/Plugins/Accelerometer.cs      |  196 ---------------
 templates/standalone/config.xml                    |    1 -
 templates/standalone/cordovalib/NativeExecution.cs |    2 +-
 4 files changed, 1 insertions(+), 199 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/b4bacc04/templates/standalone/CordovaAppProj.csproj
----------------------------------------------------------------------
diff --git a/templates/standalone/CordovaAppProj.csproj b/templates/standalone/CordovaAppProj.csproj
index 0bfcad2..15e674c 100644
--- a/templates/standalone/CordovaAppProj.csproj
+++ b/templates/standalone/CordovaAppProj.csproj
@@ -166,7 +166,6 @@
     <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Plugins\Accelerometer.cs" />
     <Compile Include="Plugins\AudioFormatsHelper.cs" />
     <Compile Include="Plugins\AudioPlayer.cs" />
     <Compile Include="Plugins\Battery.cs" />

http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/b4bacc04/templates/standalone/Plugins/Accelerometer.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/Plugins/Accelerometer.cs b/templates/standalone/Plugins/Accelerometer.cs
deleted file mode 100644
index cba911c..0000000
--- a/templates/standalone/Plugins/Accelerometer.cs
+++ /dev/null
@@ -1,196 +0,0 @@
-/*  
-	Licensed under the Apache License, Version 2.0 (the "License");
-	you may not use this file except in compliance with the License.
-	You may obtain a copy of the License at
-	
-	http://www.apache.org/licenses/LICENSE-2.0
-	
-	Unless required by applicable law or agreed to in writing, software
-	distributed under the License is distributed on an "AS IS" BASIS,
-	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-	See the License for the specific language governing permissions and
-	limitations under the License.
-*/
-
-
-using System;
-using System.Collections.Generic;
-using System.Runtime.Serialization;
-using System.Threading;
-using Microsoft.Devices.Sensors;
-using System.Globalization;
-using System.Diagnostics;
-
-namespace WPCordovaClassLib.Cordova.Commands
-{
-    /// <summary>
-    /// Captures device motion in the x, y, and z direction.
-    /// </summary>
-    public class Accelerometer : BaseCommand
-    {
-        #region AccelerometerOptions class
-        /// <summary>
-        /// Represents Accelerometer options.
-        /// </summary>
-        [DataContract]
-        public class AccelerometerOptions
-        {
-            /// <summary>
-            /// How often to retrieve the Acceleration in milliseconds
-            /// </summary>
-            [DataMember(IsRequired = false, Name = "frequency")]
-            public int Frequency { get; set; }
-
-            /// <summary>
-            /// Watcher id
-            /// </summary>
-            [DataMember(IsRequired = false, Name = "id")]
-            public string Id { get; set; }
-
-            /// <summary>
-            /// Creates options object with default parameters
-            /// </summary>
-            public AccelerometerOptions()
-            {
-                this.SetDefaultValues(new StreamingContext());
-            }
-
-            /// <summary>
-            /// Initializes default values for class fields.
-            /// Implemented in separate method because default constructor is not invoked during deserialization.
-            /// </summary>
-            /// <param name="context"></param>
-            [OnDeserializing()]
-            public void SetDefaultValues(StreamingContext context)
-            {
-                this.Frequency = 10000;
-            }
-        }
-
-        #endregion
-
-        #region Status codes and Constants
-
-        public const int Stopped = 0;
-        public const int Starting = 1;
-        public const int Running = 2;
-        public const int ErrorFailedToStart = 3;
-
-        public const double gConstant = -9.81;
-
-        #endregion
-
-        #region Static members
-
-        /// <summary>
-        /// Status of listener
-        /// </summary>
-        private static int currentStatus;
-
-        /// <summary>
-        /// Accelerometer
-        /// </summary>
-        private static Microsoft.Devices.Sensors.Accelerometer accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
-
-        private static DateTime StartOfEpoch = new DateTime(1970, 1, 1, 0, 0, 0);
-
-        #endregion
-
-        /// <summary>
-        /// Sensor listener event
-        /// </summary>        
-        private void accelerometer_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
-        {
-            this.SetStatus(Running);
-
-            PluginResult result = new PluginResult(PluginResult.Status.OK, GetCurrentAccelerationFormatted());
-            result.KeepCallback = true;
-            DispatchCommandResult(result);
-        }
-
-        /// <summary>
-        /// Starts listening for acceleration sensor
-        /// </summary>
-        /// <returns>status of listener</returns>
-        public void start(string options)
-        {
-            if ((currentStatus == Running) || (currentStatus == Starting))
-            {
-                return;
-            }
-            try
-            {
-                lock (accelerometer)
-                {
-                    accelerometer.CurrentValueChanged += accelerometer_CurrentValueChanged;
-                    accelerometer.Start();
-                    this.SetStatus(Starting);
-                }
-
-                long timeout = 2000;
-                while ((currentStatus == Starting) && (timeout > 0))
-                {
-                    timeout = timeout - 100;
-                    Thread.Sleep(100);
-                }
-
-                if (currentStatus != Running)
-                {
-                    this.SetStatus(ErrorFailedToStart);
-                    DispatchCommandResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, ErrorFailedToStart));
-                    return;
-                }
-            }
-            catch (Exception)
-            {
-                this.SetStatus(ErrorFailedToStart);
-                DispatchCommandResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, ErrorFailedToStart));
-                return;
-            }
-            PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
-            result.KeepCallback = true;
-            DispatchCommandResult(result);
-        }
-
-        public void stop(string options)
-        {
-            if (currentStatus == Running)
-            {
-                lock (accelerometer)
-                {
-                    accelerometer.CurrentValueChanged -= accelerometer_CurrentValueChanged;
-                    accelerometer.Stop();
-                    this.SetStatus(Stopped);
-                }
-            }
-            DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
-        }
-
-        /// <summary>
-        /// Formats current coordinates into JSON format
-        /// </summary>
-        /// <returns>Coordinates in JSON format</returns>
-        private string GetCurrentAccelerationFormatted()
-        {
-            // convert to unix timestamp
-            // long timestamp = ((accelerometer.CurrentValue.Timestamp.DateTime - StartOfEpoch).Ticks) / 10000;
-            // Note: Removed timestamp, to let the JS side create it using (new Date().getTime()) -jm
-            // this resolves an issue with inconsistencies between JS dates and Native DateTime 
-            string resultCoordinates = String.Format("\"x\":{0},\"y\":{1},\"z\":{2}",
-                            (accelerometer.CurrentValue.Acceleration.X * gConstant).ToString("0.00000", CultureInfo.InvariantCulture),
-                            (accelerometer.CurrentValue.Acceleration.Y * gConstant).ToString("0.00000", CultureInfo.InvariantCulture),
-                            (accelerometer.CurrentValue.Acceleration.Z * gConstant).ToString("0.00000", CultureInfo.InvariantCulture));
-            return  "{" + resultCoordinates + "}";
-        }
-
-        /// <summary>
-        /// Sets current status
-        /// </summary>
-        /// <param name="status">current status</param>
-        private void SetStatus(int status)
-        {
-            currentStatus = status;
-        }
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/b4bacc04/templates/standalone/config.xml
----------------------------------------------------------------------
diff --git a/templates/standalone/config.xml b/templates/standalone/config.xml
index 170f9fe..93ac43a 100644
--- a/templates/standalone/config.xml
+++ b/templates/standalone/config.xml
@@ -25,7 +25,6 @@
     <plugin name="Device"/>
     <plugin name="Logger"/>
     <plugin name="Compass"/>
-    <plugin name="Accelerometer"/>
     <plugin name="Camera"/>
     <plugin name="NetworkStatus"/>
     <plugin name="Contacts"/>

http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/b4bacc04/templates/standalone/cordovalib/NativeExecution.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/NativeExecution.cs b/templates/standalone/cordovalib/NativeExecution.cs
index af6b207..d928f4f 100644
--- a/templates/standalone/cordovalib/NativeExecution.cs
+++ b/templates/standalone/cordovalib/NativeExecution.cs
@@ -133,7 +133,7 @@ namespace WPCordovaClassLib.Cordova
                     }
                 };
 
-                if ((bc is File) || (bc is Accelerometer))
+                if ((bc is File))
                 {
                     // Due to some issues with the IsolatedStorage in current version of WP8 SDK we have to run all File Api commands synchronously.
                     // TODO: test this in WP8 RTM