sdk: notification: allow forcing notification color for preview
Parts uses notifications to preview custom notification lights. Since Android O we got NotificationChannels and the internal API uses the color values of the channel instead of the color set at the notification. To prevent unexpected breakage in future, introduce a flag to be used for providing preview colors in a bundle to force said color. Also introduce flags to control the ON and OFF duration. Change-Id: Ifbb7995a19d95b6ddb2627c1b14dd201f9dc5430 Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
This commit is contained in:
committed by
Michael Bestas
parent
952ef00123
commit
da392f9195
@@ -33,4 +33,26 @@ public class LineageNotification {
|
||||
* a specific light brightness.
|
||||
*/
|
||||
public static final String EXTRA_FORCE_LIGHT_BRIGHTNESS = "lineage.forceLightBrightness";
|
||||
|
||||
/**
|
||||
* Used by light picker in Settings to force
|
||||
* a specific light color.
|
||||
*/
|
||||
public static final String EXTRA_FORCE_COLOR = "lineage.forceColor";
|
||||
|
||||
/**
|
||||
* Used by light picker in Settings to force
|
||||
* a specific light on duration.
|
||||
*
|
||||
* Value must be greater than or equal to 0.
|
||||
*/
|
||||
public static final String EXTRA_FORCE_LIGHT_ON_MS = "lineage.forceLightOnMs";
|
||||
|
||||
/**
|
||||
* Used by light picker in Settings to force
|
||||
* a specific light off duration.
|
||||
*
|
||||
* Value must be greater than or equal to 0.
|
||||
*/
|
||||
public static final String EXTRA_FORCE_LIGHT_OFF_MS = "lineage.forceLightOffMs";
|
||||
}
|
||||
|
||||
@@ -222,6 +222,27 @@ public final class LineageNotificationLights {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getForcedColor(Notification n) {
|
||||
if (n.extras != null) {
|
||||
return n.extras.getInt(LineageNotification.EXTRA_FORCE_COLOR, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getForcedLightOnMs(Notification n) {
|
||||
if (n.extras != null) {
|
||||
return n.extras.getInt(LineageNotification.EXTRA_FORCE_LIGHT_ON_MS, -1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getForcedLightOffMs(Notification n) {
|
||||
if (n.extras != null) {
|
||||
return n.extras.getInt(LineageNotification.EXTRA_FORCE_LIGHT_OFF_MS, -1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void setZenMode(int zenMode) {
|
||||
mZenMode = zenMode;
|
||||
mLedUpdater.update();
|
||||
@@ -234,6 +255,9 @@ public final class LineageNotificationLights {
|
||||
boolean screenActive, int suppressedEffects) {
|
||||
final boolean forcedOn = isForcedOn(n);
|
||||
final int forcedBrightness = getForcedBrightness(n);
|
||||
final int forcedColor = getForcedColor(n);
|
||||
final int forcedLightOnMs = getForcedLightOnMs(n);
|
||||
final int forcedLightOffMs = getForcedLightOffMs(n);
|
||||
final boolean suppressScreenOff =
|
||||
(suppressedEffects & SUPPRESSED_EFFECT_SCREEN_OFF) != 0;
|
||||
final boolean suppressScreenOn =
|
||||
@@ -248,6 +272,9 @@ public final class LineageNotificationLights {
|
||||
+ " suppressedEffects=" + suppressedEffects
|
||||
+ " forcedOn=" + forcedOn
|
||||
+ " forcedBrightness=" + forcedBrightness
|
||||
+ " forcedColor=" + forcedColor
|
||||
+ " forcedLightOnMs=" + forcedLightOnMs
|
||||
+ " forcedLightOffMs=" + forcedLightOffMs
|
||||
+ " suppressScreenOff=" + suppressScreenOff
|
||||
+ " suppressScreenOn=" + suppressScreenOn
|
||||
+ " mCanAdjustBrightness=" + mCanAdjustBrightness
|
||||
@@ -318,6 +345,18 @@ public final class LineageNotificationLights {
|
||||
ledValues.setOnMs(mDefaultNotificationLedOn);
|
||||
ledValues.setOffMs(mDefaultNotificationLedOff);
|
||||
}
|
||||
|
||||
// Use forced color and durations, if specified
|
||||
if (forcedColor != 0) {
|
||||
ledValues.setColor(forcedColor);
|
||||
}
|
||||
if (forcedLightOnMs >= 0) {
|
||||
ledValues.setOnMs(forcedLightOnMs);
|
||||
}
|
||||
if (forcedLightOffMs >= 0) {
|
||||
ledValues.setOffMs(forcedLightOffMs);
|
||||
}
|
||||
|
||||
// If lights HAL does not support adjustable notification brightness then
|
||||
// scale color value here instead.
|
||||
if (mCanAdjustBrightness && !mHALAdjustableBrightness) {
|
||||
|
||||
Reference in New Issue
Block a user