cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject git commit: [CB-4114] remove dupe code
Date Mon, 08 Jul 2013 22:04:55 GMT
Updated Branches:
  refs/heads/master 65b5d574a -> 3f85d7bd6


[CB-4114] remove dupe code


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/commit/3f85d7bd
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/tree/3f85d7bd
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/diff/3f85d7bd

Branch: refs/heads/master
Commit: 3f85d7bd602c6843fdf0bcbf9743c117b5d65c30
Parents: 65b5d57
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Mon Jul 8 15:04:40 2013 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Mon Jul 8 15:04:40 2013 -0700

----------------------------------------------------------------------
 plugin.xml               |   4 +-
 src/wp/Accelerometer.cs  | 196 ++++++++++++++++++++++++++++++++++++++++++
 src/wp7/Accelerometer.cs | 196 ------------------------------------------
 src/wp8/Accelerometer.cs | 196 ------------------------------------------
 4 files changed, 198 insertions(+), 394 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/3f85d7bd/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 8ed0281..a987f0b 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -61,7 +61,7 @@
             <Capability Name="ID_CAP_SENSORS" />
         </config-file>
 
-        <source-file src="src/wp7/Accelerometer.cs" />
+        <source-file src="src/wp/Accelerometer.cs" />
     </platform>
 
     <!-- wp8 -->
@@ -76,7 +76,7 @@
             <Capability Name="ID_CAP_SENSORS" />
         </config-file>
 
-        <source-file src="src/wp8/Accelerometer.cs" />
+        <source-file src="src/wp/Accelerometer.cs" />
     </platform>
     
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/3f85d7bd/src/wp/Accelerometer.cs
----------------------------------------------------------------------
diff --git a/src/wp/Accelerometer.cs b/src/wp/Accelerometer.cs
new file mode 100644
index 0000000..cba911c
--- /dev/null
+++ b/src/wp/Accelerometer.cs
@@ -0,0 +1,196 @@
+/*  
+	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-plugin-device-motion/blob/3f85d7bd/src/wp7/Accelerometer.cs
----------------------------------------------------------------------
diff --git a/src/wp7/Accelerometer.cs b/src/wp7/Accelerometer.cs
deleted file mode 100644
index cba911c..0000000
--- a/src/wp7/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-plugin-device-motion/blob/3f85d7bd/src/wp8/Accelerometer.cs
----------------------------------------------------------------------
diff --git a/src/wp8/Accelerometer.cs b/src/wp8/Accelerometer.cs
deleted file mode 100644
index cba911c..0000000
--- a/src/wp8/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;
-        }
-    }
-}
-


Mime
View raw message