Search in sources :

Example 1 with BatteryManager

use of android.os.BatteryManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DarkThemeSlice method isAvailable.

@VisibleForTesting
boolean isAvailable(Context context) {
    // checking dark theme mode.
    if (isDarkThemeMode(context)) {
        return false;
    }
    // checking the current battery level
    final BatteryManager batteryManager = context.getSystemService(BatteryManager.class);
    final int level = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
    Log.d(TAG, "battery level=" + level);
    return level <= BATTERY_LEVEL_THRESHOLD;
}
Also used : BatteryManager(android.os.BatteryManager) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 2 with BatteryManager

use of android.os.BatteryManager in project android_packages_apps_Settings by omnirom.

the class DarkThemeSlice method isAvailable.

@VisibleForTesting
boolean isAvailable(Context context) {
    // check if dark theme mode is enabled or if dark theme scheduling is on.
    if (Utils.isNightMode(context) || isNightModeScheduled()) {
        return false;
    }
    // checking the current battery level
    final BatteryManager batteryManager = context.getSystemService(BatteryManager.class);
    final int level = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
    Log.d(TAG, "battery level = " + level);
    return level <= BATTERY_LEVEL_THRESHOLD;
}
Also used : BatteryManager(android.os.BatteryManager) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 3 with BatteryManager

use of android.os.BatteryManager in project Taskbar by farmerbb.

the class TaskbarController method getBatteryDrawable.

@TargetApi(Build.VERSION_CODES.M)
private Drawable getBatteryDrawable() {
    BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
    int batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
    if (batLevel == Integer.MIN_VALUE)
        return null;
    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = context.registerReceiver(null, ifilter);
    int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
    boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
    String batDrawable;
    if (batLevel < 10 && !isCharging)
        batDrawable = "alert";
    else if (batLevel < 25)
        batDrawable = "20";
    else if (batLevel < 40)
        batDrawable = "30";
    else if (batLevel < 55)
        batDrawable = "50";
    else if (batLevel < 70)
        batDrawable = "60";
    else if (batLevel < 85)
        batDrawable = "80";
    else if (batLevel < 95)
        batDrawable = "90";
    else
        batDrawable = "full";
    String charging;
    if (isCharging)
        charging = "charging_";
    else
        charging = "";
    String batRes = "tb_battery_" + charging + batDrawable;
    int id = getResourceIdFor(batRes);
    return getDrawableForSysTray(id);
}
Also used : IntentFilter(android.content.IntentFilter) BatteryManager(android.os.BatteryManager) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Aggregations

BatteryManager (android.os.BatteryManager)3 VisibleForTesting (androidx.annotation.VisibleForTesting)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Point (android.graphics.Point)1 RecognizerIntent (android.speech.RecognizerIntent)1