Merge "Add Night display settings" into nyc-mr1-dev

This commit is contained in:
Justin Klaassen
2016-07-08 21:07:47 +00:00
committed by Android (Google) Code Review
7 changed files with 443 additions and 0 deletions

View File

@@ -20,6 +20,7 @@
-keep class com.android.settings.overlay.FeatureFactoryImpl -keep class com.android.settings.overlay.FeatureFactoryImpl
-keep class com.android.settings.accessibility.*FragmentForSetupWizard -keep class com.android.settings.accessibility.*FragmentForSetupWizard
-keep class com.android.settings.display.*FragmentForSetupWizard -keep class com.android.settings.display.*FragmentForSetupWizard
-keep class com.android.settings.display.NightDisplaySettings
# Keep click responders # Keep click responders
-keepclassmembers class com.android.settings.inputmethod.UserDictionaryAddWordActivity { -keepclassmembers class com.android.settings.inputmethod.UserDictionaryAddWordActivity {

View File

@@ -2133,6 +2133,39 @@
<!-- Sound & display settings screen, setting option summary to enable adaptive brightness [CHAR LIMIT=100] --> <!-- Sound & display settings screen, setting option summary to enable adaptive brightness [CHAR LIMIT=100] -->
<string name="auto_brightness_summary">Optimize brightness level for available light</string> <string name="auto_brightness_summary">Optimize brightness level for available light</string>
<!-- Night display screen, setting option name to enable night display. [CHAR LIMIT=30] -->
<string name="night_display_title">Night display</string>
<!-- Night display screen, description of night display feature. [CHAR LIMIT=NONE] -->
<string name="night_display_text">Night display tints your screen red at night. This makes it easier to look at your screen in dim light and may help you fall asleep more easily.</string>
<!-- Night display screen, setting option name to configure whether night display turn on/off automatically. [CHAR LIMIT=30] -->
<string name="night_display_auto_mode_title">Turn on automatically</string>
<!-- Night display screen, setting option value for night display to *never* turn on/off automatically. [CHAR LIMIT=30] -->
<string name="night_display_auto_mode_never">Never</string>
<!-- Night display screen, setting option value for night display to turn on/off automatically according to a user defined schedule. [CHAR LIMIT=30] -->
<string name="night_display_auto_mode_custom">Custom schedule</string>
<!-- Night display screen, setting option value for night display to turn on/off automatically at sunset/sunrise. [CHAR LIMIT=30] -->
<string name="night_display_auto_mode_twilight">Sunset to sunrise</string>
<!-- Night display screen, setting option name to configure time to automatically turn on night display. [CHAR LIMIT=30] -->
<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>
<!-- 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] -->
<string name="night_display_summary_off_auto_mode_never">Never turn on automatically</string>
<!-- Display settings screen, summary format of night display when off and will turn on automatically at a user defined time. [CHAR LIMIT=NONE] -->
<string name="night_display_summary_off_auto_mode_custom">Turn on automatically at <xliff:g name="time" example="6 AM">%1$s</xliff:g></string>
<!-- Display settings screen, summary of night display when off and will turn on automatically at sunset. [CHAR LIMIT=NONE] -->
<string name="night_display_summary_off_auto_mode_twilight">Turn on automatically at sunset</string>
<!-- Display settings screen, summary format of night display when on. [CHAR LIMIT=NONE] -->
<string name="night_display_summary_on">On / <xliff:g name="auto_mode_summary" example="Never turn off automatically">%1$s</xliff:g></string>
<!-- Display settings screen, summary of night display when on and will *never* turn off automatically. [CHAR LIMIT=NONE] -->
<string name="night_display_summary_on_auto_mode_never">Never turn off automatically</string>
<!-- Display settings screen, summary format of night display when on and will turn off automatically at a user defined time. [CHAR LIMIT=NONE] -->
<string name="night_display_summary_on_auto_mode_custom">Turn off automatically at <xliff:g name="time" example="10 PM">%1$s</xliff:g></string>
<!-- Display settings screen, summary of night display when on and will turn off automatically at sunrise. [CHAR LIMIT=NONE] -->
<string name="night_display_summary_on_auto_mode_twilight">Turn off automatically at sunrise</string>
<!-- Sound & display settings screen, setting option name to change screen timeout --> <!-- Sound & display settings screen, setting option name to change screen timeout -->
<string name="screen_timeout">Sleep</string> <string name="screen_timeout">Sleep</string>
<!-- Sound & display settings screen, setting option name to change screen timeout [CHAR LIMIT=30] --> <!-- Sound & display settings screen, setting option name to change screen timeout [CHAR LIMIT=30] -->
@@ -5825,6 +5858,7 @@
<string name="keywords_display">screen, touchscreen</string> <string name="keywords_display">screen, touchscreen</string>
<string name="keywords_display_brightness_level">dim screen, touchscreen, battery</string> <string name="keywords_display_brightness_level">dim screen, touchscreen, battery</string>
<string name="keywords_display_auto_brightness">dim screen, touchscreen, battery</string> <string name="keywords_display_auto_brightness">dim screen, touchscreen, battery</string>
<string name="keywords_display_night_display">dim screen, night, tint</string>
<string name="keywords_display_wallpaper">background, personalize, customize display</string> <string name="keywords_display_wallpaper">background, personalize, customize display</string>
<string name="keywords_display_font_size">text size</string> <string name="keywords_display_font_size">text size</string>
<string name="keywords_display_cast_screen">project, cast</string> <string name="keywords_display_cast_screen">project, cast</string>

View File

@@ -32,6 +32,12 @@
settings:keywords="@string/keywords_display_auto_brightness" settings:keywords="@string/keywords_display_auto_brightness"
android:summary="@string/auto_brightness_summary" /> android:summary="@string/auto_brightness_summary" />
<com.android.settings.display.NightDisplayPreference
android:key="night_display"
android:title="@string/night_display_title"
android:fragment="com.android.settings.display.NightDisplaySettings"
settings:keywords="@string/keywords_display_night_display" />
<!-- Hide night mode for now <!-- Hide night mode for now
<ListPreference <ListPreference
android:key="night_mode" android:key="night_mode"

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 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.
-->
<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">
<DropDownPreference
android:key="night_display_auto_mode"
android:title="@string/night_display_auto_mode_title"
android:persistent="false"
android:summary="%s" />
<Preference
android:key="night_display_start_time"
android:title="@string/night_display_start_time_title" />
<Preference
android:key="night_display_end_time"
android:title="@string/night_display_end_time_title" />
<com.android.settings.fuelgauge.WallOfTextPreference
android:summary="@string/night_display_text"
android:selectable="false"
settings:allowDividerAbove="true" />
</PreferenceScreen>

View File

@@ -44,6 +44,7 @@ import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.android.internal.app.NightDisplayController;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent; import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.internal.view.RotationPolicy; import com.android.internal.view.RotationPolicy;
@@ -83,6 +84,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
private static final String KEY_TAP_TO_WAKE = "tap_to_wake"; private static final String KEY_TAP_TO_WAKE = "tap_to_wake";
private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness"; private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness";
private static final String KEY_AUTO_ROTATE = "auto_rotate"; private static final String KEY_AUTO_ROTATE = "auto_rotate";
private static final String KEY_NIGHT_DISPLAY = "night_display";
private static final String KEY_NIGHT_MODE = "night_mode"; private static final String KEY_NIGHT_MODE = "night_mode";
private static final String KEY_CAMERA_GESTURE = "camera_gesture"; private static final String KEY_CAMERA_GESTURE = "camera_gesture";
private static final String KEY_WALLPAPER = "wallpaper"; private static final String KEY_WALLPAPER = "wallpaper";
@@ -129,6 +131,10 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
removePreference(KEY_AUTO_BRIGHTNESS); removePreference(KEY_AUTO_BRIGHTNESS);
} }
if (!NightDisplayController.isAvailable(activity)) {
removePreference(KEY_NIGHT_DISPLAY);
}
if (isLiftToWakeAvailable(activity)) { if (isLiftToWakeAvailable(activity)) {
mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE); mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE);
mLiftToWakePreference.setOnPreferenceChangeListener(this); mLiftToWakePreference.setOnPreferenceChangeListener(this);
@@ -496,6 +502,9 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
if (!isAutomaticBrightnessAvailable(context.getResources())) { if (!isAutomaticBrightnessAvailable(context.getResources())) {
result.add(KEY_AUTO_BRIGHTNESS); result.add(KEY_AUTO_BRIGHTNESS);
} }
if (!NightDisplayController.isAvailable(context)) {
result.add(KEY_NIGHT_DISPLAY);
}
if (!isLiftToWakeAvailable(context)) { if (!isLiftToWakeAvailable(context)) {
result.add(KEY_LIFT_TO_WAKE); result.add(KEY_LIFT_TO_WAKE);
} }

