Add Night display QSTile

Bug: 28615069
Bug: 29619615
Change-Id: Ie23bd1ed9266941682eceb5f2086201bf02af765
This commit is contained in:
Justin Klaassen
2016-06-21 20:28:12 -07:00
parent f90128c68d
commit 137909005c
6 changed files with 166 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<!--
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="64dp"
android:height="64dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:alpha="0.3">
<path
android:fillColor="#FFF"
android:pathData="M6,12c0,5.5,4.5,10,10,10c1,0,2-0.2,3-0.5c-4.1-1.3-7-5.1-7-9.5s2.9-8.3,7-9.5C18.1,2.2,17.1,2,16,2C10.5,2,6,6.5,6,12z" />
</vector>

View File

@@ -0,0 +1,26 @@
<!--
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="64dp"
android:height="64dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFF"
android:pathData="M6,12c0,5.5,4.5,10,10,10c1,0,2-0.2,3-0.5c-4.1-1.3-7-5.1-7-9.5s2.9-8.3,7-9.5C18.1,2.2,17.1,2,16,2C10.5,2,6,6.5,6,12z" />
</vector>

View File

@@ -752,6 +752,12 @@
<string name="quick_settings_cellular_detail_data_warning"><xliff:g id="data_limit" example="2.0 GB">%s</xliff:g> warning</string>
<!-- QuickSettings: Work mode [CHAR LIMIT=NONE] -->
<string name="quick_settings_work_mode_label">Work mode</string>
<!-- QuickSettings: Label for the toggle to activate Night display (renamed "Night Light" with title caps). [CHAR LIMIT=20] -->
<string name="quick_settings_night_display_label">Night Light</string>
<!-- QuickSettings: Summary for the toggle to deactivate Night display when it's on (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->
<string name="quick_settings_night_display_summary_on">Night Light on, tap to turn off</string>
<!-- QuickSettings: Label for the toggle to activate Night display when it's off (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->
<string name="quick_settings_night_display_summary_off">Night Light off, tap to turn on</string>
<!-- Recents: The empty recents string. [CHAR LIMIT=NONE] -->
<string name="recents_empty_message">No recent items</string>

View File

@@ -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<QSTile.BooleanState>
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();
}
}

View File

@@ -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);

View File

@@ -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