|
1 | 1 | # @nativescript/brightness
|
2 | 2 |
|
| 3 | +A plugin that get and set the device's brightness level. |
| 4 | + |
| 5 | +## Contents |
| 6 | +* [Installation](#installation) |
| 7 | +* [Required permissions for Android](#required-permissions-for-android) |
| 8 | +* [Use @nativescript/brightness](#use-nativescriptbrightness) |
| 9 | + * [Set the device brightness level](#set-the-device-brightness-level) |
| 10 | + * [Get the device brightness level](#get-the-device-brightness-level) |
| 11 | +* [API](#api) |
| 12 | + * [Brightness class](#brightness-class) |
| 13 | + * [BrightnessOptions interface](#brightnessoptions-interface) |
| 14 | +* [License](#license) |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
3 | 18 | ```cli
|
4 | 19 | npm install @nativescript/brightness
|
5 | 20 | ```
|
6 | 21 |
|
7 |
| -> **Note:** This plugin requires `<uses-permission android:name="android.permission.WRITE_SETTINGS"/>` to be added in the `AndroidManifest.xml`. |
| 22 | +## Required permissions for Android |
8 | 23 |
|
9 |
| -## Usage |
| 24 | +Add the following permission to the `App_Resources/src/main/AndroidManifest.xml` file: |
| 25 | + |
| 26 | +- `<uses-permission android:name="android.permission.WRITE_SETTINGS"/>` |
| 27 | + |
| 28 | +```xml |
| 29 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 30 | + package="es.amplya.app_inventario"> |
| 31 | + |
| 32 | + <uses-permission android:name="android.permission.WRITE_SETTINGS"/> |
| 33 | + |
| 34 | + <application android:name="com.tns.NativeScriptApplication"> |
| 35 | + ... |
10 | 36 |
|
11 |
| -To use the plugin, you should first import it. |
12 |
| -```typescript |
13 |
| -// TypeScript |
14 |
| -import { Brightness } from '@nativescript/brightness'; |
15 | 37 | ```
|
16 | 38 |
|
17 |
| -### Setting the device brightness level |
18 |
| -To set the brightness level of the device, call the `set()` method passing it the [BrightnessOptions](#brightnessoptions) object with the desired `intensity` value. |
| 39 | +## Use @nativescript/brightness |
| 40 | + |
| 41 | +### Set the device brightness level |
19 | 42 |
|
20 |
| -```js |
21 |
| -// TypeScript |
| 43 | +To set the device's brightness level, call the `set()` method on an instance of the [Brightness class](#brightness-class), passing it the [BrightnessOptions](#brightnessoptions) object with the desired `intensity` value. |
| 44 | + |
| 45 | +```typescript |
| 46 | + |
| 47 | +import { Brightness } from '@nativescript/brightness'; |
22 | 48 | const brightness = new Brightness();
|
23 | 49 |
|
24 | 50 | brightness.set({
|
25 | 51 | intensity: 25,
|
26 | 52 | });
|
27 | 53 | ```
|
28 | 54 |
|
29 |
| -The `intensity` value can range from `1` to `100`. |
| 55 | +### Get the device brightness level |
| 56 | + |
| 57 | +To get the device's brightness level, call the `get()` method on an instance of the [Brightness class](#brightness-class). |
30 | 58 |
|
31 |
| -### Getting the device brightness Level |
32 |
| -To get the device's brightness, call the `get()` method. |
33 | 59 | ```ts
|
34 | 60 | bightnessLevel : number = brightness.get()
|
35 | 61 | ```
|
36 | 62 |
|
37 | 63 | ## API
|
38 | 64 |
|
39 |
| -### Methods |
| 65 | +### Brightness class |
40 | 66 |
|
41 |
| -| Method | Description | |
42 |
| -| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | |
43 |
| -| `set(options: BrightnessOptions)` | Sets screen's brightness to the desired intensity | |
44 |
| -| `get()` | Returns current screen brightness value as a number between `0` and `100` | |
45 |
| -| `getNative() ` | returns current screen brightness value as returned from the native api: between` 0.0` and `1.0` for iOS and `0` and `255` for android | |
| 67 | +| Method | Returns | Description |
| 68 | +|:-------|:--------|:----------- |
| 69 | +| `set(options: BrightnessOptions)`| `void` | Sets screen's brightness level to the desired intensity | |
| 70 | +| `get()`| `number` | Returns current screen brightness value as a number between `0` and `100` | |
| 71 | +| `getNative() `| `number` | Returns current native screen brightness value. <br> iOS: a value between` 0.0` and `1.0`. <br> Android: `0` and `255` | |
46 | 72 |
|
47 |
| -### BrightnessOptions |
| 73 | +### BrightnessOptions interface |
48 | 74 |
|
49 | 75 | | Property | Default | Description |
|
50 | 76 | | --------- | ------- | --------------------------------------------------------------------------------- |
|
51 |
| -| intensity | 100 | defines the desired brightness value, which should be a number between 0 and 100. | |
| 77 | +| `intensity` | `100` | Defines the desired brightness value, which should be a number between `0` and `100`. | |
52 | 78 |
|
53 | 79 | ## License
|
54 | 80 |
|
|
0 commit comments