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

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

Merge "Add color temperature preference to Night Display"

parents 9392681a c53ab43d
Loading
Loading
Loading
Loading
+35 −67
Original line number Diff line number Diff line
@@ -15,47 +15,23 @@
-->

<!-- Layout used by SeekBarPreference for the seekbar widget style. -->
<!-- Same as frameworks/base/core/res/res/layout/preference_widget_seekbar_material.xml with
     reserved icon space -->
<LinearLayout
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="center_vertical"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">

    <LinearLayout
        android:id="@+id/icon_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="60dp"
        android:gravity="start|center_vertical"
        android:orientation="horizontal"
        android:paddingEnd="12dp"
        android:paddingTop="4dp"
        android:paddingBottom="4dp">
        <com.android.internal.widget.PreferenceImageView
            android:id="@android:id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxWidth="48dp"
            android:maxHeight="48dp"/>
    </LinearLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dip"
        android:layout_marginTop="6dip"
        android:layout_marginBottom="6dip"
        android:layout_weight="1">
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingBottom="6dp"
    android:paddingTop="6dp">

    <TextView
        android:id="@android:id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="60dp"
        android:layout_marginEnd="8dp"
        android:singleLine="true"
        android:textAppearance="@android:style/TextAppearance.Material.Subhead"
        android:textColor="?android:attr/textColorPrimary"
@@ -66,30 +42,22 @@
        android:id="@android:id/summary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="60dp"
        android:layout_marginEnd="8dp"
        android:layout_below="@android:id/title"
        android:layout_alignStart="@android:id/title"
        android:textAppearance="?android:attr/textAppearanceListItemSecondary"
        android:textColor="?android:attr/textColorSecondary"
        android:maxLines="4" />

        <!-- Preference should place its actual preference widget here. -->
        <LinearLayout
            android:id="@android:id/widget_frame"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_below="@android:id/summary"
            android:layout_alignStart="@android:id/title"
            android:gravity="center"
            android:orientation="vertical"/>

        <SeekBar
    <com.android.settings.widget.DefaultIndicatorSeekBar
        android:id="@*android:id/seekbar"
        style="@android:style/Widget.Material.SeekBar.Discrete"
        android:layout_width="match_parent"
            android:layout_height="wrap_content"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:layout_below="@android:id/summary"
            android:layout_toEndOf="@android:id/widget_frame"
            android:layout_alignParentEnd="true"/>
        android:layout_marginEnd="8dp"
        android:layout_marginStart="44dp" />

</RelativeLayout>

</LinearLayout>
+2 −0
Original line number Diff line number Diff line
@@ -2230,6 +2230,8 @@
    <string name="night_display_start_time_title">Start time</string>
    <!-- Night display screen, setting option name to configure time to automatically turn off night display. [CHAR LIMIT=30] -->
    <string name="night_display_end_time_title">End time</string>
    <!-- Night display screen, setting the color temperature of the display. [CHAR LIMIT=30] -->
    <string name="night_display_temperature_title">Intensity</string>
    <!-- Display settings screen, summary format of night display when off. [CHAR LIMIT=NONE] -->
    <string name="night_display_summary_off">Off. <xliff:g name="auto_mode_summary" example="Never turn on automatically">%1$s</xliff:g></string>
    <!-- Display settings screen, summary of night display when off and will *never* turn on automatically. [CHAR LIMIT=NONE] -->
+4 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

<PreferenceScreen
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:settings="http://schemas.android.com/apk/res-auto"
        android:title="@string/night_display_title">

    <PreferenceCategory
@@ -44,6 +43,10 @@
                android:key="night_display_activated"
                android:title="@string/night_display_title" />

        <com.android.settings.SeekBarPreference
            android:key="night_display_temperature"
            android:title="@string/night_display_temperature_title"/>

    </PreferenceCategory>

</PreferenceScreen>
 No newline at end of file
+36 −7
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.content.res.TypedArrayUtils;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.view.KeyEvent;
@@ -29,6 +28,7 @@ import android.view.View;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.android.settings.widget.DefaultIndicatorSeekBar;
import com.android.settingslib.RestrictedPreference;

