aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Martinz <amartinz@shiftphones.com>2019-03-19 19:02:38 +0100
committerMichael Bestas <mkbestas@lineageos.org>2019-04-12 01:28:27 +0200
commitda392f91951cb2e57bf2f66bfcbcc4816432dc67 (patch)
tree37afd2e6d9b8768688e9e5259810b95ca8536596
parent952ef00123d9a3cffee5d71924e997edf2826a8f (diff)
downloadlineage-sdk-da392f91951cb2e57bf2f66bfcbcc4816432dc67.tar.gz
lineage-sdk-da392f91951cb2e57bf2f66bfcbcc4816432dc67.tar.bz2
lineage-sdk-da392f91951cb2e57bf2f66bfcbcc4816432dc67.zip
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>
-rw-r--r--sdk/src/java/org/lineageos/internal/notification/LineageNotification.java22
-rw-r--r--sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java39
2 files changed, 61 insertions, 0 deletions
diff --git a/sdk/src/java/org/lineageos/internal/notification/LineageNotification.java b/sdk/src/java/org/lineageos/internal/notification/LineageNotification.java
index f71c6a7a..68462521 100644
--- a/sdk/src/java/org/lineageos/internal/notification/LineageNotification.java
+++ b/sdk/src/java/org/lineageos/internal/notification/LineageNotification.java
@@ -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";
}
diff --git a/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java b/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java
index 75a325fb..283cefc1 100644
--- a/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java
+++ b/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java
@@ -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) {