Skip to content
Snippets Groups Projects
Commit 633792e2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add time until Night Light is on/off as secondary label"

parents ef5af2b6 785f3d7f
No related branches found
No related tags found
No related merge requests found
......@@ -775,6 +775,15 @@
<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: Secondary text for when the Night Light will be enabled at sunset. [CHAR LIMIT=20] -->
<string name="quick_settings_night_secondary_label_on_at_sunset">On at sunset</string>
<!-- QuickSettings: Secondary text for when the Night Light will be on until sunrise. [CHAR LIMIT=20] -->
<string name="quick_settings_night_secondary_label_until_sunrise">Until sunrise</string>
<!-- QuickSettings: Secondary text for when the Night Light will be enabled at some user-selected time. [CHAR LIMIT=20] -->
<string name="quick_settings_night_secondary_label_on_at">On at <xliff:g id="time" example="10 pm">%s</xliff:g></string>
<!-- QuickSettings: Secondary text for when the Night Light will be on until some user-selected time. [CHAR LIMIT=20] -->
<string name="quick_settings_night_secondary_label_until">Until <xliff:g id="time" example="7 am">%s</xliff:g></string>
<!-- QuickSettings: NFC tile [CHAR LIMIT=NONE] -->
<string name="quick_settings_nfc_label">NFC</string>
<!-- QuickSettings: NFC (off) [CHAR LIMIT=NONE] -->
......
......@@ -29,7 +29,6 @@ import android.widget.TextView;
import com.android.systemui.FontSizeUtils;
import com.android.systemui.R;
import com.android.systemui.R.id;
import com.android.systemui.plugins.qs.QSIconView;
import com.android.systemui.plugins.qs.QSTile;
......
......@@ -16,6 +16,7 @@
package com.android.systemui.qs.tiles;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.content.Intent;
import android.provider.Settings;
......@@ -29,9 +30,17 @@ import com.android.systemui.qs.QSHost;
import com.android.systemui.plugins.qs.QSTile.BooleanState;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import java.time.format.DateTimeFormatter;
public class NightDisplayTile extends QSTileImpl<BooleanState>
implements ColorDisplayController.Callback {
/**
* Pattern for {@link java.time.format.DateTimeFormatter} used to approximate the time to the
* nearest hour and add on the AM/PM indicator.
*/
private static final String APPROXIMATE_HOUR_DATE_TIME_PATTERN = "H a";
private ColorDisplayController mController;
private boolean mIsListening;
......@@ -74,13 +83,49 @@ public class NightDisplayTile extends QSTileImpl<BooleanState>
@Override
protected void handleUpdateState(BooleanState state, Object arg) {
final boolean isActivated = mController.isActivated();
state.value = isActivated;
state.value = mController.isActivated();
state.label = state.contentDescription =
mContext.getString(R.string.quick_settings_night_display_label);
state.icon = ResourceIcon.get(R.drawable.ic_qs_night_display_on);
state.expandedAccessibilityClassName = Switch.class.getName();
state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
state.secondaryLabel = getSecondaryLabel(state.value);
}
/**
* Returns a {@link String} for the secondary label that reflects when the light will be turned
* on or off based on the current auto mode and night light activated status.
*/
@Nullable
private String getSecondaryLabel(boolean isNightLightActivated) {
switch(mController.getAutoMode()) {
case ColorDisplayController.AUTO_MODE_TWILIGHT:
// Auto mode related to sunrise & sunset. If the light is on, it's guaranteed to be
// turned off at sunrise. If it's off, it's guaranteed to be turned on at sunset.
return isNightLightActivated
? mContext.getString(
R.string.quick_settings_night_secondary_label_until_sunrise)
: mContext.getString(
R.string.quick_settings_night_secondary_label_on_at_sunset);
case ColorDisplayController.AUTO_MODE_CUSTOM:
// User-specified time, approximated to the nearest hour.
return isNightLightActivated
? mContext.getString(
R.string.quick_settings_night_secondary_label_until,
mController.getCustomEndTime().format(
DateTimeFormatter.ofPattern(
APPROXIMATE_HOUR_DATE_TIME_PATTERN)))
: mContext.getString(
R.string.quick_settings_night_secondary_label_on_at,
mController.getCustomStartTime().format(
DateTimeFormatter.ofPattern(
APPROXIMATE_HOUR_DATE_TIME_PATTERN)));
default:
// No secondary label when auto mode is disabled.
return null;
}
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment