i want to decrease brightness slowly and gradually and user does not fell the brightness change but problem is every time lux value changed and when i decresee value and use thread to sleep it app hanged. is there any other way to handle lux value and also get Accuracy in brightness.... here is the code....
When eEXecuteEquation() method call b_v1(brightness value) updated....
suppose min=20 and max=70
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_LIGHT) {
mLux = (int) event.values[0];
String luxStr = String.valueOf(mLux);
pr_lux = mLux; //both are int
eEXecuteEquation();
tv.setText("Max: " + maxb + " Min: " + minb + " Lux: " + luxStr
+ " Brightness Value: " + b_v1 );
if (b_v1 > -1) {
if (b_v1 < minb) {
try {
setBrightnessLevel(minb);
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (b_v1 > maxb) {
try {
setBrightnessLevel(maxb);
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (b_v1 >= minb && b_v1 < maxb) {
try {
b2 = b_v1;
setBrightnessLevel(b_v1);
sendvalue=1;
while (b_v1 == b2) {
try {
setBrightnessLevel(b2--);
} catch (SettingNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
sendvalue=0;
//new LongOperation().execute("");
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
int temp_max;
private void setBrightnessLevel(int SysBackLightValue11)
throws SettingNotFoundException {
int brightnessMode = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE);
if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
Settings.System.putInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
}
Settings.System.putInt(this.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, SysBackLightValue11);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = (float) SysBackLightValue11 / 100;// 100 / 100.0f;
getWindow().setAttributes(lp);
}