Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LuckyDucko/BrightnessService
React to brightness changes in realtime
https://github.com/LuckyDucko/BrightnessService
android brightness ios plugin xamarin
Last synced: 30 days ago
JSON representation
React to brightness changes in realtime
- Host: GitHub
- URL: https://github.com/LuckyDucko/BrightnessService
- Owner: LuckyDucko
- Archived: true
- Created: 2020-04-06T08:23:20.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-17T19:10:10.000Z (almost 3 years ago)
- Last Synced: 2024-11-05T18:55:42.297Z (about 1 month ago)
- Topics: android, brightness, ios, plugin, xamarin
- Language: C#
- Homepage:
- Size: 428 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-xamarin-forms - BrightnessService ★6 - time. (Plugins)
README
BrightnessService
React to brightness changes in real-time
## Table of Contents
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/1d6fc153e83044d39daf23b3383ab8e2)](https://www.codacy.com/manual/LuckyDucko/BrightnessService?utm_source=github.com&utm_medium=referral&utm_content=LuckyDucko/BrightnessService&utm_campaign=Badge_Grade)
[![nuget](https://img.shields.io/nuget/v/Plugin.BrightnessService.svg)](https://www.nuget.org/packages/Plugin.BrightnessService)* [Getting Started](#getting-started)
* [Installation](#installation)
* [Usage](#usage)
* [Contributing](#contributing)
* [License](#license)
* [Contact](#contact)
* [Acknowledgements](#acknowledgements)## 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
![Gif Example](https://j.gifs.com/nx4PqD.gif)
## 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
```csharp
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 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 use `Attach`, `Attached` and `OverWriteFunctions` 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 use `OverwriteRefreshResolution` 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 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 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](https://github.com/LuckyDucko),
or reach me on the [Xamarin Slack](https://xamarinchat.herokuapp.com/),
or on my [E-mail]([email protected])Project Link: [BrightnessService](https://github.com/LuckyDucko/BrightnessService)