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

Commit eae637c7 authored by Dave Daynard's avatar Dave Daynard Committed by Gerrit Code Review
Browse files

Settings: Livedisplay: Respect default values passed from CMHW

Not all CMHW color calibration uses a default value of 100%, nor does it
use a minimum of 20%

Change-Id: I5ca925e77e41ebf050f2a7c5a81c4e10d9406f91
parent ab062c11
Loading
Loading
Loading
Loading
+35 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.livedisplay;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.hardware.CmHardwareManager;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@@ -34,6 +35,8 @@ import android.widget.TextView;
import com.android.settings.IntervalSeekBar;
import com.android.settings.R;

import static android.hardware.CmHardwareManager.FEATURE_DISPLAY_COLOR_CALIBRATION;

/**
 * Special preference type that allows configuration of Color settings
 */
@@ -42,6 +45,11 @@ public class DisplayColor extends DialogPreference {

    private final Context mContext;

    private final int minRGB;
    private final int maxRGB;
    private final float defaultRGB;
    private final boolean useCMHW;

    // These arrays must all match in length and order
    private static final int[] SEEKBAR_ID = new int[] {
        R.id.color_red_seekbar,
@@ -65,6 +73,20 @@ public class DisplayColor extends DialogPreference {

        mContext = context;

        final CmHardwareManager mCmHardwareManager =
                (CmHardwareManager) mContext.getSystemService(Context.CMHW_SERVICE);
        useCMHW = mCmHardwareManager.isSupported(FEATURE_DISPLAY_COLOR_CALIBRATION);
        if (useCMHW) {
            minRGB = mCmHardwareManager.getDisplayColorCalibrationMin();
            maxRGB = mCmHardwareManager.getDisplayColorCalibrationMax();
            defaultRGB = (float) mCmHardwareManager.getDisplayColorCalibrationDefault() / maxRGB;
        } else {
            // Initialize these just to avoid compiler errors.
            minRGB = 20;
            maxRGB = 100;
            defaultRGB = 1.0f;
        }

        setDialogLayoutResource(R.layout.display_color_calibration);
    }

@@ -88,16 +110,17 @@ public class DisplayColor extends DialogPreference {
        String[] colorAdjustment = colorAdjustmentTemp == null ?
                null : colorAdjustmentTemp.split(" ");
        if (colorAdjustment == null || colorAdjustment.length != 3) {
            colorAdjustment = new String[] { "1.0", "1.0", "1.0" };
            colorAdjustment = new String[] { Float.toString(defaultRGB),
                    Float.toString(defaultRGB), Float.toString(defaultRGB) };
        }
        try {
            mOriginalColors[0] = Float.parseFloat(colorAdjustment[0]);
            mOriginalColors[1] = Float.parseFloat(colorAdjustment[1]);
            mOriginalColors[2] = Float.parseFloat(colorAdjustment[2]);
        } catch (NumberFormatException e) {
            mOriginalColors[0] = 1.0f;
            mOriginalColors[1] = 1.0f;
            mOriginalColors[2] = 1.0f;
            mOriginalColors[0] = defaultRGB;
            mOriginalColors[1] = defaultRGB;
            mOriginalColors[2] = defaultRGB;
        }

        System.arraycopy(mOriginalColors, 0, mCurrentColors, 0, 3);
@@ -106,6 +129,12 @@ public class DisplayColor extends DialogPreference {
            IntervalSeekBar seekBar = (IntervalSeekBar) view.findViewById(SEEKBAR_ID[i]);
            TextView value = (TextView) view.findViewById(SEEKBAR_VALUE_ID[i]);
            mSeekBars[i] = new ColorSeekBar(seekBar, value, i);
            if (useCMHW) {
                mSeekBars[i].mSeekBar.setMinimum((float) minRGB / maxRGB);
                /* Maximum hasn't changed but it's relative to the minimum so it needs
                   to be reset */
                mSeekBars[i].mSeekBar.setMaximum(1.0f);
            }
            mSeekBars[i].mSeekBar.setProgressFloat(mCurrentColors[i]);
            int percent = Math.round(100F * mCurrentColors[i]);
            value.setText(String.format("%d%%", percent));
@@ -124,8 +153,8 @@ public class DisplayColor extends DialogPreference {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < mSeekBars.length; i++) {
                    mSeekBars[i].mSeekBar.setProgressFloat(1.00f);
                    mCurrentColors[i] = 1.0f;
                    mSeekBars[i].mSeekBar.setProgressFloat(defaultRGB);
                    mCurrentColors[i] = defaultRGB;
                }
                updateColors(mCurrentColors);
            }