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

Commit 77df0924 authored by Christine Franks's avatar Christine Franks
Browse files

Add night display pref controllers and change UX

- Convert NightDisplaySettings to a DashboardFragment
- Add preference controllers for all Night Display settings
- Change UX for activation from a toggle to a button

Bug: 73739388
Bug: 69912911
Test: make -j100 and make RunSettingsRoboTests -j100
Change-Id: Ia173f16207ba59bf57eb7546cbb1e2dbca67b063
Merged-In: Ia173f16207ba59bf57eb7546cbb1e2dbca67b063
parent 9b29aeba
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2018 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/night_display_turn_on_button"
        style="@style/ActionPrimaryButton"
        android:layout_marginStart="@dimen/screen_margin_sides"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start" />

    <Button
        android:id="@+id/night_display_turn_off_button"
        style="@style/ActionSecondaryButton"
        android:layout_marginStart="@dimen/screen_margin_sides"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start" />

</FrameLayout>
 No newline at end of file
+31 −18
Original line number Diff line number Diff line
@@ -24,22 +24,35 @@
    <DropDownPreference
        android:key="night_display_auto_mode"
        android:title="@string/night_display_auto_mode_title"
            android:summary="%s" />
        android:summary="%s"
        settings:controller="com.android.settings.display.NightDisplayAutoModePreferenceController" />

    <Preference
        android:key="night_display_start_time"
            android:title="@string/night_display_start_time_title" />
        android:title="@string/night_display_start_time_title"
        settings:controller="com.android.settings.display.NightDisplayCustomStartTimePreferenceController" />

    <Preference
        android:key="night_display_end_time"
            android:title="@string/night_display_end_time_title" />

    <com.android.settings.display.NightDisplayPreference
            android:key="night_display_activated"
            android:title="@string/night_display_status_title" />
        android:title="@string/night_display_end_time_title"
        settings:controller="com.android.settings.display.NightDisplayCustomEndTimePreferenceController" />

    <com.android.settings.widget.SeekBarPreference
        android:key="night_display_temperature"
            android:title="@string/night_display_temperature_title"/>
        android:title="@string/night_display_temperature_title"
        settings:keywords="@string/keywords_display_night_display"
        settings:controller="com.android.settings.display.NightDisplayIntensityPreferenceController" />

    <com.android.settings.applications.LayoutPreference
        android:key="night_display_activated"
        android:title="@string/night_display_status_title"
        android:selectable="false"
        android:layout="@layout/night_display_activation_button"
        settings:keywords="@string/keywords_display_night_display"
        settings:controller="com.android.settings.display.NightDisplayActivationPreferenceController" />

    <PreferenceCategory android:key="night_display_footer_category">
        <com.android.settingslib.widget.FooterPreference />
    </PreferenceCategory>

</PreferenceScreen>
 No newline at end of file
+7 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ package com.android.settings.core;

import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.SeekBarPreference;

import com.android.settings.slices.SliceData;

@@ -34,7 +33,13 @@ public abstract class SliderPreferenceController extends BasePreferenceControlle

    @Override
    public void updateState(Preference preference) {
        ((SeekBarPreference) preference).setValue(getSliderPosition());
        if (preference instanceof com.android.settings.widget.SeekBarPreference) {
            ((com.android.settings.widget.SeekBarPreference) preference)
                .setProgress(getSliderPosition());
        } else if (preference instanceof android.support.v7.preference.SeekBarPreference) {
            ((android.support.v7.preference.SeekBarPreference) preference)
                .setValue(getSliderPosition());
        }
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -42,8 +42,8 @@ public abstract class TogglePreferenceController extends BasePreferenceControlle
    /**
     * Set the Setting to {@param isChecked}
     *
     * @param isChecked Is {@true} when the setting should be enabled.
     * @return {@true} if the underlying setting is updated.
     * @param isChecked Is {@code true} when the setting should be enabled.
     * @return {@code true} if the underlying setting is updated.
     */
    public abstract boolean setChecked(boolean isChecked);

+126 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.display;

import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.android.internal.app.ColorDisplayController;
import com.android.settings.R;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.TogglePreferenceController;

public class NightDisplayActivationPreferenceController extends TogglePreferenceController {

    private ColorDisplayController mController;
    private NightDisplayTimeFormatter mTimeFormatter;
    private Button mTurnOffButton;
    private Button mTurnOnButton;

    private final OnClickListener mListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            mController.setActivated(!mController.isActivated());
            updateStateInternal();
        }
    };

    public NightDisplayActivationPreferenceController(Context context, String key) {
        super(context, key);
        mController = new ColorDisplayController(context);
        mTimeFormatter = new NightDisplayTimeFormatter(context);
    }

    @Override
    public int getAvailabilityStatus() {
        return ColorDisplayController.isAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);

        final LayoutPreference preference = (LayoutPreference) screen.findPreference(
                getPreferenceKey());
        mTurnOnButton = preference.findViewById(R.id.night_display_turn_on_button);
        mTurnOnButton.setOnClickListener(mListener);
        mTurnOffButton = preference.findViewById(R.id.night_display_turn_off_button);
        mTurnOffButton.setOnClickListener(mListener);
    }

    @Override
    public final void updateState(Preference preference) {
        updateStateInternal();
    }

    /** FOR SLICES */

    @Override
    public boolean isChecked() {
        return mController.isActivated();
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        return mController.setActivated(isChecked);
    }

    @Override
    public CharSequence getSummary() {
        return mTimeFormatter.getAutoModeTimeSummary(mContext, mController);
    }

    private void updateStateInternal() {
        if (mTurnOnButton == null || mTurnOffButton == null) {
            return;
        }

        final boolean isActivated = mController.isActivated();
        final int autoMode = mController.getAutoMode();

        String buttonText;
        if (autoMode == ColorDisplayController.AUTO_MODE_CUSTOM) {
            buttonText = mContext.getString(isActivated
                            ? R.string.night_display_activation_off_custom
                            : R.string.night_display_activation_on_custom,
                    mTimeFormatter.getFormattedTimeString(isActivated
                            ? mController.getCustomStartTime()
                            : mController.getCustomEndTime()));
        } else if (autoMode == ColorDisplayController.AUTO_MODE_TWILIGHT) {
            buttonText = mContext.getString(isActivated
                    ? R.string.night_display_activation_off_twilight
                    : R.string.night_display_activation_on_twilight);
        } else {
            buttonText = mContext.getString(isActivated
                    ? R.string.night_display_activation_off_manual
                    : R.string.night_display_activation_on_manual);
        }

        if (isActivated) {
            mTurnOnButton.setVisibility(View.GONE);
            mTurnOffButton.setVisibility(View.VISIBLE);
            mTurnOffButton.setText(buttonText);
        } else {
            mTurnOnButton.setVisibility(View.VISIBLE);
            mTurnOffButton.setVisibility(View.GONE);
            mTurnOnButton.setText(buttonText);
        }
    }
}
Loading