Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de94ee59 authored by Danny Baumann's avatar Danny Baumann
Browse files

Some post-merge cleanup for automatic brightness adjustment

- Remove some unused strings
- Use (device-dependant) minimum brightness level (as calculated by
  DisplayPowerController) as '0%' instead of the actual value 0.

Change-Id: I79123d2421c9ab35fa0f1808d82d785463e8fbaa
parent eb7a665c
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -5150,8 +5150,6 @@
    <string name="auto_brightness_brightness_format"><xliff:g id="percent">%s</xliff:g>%%</string>
    <string name="auto_brightness_adjust_button">Adjust</string>
    <string name="auto_brightness_reset_button">Reset</string>
    <string name="auto_brightness_remove_button">Remove</string>
    <string name="auto_brightness_add_line">Add line</string>
    <string name="auto_brightness_lux_dialog_title">Ambient brightness range</string>
    <string name="auto_brightness_split_dialog_title">Split brightness level</string>
    <string name="auto_brightness_start_lux">Range start (lux)</string>
+26 −9
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog
    };

    private SettingRowAdapter mAdapter;
    private int mMinLevel;
    private boolean mIsDefault;

    private SensorEventListener mLightSensorListener = new SensorEventListener() {
@@ -92,6 +93,9 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog
        mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        mMinLevel = pm.getMinimumAbsoluteScreenBrightness();

        mSensorLevel = (TextView) view.findViewById(R.id.light_sensor_value);
        mBrightnessLevel = (TextView) view.findViewById(R.id.current_brightness);

@@ -453,6 +457,16 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog
            mAdapter.notifyDataSetChanged();
        }

        private int brightnessToProgress(int brightness) {
            brightness -= mMinLevel;
            return brightness * 100;
        }

        private float progressToBrightness(int progress) {
            float brightness = (float) progress / 100F;
            return brightness + mMinLevel;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final Holder holder;
@@ -466,7 +480,7 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog
                holder.percent = (TextView) convertView.findViewById(R.id.backlight_percent);
                convertView.setTag(holder);

                holder.backlight.setMax(100 * PowerManager.BRIGHTNESS_ON);
                holder.backlight.setMax(brightnessToProgress(PowerManager.BRIGHTNESS_ON));
                holder.backlight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    private boolean mIsDragging = false;

@@ -481,9 +495,12 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        int pos = (Integer) seekBar.getTag();
                        if (fromUser) {
                            int minValue = (pos == 0) ? 0 : getItem(pos - 1).backlight * 100;
                            int minValue = pos == 0
                                    ? 0
                                    : brightnessToProgress(getItem(pos - 1).backlight);
                            int maxValue = isLastItem(pos)
                                    ? seekBar.getMax() : getItem(pos + 1).backlight * 100;
                                    ? seekBar.getMax()
                                    : brightnessToProgress(getItem(pos + 1).backlight);

                            if (progress < minValue) {
                                seekBar.setProgress(minValue);
@@ -493,21 +510,21 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog
                                return;
                            }

                            getItem(pos).backlight = (progress + 50) / 100;
                            getItem(pos).backlight = Math.round(progressToBrightness(progress));
                            mIsDefault = false;
                        }

                        if (mIsDragging) {
                            final float brightness = (float) progress / seekBar.getMax();
                            updateBrightness(brightness);
                            float brightness = progressToBrightness(progress);
                            updateBrightness(brightness / PowerManager.BRIGHTNESS_ON);
                        }

                        holder.updatePercent();
                    }
                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                        final float brightness = (float) seekBar.getProgress() / seekBar.getMax();
                        updateBrightness(brightness);
                        float brightness = progressToBrightness(seekBar.getProgress());
                        updateBrightness(brightness / PowerManager.BRIGHTNESS_ON);
                        mIsDragging = true;
                    }
                    @Override
@@ -527,7 +544,7 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog
                    String.valueOf(row.luxFrom), to));

            holder.backlight.setTag(position);
            holder.backlight.setProgress(100 * row.backlight);
            holder.backlight.setProgress(brightnessToProgress(row.backlight));
            holder.updatePercent();

            return convertView;