Merge "Add handling for gesture settings for double twist for camera flip." into nyc-mr1-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 6b79f19..e633741 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2933,6 +2933,8 @@
android:value="com.android.settings.category.device" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.gestures.GestureSettings" />
+ <meta-data android:name="com.android.settings.summary"
+ android:resource="@string/gesture_preference_summary" />
</activity>
<activity android:name="BackupSettingsActivity"
diff --git a/proguard.flags b/proguard.flags
index f3c218a..040fa6c 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -20,6 +20,7 @@
-keep class com.android.settings.overlay.FeatureFactoryImpl
-keep class com.android.settings.accessibility.*FragmentForSetupWizard
-keep class com.android.settings.display.*FragmentForSetupWizard
+-keep class com.android.settings.display.NightDisplaySettings
# Keep click responders
-keepclassmembers class com.android.settings.inputmethod.UserDictionaryAddWordActivity {
diff --git a/res/layout/device_profiles_settings.xml b/res/layout/device_profiles_settings.xml
index bd78bea..260fa05 100644
--- a/res/layout/device_profiles_settings.xml
+++ b/res/layout/device_profiles_settings.xml
@@ -14,48 +14,56 @@
limitations under the License.
-->
-<LinearLayout
+<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="25dp"
- android:orientation="vertical">
-
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/bluetooth_preference_paired_dialog_name_label"
- android:textAppearance="@android:style/TextAppearance.Material.Body1"
- android:textColor="?android:attr/textColorSecondary"
- android:textDirection="locale"
- android:paddingTop="16dp"
- style="@style/bt_item_label" />
-
- <EditText
- android:id="@+id/name"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="textNoSuggestions"
- android:maxLength="@integer/bluetooth_name_length"
- android:singleLine="true"
- android:paddingBottom="@dimen/bluetooth_dialog_padding"
- android:textDirection="locale"
- style="@style/bt_item_edit_content" />
-
- <TextView
- android:id="@+id/profiles_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="16dp"
- android:paddingBottom="4dp"
- android:text="@string/bluetooth_device_advanced_profile_header_title"
- android:textAppearance="@android:style/TextAppearance.Material.Body1"
- android:textColor="?android:attr/textColorSecondary" />
+ android:paddingEnd="25dp">
<LinearLayout
- android:id="@+id/profiles_section"
- android:orientation="vertical"
android:layout_width="match_parent"
- android:layout_height="wrap_content" />
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
-</LinearLayout>
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/bluetooth_preference_paired_dialog_name_label"
+ android:textAppearance="@android:style/TextAppearance.Material.Body1"
+ android:textColor="?android:attr/textColorSecondary"
+ android:textDirection="locale"
+ android:paddingTop="16dp"
+ style="@style/bt_item_label"/>
+
+ <EditText
+ android:id="@+id/name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="textNoSuggestions"
+ android:maxLength="@integer/bluetooth_name_length"
+ android:singleLine="true"
+ android:paddingBottom="@dimen/bluetooth_dialog_padding"
+ android:textDirection="locale"
+ style="@style/bt_item_edit_content"/>
+
+ <TextView
+ android:id="@+id/profiles_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="16dp"
+ android:paddingBottom="4dp"
+ android:text="@string/bluetooth_device_advanced_profile_header_title"
+ android:textAppearance="@android:style/TextAppearance.Material.Body1"
+ android:textColor="?android:attr/textColorSecondary"/>
+
+
+ <LinearLayout
+ android:id="@+id/profiles_section"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ </LinearLayout>
+
+</ScrollView>
diff --git a/res/layout/support_tile.xml b/res/layout/support_tile.xml
index 5f7ced4..053f748 100644
--- a/res/layout/support_tile.xml
+++ b/res/layout/support_tile.xml
@@ -21,7 +21,7 @@
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
- android:minHeight="@dimen/dashboard_tile_minimum_height"
+ android:minHeight="@dimen/support_tile_min_height"
android:orientation="horizontal">
<ImageView
android:id="@android:id/icon"
diff --git a/res/layout/support_tile_spacer.xml b/res/layout/support_tile_spacer.xml
new file mode 100644
index 0000000..95aea0b
--- /dev/null
+++ b/res/layout/support_tile_spacer.xml
@@ -0,0 +1,22 @@
+<?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.
+-->
+
+<Space
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/support_spacer_height"
+ android:background="@color/card_background"/>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 09cd8f0..b2d0570 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -300,4 +300,9 @@
<dimen name="gestures_settings_padding_top_bottom">20dp</dimen>
<dimen name="gestures_play_button_size">36dp</dimen>
<dimen name="gesture_animation_padding">0dp</dimen>
+
+ <!-- Support tile minimum height -->
+ <dimen name="support_tile_min_height">48dp</dimen>
+ <!-- support spacer layout height -->
+ <dimen name="support_spacer_height">8dp</dimen>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 369210f..c6b278c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2133,6 +2133,39 @@
<!-- 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>
+ <!-- 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 -->
<string name="screen_timeout">Sleep</string>
<!-- 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_brightness_level">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_font_size">text size</string>
<string name="keywords_display_cast_screen">project, cast</string>
@@ -7652,29 +7686,32 @@
<!-- Preference title for gesture settings [CHAR LIMIT=25]-->
<string name="gesture_preference_title">Gestures</string>
+ <!-- Preference summary for gesture settings [CHAR LIMIT=NONE]-->
+ <string name="gesture_preference_summary">Quick gestures to control your phone</string>
+
<!-- Title text for double tap power for camera [CHAR LIMIT=60]-->
<string name="double_tap_power_for_camera_title">Jump to Camera</string>
<!-- Summary text for double tap power for camera [CHAR LIMIT=160]-->
- <string name="double_tap_power_for_camera_summary">To quickly open camera, just double-tap the power button. Works from any screen.</string>
+ <string name="double_tap_power_for_camera_summary">To quickly open camera, just double-tap the power button. Works from any screen</string>
<!-- Title text for double twist for camera mode [CHAR LIMIT=60]-->
<string name="double_twist_for_camera_mode_title">Flip camera</string>
<!-- Summary text for double twist for camera mode [CHAR LIMIT=160]-->
- <string name="double_twist_for_camera_mode_summary">To switch between front and back cameras, double-twist.</string>
+ <string name="double_twist_for_camera_mode_summary">To switch between front and back cameras, double-twist</string>
<!-- Title text for ambient display [CHAR LIMIT=60]-->
<string name="ambient_display_title">Quick screen check</string>
<!-- Summary text for ambient display [CHAR LIMIT=160]-->
- <string name="ambient_display_summary">To check your phone without waking it up fully, nudge or pick it up.</string>
+ <string name="ambient_display_summary">To check your phone without waking it up, double-tap the screen or raise the device</string>
<!-- Title text for fingerprint swipe for notifications [CHAR LIMIT=60]-->
<string name="fingerprint_swipe_for_notifications_title">Swipe for notifications</string>
<!-- Summary text for fingerprint swipe for notifications [CHAR LIMIT=160]-->
- <string name="fingerprint_swipe_for_notifications_summary">To check your notifications from any screen, swipe down on the fingerprint sensor.</string>
+ <string name="fingerprint_swipe_for_notifications_summary">To check your notifications from any screen, swipe down on the fingerprint sensor</string>
<!-- Switch text for each gesture setting state -->
<string name="gesture_setting_on">On</string>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index b540c8f..0630b55 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -32,6 +32,12 @@
settings:keywords="@string/keywords_display_auto_brightness"
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
<ListPreference
android:key="night_mode"
@@ -75,7 +81,7 @@
<PreferenceScreen
android:key="doze"
android:title="@string/doze_title"
- android:summary="@string/doze_summary"
+ android:summary="@string/ambient_display_summary"
android:fragment="com.android.settings.gestures.GestureSettings" >
<extra android:name="gesture_scroll_to_preference"
android:value="gesture_pick_up_and_nudge" />
diff --git a/res/xml/gesture_settings.xml b/res/xml/gesture_settings.xml
index 5adc311..78f65a6 100644
--- a/res/xml/gesture_settings.xml
+++ b/res/xml/gesture_settings.xml
@@ -41,6 +41,6 @@
android:key="gesture_pick_up_and_nudge"
android:title="@string/ambient_display_title"
android:summary="@string/ambient_display_summary"
- settings:animation="@raw/gesture_ambient_move_lift"/>
+ settings:animation="@raw/gesture_ambient_tap"/>
</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/night_display_settings.xml b/res/xml/night_display_settings.xml
new file mode 100644
index 0000000..531f606
--- /dev/null
+++ b/res/xml/night_display_settings.xml
@@ -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>
\ No newline at end of file
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index bb10570..2821eb2 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -44,6 +44,7 @@
import android.text.TextUtils;
import android.util.Log;
+import com.android.internal.app.NightDisplayController;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.internal.view.RotationPolicy;
@@ -83,6 +84,7 @@
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_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_CAMERA_GESTURE = "camera_gesture";
private static final String KEY_WALLPAPER = "wallpaper";
@@ -129,6 +131,10 @@
removePreference(KEY_AUTO_BRIGHTNESS);
}
+ if (!NightDisplayController.isAvailable(activity)) {
+ removePreference(KEY_NIGHT_DISPLAY);
+ }
+
if (isLiftToWakeAvailable(activity)) {
mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE);
mLiftToWakePreference.setOnPreferenceChangeListener(this);
@@ -496,6 +502,9 @@
if (!isAutomaticBrightnessAvailable(context.getResources())) {
result.add(KEY_AUTO_BRIGHTNESS);
}
+ if (!NightDisplayController.isAvailable(context)) {
+ result.add(KEY_NIGHT_DISPLAY);
+ }
if (!isLiftToWakeAvailable(context)) {
result.add(KEY_LIFT_TO_WAKE);
}
diff --git a/src/com/android/settings/dashboard/SupportItemAdapter.java b/src/com/android/settings/dashboard/SupportItemAdapter.java
index 4e9153c..52440e9 100644
--- a/src/com/android/settings/dashboard/SupportItemAdapter.java
+++ b/src/com/android/settings/dashboard/SupportItemAdapter.java
@@ -60,6 +60,7 @@
private static final int TYPE_ESCALATION_OPTIONS_OFFLINE =
R.layout.support_offline_escalation_options;
private static final int TYPE_SUPPORT_TILE = R.layout.support_tile;
+ private static final int TYPE_SUPPORT_TILE_SPACER = R.layout.support_tile_spacer;
private static final int TYPE_SIGN_IN_BUTTON = R.layout.support_sign_in_button;
private final Activity mActivity;
@@ -111,6 +112,8 @@
case TYPE_ESCALATION_OPTIONS_OFFLINE:
bindOfflineEscalationOptions(holder, (OfflineEscalationData) data);
break;
+ case TYPE_SUPPORT_TILE_SPACER:
+ break;
default:
bindSupportTile(holder, data);
break;
@@ -219,7 +222,9 @@
private void addOfflineEscalationCards() {
final CharSequence operatingHours;
- if (mSupportFeatureProvider.isAlwaysOperating(PHONE, mSelectedCountry)) {
+ final boolean isPhoneSupportAlwaysOperating =
+ mSupportFeatureProvider.isAlwaysOperating(PHONE, mSelectedCountry);
+ if (isPhoneSupportAlwaysOperating) {
operatingHours = mActivity.getString(R.string.support_escalation_24_7_summary);
} else {
operatingHours = mSupportFeatureProvider.getOperationHours(mActivity,
@@ -231,7 +236,9 @@
mSelectedCountry, true /* isTollFree */))
.setTolledPhone(mSupportFeatureProvider.getSupportPhones(
mSelectedCountry, false /* isTollFree */))
- .setTileTitle(R.string.support_escalation_title)
+ .setTileTitle(isPhoneSupportAlwaysOperating
+ ? R.string.support_escalation_24_7_title
+ : R.string.support_escalation_title)
.setTileSummary(operatingHours)
.build());
}
@@ -246,6 +253,7 @@
}
private void addMoreHelpItems() {
+ mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE_SPACER).build());
mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE)
.setIcon(R.drawable.ic_help_24dp)
.setTileTitle(R.string.support_help_feedback_title)
diff --git a/src/com/android/settings/display/NightDisplayPreference.java b/src/com/android/settings/display/NightDisplayPreference.java
new file mode 100644
index 0000000..73ecf49
--- /dev/null
+++ b/src/com/android/settings/display/NightDisplayPreference.java
@@ -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();
+ }
+}
diff --git a/src/com/android/settings/display/NightDisplaySettings.java b/src/com/android/settings/display/NightDisplaySettings.java
new file mode 100644
index 0000000..ecba527
--- /dev/null
+++ b/src/com/android/settings/display/NightDisplaySettings.java
@@ -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;
+ }
+}