From 14683b949d985fb2ed072c392a331e8812b18bd7 Mon Sep 17 00:00:00 2001 From: Petr Sedlacek Date: Mon, 8 Feb 2016 22:26:25 +0100 Subject: [PATCH] cmsdk: Add notification light setting to system profiles (1/2) Change-Id: Ic6705792948c5393fc5ca9b207bc250b252e66da --- src/java/cyanogenmod/app/Profile.java | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/java/cyanogenmod/app/Profile.java b/src/java/cyanogenmod/app/Profile.java index 908110a..b8406e6 100755 --- a/src/java/cyanogenmod/app/Profile.java +++ b/src/java/cyanogenmod/app/Profile.java @@ -94,6 +94,8 @@ public final class Profile implements Parcelable, Comparable { private int mDozeMode = DozeMode.DEFAULT; + private int mNotificationLightMode = NotificationLightMode.DEFAULT; + /** * Lock modes of a device */ @@ -130,6 +132,18 @@ public final class Profile implements Parcelable, Comparable { public static final int DISABLE = 2; } + /** + * Notification light modes available on a device + */ + public static class NotificationLightMode { + /** Represents a default Notification light mode (user choice) */ + public static final int DEFAULT = 0; + /** Represents an enabled Notification light mode */ + public static final int ENABLE = 1; + /** Represents a disabled Notification light mode */ + public static final int DISABLE = 2; + } + /** * Available trigger types on the device, usually hardware */ @@ -621,6 +635,9 @@ public final class Profile implements Parcelable, Comparable { dest.writeInt(mExpandedDesktopMode); dest.writeInt(mDozeMode); + // === ELDERBERRY === + dest.writeInt(mNotificationLightMode); + // Go back and write size int parcelableSize = dest.dataPosition() - startPosition; dest.setDataPosition(sizePosition); @@ -695,6 +712,9 @@ public final class Profile implements Parcelable, Comparable { mExpandedDesktopMode = in.readInt(); mDozeMode = in.readInt(); } + if (parcelableVersion >= Build.CM_VERSION_CODES.ELDERBERRY) { + mNotificationLightMode = in.readInt(); + } in.setDataPosition(startPosition + parcelableSize); } @@ -883,6 +903,28 @@ public final class Profile implements Parcelable, Comparable { mDirty = true; } + /** + * Get the {@link NotificationLightMode} associated with the {@link Profile} + * @return + */ + public int getNotificationLightMode() { + return mNotificationLightMode; + } + + /** + * Set the {@link NotificationLightMode} associated with the {@link Profile} + * @return + */ + public void setNotificationLightMode(int notificationLightMode) { + if (notificationLightMode < NotificationLightMode.DEFAULT + || notificationLightMode > NotificationLightMode.DISABLE) { + mNotificationLightMode = NotificationLightMode.DEFAULT; + } else { + mNotificationLightMode = notificationLightMode; + } + mDirty = true; + } + /** * Get the {@link AirplaneModeSettings} associated with the {@link Profile} * @return @@ -993,6 +1035,10 @@ public final class Profile implements Parcelable, Comparable { builder.append(mDozeMode); builder.append("\n"); + builder.append(""); + builder.append(mNotificationLightMode); + builder.append("\n"); + mAirplaneMode.getXmlString(builder, context); mBrightness.getXmlString(builder, context); @@ -1141,6 +1187,9 @@ public final class Profile implements Parcelable, Comparable { if (name.equals("doze-mode")) { profile.setDozeMode(Integer.valueOf(xpp.nextText())); } + if (name.equals("notification-light-mode")) { + profile.setNotificationLightMode(Integer.valueOf(xpp.nextText())); + } if (name.equals("profileGroup")) { ProfileGroup pg = ProfileGroup.fromXml(xpp, context); profile.addProfileGroup(pg); @@ -1213,6 +1262,14 @@ public final class Profile implements Parcelable, Comparable { mDozeMode == DozeMode.ENABLE ? 1 : 0, UserHandle.USER_CURRENT); } + + // Set notification light mode + if (mNotificationLightMode != NotificationLightMode.DEFAULT) { + Settings.System.putIntForUser(context.getContentResolver(), + Settings.System.NOTIFICATION_LIGHT_PULSE, + mNotificationLightMode == NotificationLightMode.ENABLE ? 1 : 0, + UserHandle.USER_CURRENT); + } } /**