/**
@@ -41,6 +41,11 @@ public class SeekBarPreference extends RestrictedPreference
    private int mMax;
    private boolean mTrackingTouch;

    private boolean mContinuousUpdates;
    private int mDefaultProgress = -1;

    private SeekBar mSeekBar;

    public SeekBarPreference(
            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
@@ -78,12 +83,15 @@ public class SeekBarPreference extends RestrictedPreference
    public void onBindViewHolder(PreferenceViewHolder view) {
        super.onBindViewHolder(view);
        view.itemView.setOnKeyListener(this);
        SeekBar seekBar = (SeekBar) view.findViewById(
        mSeekBar = (SeekBar) view.findViewById(
                com.android.internal.R.id.seekbar);
        seekBar.setOnSeekBarChangeListener(this);
        seekBar.setMax(mMax);
        seekBar.setProgress(mProgress);
        seekBar.setEnabled(isEnabled());
        mSeekBar.setOnSeekBarChangeListener(this);
        mSeekBar.setMax(mMax);
        mSeekBar.setProgress(mProgress);
        mSeekBar.setEnabled(isEnabled());
        if (mSeekBar instanceof DefaultIndicatorSeekBar) {
            ((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
        }
    }

    @Override
@@ -126,6 +134,27 @@ public class SeekBarPreference extends RestrictedPreference
        setProgress(progress, true);
    }

    /**
     * Sets the progress point to draw a single tick mark representing a default value.
     */
    public void setDefaultProgress(int defaultProgress) {
        if (mDefaultProgress != defaultProgress) {
            mDefaultProgress = defaultProgress;
            if (mSeekBar instanceof DefaultIndicatorSeekBar) {
                ((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
            }
        }
    }

    /**
     * When {@code continuousUpdates} is true, update the persisted setting immediately as the thumb
     * is dragged along the SeekBar. Otherwise, only update the value of the setting when the thumb
     * is dropped.
     */
    public void setContinuousUpdates(boolean continuousUpdates) {
        mContinuousUpdates = continuousUpdates;
    }

    private void setProgress(int progress, boolean notifyChanged) {
        if (progress > mMax) {
            progress = mMax;
@@ -164,7 +193,7 @@ public class SeekBarPreference extends RestrictedPreference
    @Override
    public void onProgressChanged(
            SeekBar seekBar, int progress, boolean fromUser) {
        if (fromUser && !mTrackingTouch) {
        if (fromUser && (mContinuousUpdates || !mTrackingTouch)) {
            syncProgress(seekBar);
        }
    }
+29 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.widget.TimePicker;
import com.android.internal.app.NightDisplayController;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SeekBarPreference;
import com.android.settings.SettingsPreferenceFragment;

import java.text.DateFormat;
@@ -44,6 +45,7 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
    private static final String KEY_NIGHT_DISPLAY_START_TIME = "night_display_start_time";
    private static final String KEY_NIGHT_DISPLAY_END_TIME = "night_display_end_time";
    private static final String KEY_NIGHT_DISPLAY_ACTIVATED = "night_display_activated";
    private static final String KEY_NIGHT_DISPLAY_TEMPERATURE = "night_display_temperature";

    private static final int DIALOG_START_TIME = 0;
    private static final int DIALOG_END_TIME = 1;
@@ -55,6 +57,7 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
    private Preference mStartTimePreference;
    private Preference mEndTimePreference;
    private TwoStatePreference mActivatedPreference;
    private SeekBarPreference mTemperaturePreference;

    @Override
    public void onCreate(Bundle savedInstanceState) {
@@ -65,6 +68,11 @@ public class NightDisplaySettings extends SettingsPreferenceFragment

        mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
        mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

        mTemperaturePreference.setMax(convertTemperature(mController.getMinimumColorTemperature()));
        mTemperaturePreference.setDefaultProgress(convertTemperature(
                mController.getDefaultColorTemperature()));
        mTemperaturePreference.setContinuousUpdates(true);
    }

    @Override
@@ -78,6 +86,7 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
        mStartTimePreference = findPreference(KEY_NIGHT_DISPLAY_START_TIME);
        mEndTimePreference = findPreference(KEY_NIGHT_DISPLAY_END_TIME);
        mActivatedPreference = (TwoStatePreference) findPreference(KEY_NIGHT_DISPLAY_ACTIVATED);
        mTemperaturePreference = (SeekBarPreference) findPreference(KEY_NIGHT_DISPLAY_TEMPERATURE);

        mAutoModePreference.setEntries(new CharSequence[] {
                getString(R.string.night_display_auto_mode_never),
@@ -91,6 +100,7 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
        });
        mAutoModePreference.setOnPreferenceChangeListener(this);
        mActivatedPreference.setOnPreferenceChangeListener(this);
        mTemperaturePreference.setOnPreferenceChangeListener(this);
    }

    @Override
@@ -105,6 +115,7 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
        onAutoModeChanged(mController.getAutoMode());
        onCustomStartTimeChanged(mController.getCustomStartTime());
        onCustomEndTimeChanged(mController.getCustomEndTime());
        onColorTemperatureChanged(mController.getColorTemperature());
    }

    @Override
@@ -166,9 +177,11 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
                return 0;
        }
    }

    @Override
    public void onActivated(boolean activated) {
        mActivatedPreference.setChecked(activated);
        mTemperaturePreference.setEnabled(activated);
    }

    @Override
@@ -180,6 +193,11 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
        mEndTimePreference.setVisible(showCustomSchedule);
    }

    @Override
    public void onColorTemperatureChanged(int colorTemperature) {
        mTemperaturePreference.setProgress(convertTemperature(colorTemperature));
    }

    private String getFormattedTimeString(NightDisplayController.LocalTime localTime) {
        final Calendar c = Calendar.getInstance();
        c.setTimeZone(mTimeFormatter.getTimeZone());
@@ -190,6 +208,15 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
        return mTimeFormatter.format(c.getTime());
    }

    /**
     * Inverts and range-adjusts a raw value from the SeekBar (i.e. [0, maxTemp-minTemp]), or
     * converts an inverted and range-adjusted value to the raw SeekBar value, depending on the
     * adjustment status of the input.
     */
    private int convertTemperature(int temperature) {
        return mController.getMaximumColorTemperature() - temperature;
    }

    @Override
    public void onCustomStartTimeChanged(NightDisplayController.LocalTime startTime) {
        mStartTimePreference.setSummary(getFormattedTimeString(startTime));
@@ -206,6 +233,8 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
            return mController.setAutoMode(Integer.parseInt((String) newValue));
        } else if (preference == mActivatedPreference) {
            return mController.setActivated((Boolean) newValue);
        } else if (preference == mTemperaturePreference) {
            return mController.setColorTemperature(convertTemperature((Integer) newValue));
        }
        return false;
    }
Loading