1
0
mirror of https://github.com/danog/termux-api.git synced 2024-12-14 02:17:25 +01:00
termux-api/app/src/main/java/com/termux/api/BrightnessAPI.java

30 lines
1.1 KiB
Java
Raw Normal View History

2018-06-14 23:41:50 +02:00
package com.termux.api;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import com.termux.api.util.ResultReturner;
public class BrightnessAPI {
public static void onReceive(final TermuxApiReceiver receiver, final Context context, final Intent intent) {
final ContentResolver contentResolver = context.getContentResolver();
2019-01-25 01:08:40 +01:00
if (intent.hasExtra("auto")) {
boolean auto = intent.getBooleanExtra("auto", false);
Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, auto?Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC:Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
}
2018-06-14 23:41:50 +02:00
int brightness = intent.getIntExtra("brightness", 0);
if (brightness <= 0) {
brightness = 0;
} else if (brightness >= 255) {
brightness = 255;
}
Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS, brightness);
ResultReturner.noteDone(receiver, intent);
}
}