-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Flashlight.shared.cs
66 lines (57 loc) · 2.22 KB
/
Flashlight.shared.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#nullable enable
using System.Threading.Tasks;
namespace Microsoft.Maui.Devices
{
/// <summary>
/// The Flashlight API has the ability to turn on or off the device's camera flash to turn it into a flashlight.
/// </summary>
public interface IFlashlight
{
/// <summary>
/// Checks if the flashlight is available and can be turned on or off.
/// </summary>
/// <returns><see langword="true"/> when the flashlight is available, or <see langword="false"/> when not</returns>
Task<bool> IsSupportedAsync();
/// <summary>
/// Turns the camera flashlight on.
/// </summary>
/// <returns>A <see cref="Task"/> object with the current status of the asynchronous operation.</returns>
Task TurnOnAsync();
/// <summary>
/// Turns the camera flashlight off.
/// </summary>
/// <returns>A <see cref="Task"/> object with the current status of the asynchronous operation.</returns>
Task TurnOffAsync();
}
/// <summary>
/// The Flashlight API has the ability to turn on or off the device's camera flash to turn it into a flashlight.
/// </summary>
public static partial class Flashlight
{
/// <summary>
/// Checks if the flashlight is available and can be turned on or off.
/// </summary>
/// <returns><see langword="true"/> when the flashlight is available, or <see langword="false"/> when not</returns>
public static Task<bool> IsSupportedAsync() => Default.IsSupportedAsync();
/// <summary>
/// Turns the camera flashlight on.
/// </summary>
/// <returns>A <see cref="Task"/> object with the current status of the asynchronous operation.</returns>
public static Task TurnOnAsync() =>
Default.TurnOnAsync();
/// <summary>
/// Turns the camera flashlight off.
/// </summary>
/// <returns>A <see cref="Task"/> object with the current status of the asynchronous operation.</returns>
public static Task TurnOffAsync() =>
Default.TurnOffAsync();
static IFlashlight? defaultImplementation;
/// <summary>
/// Provides the default implementation for static usage of this API.
/// </summary>
public static IFlashlight Default =>
defaultImplementation ??= new FlashlightImplementation();
internal static void SetDefault(IFlashlight? implementation) =>
defaultImplementation = implementation;
}
}