From 137909005cd3fab785539dc1232b67d80007d8fb Mon Sep 17 00:00:00 2001 From: Justin Klaassen Date: Tue, 21 Jun 2016 20:28:12 -0700 Subject: [PATCH] Add Night display QSTile Bug: 28615069 Bug: 29619615 Change-Id: Ie23bd1ed9266941682eceb5f2086201bf02af765 --- .../res/drawable/ic_qs_night_display_off.xml | 27 ++++++ .../res/drawable/ic_qs_night_display_on.xml | 26 ++++++ packages/SystemUI/res/values/strings.xml | 6 ++ .../systemui/qs/tiles/NightDisplayTile.java | 99 ++++++++++++++++++++++ .../systemui/statusbar/phone/QSTileHost.java | 2 + proto/src/metrics_constants.proto | 6 ++ 6 files changed, 166 insertions(+) create mode 100644 packages/SystemUI/res/drawable/ic_qs_night_display_off.xml create mode 100644 packages/SystemUI/res/drawable/ic_qs_night_display_on.xml create mode 100644 packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java diff --git a/packages/SystemUI/res/drawable/ic_qs_night_display_off.xml b/packages/SystemUI/res/drawable/ic_qs_night_display_off.xml new file mode 100644 index 000000000000..778ccbc5f4a4 --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_night_display_off.xml @@ -0,0 +1,27 @@ + + + + + + diff --git a/packages/SystemUI/res/drawable/ic_qs_night_display_on.xml b/packages/SystemUI/res/drawable/ic_qs_night_display_on.xml new file mode 100644 index 000000000000..aaca663e59e9 --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_night_display_on.xml @@ -0,0 +1,26 @@ + + + + + + diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 3ed071177de8..5324968969aa 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -752,6 +752,12 @@ %s warning Work mode + + Night Light + + Night Light on, tap to turn off + + Night Light off, tap to turn on No recent items diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java new file mode 100644 index 000000000000..9a3549eb6a75 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java @@ -0,0 +1,99 @@ +/* + * 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.systemui.qs.tiles; + +import android.content.Intent; +import android.provider.Settings; +import android.widget.Switch; + +import com.android.internal.app.NightDisplayController; +import com.android.internal.logging.MetricsLogger; +import com.android.internal.logging.MetricsProto.MetricsEvent; +import com.android.systemui.R; +import com.android.systemui.qs.QSTile; + +public class NightDisplayTile extends QSTile + implements NightDisplayController.Callback { + + private final NightDisplayController mController; + + public NightDisplayTile(Host host) { + super(host); + mController = new NightDisplayController(mContext); + } + + @Override + public boolean isAvailable() { + return NightDisplayController.isAvailable(mContext); + } + + @Override + public BooleanState newTileState() { + return new BooleanState(); + } + + @Override + protected void handleClick() { + final boolean activated = !mState.value; + MetricsLogger.action(mContext, getMetricsCategory(), activated); + mController.setActivated(activated); + } + + @Override + protected void handleUpdateState(BooleanState state, Object arg) { + final boolean isActivated = mController.isActivated(); + state.value = isActivated; + state.label = mContext.getString(R.string.quick_settings_night_display_label); + state.icon = ResourceIcon.get(isActivated ? R.drawable.ic_qs_night_display_on + : R.drawable.ic_qs_night_display_off); + state.contentDescription = mContext.getString(isActivated + ? R.string.quick_settings_night_display_summary_on + : R.string.quick_settings_night_display_summary_off); + state.minimalAccessibilityClassName = state.expandedAccessibilityClassName + = Switch.class.getName(); + } + + @Override + public int getMetricsCategory() { + return MetricsEvent.QS_NIGHT_DISPLAY; + } + + @Override + public Intent getLongClickIntent() { + return new Intent(Settings.ACTION_DISPLAY_SETTINGS); + } + + @Override + protected void setListening(boolean listening) { + if (listening) { + mController.setListener(this); + refreshState(); + } else { + mController.setListener(null); + } + } + + @Override + public CharSequence getTileLabel() { + return mContext.getString(R.string.quick_settings_night_display_label); + } + + @Override + public void onActivated(boolean activated) { + refreshState(); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java index ca7f9051f56d..15e235dd4d5f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java @@ -52,6 +52,7 @@ import com.android.systemui.qs.tiles.FlashlightTile; import com.android.systemui.qs.tiles.HotspotTile; import com.android.systemui.qs.tiles.IntentTile; import com.android.systemui.qs.tiles.LocationTile; +import com.android.systemui.qs.tiles.NightDisplayTile; import com.android.systemui.qs.tiles.RotationLockTile; import com.android.systemui.qs.tiles.UserTile; import com.android.systemui.qs.tiles.WifiTile; @@ -440,6 +441,7 @@ public class QSTileHost implements QSTile.Host, Tunable { else if (tileSpec.equals("user")) return new UserTile(this); else if (tileSpec.equals("battery")) return new BatteryTile(this); else if (tileSpec.equals("saver")) return new DataSaverTile(this); + else if (tileSpec.equals("night")) return new NightDisplayTile(this); // Intent tiles. else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec); else if (tileSpec.startsWith(CustomTile.PREFIX)) return CustomTile.create(this,tileSpec); diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto index 966d0ec44835..ba59c2f0192a 100644 --- a/proto/src/metrics_constants.proto +++ b/proto/src/metrics_constants.proto @@ -2188,6 +2188,12 @@ message MetricsEvent { // Settings launched from collapsed quick settings. ACTION_QS_COLLAPSED_SETTINGS_LAUNCH = 490; + // OPEN: QS Night mode tile shown + // ACTION: QS Night mode tile tapped + // SUBTYPE: 0 is off, 1 is on + // CATEGORY: QUICK_SETTINGS + QS_NIGHT_DISPLAY = 491; + // ---- End N-MR1 Constants, all N-MR1 constants go above this line ---- // Add new aosp constants above this line. // END OF AOSP CONSTANTS -- 2.11.0