Loading res/layout/night_display_activation_button.xml 0 → 100644 +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 res/xml/night_display_settings.xml +31 −18 Original line number Diff line number Diff line Loading @@ -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 src/com/android/settings/core/SliderPreferenceController.java +7 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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()); } } /** Loading src/com/android/settings/core/TogglePreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -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); Loading src/com/android/settings/display/NightDisplayActivationPreferenceController.java 0 → 100644 +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
res/layout/night_display_activation_button.xml 0 → 100644 +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
res/xml/night_display_settings.xml +31 −18 Original line number Diff line number Diff line Loading @@ -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
src/com/android/settings/core/SliderPreferenceController.java +7 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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()); } } /** Loading
src/com/android/settings/core/TogglePreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -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); Loading
src/com/android/settings/display/NightDisplayActivationPreferenceController.java 0 → 100644 +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); } } }