View File

@@ -0,0 +1,126 @@
/*
* Copyright (C) 2016 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.util.AttributeSet;
import com.android.internal.app.NightDisplayController;
import com.android.settings.R;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.TimeZone;
public class NightDisplayPreference extends Preference implements NightDisplayController.Callback {
private NightDisplayController mController;
private DateFormat mTimeFormatter;
public NightDisplayPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mController = new NightDisplayController(context);
mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
}
@Override
public void onAttached() {
super.onAttached();
// Listen for changes only while attached.
mController.setListener(this);
// Update the summary since the state may have changed while not attached.
updateSummary();
}
@Override
public void onDetached() {
super.onDetached();
// Stop listening for state changes.
mController.setListener(null);
}
private String getFormattedTimeString(NightDisplayController.LocalTime localTime) {
final Calendar c = Calendar.getInstance();
c.setTimeZone(mTimeFormatter.getTimeZone());
c.set(Calendar.HOUR_OF_DAY, localTime.hourOfDay);
c.set(Calendar.MINUTE, localTime.minute);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return mTimeFormatter.format(c.getTime());
}
private void updateSummary() {
final Context context = getContext();
final boolean isActivated = mController.isActivated();
final int autoMode = mController.getAutoMode();
final String autoModeSummary;
switch (autoMode) {
default:
case NightDisplayController.AUTO_MODE_DISABLED:
autoModeSummary = context.getString(isActivated
? R.string.night_display_summary_on_auto_mode_never
: R.string.night_display_summary_off_auto_mode_never);
break;
case NightDisplayController.AUTO_MODE_CUSTOM:
if (isActivated) {
autoModeSummary = context.getString(
R.string.night_display_summary_on_auto_mode_custom,
getFormattedTimeString(mController.getCustomEndTime()));
} else {
autoModeSummary = context.getString(
R.string.night_display_summary_off_auto_mode_custom,
getFormattedTimeString(mController.getCustomStartTime()));
}
break;
case NightDisplayController.AUTO_MODE_TWILIGHT:
autoModeSummary = context.getString(isActivated
? R.string.night_display_summary_on_auto_mode_twilight
: R.string.night_display_summary_off_auto_mode_twilight);
break;
}
final int summaryFormatResId = isActivated ? R.string.night_display_summary_on
: R.string.night_display_summary_off;
setSummary(context.getString(summaryFormatResId, autoModeSummary));
}
@Override
public void onActivated(boolean activated) {
updateSummary();
}
@Override
public void onAutoModeChanged(int autoMode) {
updateSummary();
}
@Override
public void onCustomStartTimeChanged(NightDisplayController.LocalTime startTime) {
updateSummary();
}
@Override
public void onCustomEndTimeChanged(NightDisplayController.LocalTime endTime) {
updateSummary();
}
}

View File

@@ -0,0 +1,226 @@
/**
* Copyright (C) 2016 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.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.preference.DropDownPreference;
import android.support.v7.preference.Preference;
import android.widget.Switch;
import android.widget.TimePicker;
import com.android.internal.app.NightDisplayController;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.widget.SwitchBar;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.TimeZone;
/**
* Settings screen for Night display.
*/
public class NightDisplaySettings extends SettingsPreferenceFragment implements
NightDisplayController.Callback,
Preference.OnPreferenceChangeListener,
SwitchBar.OnSwitchChangeListener {
private static final String KEY_NIGHT_DISPLAY_AUTO_MODE = "night_display_auto_mode";
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 int DIALOG_START_TIME = 0;
private static final int DIALOG_END_TIME = 1;
private NightDisplayController mController;
private DateFormat mTimeFormatter;
private DropDownPreference mAutoModePreference;
private Preference mStartTimePreference;
private Preference mEndTimePreference;
private SwitchBar mSwitchBar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Context context = getContext();
mController = new NightDisplayController(context);
mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreatePreferences(savedInstanceState, rootKey);
// Load the preferences from xml.
addPreferencesFromResource(R.xml.night_display_settings);
mAutoModePreference = (DropDownPreference) findPreference(KEY_NIGHT_DISPLAY_AUTO_MODE);
mStartTimePreference = findPreference(KEY_NIGHT_DISPLAY_START_TIME);
mEndTimePreference = findPreference(KEY_NIGHT_DISPLAY_END_TIME);
mAutoModePreference.setEntries(new CharSequence[] {
getString(R.string.night_display_auto_mode_never),
getString(R.string.night_display_auto_mode_custom),
getString(R.string.night_display_auto_mode_twilight)
});
mAutoModePreference.setEntryValues(new CharSequence[] {
String.valueOf(NightDisplayController.AUTO_MODE_DISABLED),
String.valueOf(NightDisplayController.AUTO_MODE_CUSTOM),
String.valueOf(NightDisplayController.AUTO_MODE_TWILIGHT)
});
mAutoModePreference.setOnPreferenceChangeListener(this);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mSwitchBar = ((SettingsActivity) getActivity()).getSwitchBar();
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.show();
}
@Override
public void onStart() {
super.onStart();
// Listen for changes only while visible.
mController.setListener(this);
// Update the current state since it have changed while not visible.
onActivated(mController.isActivated());
onAutoModeChanged(mController.getAutoMode());
onCustomStartTimeChanged(mController.getCustomStartTime());
onCustomEndTimeChanged(mController.getCustomEndTime());
}
@Override
public void onStop() {
super.onStop();
// Stop listening for state changes.
mController.setListener(null);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference == mStartTimePreference) {
showDialog(DIALOG_START_TIME);
return true;
} else if (preference == mEndTimePreference) {
showDialog(DIALOG_END_TIME);
return true;
}
return super.onPreferenceTreeClick(preference);
}
@Override
public Dialog onCreateDialog(final int dialogId) {
if (dialogId == DIALOG_START_TIME || dialogId == DIALOG_END_TIME) {
final NightDisplayController.LocalTime initialTime;
if (dialogId == DIALOG_START_TIME) {
initialTime = mController.getCustomStartTime();
} else {
initialTime = mController.getCustomEndTime();
}
final Context context = getContext();
final boolean use24HourFormat = android.text.format.DateFormat.is24HourFormat(context);
return new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
final NightDisplayController.LocalTime time =
new NightDisplayController.LocalTime(hourOfDay, minute);
if (dialogId == DIALOG_START_TIME) {
mController.setCustomStartTime(time);
} else {
mController.setCustomEndTime(time);
}
}
}, initialTime.hourOfDay, initialTime.minute, use24HourFormat);
}
return super.onCreateDialog(dialogId);
}
@Override
public void onActivated(boolean activated) {
mSwitchBar.setChecked(activated);
}
@Override
public void onAutoModeChanged(int autoMode) {
mAutoModePreference.setValue(String.valueOf(autoMode));
final boolean showCustomSchedule = autoMode == NightDisplayController.AUTO_MODE_CUSTOM;
mStartTimePreference.setVisible(showCustomSchedule);
mEndTimePreference.setVisible(showCustomSchedule);
}
private String getFormattedTimeString(NightDisplayController.LocalTime localTime) {
final Calendar c = Calendar.getInstance();
c.setTimeZone(mTimeFormatter.getTimeZone());
c.set(Calendar.HOUR_OF_DAY, localTime.hourOfDay);
c.set(Calendar.MINUTE, localTime.minute);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return mTimeFormatter.format(c.getTime());
}
@Override
public void onCustomStartTimeChanged(NightDisplayController.LocalTime startTime) {
mStartTimePreference.setSummary(getFormattedTimeString(startTime));
}
@Override
public void onCustomEndTimeChanged(NightDisplayController.LocalTime endTime) {
mEndTimePreference.setSummary(getFormattedTimeString(endTime));
}
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
// Attempt to update the NIGHT_DISPLAY_ACTIVATED setting if necessary.
final boolean isActivated = mController.isActivated();
if (isActivated != isChecked) {
if (mController.setActivated(isChecked)) {
switchView.setChecked(isActivated);
}
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mAutoModePreference) {
return mController.setAutoMode(Integer.parseInt((String) newValue));
}
return false;
}
@Override
protected int getMetricsCategory() {
return MetricsEvent.NIGHT_DISPLAY_SETTINGS;
}
}