summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAdrianDC <radian.dc@gmail.com>2015-08-18 19:33:18 +0200
committerSteve Kondik <steve@cyngn.com>2015-10-28 13:30:30 -0700
commit89d8d436e156a3894d6bdee88607c6d69cbc243a (patch)
treed54004e0a28777024eaa4765e64e617337684c2c /packages
parent3d8260d65d28a22f2762713fdabf98ca7a81e350 (diff)
downloadframeworks_base-89d8d436e156a3894d6bdee88607c6d69cbc243a.zip
frameworks_base-89d8d436e156a3894d6bdee88607c6d69cbc243a.tar.gz
frameworks_base-89d8d436e156a3894d6bdee88607c6d69cbc243a.tar.bz2
LEDs Brightness [2/2]: Lights notifications brightness support
Implement the support of an overall brightness control for the LEDs. The setting is deactivated by default and will be ignored by the unimplemented phones. Current LibLights will simply not use the new variable. Changes includes : frameworks/base packages/Apps/Settings Change-Id: I1c0de01b1c6a2a2cf1432028a2e69f90b2373b2c Signed-off-by: AdrianDC <radian.dc@gmail.com>
Diffstat (limited to 'packages')
-rw-r--r--packages/SettingsProvider/res/values/defaults.xml4
-rw-r--r--packages/SystemUI/AndroidManifest.xml14
-rw-r--r--packages/SystemUI/res/layout/quick_settings_notification_brightness_dialog.xml31
-rw-r--r--packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessController.java223
-rw-r--r--packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessDialog.java75
5 files changed, 347 insertions, 0 deletions
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index a2d9459..d6e2c92 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -66,6 +66,10 @@
pending notification -->
<bool name="def_notification_pulse">true</bool>
+ <!-- Default value for the notification LEDs brightness
+ on devices equiped with configurable LED controller -->
+ <integer name="def_notification_brightness_level">255</integer>
+
<bool name="def_mount_play_notification_snd">true</bool>
<bool name="def_mount_ums_autostart">false</bool>
<bool name="def_mount_ums_prompt">true</bool>
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index b2f60f8..fd194c5 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -400,6 +400,20 @@
</intent-filter>
</activity>
+ <activity
+ android:name=".settings.NotificationBrightnessDialog"
+ android:label="@string/quick_settings_brightness_dialog_title"
+ android:theme="@android:style/Theme.DeviceDefault.Dialog"
+ android:finishOnCloseSystemDialogs="true"
+ android:launchMode="singleInstance"
+ android:excludeFromRecents="true"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.SHOW_NOTIFICATION_BRIGHTNESS_DIALOG" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
<!-- Doze with notifications, run in main sysui process for every user -->
<service
android:name=".doze.DozeService"
diff --git a/packages/SystemUI/res/layout/quick_settings_notification_brightness_dialog.xml b/packages/SystemUI/res/layout/quick_settings_notification_brightness_dialog.xml
new file mode 100644
index 0000000..561eff6
--- /dev/null
+++ b/packages/SystemUI/res/layout/quick_settings_notification_brightness_dialog.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012-2015 The CyanogenMod 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"
+
+ style="@style/BrightnessDialogContainer">
+
+ <com.android.systemui.settings.ToggleSlider
+ android:id="@+id/notification_brightness_slider"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_weight="1"
+ systemui:text="" />
+
+</LinearLayout>
diff --git a/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessController.java
new file mode 100644
index 0000000..ef1356b
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessController.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2012-2015 The CyanogenMod 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.settings;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.UserHandle;
+import android.provider.Settings;
+
+import java.lang.Exception;
+import java.util.ArrayList;
+
+public class NotificationBrightnessController implements ToggleSlider.Listener {
+ private static final String TAG = "StatusBar.NotificationBrightnessController";
+
+ public static final int LIGHT_BRIGHTNESS_MINIMUM = 1;
+ public static final int LIGHT_BRIGHTNESS_MAXIMUM = 255;
+
+ private int mCurrentBrightness;
+ private final int mMinimumBrightness;
+ private final int mMaximumBrightness;
+
+ private final Context mContext;
+ private final ToggleSlider mControl;
+ private final CurrentUserTracker mUserTracker;
+ private final Handler mHandler;
+ private final NotificationBrightnessObserver mBrightnessObserver;
+
+ private ArrayList<BrightnessStateChangeCallback> mChangeCallbacks =
+ new ArrayList<BrightnessStateChangeCallback>();
+
+ private boolean mListening;
+ private boolean mExternalChange;
+
+ private boolean mNotificationAllow;
+ private final Bundle mNotificationBundle;
+ private final Notification.Builder mNotificationBuilder;
+ private NotificationManager mNotificationManager;
+
+ public interface BrightnessStateChangeCallback {
+ public void onBrightnessLevelChanged();
+ }
+
+ /** ContentObserver to watch brightness **/
+ private class NotificationBrightnessObserver extends ContentObserver {
+
+ private final Uri NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_URI =
+ Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL);
+
+ public NotificationBrightnessObserver(Handler handler) {
+ super(handler);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ onChange(selfChange, null);
+ }
+
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ if (selfChange) return;
+ try {
+ mExternalChange = true;
+ updateSlider();
+ for (BrightnessStateChangeCallback cb : mChangeCallbacks) {
+ cb.onBrightnessLevelChanged();
+ }
+ } finally {
+ mExternalChange = false;
+ }
+ }
+
+ public void startObserving() {
+ final ContentResolver cr = mContext.getContentResolver();
+ cr.unregisterContentObserver(this);
+ cr.registerContentObserver(
+ NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_URI,
+ false, this, UserHandle.USER_ALL);
+ }
+
+ public void stopObserving() {
+ final ContentResolver cr = mContext.getContentResolver();
+ cr.unregisterContentObserver(this);
+ }
+
+ }
+
+ public NotificationBrightnessController(Context context, ToggleSlider control) {
+ mContext = context;
+ mControl = control;
+ mHandler = new Handler();
+ mUserTracker = new CurrentUserTracker(mContext) {
+ @Override
+ public void onUserSwitched(int newUserId) {
+ updateSlider();
+ }
+ };
+ mBrightnessObserver = new NotificationBrightnessObserver(mHandler);
+
+ mMinimumBrightness = LIGHT_BRIGHTNESS_MINIMUM;
+ mMaximumBrightness = LIGHT_BRIGHTNESS_MAXIMUM;
+ mCurrentBrightness = LIGHT_BRIGHTNESS_MAXIMUM;
+
+ mNotificationManager =
+ (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+
+ mNotificationBundle = new Bundle();
+ mNotificationBuilder = new Notification.Builder(mContext);
+
+ mNotificationBundle.putBoolean(Notification.EXTRA_FORCE_SHOW_LIGHTS, true);
+ mNotificationBuilder.setExtras(mNotificationBundle);
+ }
+
+ public void addStateChangedCallback(BrightnessStateChangeCallback cb) {
+ mChangeCallbacks.add(cb);
+ }
+
+ public boolean removeStateChangedCallback(BrightnessStateChangeCallback cb) {
+ return mChangeCallbacks.remove(cb);
+ }
+
+ @Override
+ public void onInit(ToggleSlider control) {
+ // Do nothing
+ }
+
+ public void registerCallbacks() {
+ if (mListening) {
+ return;
+ }
+
+ // Update the slider and mode before attaching the listener so we don't
+ // receive the onChanged notifications for the initial values.
+ mNotificationAllow = true;
+ updateSlider();
+
+ mBrightnessObserver.startObserving();
+ mUserTracker.startTracking();
+
+ mControl.setOnChangedListener(this);
+ mListening = true;
+ }
+
+ /** Unregister all call backs, both to and from the controller */
+ public void unregisterCallbacks() {
+ if (!mListening) {
+ return;
+ }
+
+ mNotificationAllow = false;
+ mBrightnessObserver.stopObserving();
+ mUserTracker.stopTracking();
+ mControl.setOnChangedListener(null);
+ mNotificationManager.cancel(1);
+ mListening = false;
+
+ Settings.System.putIntForUser(mContext.getContentResolver(),
+ Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
+ mCurrentBrightness, UserHandle.USER_CURRENT);
+ }
+
+ @Override
+ public void onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value,
+ boolean stopTracking) {
+ if (mExternalChange) return;
+
+ mCurrentBrightness = value + mMinimumBrightness;
+ updateNotification();
+
+ for (BrightnessStateChangeCallback cb : mChangeCallbacks) {
+ cb.onBrightnessLevelChanged();
+ }
+ }
+
+ /** Fetch the brightness from the system settings and update the slider */
+ private void updateSlider() {
+ mCurrentBrightness = Settings.System.getIntForUser(mContext.getContentResolver(),
+ Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
+ mMaximumBrightness, UserHandle.USER_CURRENT);
+
+ Settings.System.putIntForUser(mContext.getContentResolver(),
+ Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
+ mMaximumBrightness, UserHandle.USER_CURRENT);
+
+ mControl.setMax(mMaximumBrightness - mMinimumBrightness);
+ mControl.setValue(mCurrentBrightness - mMinimumBrightness);
+ updateNotification();
+ }
+
+ /** Fetch the brightness from the system settings and update the slider */
+ private void updateNotification() {
+ if (mNotificationAllow) {
+ // Instead of canceling the notification, force it to update with the color.
+ int notificationColor = mCurrentBrightness +
+ (mCurrentBrightness << 8) +
+ (mCurrentBrightness << 16);
+ mNotificationBuilder.setLights(notificationColor, 1, 0);
+ mNotificationManager.notify(1, mNotificationBuilder.build());
+ }
+ }
+
+}
diff --git a/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessDialog.java b/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessDialog.java
new file mode 100644
index 0000000..dae4e4e
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessDialog.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012-2015 The CyanogenMod 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.settings;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.Gravity;
+import android.view.KeyEvent;
+import android.view.Window;
+import android.view.WindowManager;
+
+import com.android.systemui.R;
+
+/** A dialog that provides controls for adjusting the notifications brightness. */
+public class NotificationBrightnessDialog extends Activity {
+
+ private NotificationBrightnessController mNotificationBrightnessController;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final Window window = getWindow();
+
+ window.setGravity(Gravity.TOP);
+ window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
+ window.requestFeature(Window.FEATURE_NO_TITLE);
+
+ setContentView(R.layout.quick_settings_notification_brightness_dialog);
+
+ final ToggleSlider slider = (ToggleSlider) findViewById(R.id.notification_brightness_slider);
+ mNotificationBrightnessController = new NotificationBrightnessController(this, slider);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mNotificationBrightnessController.registerCallbacks();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mNotificationBrightnessController.unregisterCallbacks();
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
+ || keyCode == KeyEvent.KEYCODE_VOLUME_UP
+ || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
+ finish();
+ }
+
+ return super.onKeyDown(keyCode, event);
+ }
+}