0

我想慢慢地逐渐降低亮度,用户不会降低亮度变化,但问题是每次勒克斯值改变时,当我降低值并使用线程休眠时,应用程序挂起。有没有其他方法可以处理勒克斯值并获得亮度精度......这是代码......

当 eEXecuteEquation() 方法调用 b_v1(brightness value) 更新时......

假设 min=20 和 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);
}
4

0 回答 0