|
1 | | -# Open Source Project Template |
| 1 | +# Device Core |
2 | 2 |
|
3 | | -This repository contains a template to seed a repository for an Open Source |
4 | | -project. |
| 3 | +{Project tag line} |
5 | 4 |
|
6 | | -## How to use this template |
| 5 | +{Small description of the purpose of the project} |
7 | 6 |
|
8 | | -1. Check out this repository |
9 | | -2. Delete the `.git` folder |
10 | | -3. Git init this repository and start working on your project! |
11 | | -4. Prior to submitting your request for publication, make sure to review the |
12 | | - [Open Source guidelines for publications](https://nventive.visualstudio.com/Internal/_wiki/wikis/Internal_wiki?wikiVersion=GBwikiMaster&pagePath=%2FOpen%20Source%2FPublishing&pageId=7120). |
| 7 | +[](LICENSE) |
13 | 8 |
|
14 | | -## Features (to keep as-is, configure or remove) |
15 | | -- [Mergify](https://mergify.io/) is configured. You can edit or remove [.mergify.yml](/.mergify.yml). |
| 9 | +## Getting Started |
16 | 10 |
|
17 | | -The following is the template for the final README.md file: |
| 11 | +1. Add the `DeviceCore.Uno.WinUI` NuGet package to your projects (Windows, Android and iOS). |
| 12 | + > 💡 If you need to implement more platforms or create custom implementations, you can use the `DeviceCore.Abstractions` NuGet package. |
18 | 13 |
|
19 | | ---- |
| 14 | +1. Create an instance of any service. We'll cover dependency injection in details later on in this documentation. |
20 | 15 |
|
21 | | -# Project Title |
| 16 | + ```cs |
| 17 | + using DeviceCore; |
22 | 18 |
|
23 | | -{Project tag line} |
| 19 | + var flashlightService = new FlashlightService(); |
| 20 | + ``` |
24 | 21 |
|
25 | | -{Small description of the purpose of the project} |
| 22 | +1. Use the service. |
26 | 23 |
|
27 | | -[](LICENSE) |
| 24 | + ```cs |
| 25 | + flashlightService.Brightness = 0.5f; |
| 26 | + flashlightService.Toggle(); |
| 27 | + ``` |
28 | 28 |
|
29 | | -## Getting Started |
| 29 | +## Next Step |
| 30 | + |
| 31 | +### Using Dependency Injection |
| 32 | + |
| 33 | +Here is a simple code that does dependency injection using `Microsoft.Extensions.DependencyInjection` and `Microsoft.Extensions.Hosting`. |
30 | 34 |
|
31 | | -{Instructions to quickly get started using the project: pre-requisites, packages |
32 | | -to install, sample code, etc.} |
| 35 | +```cs |
| 36 | +using DeviceCore; |
| 37 | +using Microsoft.Extensions.DependencyInjection; |
| 38 | +using Microsoft.Extensions.Hosting; |
| 39 | + |
| 40 | +var host = new HostBuilder() |
| 41 | + .ConfigureServices(serviceCollection => serviceCollection |
| 42 | + .AddSingleton(_ => DispatcherQueue.GetForCurrentThread()) |
| 43 | + .AddSingleton<IAccelerometerService, AccelerometerService>() |
| 44 | + .AddSingleton<IAmbientLightProvider, AmbientLightProvider>() |
| 45 | + .AddSingleton<IBatteryInformationProvider, BatteryInformationProvider>() |
| 46 | + .AddSingleton<IFlashlightService, FlashlightService>() |
| 47 | + .AddSingleton<IScreenWakeLockService, ScreenWakeLockService>() |
| 48 | + ) |
| 49 | + .Build(); |
| 50 | +``` |
33 | 51 |
|
34 | 52 | ## Features |
35 | 53 |
|
36 | | -{More details/listing of features of the project} |
| 54 | +Now that everything is setup, Let's see what else we can do! |
| 55 | + |
| 56 | +### Accelerometer |
| 57 | + |
| 58 | +The `AccelerometerService` provides access to the device's accelerometer sensor, allowing you to read acceleration data in three dimensions (X, Y, Z). |
| 59 | + |
| 60 | +> 💡 The `ObserveAcceleration` and `ObserveDeviceShaken` methods and will return an observable yielding `null` on devices that do not support `Accelerometer` or devices that do not have such a sensor. |
| 61 | +
|
| 62 | +> 💡 Unsubscribe from the `ObserveAcceleration` and `ObserveDeviceShaken` observables when you no longer need the readings to avoid unnecessary battery consumption. |
| 63 | +
|
| 64 | +> 💡 On iOS features built-in shake gesture recognition. Android use a common implementation to approximate shake detection. You can implement custom shake detection using the `ObserveAcceleration` method if needed. |
| 65 | +
|
| 66 | +> 💡 On Android, if both `ObserveAcceleration` and `ObserveDeviceShaken` observables are used and `ReportInterval` is set high, they may be yielding reading more often than requested due to multiple subscribers. |
| 67 | +
|
| 68 | +### Light Sensor |
| 69 | + |
| 70 | +The `AmbientLightProvider` provides access to the device's ambient light sensor, allowing you to read the current light level. |
| 71 | + |
| 72 | +> 💡 The `ObserveCurrentReading` method and will return an observable yielding `null` on devices that do not support `Accelerometer`, on devices that do not have such a sensor, or on iOS. |
| 73 | +
|
| 74 | +> 💡 Unsubscribe from the `ObserveCurrentReading` observable when you no longer need the readings to avoid unnecessary battery consumption. |
| 75 | +
|
| 76 | +### Battery Information |
| 77 | + |
| 78 | +The `BatteryInformationProvider` provides access to the device's battery information, allowing you to read the current battery level and status. |
| 79 | + |
| 80 | +> 💡 On Android, the `GetAndObserveRemainingChargePercent` observable is not updated continuously as there is no API that provides such events. It is triggered by system `Low` and `Ok` battery state broadcasts only. The `RemainingChargePercent` property always returns the up-to-date value. For continuous monitoring you can set up periodic polling. |
| 81 | +
|
| 82 | +#### Android |
| 83 | + |
| 84 | +To use the battery information on Android, ensure you have the correct permissions in your `AndroidManifest.xml`. |
| 85 | + |
| 86 | +```xml |
| 87 | +<uses-permission android:name="android.permission.BATTERY_STATS" /> |
| 88 | +``` |
| 89 | + |
| 90 | +### Flashlight |
| 91 | + |
| 92 | +The `FlashlightService` allows you to turn the phone's camera flashlight on and off. |
| 93 | + |
| 94 | +> 💡 On Android, flashlight brightness cannot be controlled, hence any non-zero brightness level results in the full brightness of the flashlight. |
| 95 | +
|
| 96 | +> 💡 On iOS, in case the device supports the torch, brightness level is fully supported. In case the device has only flash, any non-zero brightness level will result in the full brightness of the flashlight. |
| 97 | +
|
| 98 | +#### Android |
| 99 | + |
| 100 | +To use the flashlight on Android, ensure you have the correct permissions in your `AndroidManifest.xml`. |
| 101 | + |
| 102 | +```xml |
| 103 | +<uses-permission android:name="android.permission.FLASHLIGHT" /> |
| 104 | +<uses-permission android:name="android.permission.CAMERA" /> |
| 105 | +``` |
| 106 | + |
| 107 | +### Keeping Screen On |
| 108 | + |
| 109 | +To enables an application to request to keep the device's screen on, use the `ScreenWakeLockService`. |
| 110 | + |
| 111 | +## Acknowledgements |
| 112 | + |
| 113 | +Take a look at [Uno.WinRT](https://platform.uno/docs/articles/features/using-winrt.html) that we use for the mobile platforms implementation. |
37 | 114 |
|
38 | 115 | ## Breaking Changes |
39 | 116 |
|
|
0 commit comments