Plugin.BrightnessService
0.0.3
dotnet add package Plugin.BrightnessService --version 0.0.3
NuGet\Install-Package Plugin.BrightnessService -Version 0.0.3
<PackageReference Include="Plugin.BrightnessService" Version="0.0.3" />
paket add Plugin.BrightnessService --version 0.0.3
#r "nuget: Plugin.BrightnessService, 0.0.3"
// Install Plugin.BrightnessService as a Cake Addin #addin nuget:?package=Plugin.BrightnessService&version=0.0.3 // Install Plugin.BrightnessService as a Cake Tool #tool nuget:?package=Plugin.BrightnessService&version=0.0.3
<br /> <p align="center"> <h1 align="center">BrightnessService</h3> <p align="center"> React to brightness changes in real-time <br /> </p> </p>
Table of Contents
About The Project
Brightness service aims to provide an interface where developers are able to create dynamic content based on the brightness of their app, allowing them to go far beyond a simple theme change.
It also includes an easy way for direct access to an android devices light sensor
Getting Started
Installation
Simply ensure that you have CrossBrightnessService.Current.Active = true;
with the package installed in both the Shared Platform and iOS/Android
Usage
To get the above effect, i used this code snippet
CrossBrightnessService.Current.Active = true;
CrossBrightnessService.Current.Attach(() =>
{
var LocalBackgroundColour = Color.Green;
LocalBackgroundColour = LocalBackgroundColour.AddLuminosity(CrossBrightnessService.Current.CheckBrightness());
LocalBackgroundColour = LocalBackgroundColour.WithLuminosity(CrossBrightnessService.Current.CheckBrightness());
LocalBackgroundColour = LocalBackgroundColour.WithHue(CrossBrightnessService.Current.CheckBrightness());
LocalBackgroundColour = LocalBackgroundColour.WithSaturation(CrossBrightnessService.Current.CheckBrightness());
BackgroundColour = LocalBackgroundColour;
});
Thats it! For a quick explainer on the details, read on
Plugin.BrightnessService allows access through the IBrightnessService
interface, which has the following members/functions available
public List<Action> TickActions { get; set; }
This is the TickActions that will be executed in parallel on a timed basis, with the timing depending on
MillisecondResolution
. All Functions are invoked on the main thread. While direct access through the setter is possible, it is recommended you useAttach
,Attached
andOverWriteFunctions
for changing its values
public double MillisecondResolution { get; set; }
This is the speed in which the timer will wait before executing
TickActions
in parallel. While direct access through the setter is possible, it is recommended you useOverwriteRefreshResolution
for changing its value
public bool Active { get; set; }
This determines if the timer is active or not.
public bool AndroidLightSensorDirect { get; set; }
This determines if Android will use the screenbrightness of the device (safe), or the direct readouts from the light sensor (be prepared for calibration difficulties.).
public event Action BrightnessResolveTick;
This is what is invoked by the timer. Feel free to attach other things to run on the exact same timing as the brightness service. However, this also serves for how the tickactions get executed. care recommended.
public double CheckBrightness();
This provides the brightness readout. if not using the Android direct light sensor, will be within 0-255
public bool BrightnessChanged();
Provides a more manual approach to checking brightness. First call will 'set' the last brightness each subsequent call will check against the last brightness recorded against the current light reading, if it is different, it will return true and update the last brightness to the current light reading
public List<Action> Attached();
Returns all functions attached and running on
TickActions
public void Attach(Action brightnessServiceFunction);
Attaches a new function ontop of
TickActions
, briefly stopping and restarting the timer when doing so.
public void OverwriteFunctions(List<Action> brightnessServiceFunctions);
Overwrites
TickFunctions
with the supplied functions, briefly stopping and restarting the timer when doing so.
public void OverwriteRefreshResolution(double millisecondResolution);
Overwrites the refresh resolution to the supplied values, briefly stopping and restarting the timer when doing so.
License
This project uses the MIT License
Contact
My Github, or reach me on the Xamarin Slack, or on my E-mail
Project Link: BrightnessService
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. monoandroid90 is compatible. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. xamarinios10 is compatible. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- No dependencies.
-
MonoAndroid 9.0
- Plugin.CurrentActivity (>= 2.1.0.4)
-
Xamarin.iOS 1.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added a check so that light sensor is only generated when it is called upon, preventing breaks on devices with no light sensor