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

Commit 3910adfb authored by Christine Franks's avatar Christine Franks Committed by Android (Google) Code Review
Browse files

Merge "Add color temperature preference for Night Display"

parents 60968b97 6418d0b8
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -6787,6 +6787,13 @@ public final class Settings {
         */
        public static final String NIGHT_DISPLAY_AUTO_MODE = "night_display_auto_mode";

        /**
         * Control the color temperature of Night Display, represented in Kelvin.
         * @hide
         */
        public static final String NIGHT_DISPLAY_COLOR_TEMPERATURE =
                "night_display_color_temperature";

        /**
         * Custom time when Night display is scheduled to activate.
         * Represented as milliseconds from midnight (e.g. 79200000 == 10pm).
@@ -7022,6 +7029,7 @@ public final class Settings {
            INCALL_POWER_BUTTON_BEHAVIOR,
            NIGHT_DISPLAY_CUSTOM_START_TIME,
            NIGHT_DISPLAY_CUSTOM_END_TIME,
            NIGHT_DISPLAY_COLOR_TEMPERATURE,
            NIGHT_DISPLAY_AUTO_MODE,
            NIGHT_DISPLAY_ACTIVATED,
            SYNC_PARENT_SOUNDS,
+2 −3
Original line number Diff line number Diff line
@@ -677,7 +677,6 @@ public abstract class AbsSeekBar extends ProgressBar {
    protected synchronized void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawThumb(canvas);

    }

    @Override
@@ -703,9 +702,9 @@ public abstract class AbsSeekBar extends ProgressBar {
    }

    /**
     * Draw the tick marks.
     * @hide
     */
    void drawTickMarks(Canvas canvas) {
    protected void drawTickMarks(Canvas canvas) {
        if (mTickMark != null) {
            final int count = getMax() - getMin();
            if (count > 1) {
+7 −0
Original line number Diff line number Diff line
@@ -850,6 +850,13 @@ public class ProgressBar extends View {
        }
    }

    /**
     * @hide
     */
    public boolean getMirrorForRtl() {
        return mMirrorForRtl;
    }

    /**
     * Applies the progress tints in order of increasing specificity.
     */
+71 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ public final class NightDisplayController {
    private static final String TAG = "NightDisplayController";
    private static final boolean DEBUG = false;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({ AUTO_MODE_DISABLED, AUTO_MODE_CUSTOM, AUTO_MODE_TWILIGHT })
    public @interface AutoMode {}
@@ -233,6 +232,65 @@ public final class NightDisplayController {
                Secure.NIGHT_DISPLAY_CUSTOM_END_TIME, endTime.toMillis(), mUserId);
    }

    /**
     * Returns the color temperature (in Kelvin) to tint the display when activated.
     */
    public int getColorTemperature() {
        int colorTemperature = Secure.getIntForUser(mContext.getContentResolver(),
                Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE, -1, mUserId);
        if (colorTemperature == -1) {
            if (DEBUG) {
                Slog.d(TAG, "Using default value for setting: "
                    + Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE);
            }
            colorTemperature = getDefaultColorTemperature();
        }
        final int minimumTemperature = getMinimumColorTemperature();
        final int maximumTemperature = getMaximumColorTemperature();
        if (colorTemperature < minimumTemperature) {
            colorTemperature = minimumTemperature;
        } else if (colorTemperature > maximumTemperature) {
            colorTemperature = maximumTemperature;
        }

        return colorTemperature;
    }

    /**
     * Sets the current temperature.
     *
     * @param colorTemperature the temperature, in Kelvin.
     * @return {@code true} if new temperature was set successfully.
     */
    public boolean setColorTemperature(int colorTemperature) {
        return Secure.putIntForUser(mContext.getContentResolver(),
            Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE, colorTemperature, mUserId);
    }

    /**
     * Returns the minimum allowed color temperature (in Kelvin) to tint the display when activated.
     */
    public int getMinimumColorTemperature() {
        return mContext.getResources().getInteger(
                R.integer.config_nightDisplayColorTemperatureMin);
    }

    /**
     * Returns the maximum allowed color temperature (in Kelvin) to tint the display when activated.
     */
    public int getMaximumColorTemperature() {
        return mContext.getResources().getInteger(
                R.integer.config_nightDisplayColorTemperatureMax);
    }

    /**
     * Returns the default color temperature (in Kelvin) to tint the display when activated.
     */
    public int getDefaultColorTemperature() {
        return mContext.getResources().getInteger(
                R.integer.config_nightDisplayColorTemperatureDefault);
    }

    private void onSettingChanged(@NonNull String setting) {
        if (DEBUG) {
            Slog.d(TAG, "onSettingChanged: " + setting);
@@ -252,6 +310,9 @@ public final class NightDisplayController {
                case Secure.NIGHT_DISPLAY_CUSTOM_END_TIME:
                    mCallback.onCustomEndTimeChanged(getCustomEndTime());
                    break;
                case Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE:
                    mCallback.onColorTemperatureChanged(getColorTemperature());
                    break;
            }
        }
    }
@@ -278,6 +339,8 @@ public final class NightDisplayController {
                        false /* notifyForDescendants */, mContentObserver, mUserId);
                cr.registerContentObserver(Secure.getUriFor(Secure.NIGHT_DISPLAY_CUSTOM_END_TIME),
                        false /* notifyForDescendants */, mContentObserver, mUserId);
                cr.registerContentObserver(Secure.getUriFor(Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE),
                        false /* notifyForDescendants */, mContentObserver, mUserId);
            }
        }
    }
@@ -417,5 +480,12 @@ public final class NightDisplayController {
         * @param endTime the local time to automatically deactivate Night display
         */
        default void onCustomEndTimeChanged(LocalTime endTime) {}

        /**
         * Callback invoked when the color temperature changes.
         *
         * @param colorTemperature the color temperature to tint the screen
         */
        default void onColorTemperatureChanged(int colorTemperature) {}
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -804,6 +804,16 @@
         Represented as milliseconds from midnight (e.g. 21600000 == 6am). -->
    <integer name="config_defaultNightDisplayCustomEndTime">21600000</integer>

    <!-- Minimum color temperature, in Kelvin, supported by Night display. -->
    <integer name="config_nightDisplayColorTemperatureMin">2596</integer>

    <!-- Default color temperature, in Kelvin, to tint the screen when Night display is
         activated. -->
    <integer name="config_nightDisplayColorTemperatureDefault">2850</integer>

    <!-- Maximum color temperature, in Kelvin, supported by Night display. -->
    <integer name="config_nightDisplayColorTemperatureMax">4082</integer>

    <!-- Indicate whether to allow the device to suspend when the screen is off
         due to the proximity sensor.  This resource should only be set to true
         if the sensor HAL correctly handles the proximity sensor as a wake-up source.
Loading