use of android.os.IPowerManager in project android_frameworks_base by crdroidandroid.
the class MetaKeyKeyListener method adjustMetaAfterKeypress.
/**
* Call this method after you handle a keypress so that the meta
* state will be reset to unshifted (if it is not still down)
* or primed to be reset to unshifted (once it is released).
*/
public static void adjustMetaAfterKeypress(Spannable content) {
adjust(content, CAP);
adjust(content, ALT);
adjust(content, SYM);
try {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
if (getMetaState(content, META_SHIFT_ON) <= 0)
power.setKeyboardLight(false, 1);
if (getMetaState(content, META_ALT_ON) <= 0)
power.setKeyboardLight(false, 2);
} catch (RemoteException doe) {
}
}
use of android.os.IPowerManager in project android_frameworks_base by crdroidandroid.
the class MetaKeyKeyListener method onKeyDown.
/**
* Handles presses of the meta keys.
*/
public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
press(content, CAP);
try {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
int state = content.getSpanFlags(CAP);
if (state == PRESSED || state == LOCKED) {
power.setKeyboardLight(true, 1);
} else {
power.setKeyboardLight(false, 1);
}
} catch (RemoteException doe) {
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT || keyCode == KeyEvent.KEYCODE_NUM) {
press(content, ALT);
try {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
int state = content.getSpanFlags(ALT);
if (state == PRESSED || state == LOCKED) {
power.setKeyboardLight(true, 2);
} else {
power.setKeyboardLight(false, 2);
}
} catch (RemoteException doe) {
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_SYM) {
press(content, SYM);
return true;
}
// no super to call through to
return false;
}
use of android.os.IPowerManager in project android_frameworks_base by ResurrectionRemix.
the class BrightnessLimit method onClick.
public void onClick(View v) {
IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
if (power != null) {
try {
power.setTemporaryScreenBrightnessSettingOverride(0);
} catch (RemoteException darn) {
}
}
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0);
}
use of android.os.IPowerManager in project android_packages_apps_Settings by omnirom.
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);
}
}
use of android.os.IPowerManager in project PhoneProfiles by henrichg.
the class CmdGoToSleep method run.
private static boolean run() {
try {
IPowerManager adapter = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
adapter.goToSleep(SystemClock.uptimeMillis(), 0, 0);
return true;
} catch (Throwable e) {
return false;
}
}
Aggregations