1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

possible fix for button lights issue (hardware button lights were always enabled after FBReader closing)

This commit is contained in:
Nikolay Pultsin 2012-01-07 18:08:40 +00:00
parent 5455bbc804
commit 4b06a390c9

View file

@ -64,13 +64,14 @@ public abstract class ZLAndroidActivity extends Activity {
return (level >= 0) ? level : 50;
}
private void disableButtonLight() {
private void setButtonLight(boolean enabled) {
try {
final WindowManager.LayoutParams attrs = getWindow().getAttributes();
final Class<?> cls = attrs.getClass();
final Field fld = cls.getField("buttonBrightness");
if (fld != null && "float".equals(fld.getType().toString())) {
fld.setFloat(attrs, 0);
fld.setFloat(attrs, enabled ? -1.0f : 0.0f);
getWindow().setAttributes(attrs);
}
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
@ -86,9 +87,6 @@ public abstract class ZLAndroidActivity extends Activity {
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(this));
requestWindowFeature(Window.FEATURE_NO_TITLE);
if (getLibrary().DisableButtonLightsOption.getValue()) {
disableButtonLight();
}
setContentView(R.layout.main);
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
@ -160,6 +158,9 @@ public abstract class ZLAndroidActivity extends Activity {
} else {
setScreenBrightnessAuto();
}
if (getLibrary().DisableButtonLightsOption.getValue()) {
setButtonLight(false);
}
registerReceiver(myBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
@ -169,6 +170,9 @@ public abstract class ZLAndroidActivity extends Activity {
unregisterReceiver(myBatteryInfoReceiver);
ZLApplication.Instance().stopTimer();
switchWakeLock(false);
if (getLibrary().DisableButtonLightsOption.getValue()) {
setButtonLight(true);
}
ZLApplication.Instance().onWindowClosing();
super.onPause();
}