{"id":19099485,"url":"https://github.com/TheCodeTraveler/AccelerometerApp","last_synced_at":"2025-04-18T17:31:26.050Z","repository":{"id":34664427,"uuid":"142353858","full_name":"brminnick/AccelerometerApp","owner":"brminnick","description":"An iOS and Android app that tracks the device's accelerometer using Xamarin.Essentials; created using Xamarin.Forms and Syncfusion","archived":false,"fork":false,"pushed_at":"2023-12-18T13:22:10.000Z","size":1000,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-01T14:08:47.639Z","etag":null,"topics":["syncfusion","xamarin","xamarin-android","xamarin-essentials","xamarin-forms","xamarin-ios"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brminnick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["brminnick"]}},"created_at":"2018-07-25T21:04:43.000Z","updated_at":"2024-02-12T20:59:56.000Z","dependencies_parsed_at":"2023-11-10T21:23:52.996Z","dependency_job_id":"15b8ad20-495d-4b03-9f82-6a4219a1e2a7","html_url":"https://github.com/brminnick/AccelerometerApp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brminnick%2FAccelerometerApp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brminnick%2FAccelerometerApp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brminnick%2FAccelerometerApp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brminnick%2FAccelerometerApp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brminnick","download_url":"https://codeload.github.com/brminnick/AccelerometerApp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783108,"owners_count":17201903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["syncfusion","xamarin","xamarin-android","xamarin-essentials","xamarin-forms","xamarin-ios"],"created_at":"2024-11-09T03:50:18.721Z","updated_at":"2025-04-18T17:31:20.661Z","avatar_url":"https://github.com/brminnick.png","language":"C#","funding_links":["https://github.com/sponsors/brminnick"],"categories":[],"sub_categories":[],"readme":"# Accelerometer App\n\nThanks to [Xamarin.Essentials](https://docs.microsoft.com/xamarin/essentials?WT.mc_id=mobile-0000-bramin) and [SyncFusion's Circular Gauge](https://www.syncfusion.com/products/xamarin/circular-gauge) control, creating a mobile app that monitors the accelerometer data has never been easier.\n\nLet's take a look at how to implement this control in a Xamarin.Forms app.\n\n![Accelerometer App](https://user-images.githubusercontent.com/13558917/43228875-b2c516ee-9017-11e8-9350-1016d7451a8f.gif)\n\n## Walkthrough\n\n### 1. Install NuGet Packages\n\n1. Install the [Syncfusion.Xamarin.SfGauge NuGet Package](https://www.nuget.org/packages/Syncfusion.Xamarin.SfGauge) into each project, this includes the Xamarin.iOS, Xamarin.Android, and the .NET Standard Project (if one is being used).\n2. Install the [Xamarin.Essentials NuGet Package](https://www.nuget.org/packages/Xamarin.Essentials) into each project, this includes the Xamarin.iOS, Xamarin.Android, and the .NET Standard Project (if one is being used).\n\n### 2. Initialize SyncFusion on iOS\n\nTo utilize the SyncFusion Circular Gauge, we first need to initialize it in `AppDelegate.FinishedLaunching`:\n\n```csharp\npublic partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate\n{\n    ...\n\n    public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)\n    {\n        ...\n\n        Syncfusion.SfGauge.XForms.iOS.SfGaugeRenderer.Init();\n        Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(\"Your SyncFusion License Key\");\n\n        ...\n    }\n}\n```\n\n### 3. Initialize SyncFusion on Android\n\nTo utilize the SyncFusion Circular Gauge, we first need to initialize it `MainActivity.OnCreate`:\n\n```csharp\npublic class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity\n{\n    ...\n\n    protected override void OnCreate(Bundle savedInstanceState)\n    {\n        ...\n\n        Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(\"Your SyncFusion License Key\");\n\n        ...\n    }\n}\n```\n\n### 4. Reference Mono.Android.Export\n\n1. In the Solution Explorer, in the Android project, right-click on **References**\n2. In the **References** menu, select **Edit References**\n\n![Edit References](https://user-images.githubusercontent.com/13558917/43227940-0804184c-9015-11e8-8225-0b04b5507219.png)\n\n3. In the **Edit References** window, select the **Packages** tab\n4. In the **Packages** tab, locate `Mono.Android.Export`\n5. In the **Packages** tab, ensure `Mono.Android.Export` is checked\n6. In the **Edit References** window, click **OK**\n\n![Refernce Mono.Android.Export](https://user-images.githubusercontent.com/13558917/43227949-0c77ed0e-9015-11e8-8ff5-26d9f767e095.png)\n\n### 5. Implement SfCircularGauge in Xamarin.Forms\n\nThis app requires 3 instances of the Circular Gauge Control in our app, so let's start by creating an implementation of `SfCircularGauge`\n\n```csharp\nusing System.Collections.ObjectModel;\nusing Syncfusion.SfGauge.XForms;\nusing Xamarin.Forms;\n\nnamespace AccelerometerApp\n{\n    class CircularGaugeView : SfCircularGauge\n    {\n        public CircularGaugeView(string headerText, double startValue, double endValue)\n        {\n            Pointer = new NeedlePointer { AnimationDuration = 0.5 };\n\n            var header = new Header\n            {\n                Text = headerText,\n                ForegroundColor = Color.Gray\n            };\n\n            var circularGaugeScale = new Scale\n            {\n                Interval = (endValue - startValue) / 10,\n                StartValue = startValue,\n                EndValue = endValue,\n                ShowTicks = true,\n                ShowLabels = true,\n                Pointers = { Pointer },\n                MinorTicksPerInterval = 4,\n            };\n\n            Scales = new ObservableCollection\u003cScale\u003e { circularGaugeScale };\n            Headers = new ObservableCollection\u003cHeader\u003e { header };\n        }\n\n        public NeedlePointer Pointer { get; }\n    }\n}\n```\n\n### 6. Create Accelerometer Page\n\nIn the Xamarin.Forms project, create a new class, `AccelerometerPage.cs`:\n\n```csharp\nusing System.Linq;\nusing Xamarin.CommunityToolkit.Markup;\nusing Xamarin.Essentials;\nusing Xamarin.Forms;\nusing Xamarin.Forms.PlatformConfiguration.iOSSpecific;\nusing static Xamarin.CommunityToolkit.Markup.GridRowsColumns;\n\nnamespace AccelerometerApp\n{\n    class AccelerometerPage : ContentPage\n    {\n        public AccelerometerPage()\n        {\n            InitializeAccelerometer();\n\n            Content = new Grid\n            {\n                Margin = new Thickness(0, 20),\n\n                RowDefinitions = Rows.Define(\n                    (Row.xGauge, Star),\n                    (Row.yGauge, Star),\n                    (Row.zGauge, Star)),\n\n                ColumnDefinitions = Columns.Define(Star),\n\n                Children =\n                {\n                    new CircularGaugeView(\"X-Axis\", -1, 1).Row(Row.xGauge),\n                    new CircularGaugeView(\"Y-Axis\", -1, 1).Row(Row.yGauge),\n                    new CircularGaugeView(\"Z-Axis\", -10, 10).Row(Row.zGauge)\n                }\n            };\n\n            On\u003cXamarin.Forms.PlatformConfiguration.iOS\u003e().SetUseSafeArea(true);\n        }\n\n        enum Row { xGauge, yGauge, zGauge }\n\n        void InitializeAccelerometer()\n        {\n            try\n            {\n                Accelerometer.Start(SensorSpeed.Default);\n                Accelerometer.ReadingChanged += HandleAccelerometerReadingChanged;\n            }\n            catch (FeatureNotSupportedException)\n            {\n                System.Diagnostics.Debug.WriteLine(\"Accelerometer Unavailable\");\n            }\n        }\n\n        void HandleAccelerometerReadingChanged(object sender, AccelerometerChangedEventArgs e)\n        {\n            var grid = (Grid)Content;\n\n            var xCircularGauge = (CircularGaugeView)grid.Children.First(x =\u003e Grid.GetRow(x) is (int)Row.xGauge);\n            var yCircularGauge = (CircularGaugeView)grid.Children.First(x =\u003e Grid.GetRow(x) is (int)Row.yGauge);\n            var zCircularGauge = (CircularGaugeView)grid.Children.First(x =\u003e Grid.GetRow(x) is (int)Row.zGauge);\n\n            MainThread.BeginInvokeOnMainThread(() =\u003e\n            {\n                xCircularGauge.Pointer.Value = e.Reading.Acceleration.X;\n                yCircularGauge.Pointer.Value = e.Reading.Acceleration.Y;\n                zCircularGauge.Pointer.Value = e.Reading.Acceleration.Z;\n            });\n        }\n    }\n}\n```\n\n### 7. Set AccelerometerPage as the MainPage\n\nIn `App.cs`, ensure that `MainPage = new AccelerometerPage();`:\n\n```csharp\nusing Xamarin.Forms;\n\nnamespace AccelerometerApp\n{\n    public class App : Application\n    {\n        public App() =\u003e MainPage = new AccelerometerPage();\n    }\n}\n```\n\n### 8. Launch the app on an iOS or Android Device\n\n## About The Author\n\nBrandon Minnick is a Developer Advocate at Microsoft specializing in Xamarin and Azure. As a Developer Advocate, Brandon works closely with the mobile app community, helping them create 5-star apps and provide their feedback to the Microsoft product teams to help improve our tools and empower every person and every organization on the planet to achieve more.\n\n[@TheCodeTraveler](https://twitter.com/intent/user?user_id=3418408341)\n\n## Resources\n\n- [Xamarin](https://visualstudio.microsoft.com/xamarin?WT.mc_id=mobile-0000-bramin)\n- [Xamarin.Essentials](https://docs.microsoft.com/xamarin/essentials/?WT.mc_id=mobile-0000-bramin)\n- [Azure IoT Central](https://azure.microsoft.com/services/iot-central/?WT.mc_id=mobile-0000-bramin)\n- [SyncFusion's Circular Gauge](https://www.syncfusion.com/products/xamarin/circular-gauge)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTheCodeTraveler%2FAccelerometerApp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTheCodeTraveler%2FAccelerometerApp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTheCodeTraveler%2FAccelerometerApp/lists"}