Search in sources :

Example 41 with IPowerManager

use of android.os.IPowerManager in project android_packages_apps_Settings by crdroidandroid.

the class SettingsAppWidgetProvider method toggleBrightness.

/**
 * Increases or decreases the brightness.
 *
 * @param context
 */
private void toggleBrightness(Context context) {
    try {
        IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
        if (power != null) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            ContentResolver cr = context.getContentResolver();
            int brightness = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS);
            int brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            // Only get brightness setting if available
            if (context.getResources().getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
                brightnessMode = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS_MODE);
            }
            // Technically, not a toggle...
            if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
                brightness = pm.getMinimumScreenBrightnessSetting();
                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            } else if (brightness < pm.getDefaultScreenBrightnessSetting()) {
                brightness = pm.getDefaultScreenBrightnessSetting();
            } else if (brightness < pm.getMaximumScreenBrightnessSetting()) {
                brightness = pm.getMaximumScreenBrightnessSetting();
            } else {
                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
                brightness = pm.getMinimumScreenBrightnessSetting();
            }
            if (context.getResources().getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
                // Set screen brightness mode (automatic or manual)
                Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, brightnessMode);
            } else {
                // Make sure we set the brightness if automatic mode isn't available
                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            }
            if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
                power.setTemporaryScreenBrightnessSettingOverride(brightness);
                Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, brightness);
            }
        }
    } catch (RemoteException e) {
        Log.d(TAG, "toggleBrightness: " + e);
    } catch (Settings.SettingNotFoundException e) {
        Log.d(TAG, "toggleBrightness: " + e);
    }
}
Also used : PowerManager(android.os.PowerManager) IPowerManager(android.os.IPowerManager) IPowerManager(android.os.IPowerManager) RemoteException(android.os.RemoteException) Settings(android.provider.Settings) ContentResolver(android.content.ContentResolver)

Example 42 with IPowerManager

use of android.os.IPowerManager in project android_packages_apps_Settings by SudaMod.

the class SettingsAppWidgetProvider method toggleBrightness.

/**
 * Increases or decreases the brightness.
 *
 * @param context
 */
private void toggleBrightness(Context context) {
    try {
        IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
        if (power != null) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            ContentResolver cr = context.getContentResolver();
            int brightness = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS);
            int brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            // Only get brightness setting if available
            if (context.getResources().getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
                brightnessMode = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS_MODE);
            }
            // Technically, not a toggle...
            if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
                brightness = pm.getMinimumScreenBrightnessSetting();
                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            } else if (brightness < pm.getDefaultScreenBrightnessSetting()) {
                brightness = pm.getDefaultScreenBrightnessSetting();
            } else if (brightness < pm.getMaximumScreenBrightnessSetting()) {
                brightness = pm.getMaximumScreenBrightnessSetting();
            } else {
                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
                brightness = pm.getMinimumScreenBrightnessSetting();
            }
            if (context.getResources().getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
                // Set screen brightness mode (automatic or manual)
                Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, brightnessMode);
            } else {
                // Make sure we set the brightness if automatic mode isn't available
                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            }
            if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
                power.setTemporaryScreenBrightnessSettingOverride(brightness);
                Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, brightness);
            }
        }
    } catch (RemoteException e) {
        Log.d(TAG, "toggleBrightness: " + e);
    } catch (Settings.SettingNotFoundException e) {
        Log.d(TAG, "toggleBrightness: " + e);
    }
}
Also used : PowerManager(android.os.PowerManager) IPowerManager(android.os.IPowerManager) IPowerManager(android.os.IPowerManager) RemoteException(android.os.RemoteException) Settings(android.provider.Settings) ContentResolver(android.content.ContentResolver)

Example 43 with IPowerManager

use of android.os.IPowerManager in project platform_packages_apps_Settings by BlissRoms.

the class SettingsAppWidgetProvider method toggleBrightness.

/**
 * Increases or decreases the brightness.
 *
 * @param context
 */
private void toggleBrightness(Context context) {
    try {
        IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
        if (power != null) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            ContentResolver cr = context.getContentResolver();
            int brightness = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS);
            int brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            // Only get brightness setting if available
            if (context.getResources().getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
                brightnessMode = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS_MODE);
            }
            // Technically, not a toggle...
            if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
                brightness = pm.getMinimumScreenBrightnessSetting();
                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            } else if (brightness < pm.getDefaultScreenBrightnessSetting()) {
                brightness = pm.getDefaultScreenBrightnessSetting();
            } else if (brightness < pm.getMaximumScreenBrightnessSetting()) {
                brightness = pm.getMaximumScreenBrightnessSetting();
            } else {
                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
                brightness = pm.getMinimumScreenBrightnessSetting();
            }
            if (context.getResources().getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
                // Set screen brightness mode (automatic or manual)
                Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, brightnessMode);
            } else {
                // Make sure we set the brightness if automatic mode isn't available
                brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            }
            if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
                power.setTemporaryScreenBrightnessSettingOverride(brightness);
                Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, brightness);
            }
        }
    } catch (RemoteException e) {
        Log.d(TAG, "toggleBrightness: " + e);
    } catch (Settings.SettingNotFoundException e) {
        Log.d(TAG, "toggleBrightness: " + e);
    }
}
Also used : PowerManager(android.os.PowerManager) IPowerManager(android.os.IPowerManager) IPowerManager(android.os.IPowerManager) RemoteException(android.os.RemoteException) Settings(android.provider.Settings) ContentResolver(android.content.ContentResolver)

Aggregations

IPowerManager (android.os.IPowerManager)43 RemoteException (android.os.RemoteException)41 ContentResolver (android.content.ContentResolver)8 PowerManager (android.os.PowerManager)7 Settings (android.provider.Settings)7 Intent (android.content.Intent)6 Point (android.graphics.Point)3 ShutdownThread (com.android.server.power.ShutdownThread)1