Browse files

Merge "Settings: Notification light(LED) settings" into ics

  • Loading branch information...
2 parents 9a2a535 + ee032ae commit 7c74ecd1a3c847f51b33d719d191cb378451e568 @maniac103 maniac103 committed with Gerrit Code Review Apr 16, 2012
View
2 AndroidManifest.xml
@@ -1388,6 +1388,8 @@
<activity android:name=".ApnEditor" />
+ <activity android:name=".notificationlight.NotificationLightSettings" />
+
<activity android:name="Settings$AnonymousStatsActivity"
android:label="@string/anonymous_statistics_title"
android:configChanges="orientation|keyboardHidden|screenSize"
View
109 res/layout/dialog_light_settings.xml
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2010 Daniel Nilsson
+ Copyright (C) 2012 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. -->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <com.android.settings.notificationlight.ColorPickerView
+ android:id="@+id/color_picker_view"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_marginLeft="10dp"
+ android:layout_marginRight="10dp" />
+
+ <LinearLayout
+ android:id="@+id/color_panel_view"
+ android:layout_width="fill_parent"
+ android:layout_height="40dp"
+ android:layout_alignLeft="@id/color_picker_view"
+ android:layout_alignRight="@id/color_picker_view"
+ android:layout_below="@id/color_picker_view"
+ android:layout_marginBottom="4dp"
+ android:layout_marginTop="4dp"
+ android:orientation="horizontal" >
+
+ <com.android.settings.notificationlight.ColorPanelView
+ android:id="@+id/old_color_panel"
+ android:layout_width="0px"
+ android:layout_height="fill_parent"
+ android:layout_weight="0.5" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_marginLeft="10dp"
+ android:layout_marginRight="10dp"
+ android:gravity="center"
+ android:text="@string/picker_arrow"
+ android:textColor="#ffffff"
+ android:textSize="20sp" />
+
+ <com.android.settings.notificationlight.ColorPanelView
+ android:id="@+id/new_color_panel"
+ android:layout_width="0px"
+ android:layout_height="fill_parent"
+ android:layout_weight="0.5" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/speed_title_view"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/color_panel_view"
+ android:layout_marginLeft="10dp"
+ android:layout_marginRight="10dp"
+ android:layout_marginTop="4dp"
+ android:orientation="vertical" >
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="2dp"
+ android:background="@android:drawable/divider_horizontal_dark" />
+
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="4dp"
+ android:text="@string/pulse_speed_title"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingBottom="4dip" >
+
+ <Spinner
+ android:id="@+id/on_spinner"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" />
+
+ <View
+ android:layout_width="8dip"
+ android:layout_height="fill_parent" />
+
+ <Spinner
+ android:id="@+id/off_spinner"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" />
+ </LinearLayout>
+ </LinearLayout>
+
+</RelativeLayout>
View
71 res/layout/preference_application_light.xml
@@ -0,0 +1,71 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/app_light_pref"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:clickable="true"
+ android:focusable="true"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:gravity="center_vertical"
+ android:background="?android:attr/selectableItemBackground" >
+
+ <ImageView
+ android:id="@+android:id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="4dip"
+ android:maxWidth="36dip"
+ android:maxHeight="36dip"
+ android:adjustViewBounds="true"
+ android:layout_gravity="center" />
+
+ <RelativeLayout
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_margin="4dip"
+ android:layout_weight="1">
+
+ <TextView android:id="@+android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal" />
+
+ <TextView android:id="@+android:id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@android:id/title"
+ android:layout_alignLeft="@android:id/title"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="?android:attr/textColorSecondary"
+ android:maxLines="1" />
+ </RelativeLayout>
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/textViewTimeOnValue"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ <TextView
+ android:id="@+id/textViewTimeOffValue"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+ </LinearLayout>
+
+ <ImageView
+ android:id="@+id/light_color"
+ android:layout_width="32dip"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center" />
+
+</LinearLayout>
View
2 res/layout/preference_icon.xml
@@ -59,4 +59,4 @@
</RelativeLayout>
-</LinearLayout>
+</LinearLayout>
View
11 res/layout/pulse_time_item.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/textViewName"
+ android:paddingLeft="4dp"
+ android:paddingRight="4dp"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ android:textAppearance="?android:attr/textAppearanceMedium" >
+
+</TextView>
View
35 res/values-de/strings.xml
@@ -597,7 +597,6 @@
<string name="vibrate_in_silent_title" msgid="3897968069156767036">"Im Lautlos-Modus vibrieren"</string>
<string name="vibrate_on_ring_title" msgid="40343855247989536">"Vibrieren und klingeln"</string>
<string name="notification_sound_title" msgid="312032901303146002">"Standardbenachrichtigung"</string>
- <string name="notification_pulse_title" msgid="1247988024534030629">"Benachrichtigungslicht"</string>
<string name="incoming_call_volume_title" msgid="8073714801365904099">"Klingelton"</string>
<string name="notification_volume_title" msgid="2012640760341080408">"Benachrichtigung"</string>
<string name="checkbox_notification_same_as_incoming_call" msgid="1073644356290338921">"Lautstärke für eingehende Anrufe für Benachrichtigungen verwenden"</string>
@@ -2021,4 +2020,38 @@
<string name="storage_switch_summary_off">Benutze SD-Karte für Apps und Medien</string>
<string name="storage_switch_unavailable">Dieses Gerät hat keinen erweiterten internen Speicher</string>
+ <!-- Display settings screen, notification light settings -->
+ <string name="notification_pulse_title">Benachrichtigungslicht</string>
+ <string name="notification_light_general_title">Allgemein</string>
+ <string name="notification_light_applist_title">Apps</string>
+ <string name="notification_light_default_value">Standard</string>
+ <string name="notification_light_use_custom">App-Anpassung</string>
+ <string name="notification_light_enabled">Farben anpassen</string>
+ <string name="notification_light_disabled">Farben nicht anpassen</string>
+
+ <!-- Notification light dialogs -->
+ <string name="edit_light_settings">Farbeinstellungen ändern</string>
+ <string name="pulse_speed_title">Pulsdauer und Geschwindigkeit</string>
+ <string name="picker_arrow">→</string>
+ <string name="default_time">Normal</string>
+ <string name="custom_time">Angepasst</string>
+ <string name="dialog_test">Test</string>
+ <string name="dialog_delete_title">Löschen</string>
+ <string name="dialog_delete_message">Anpassung für diese App entfernen?</string>
+ <string name="dialog_test_message">Display abschalten, um diese Einstellung zu testen.</string>
+ <string name="dialog_test_button">Abbrechen</string>
+
+ <!-- Values for the notification light pulse spinners -->
+ <string name="pulse_length_always_on">Immer an</string>
+ <string name="pulse_length_very_short">Sehr kurz</string>
+ <string name="pulse_length_short">Kurz</string>
+ <string name="pulse_length_normal">Normal</string>
+ <string name="pulse_length_long">Lang</string>
+ <string name="pulse_length_very_long">Sehr lang</string>
+ <string name="pulse_speed_very_fast">Sehr schnell</string>
+ <string name="pulse_speed_fast">Schnell</string>
+ <string name="pulse_speed_normal">Normal</string>
+ <string name="pulse_speed_slow">Langsam</string>
+ <string name="pulse_speed_very_slow">Sehr langsam</string>
+
</resources>
View
37 res/values/arrays.xml
@@ -1078,12 +1078,47 @@
<item>@string/root_access_all</item>
</string-array>
- <string-array name="root_access_values">
+ <string-array name="root_access_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
+ <!-- Values for the notification light pulse spinners -->
+ <string-array name="notification_pulse_length_entries">
+ <item>@string/pulse_length_always_on</item>
+ <item>@string/pulse_length_very_short</item>
+ <item>@string/pulse_length_short</item>
+ <item>@string/pulse_length_normal</item>
+ <item>@string/pulse_length_long</item>
+ <item>@string/pulse_length_very_long</item>
+ </string-array>
+
+ <string-array name="notification_pulse_length_values" translatable="false">
+ <item>0</item>
+ <item>250</item>
+ <item>500</item>
+ <item>1000</item>
+ <item>2500</item>
+ <item>5000</item>
+ </string-array>
+
+ <string-array name="notification_pulse_speed_entries">
+ <item>@string/pulse_speed_very_fast</item>
+ <item>@string/pulse_speed_fast</item>
+ <item>@string/pulse_speed_normal</item>
+ <item>@string/pulse_speed_slow</item>
+ <item>@string/pulse_speed_very_slow</item>
+ </string-array>
+
+ <string-array name="notification_pulse_speed_values" translatable="false">
+ <item>250</item>
+ <item>500</item>
+ <item>1000</item>
+ <item>2500</item>
+ <item>5000</item>
+ </string-array>
+
<!-- **** CYANOGENMOD EDITS END **** -->
</resources>
View
1 res/values/dimens.xml
@@ -39,4 +39,5 @@
<dimen name="normal_height">64dip</dimen>
<!-- height of an expanded list item in edit playlist mode -->
<dimen name="expanded_height">128dip</dimen>
+ <dimen name="dialog_light_settings_width">400dip</dimen>
</resources>
View
50 res/values/strings.xml
@@ -592,8 +592,6 @@
<string name="vibrate_on_ring_title">Vibrate and ring</string>
<!-- Sound settings screen, setting option name -->
<string name="notification_sound_title">Default notification</string>
- <!-- Sound settings screen, notification light repeat pulsing title -->
- <string name="notification_pulse_title">Pulse notification light</string>
<!-- Sound settings screen, the title of the volume bar to adjust the incoming call volume -->
<string name="incoming_call_volume_title">Ringtone</string>
<!-- Sound settings screen, the title of the volume bar to adjust the notification volume -->
@@ -758,13 +756,47 @@
<string name="ll_bad_levels">Levels must be increasing</string>
<string name="ll_num_levels">Set number of levels</string>
+ <!-- Display settings screen, notification light settings -->
+ <string name="notification_pulse_title">Notification light</string>
+ <string name="notification_light_general_title">General</string>
+ <string name="notification_light_applist_title">Applications</string>
+ <string name="notification_light_default_value">Default</string>
+ <string name="notification_light_use_custom">Use custom values</string>
+ <string name="notification_light_enabled">Enabled</string>
+ <string name="notification_light_disabled">Disabled</string>
+
+ <!-- Notification light dialogs -->
+ <string name="edit_light_settings">Edit light settings</string>
+ <string name="pulse_speed_title">Pulse length and speed</string>
+ <string name="picker_arrow">→</string>
+ <string name="default_time">Normal</string>
+ <string name="custom_time">Custom</string>
+ <string name="dialog_test">Test</string>
+ <string name="dialog_delete_title">Delete</string>
+ <string name="dialog_delete_message">Remove selected item?</string>
+ <string name="dialog_test_message">Turn the screen off to see the selected notification in action or dismiss this dialog to stop the test</string>
+ <string name="dialog_test_button">Dismiss</string>
+
+ <!-- Values for the notification light pulse spinners -->
+ <string name="pulse_length_always_on">Always on</string>
+ <string name="pulse_length_very_short">Very short</string>
+ <string name="pulse_length_short">Short</string>
+ <string name="pulse_length_normal">Normal</string>
+ <string name="pulse_length_long">Long</string>
+ <string name="pulse_length_very_long">Very long</string>
+ <string name="pulse_speed_very_fast">Very fast</string>
+ <string name="pulse_speed_fast">Fast</string>
+ <string name="pulse_speed_normal">Normal</string>
+ <string name="pulse_speed_slow">Slow</string>
+ <string name="pulse_speed_very_slow">Very slow</string>
+
<!-- Advanced, Device specific (DeviceParts) settings #CM -->
<string name="advanced_settings_title">Advanced</string>
-
+
<!-- INTERFACE Settings #CM -->
<!-- Settings main menu category heading. Interface (Launcher, Themes, System). [CHAR LIMIT=40] -->
<string name="header_category_interface">INTERFACE</string>
-
+
<!-- Launcher settings #CM -->
<string name="launcher_settings_title">Launcher</string>
@@ -896,12 +928,12 @@
<!-- Reset Profiles -->
<string name="profile_reset_title">Reset</string>
- <string name="profile_reset_message">Do you want to delete all user created profiles and application groups and restore them to default?</string>
+ <string name="profile_reset_message">Delete all user created profiles and application groups and restore them to default?</string>
<!-- Delete confimation messages -->
- <string name="profile_delete_confirm">Are you sure you want to delete this profile?</string>
- <string name="profile_app_delete_confirm">Are you sure you want to remove this application?</string>
- <string name="profile_cannot_delete">You cannot delete the active profile</string>
+ <string name="profile_delete_confirm">Delete this profile?</string>
+ <string name="profile_app_delete_confirm">Remove this application?</string>
+ <string name="profile_cannot_delete">An active profile cannot be deleted</string>
<!-- Profile Config screen PreferenceGroup titles -->
<string name="profile_connectionoverrides_title">Connection overrides</string>
@@ -937,7 +969,7 @@
<string name="profile_appgroups_title">Application groups</string>
<string name="profile_applist_title">Applications</string>
<string name="profile_new_appgroup">New application group</string>
- <string name="profile_delete_appgroup">Delete this application group</string>
+ <string name="profile_delete_appgroup">Delete this application group?</string>
<string name="profile_appgroup_name_prompt">Enter a name for the new application group</string>
<string name="profile_appgroup_name_title">Name</string>
<string name="profile_add_app">Add application</string>
View
12 res/xml/display_settings.xml
@@ -24,10 +24,10 @@
android:dialogTitle="@string/brightness" />
<PreferenceScreen
- android:key="backlight_widget"
- android:fragment="com.android.settings.cyanogenmod.Backlight"
- android:title="@string/backlight_title"
- android:summary="@string/backlight_summary" />
+ android:key="backlight_widget"
+ android:fragment="com.android.settings.cyanogenmod.Backlight"
+ android:title="@string/backlight_title"
+ android:summary="@string/backlight_summary" />
<PreferenceScreen
android:key="display_rotation"
@@ -42,10 +42,10 @@
android:entries="@array/screen_timeout_entries"
android:entryValues="@array/screen_timeout_values" />
- <CheckBoxPreference
+ <PreferenceScreen
android:key="notification_pulse"
android:title="@string/notification_pulse_title"
- android:persistent="false" />
+ android:fragment="com.android.settings.notificationlight.NotificationLightSettings" />
<CheckBoxPreference
android:key="battery_pulse"
View
44 res/xml/notification_light_settings.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+ <PreferenceCategory
+ android:key="general_section"
+ android:title="@string/notification_light_general_title">
+
+ <CheckBoxPreference
+ android:key="pulse_enabled"
+ android:title="@string/notification_pulse_title" />
+
+ <com.android.settings.notificationlight.ApplicationLightPreference
+ android:key="default"
+ android:title="@string/notification_light_default_value"
+ android:persistent="false" />
+
+ <CheckBoxPreference
+ android:key="custom_enabled"
+ android:title="@string/notification_light_use_custom" />
+
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:key="applications_list"
+ android:title="@string/notification_light_applist_title" >
+ </PreferenceCategory>
+
+</PreferenceScreen>
View
52 src/com/android/settings/DisplaySettings.java
@@ -18,31 +18,23 @@
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
-import android.app.ActivityManagerNative;
+import java.util.ArrayList;
+
import android.app.admin.DevicePolicyManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Configuration;
-import android.content.res.Resources;
import android.database.ContentObserver;
import android.os.Bundle;
import android.os.Handler;
-import android.os.RemoteException;
-import android.os.ServiceManager;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
import android.util.Log;
-import android.view.IWindowManager;
-import android.view.Surface;
import com.android.settings.cyanogenmod.DisplayRotation;
-import com.android.settings.R;
-
-import java.util.ArrayList;
public class DisplaySettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
@@ -66,8 +58,8 @@
private static final String ROTATION_ANGLE_DELIM_FINAL = " & ";
private CheckBoxPreference mVolumeWake;
- private CheckBoxPreference mNotificationPulse;
private CheckBoxPreference mBatteryPulse;
+ private PreferenceScreen mNotificationPulse;
private final Configuration mCurConfig = new Configuration();
@@ -106,18 +98,12 @@ public void onCreate(Bundle savedInstanceState) {
getPreferenceScreen().removePreference(mAutomaticBacklightPreference);
}
- mNotificationPulse = (CheckBoxPreference) findPreference(KEY_NOTIFICATION_PULSE);
- if (mNotificationPulse != null
- && getResources().getBoolean(
- com.android.internal.R.bool.config_intrusiveNotificationLed) == false) {
- getPreferenceScreen().removePreference(mNotificationPulse);
- } else {
- try {
- mNotificationPulse.setChecked(Settings.System.getInt(resolver,
- Settings.System.NOTIFICATION_LIGHT_PULSE) == 1);
- mNotificationPulse.setOnPreferenceChangeListener(this);
- } catch (SettingNotFoundException snfe) {
- Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found");
+ mNotificationPulse = (PreferenceScreen) findPreference(KEY_NOTIFICATION_PULSE);
+ if (mNotificationPulse != null) {
+ if (!getResources().getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) {
+ getPreferenceScreen().removePreference(mNotificationPulse);
+ } else {
+ updateLightPulseDescription();
}
}
@@ -153,7 +139,7 @@ private void updateDisplayRotationPreferenceDescription() {
if (!rotationEnabled) {
summary.append(getString(R.string.display_rotation_disabled));
} else {
- ArrayList rotationList = new ArrayList();
+ ArrayList<String> rotationList = new ArrayList<String>();
String delim = "";
summary.append(getString(R.string.display_rotation_enabled) + " ");
if ((mode & DisplayRotation.ROTATION_0_MODE) != 0) {
@@ -239,10 +225,20 @@ private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) {
screenTimeoutPreference.setEnabled(revisedEntries.size() > 0);
}
+ private void updateLightPulseDescription() {
+ if (Settings.System.getInt(getActivity().getContentResolver(),
+ Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1) {
+ mNotificationPulse.setSummary(getString(R.string.notification_light_enabled));
+ } else {
+ mNotificationPulse.setSummary(getString(R.string.notification_light_disabled));
+ }
+ }
+
@Override
public void onResume() {
super.onResume();
updateDisplayRotationPreferenceDescription();
+ updateLightPulseDescription();
getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true,
@@ -258,12 +254,7 @@ public void onPause() {
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
- if (preference == mNotificationPulse) {
- boolean value = mNotificationPulse.isChecked();
- Settings.System.putInt(getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE,
- value ? 1 : 0);
- return true;
- } else if (preference == mBatteryPulse) {
+ if (preference == mBatteryPulse) {
boolean value = mBatteryPulse.isChecked();
Settings.System.putInt(getContentResolver(), Settings.System.BATTERY_LIGHT_PULSE,
value ? 1 : 0);
@@ -288,7 +279,6 @@ public boolean onPreferenceChange(Preference preference, Object objValue) {
Log.e(TAG, "could not persist screen timeout setting", e);
}
}
-
return true;
}
}
View
123 src/com/android/settings/notificationlight/AlphaPatternDrawable.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2010 Daniel Nilsson
+ * Copyright (C) 2012 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.settings.notificationlight;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.Bitmap.Config;
+import android.graphics.drawable.Drawable;
+
+/**
+ * This drawable that draws a simple white and gray chess board pattern. It's
+ * pattern you will often see as a background behind a partly transparent image
+ * in many applications.
+ *
+ * @author Daniel Nilsson
+ */
+public class AlphaPatternDrawable extends Drawable {
+
+ private int mRectangleSize = 10;
+
+ private Paint mPaint = new Paint();
+ private Paint mPaintWhite = new Paint();
+ private Paint mPaintGray = new Paint();
+
+ private int numRectanglesHorizontal;
+ private int numRectanglesVertical;
+
+ /**
+ * Bitmap in which the pattern will be cached.
+ */
+ private Bitmap mBitmap;
+
+ public AlphaPatternDrawable(int rectangleSize) {
+ mRectangleSize = rectangleSize;
+ mPaintWhite.setColor(0xffffffff);
+ mPaintGray.setColor(0xffcbcbcb);
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ canvas.drawBitmap(mBitmap, null, getBounds(), mPaint);
+ }
+
+ @Override
+ public int getOpacity() {
+ return 0;
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ throw new UnsupportedOperationException("Alpha is not supported by this drawwable.");
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter cf) {
+ throw new UnsupportedOperationException("ColorFilter is not supported by this drawwable.");
+ }
+
+ @Override
+ protected void onBoundsChange(Rect bounds) {
+ super.onBoundsChange(bounds);
+
+ int height = bounds.height();
+ int width = bounds.width();
+
+ numRectanglesHorizontal = (int) Math.ceil((width / mRectangleSize));
+ numRectanglesVertical = (int) Math.ceil(height / mRectangleSize);
+
+ generatePatternBitmap();
+ }
+
+ /**
+ * This will generate a bitmap with the pattern as big as the rectangle we
+ * were allow to draw on. We do this to cache the bitmap so we don't need
+ * to recreate it each time draw() is called since it takes a few
+ * milliseconds.
+ */
+ private void generatePatternBitmap() {
+
+ if (getBounds().width() <= 0 || getBounds().height() <= 0) {
+ return;
+ }
+
+ mBitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888);
+ Canvas canvas = new Canvas(mBitmap);
+
+ Rect r = new Rect();
+ boolean verticalStartWhite = true;
+ for (int i = 0; i <= numRectanglesVertical; i++) {
+ boolean isWhite = verticalStartWhite;
+ for (int j = 0; j <= numRectanglesHorizontal; j++) {
+ r.top = i * mRectangleSize;
+ r.left = j * mRectangleSize;
+ r.bottom = r.top + mRectangleSize;
+ r.right = r.left + mRectangleSize;
+
+ canvas.drawRect(r, isWhite ? mPaintWhite : mPaintGray);
+
+ isWhite = !isWhite;
+ }
+
+ verticalStartWhite = !verticalStartWhite;
+ }
+ }
+}
View
356 src/com/android/settings/notificationlight/ApplicationLightPreference.java
@@ -0,0 +1,356 @@
+/*
+ * Copyright (C) 2012 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.settings.notificationlight;
+
+import android.app.AlertDialog;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.Resources;
+import android.graphics.drawable.ShapeDrawable;
+import android.graphics.drawable.shapes.RectShape;
+import android.preference.Preference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.View.OnLongClickListener;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.LinearLayout.LayoutParams;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.Utils;
+
+public class ApplicationLightPreference extends Preference implements
+ View.OnClickListener {
+
+ private static String TAG = "AppLightPreference";
+ public static final int DEFAULT_TIME = 1000;
+ public static final int DEFAULT_COLOR = 0xFFFFFF; //White
+
+ private ImageView mLightColorView;
+ private TextView mOnValueView;
+ private TextView mOffValueView;
+
+ private int mColorValue;
+ private int mOnValue;
+ private int mOffValue;
+ private OnLongClickListener mParent;
+ private Resources mResources;
+ private ScreenReceiver mReceiver = null;
+ private AlertDialog mTestDialog;
+
+ /**
+ * @param context
+ * @param attrs
+ */
+ public ApplicationLightPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mColorValue = DEFAULT_COLOR;
+ mOnValue = DEFAULT_TIME;
+ mOffValue = DEFAULT_TIME;
+ mParent = null;
+ init();
+ }
+
+ /**
+ * @param context
+ * @param color
+ * @param onValue
+ * @param offValue
+ */
+ public ApplicationLightPreference(Context context, int color, int onValue, int offValue) {
+ super(context);
+ mColorValue = color;
+ mOnValue = onValue;
+ mOffValue = offValue;
+ mParent = null;
+ init();
+ }
+
+ /**
+ * @param context
+ * @param onLongClickListener
+ * @param color
+ * @param onValue
+ * @param offValue
+ */
+ public ApplicationLightPreference(Context context, OnLongClickListener parent, int color, int onValue, int offValue) {
+ super(context);
+ mColorValue = color;
+ mOnValue = onValue;
+ mOffValue = offValue;
+ mParent = parent;
+ init();
+ }
+
+ private void init() {
+ setLayoutResource(R.layout.preference_application_light);
+ mResources = getContext().getResources();
+ }
+
+ @Override
+ public View getView(View convertView, ViewGroup parent) {
+ View view = super.getView(convertView, parent);
+
+ View lightPref = (LinearLayout) view.findViewById(R.id.app_light_pref);
+ if ((lightPref != null) && lightPref instanceof LinearLayout) {
+ lightPref.setOnClickListener(this);
+ if (mParent != null) {
+ lightPref.setOnLongClickListener(mParent);
+ }
+ }
+
+ return view;
+ }
+
+ @Override
+ protected void onBindView(View view) {
+ super.onBindView(view);
+ mLightColorView = (ImageView) view.findViewById(R.id.light_color);
+ mOnValueView = (TextView) view.findViewById(R.id.textViewTimeOnValue);
+ mOffValueView = (TextView) view.findViewById(R.id.textViewTimeOffValue);
+
+ // Hide the summary text - it takes up too much space on a low res device
+ // We use it for storing the package name for the longClickListener
+ TextView tView = (TextView) view.findViewById(android.R.id.summary);
+ tView.setVisibility(View.GONE);
+
+ updatePreferenceViews();
+ }
+
+ private void updatePreferenceViews() {
+ final int width = (int) mResources.getDimension(R.dimen.device_memory_usage_button_width);
+ final int height = (int) mResources.getDimension(R.dimen.device_memory_usage_button_height);
+
+ if (mLightColorView != null) {
+ mLightColorView.setEnabled(true);
+ mLightColorView.setImageDrawable(createRectShape(width, height, 0xFF000000 + mColorValue));
+ }
+ if (mOnValueView != null) {
+ mOnValueView.setText(mapLengthValue(mOnValue));
+ }
+ if (mOffValueView != null) {
+ if (mOnValue == 0) {
+ mOffValueView.setVisibility(View.GONE);
+ } else {
+ mOffValueView.setVisibility(View.VISIBLE);
+ }
+ mOffValueView.setText(mapSpeedValue(mOffValue));
+ }
+ }
+
+ @Override
+ public void onClick(View v) {
+ if ((v != null) && (R.id.app_light_pref == v.getId())) {
+ editPreferenceValues();
+ }
+ }
+
+ private void editPreferenceValues() {
+ final LightSettingsDialog d = new LightSettingsDialog(getContext(), 0xFF000000 + mColorValue, mOnValue, mOffValue);
+ final int width = (int) mResources.getDimension(R.dimen.dialog_light_settings_width);
+ d.setAlphaSliderVisible(false);
+ Resources resources = getContext().getResources();
+
+ d.setButton(AlertDialog.BUTTON_POSITIVE, resources.getString(R.string.ok), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mColorValue = d.getColor() - 0xFF000000; // strip alpha, led does not support it
+ mOnValue = d.getPulseSpeedOn();
+ mOffValue = d.getPulseSpeedOff();
+ updatePreferenceViews();
+ callChangeListener(this);
+ }
+ });
+ d.setButton(AlertDialog.BUTTON_NEUTRAL, resources.getString(R.string.dialog_test), (DialogInterface.OnClickListener) null);
+ d.setButton(AlertDialog.BUTTON_NEGATIVE, resources.getString(R.string.cancel), (DialogInterface.OnClickListener) null);
+ d.show();
+
+ // Intercept the click on the middle button to show the test dialog and prevent the onDismiss
+ d.findViewById(android.R.id.button3).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ showTestDialog(d.getColor() - 0xFF000000, d.getPulseSpeedOn(), d.getPulseSpeedOff());
+ }
+ });
+
+ if (Utils.isScreenLarge()) {
+ // Make the dialog smaller on large screen devices
+ d.getWindow().setLayout(width, LayoutParams.WRAP_CONTENT);
+ }
+ }
+
+ private void showTestDialog(int color, int speedOn, int speedOff) {
+ final Context context = getContext();
+
+ if (mReceiver != null) {
+ context.getApplicationContext().unregisterReceiver(mReceiver);
+ }
+ if (mTestDialog != null) {
+ mTestDialog.dismiss();
+ }
+
+ mReceiver = new ScreenReceiver(color, speedOn, speedOff);
+
+ IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
+ filter.addAction(Intent.ACTION_SCREEN_ON);
+ context.getApplicationContext().registerReceiver(mReceiver, filter);
+
+ mTestDialog = new AlertDialog.Builder(context)
+ .setTitle(R.string.dialog_test)
+ .setMessage(R.string.dialog_test_message)
+ .setPositiveButton(R.string.dialog_test_button, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (mReceiver != null) {
+ context.getApplicationContext().unregisterReceiver(mReceiver);
+ mReceiver = null;
+ }
+ }
+ })
+ .create();
+
+ mTestDialog.show();
+ }
+
+ /**
+ * Getters and Setters
+ */
+
+ public int getColor() {
+ return mColorValue;
+ }
+
+ public void setColor(int color) {
+ mColorValue = color;
+ updatePreferenceViews();
+ }
+
+ public void setOnValue(int value) {
+ mOnValue = value;
+ updatePreferenceViews();
+ }
+
+ public int getOnValue() {
+ return mOnValue;
+ }
+
+ public void setOffValue(int value) {
+ mOffValue = value;
+ updatePreferenceViews();
+ }
+
+ public int getOffValue() {
+ return mOffValue;
+ }
+
+ public void setAllValues(int color, int onValue, int offValue) {
+ mColorValue = color;
+ mOnValue = onValue;
+ mOffValue = offValue;
+ updatePreferenceViews();
+ }
+
+ public void setOnOffValue(int onValue, int offValue) {
+ mOnValue = onValue;
+ mOffValue = offValue;
+ updatePreferenceViews();
+ }
+
+ /**
+ * Utility methods
+ */
+ public class ScreenReceiver extends BroadcastReceiver {
+ protected int timeon;
+ protected int timeoff;
+ protected int color;
+
+ public ScreenReceiver(int color, int timeon, int timeoff) {
+ this.timeon = timeon;
+ this.timeoff = timeoff;
+ this.color = color;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final NotificationManager nm =
+ (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+
+ if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
+ Notification.Builder builder = new Notification.Builder(context);
+ builder.setAutoCancel(true);
+ builder.setLights(color, timeon, timeoff);
+ nm.notify(1, builder.getNotification());
+ } else if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
+ nm.cancel(1);
+ context.getApplicationContext().unregisterReceiver(mReceiver);
+ mReceiver = null;
+ mTestDialog.dismiss();
+ mTestDialog = null;
+ }
+ }
+ }
+
+ private static ShapeDrawable createRectShape(int width, int height, int color) {
+ ShapeDrawable shape = new ShapeDrawable(new RectShape());
+ shape.setIntrinsicHeight(height);
+ shape.setIntrinsicWidth(width);
+ shape.getPaint().setColor(color);
+ return shape;
+ }
+
+ private String mapLengthValue(Integer time) {
+ if (time == DEFAULT_TIME) {
+ return getContext().getString(R.string.default_time);
+ }
+
+ String[] timeNames = mResources.getStringArray(R.array.notification_pulse_length_entries);
+ String[] timeValues = mResources.getStringArray(R.array.notification_pulse_length_values);
+
+ for (int i = 0; i < timeValues.length; i++) {
+ if (Integer.decode(timeValues[i]).equals(time)) {
+ return timeNames[i];
+ }
+ }
+
+ return getContext().getString(R.string.custom_time);
+ }
+
+ private String mapSpeedValue(Integer time) {
+ if (time == DEFAULT_TIME) {
+ return getContext().getString(R.string.default_time);
+ }
+
+ String[] timeNames = mResources.getStringArray(R.array.notification_pulse_speed_entries);
+ String[] timeValues = mResources.getStringArray(R.array.notification_pulse_speed_values);
+
+ for (int i = 0; i < timeValues.length; i++) {
+ if (Integer.decode(timeValues[i]).equals(time)) {
+ return timeNames[i];
+ }
+ }
+
+ return getContext().getString(R.string.custom_time);
+ }
+
+}
View
171 src/com/android/settings/notificationlight/ColorPanelView.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2010 Daniel Nilsson
+ * Copyright (C) 2012 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.settings.notificationlight;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.util.AttributeSet;
+import android.view.View;
+
+/**
+ * This class draws a panel which which will be filled with a color which can be
+ * set. It can be used to show the currently selected color which you will get
+ * from the {@link ColorPickerView}.
+ *
+ * @author Daniel Nilsson
+ */
+public class ColorPanelView extends View {
+
+ /**
+ * The width in pixels of the border surrounding the color panel.
+ */
+ private final static float BORDER_WIDTH_PX = 1;
+
+ private static float mDensity = 1f;
+
+ private int mBorderColor = 0xff6E6E6E;
+ private int mColor = 0xff000000;
+
+ private Paint mBorderPaint;
+ private Paint mColorPaint;
+
+ private RectF mDrawingRect;
+ private RectF mColorRect;
+
+ private AlphaPatternDrawable mAlphaPattern;
+
+ public ColorPanelView(Context context) {
+ this(context, null);
+ }
+
+ public ColorPanelView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public ColorPanelView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ init();
+ }
+
+ private void init() {
+ mBorderPaint = new Paint();
+ mColorPaint = new Paint();
+ mDensity = getContext().getResources().getDisplayMetrics().density;
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+
+ final RectF rect = mColorRect;
+
+ if (BORDER_WIDTH_PX > 0) {
+ mBorderPaint.setColor(mBorderColor);
+ canvas.drawRect(mDrawingRect, mBorderPaint);
+ }
+
+ if (mAlphaPattern != null) {
+ mAlphaPattern.draw(canvas);
+ }
+
+ mColorPaint.setColor(mColor);
+
+ canvas.drawRect(rect, mColorPaint);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+
+ int width = MeasureSpec.getSize(widthMeasureSpec);
+ int height = MeasureSpec.getSize(heightMeasureSpec);
+
+ setMeasuredDimension(width, height);
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+
+ mDrawingRect = new RectF();
+ mDrawingRect.left = getPaddingLeft();
+ mDrawingRect.right = w - getPaddingRight();
+ mDrawingRect.top = getPaddingTop();
+ mDrawingRect.bottom = h - getPaddingBottom();
+
+ setUpColorRect();
+
+ }
+
+ private void setUpColorRect() {
+ final RectF dRect = mDrawingRect;
+
+ float left = dRect.left + BORDER_WIDTH_PX;
+ float top = dRect.top + BORDER_WIDTH_PX;
+ float bottom = dRect.bottom - BORDER_WIDTH_PX;
+ float right = dRect.right - BORDER_WIDTH_PX;
+
+ mColorRect = new RectF(left, top, right, bottom);
+
+ mAlphaPattern = new AlphaPatternDrawable((int) (5 * mDensity));
+
+ mAlphaPattern.setBounds(Math.round(mColorRect.left),
+ Math.round(mColorRect.top),
+ Math.round(mColorRect.right),
+ Math.round(mColorRect.bottom));
+
+ }
+
+ /**
+ * Set the color that should be shown by this view.
+ *
+ * @param color
+ */
+ public void setColor(int color) {
+ mColor = color;
+ invalidate();
+ }
+
+ /**
+ * Get the color currently show by this view.
+ *
+ * @return
+ */
+ public int getColor() {
+ return mColor;
+ }
+
+ /**
+ * Set the color of the border surrounding the panel.
+ *
+ * @param color
+ */
+ public void setBorderColor(int color) {
+ mBorderColor = color;
+ invalidate();
+ }
+
+ /**
+ * Get the color of the border surrounding the panel.
+ */
+ public int getBorderColor() {
+ return mBorderColor;
+ }
+
+}
View
954 src/com/android/settings/notificationlight/ColorPickerView.java
@@ -0,0 +1,954 @@
+/*
+ * Copyright (C) 2010 Daniel Nilsson
+ * Copyright (C) 2012 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.settings.notificationlight;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ComposeShader;
+import android.graphics.LinearGradient;
+import android.graphics.Paint;
+import android.graphics.Point;
+import android.graphics.PorterDuff;
+import android.graphics.RectF;
+import android.graphics.Shader;
+import android.graphics.Paint.Align;
+import android.graphics.Paint.Style;
+import android.graphics.Shader.TileMode;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+
+/**
+ * Displays a color picker to the user and allow them to select a color. A
+ * slider for the alpha channel is also available. Enable it by setting
+ * setAlphaSliderVisible(boolean) to true.
+ *
+ * @author Daniel Nilsson
+ */
+public class ColorPickerView extends View {
+
+ public interface OnColorChangedListener {
+ public void onColorChanged(int color);
+ }
+
+ private final static int PANEL_SAT_VAL = 0;
+ private final static int PANEL_HUE = 1;
+ private final static int PANEL_ALPHA = 2;
+
+ /**
+ * The width in pixels of the border surrounding all color panels.
+ */
+ private final static float BORDER_WIDTH_PX = 1;
+
+ /**
+ * The width in dp of the hue panel.
+ */
+ private float HUE_PANEL_WIDTH = 30f;
+ /**
+ * The height in dp of the alpha panel
+ */
+ private float ALPHA_PANEL_HEIGHT = 20f;
+ /**
+ * The distance in dp between the different color panels.
+ */
+ private float PANEL_SPACING = 10f;
+ /**
+ * The radius in dp of the color palette tracker circle.
+ */
+ private float PALETTE_CIRCLE_TRACKER_RADIUS = 5f;
+ /**
+ * The dp which the tracker of the hue or alpha panel will extend outside of
+ * its bounds.
+ */
+ private float RECTANGLE_TRACKER_OFFSET = 2f;
+
+ private static float mDensity = 1f;
+
+ private OnColorChangedListener mListener;
+
+ private Paint mSatValPaint;
+ private Paint mSatValTrackerPaint;
+
+ private Paint mHuePaint;
+ private Paint mHueTrackerPaint;
+
+ private Paint mAlphaPaint;
+ private Paint mAlphaTextPaint;
+
+ private Paint mBorderPaint;
+
+ private Shader mValShader;
+ private Shader mSatShader;
+ private Shader mHueShader;
+ private Shader mAlphaShader;
+
+ private int mAlpha = 0xff;
+ private float mHue = 360f;
+ private float mSat = 0f;
+ private float mVal = 0f;
+
+ private String mAlphaSliderText = "Alpha";
+ private int mSliderTrackerColor = 0xff1c1c1c;
+ private int mBorderColor = 0xff6E6E6E;
+ private boolean mShowAlphaPanel = false;
+
+ /*
+ * To remember which panel that has the "focus" when processing hardware
+ * button data.
+ */
+ private int mLastTouchedPanel = PANEL_SAT_VAL;
+
+ /**
+ * Offset from the edge we must have or else the finger tracker will get
+ * clipped when it is drawn outside of the view.
+ */
+ private float mDrawingOffset;
+
+ /*
+ * Distance form the edges of the view of where we are allowed to draw.
+ */
+ private RectF mDrawingRect;
+
+ private RectF mSatValRect;
+ private RectF mHueRect;
+ private RectF mAlphaRect;
+
+ private AlphaPatternDrawable mAlphaPattern;
+
+ private Point mStartTouchPoint = null;
+
+ public ColorPickerView(Context context) {
+ this(context, null);
+ }
+
+ public ColorPickerView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public ColorPickerView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init();
+ }
+
+ private void init() {
+ mDensity = getContext().getResources().getDisplayMetrics().density;
+ PALETTE_CIRCLE_TRACKER_RADIUS *= mDensity;
+ RECTANGLE_TRACKER_OFFSET *= mDensity;
+ HUE_PANEL_WIDTH *= mDensity;
+ ALPHA_PANEL_HEIGHT *= mDensity;
+ PANEL_SPACING = PANEL_SPACING * mDensity;
+
+ mDrawingOffset = calculateRequiredOffset();
+
+ initPaintTools();
+
+ // Needed for receiving track ball motion events.
+ setFocusable(true);
+ setFocusableInTouchMode(true);
+ }
+
+ private void initPaintTools() {
+
+ mSatValPaint = new Paint();
+ mSatValTrackerPaint = new Paint();
+ mHuePaint = new Paint();
+ mHueTrackerPaint = new Paint();
+ mAlphaPaint = new Paint();
+ mAlphaTextPaint = new Paint();
+ mBorderPaint = new Paint();
+
+ mSatValTrackerPaint.setStyle(Style.STROKE);
+ mSatValTrackerPaint.setStrokeWidth(2f * mDensity);
+ mSatValTrackerPaint.setAntiAlias(true);
+
+ mHueTrackerPaint.setColor(mSliderTrackerColor);
+ mHueTrackerPaint.setStyle(Style.STROKE);
+ mHueTrackerPaint.setStrokeWidth(2f * mDensity);
+ mHueTrackerPaint.setAntiAlias(true);
+
+ mAlphaTextPaint.setColor(0xff1c1c1c);
+ mAlphaTextPaint.setTextSize(14f * mDensity);
+ mAlphaTextPaint.setAntiAlias(true);
+ mAlphaTextPaint.setTextAlign(Align.CENTER);
+ mAlphaTextPaint.setFakeBoldText(true);
+
+ }
+
+ private float calculateRequiredOffset() {
+ float offset = Math.max(PALETTE_CIRCLE_TRACKER_RADIUS, RECTANGLE_TRACKER_OFFSET);
+ offset = Math.max(offset, BORDER_WIDTH_PX * mDensity);
+
+ return offset * 1.5f;
+ }
+
+ private int[] buildHueColorArray() {
+
+ int[] hue = new int[361];
+
+ int count = 0;
+ for (int i = hue.length - 1; i >= 0; i--, count++) {
+ hue[count] = Color.HSVToColor(new float[] {
+ i, 1f, 1f
+ });
+ }
+
+ return hue;
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+
+ if (mDrawingRect.width() <= 0 || mDrawingRect.height() <= 0)
+ return;
+
+ drawSatValPanel(canvas);
+ drawHuePanel(canvas);
+ drawAlphaPanel(canvas);
+
+ }
+
+ private void drawSatValPanel(Canvas canvas) {
+
+ final RectF rect = mSatValRect;
+
+ if (BORDER_WIDTH_PX > 0) {
+ mBorderPaint.setColor(mBorderColor);
+ canvas.drawRect(mDrawingRect.left, mDrawingRect.top, rect.right + BORDER_WIDTH_PX,
+ rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
+ }
+
+ if (mValShader == null) {
+ mValShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom,
+ 0xffffffff, 0xff000000, TileMode.CLAMP);
+ }
+
+ int rgb = Color.HSVToColor(new float[] {
+ mHue, 1f, 1f
+ });
+
+ mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
+ 0xffffffff, rgb, TileMode.CLAMP);
+ ComposeShader mShader = new ComposeShader(mValShader, mSatShader, PorterDuff.Mode.MULTIPLY);
+ mSatValPaint.setShader(mShader);
+
+ canvas.drawRect(rect, mSatValPaint);
+
+ Point p = satValToPoint(mSat, mVal);
+
+ mSatValTrackerPaint.setColor(0xff000000);
+ canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS - 1f * mDensity,
+ mSatValTrackerPaint);
+
+ mSatValTrackerPaint.setColor(0xffdddddd);
+ canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS, mSatValTrackerPaint);
+
+ }
+
+ private void drawHuePanel(Canvas canvas) {
+
+ final RectF rect = mHueRect;
+
+ if (BORDER_WIDTH_PX > 0) {
+ mBorderPaint.setColor(mBorderColor);
+ canvas.drawRect(rect.left - BORDER_WIDTH_PX,
+ rect.top - BORDER_WIDTH_PX,
+ rect.right + BORDER_WIDTH_PX,
+ rect.bottom + BORDER_WIDTH_PX,
+ mBorderPaint);
+ }
+
+ if (mHueShader == null) {
+ mHueShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom,
+ buildHueColorArray(), null, TileMode.CLAMP);
+ mHuePaint.setShader(mHueShader);
+ }
+
+ canvas.drawRect(rect, mHuePaint);
+
+ float rectHeight = 4 * mDensity / 2;
+
+ Point p = hueToPoint(mHue);
+
+ RectF r = new RectF();
+ r.left = rect.left - RECTANGLE_TRACKER_OFFSET;
+ r.right = rect.right + RECTANGLE_TRACKER_OFFSET;
+ r.top = p.y - rectHeight;
+ r.bottom = p.y + rectHeight;
+
+ canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
+
+ }
+
+ private void drawAlphaPanel(Canvas canvas) {
+
+ if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null)
+ return;
+
+ final RectF rect = mAlphaRect;
+
+ if (BORDER_WIDTH_PX > 0) {
+ mBorderPaint.setColor(mBorderColor);
+ canvas.drawRect(rect.left - BORDER_WIDTH_PX,
+ rect.top - BORDER_WIDTH_PX,
+ rect.right + BORDER_WIDTH_PX,
+ rect.bottom + BORDER_WIDTH_PX,
+ mBorderPaint);
+ }
+
+ mAlphaPattern.draw(canvas);
+
+ float[] hsv = new float[] {
+ mHue, mSat, mVal
+ };
+ int color = Color.HSVToColor(hsv);
+ int acolor = Color.HSVToColor(0, hsv);
+
+ mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
+ color, acolor, TileMode.CLAMP);
+
+ mAlphaPaint.setShader(mAlphaShader);
+
+ canvas.drawRect(rect, mAlphaPaint);
+
+ if (mAlphaSliderText != null && mAlphaSliderText != "") {
+ canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity,
+ mAlphaTextPaint);
+ }
+
+ float rectWidth = 4 * mDensity / 2;
+
+ Point p = alphaToPoint(mAlpha);
+
+ RectF r = new RectF();
+ r.left = p.x - rectWidth;
+ r.right = p.x + rectWidth;
+ r.top = rect.top - RECTANGLE_TRACKER_OFFSET;
+ r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;
+
+ canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
+
+ }
+
+ private Point hueToPoint(float hue) {
+
+ final RectF rect = mHueRect;
+ final float height = rect.height();
+
+ Point p = new Point();
+
+ p.y = (int) (height - (hue * height / 360f) + rect.top);
+ p.x = (int) rect.left;
+
+ return p;
+ }
+
+ private Point satValToPoint(float sat, float val) {
+
+ final RectF rect = mSatValRect;
+ final float height = rect.height();
+ final float width = rect.width();
+
+ Point p = new Point();
+
+ p.x = (int) (sat * width + rect.left);
+ p.y = (int) ((1f - val) * height + rect.top);
+
+ return p;
+ }
+
+ private Point alphaToPoint(int alpha) {
+
+ final RectF rect = mAlphaRect;
+ final float width = rect.width();
+
+ Point p = new Point();
+
+ p.x = (int) (width - (alpha * width / 0xff) + rect.left);
+ p.y = (int) rect.top;
+
+ return p;
+
+ }
+
+ private float[] pointToSatVal(float x, float y) {
+
+ final RectF rect = mSatValRect;
+ float[] result = new float[2];
+
+ float width = rect.width();
+ float height = rect.height();
+
+ if (x < rect.left) {
+ x = 0f;
+ }
+ else if (x > rect.right) {
+ x = width;
+ }
+ else {
+ x = x - rect.left;
+ }
+
+ if (y < rect.top) {
+ y = 0f;
+ }
+ else if (y > rect.bottom) {
+ y = height;
+ }
+ else {
+ y = y - rect.top;
+ }
+
+ result[0] = 1.f / width * x;
+ result[1] = 1.f - (1.f / height * y);
+
+ return result;
+ }
+
+ private float pointToHue(float y) {
+
+ final RectF rect = mHueRect;
+
+ float height = rect.height();
+
+ if (y < rect.top) {
+ y = 0f;
+ }
+ else if (y > rect.bottom) {
+ y = height;
+ }
+ else {
+ y = y - rect.top;
+ }
+
+ return 360f - (y * 360f / height);
+ }
+
+ private int pointToAlpha(int x) {
+
+ final RectF rect = mAlphaRect;
+ final int width = (int) rect.width();
+
+ if (x < rect.left) {
+ x = 0;
+ }
+ else if (x > rect.right) {
+ x = width;
+ }
+ else {
+ x = x - (int) rect.left;
+ }
+
+ return 0xff - (x * 0xff / width);
+
+ }
+
+ @Override
+ public boolean onTrackballEvent(MotionEvent event) {
+
+ float x = event.getX();
+ float y = event.getY();
+
+ boolean update = false;
+
+ if (event.getAction() == MotionEvent.ACTION_MOVE) {
+
+ switch (mLastTouchedPanel) {
+
+ case PANEL_SAT_VAL:
+
+ float sat,
+ val;
+
+ sat = mSat + x / 50f;
+ val = mVal - y / 50f;
+
+ if (sat < 0f) {
+ sat = 0f;
+ }
+ else if (sat > 1f) {
+ sat = 1f;
+ }
+
+ if (val < 0f) {
+ val = 0f;
+ }
+ else if (val > 1f) {
+ val = 1f;
+ }
+
+ mSat = sat;
+ mVal = val;
+
+ update = true;
+
+ break;
+
+ case PANEL_HUE:
+
+ float hue = mHue - y * 10f;
+
+ if (hue < 0f) {
+ hue = 0f;
+ }
+ else if (hue > 360f) {
+ hue = 360f;
+ }
+
+ mHue = hue;
+
+ update = true;
+
+ break;
+
+ case PANEL_ALPHA:
+
+ if (!mShowAlphaPanel || mAlphaRect == null) {
+ update = false;
+ }
+ else {
+
+ int alpha = (int) (mAlpha - x * 10);
+
+ if (alpha < 0) {
+ alpha = 0;
+ }
+ else if (alpha > 0xff) {
+ alpha = 0xff;
+ }
+
+ mAlpha = alpha;
+
+ update = true;
+ }
+
+ break;
+ }
+
+ }
+
+ if (update) {
+
+ if (mListener != null) {
+ mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[] {
+ mHue, mSat, mVal
+ }));
+ }
+
+ invalidate();
+ return true;
+ }
+
+ return super.onTrackballEvent(event);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+
+ boolean update = false;
+
+ switch (event.getAction()) {
+
+ case MotionEvent.ACTION_DOWN:
+
+ mStartTouchPoint = new Point((int) event.getX(), (int) event.getY());
+
+ update = moveTrackersIfNeeded(event);
+
+ break;
+
+ case MotionEvent.ACTION_MOVE:
+
+ update = moveTrackersIfNeeded(event);
+
+ break;
+
+ case MotionEvent.ACTION_UP:
+
+ mStartTouchPoint = null;
+
+ update = moveTrackersIfNeeded(event);
+
+ break;
+
+ }
+
+ if (update) {
+
+ if (mListener != null) {
+ mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[] {
+ mHue, mSat, mVal
+ }));
+ }
+
+ invalidate();
+ return true;
+ }
+
+ return super.onTouchEvent(event);
+ }
+
+ private boolean moveTrackersIfNeeded(MotionEvent event) {
+
+ if (mStartTouchPoint == null)
+ return false;
+
+ boolean update = false;
+
+ int startX = mStartTouchPoint.x;
+ int startY = mStartTouchPoint.y;
+
+ if (mHueRect.contains(startX, startY)) {
+ mLastTouchedPanel = PANEL_HUE;
+
+ mHue = pointToHue(event.getY());
+
+ update = true;
+ }
+ else if (mSatValRect.contains(startX, startY)) {
+
+ mLastTouchedPanel = PANEL_SAT_VAL;
+
+ float[] result = pointToSatVal(event.getX(), event.getY());
+
+ mSat = result[0];
+ mVal = result[1];
+
+ update = true;
+ }
+ else if (mAlphaRect != null && mAlphaRect.contains(startX, startY)) {
+
+ mLastTouchedPanel = PANEL_ALPHA;
+
+ mAlpha = pointToAlpha((int) event.getX());
+
+ update = true;
+ }
+
+ return update;
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+
+ int width = 0;
+ int height = 0;
+
+ int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+ int heightMode = MeasureSpec.getMode(heightMeasureSpec);
+
+ int widthAllowed = MeasureSpec.getSize(widthMeasureSpec);
+ int heightAllowed = MeasureSpec.getSize(heightMeasureSpec);
+
+ widthAllowed = chooseWidth(widthMode, widthAllowed);
+ heightAllowed = chooseHeight(heightMode, heightAllowed);
+
+ if (!mShowAlphaPanel) {
+ height = (int) (widthAllowed - PANEL_SPACING - HUE_PANEL_WIDTH);
+
+ // If calculated height (based on the width) is more than the
+ // allowed height.
+ if (height > heightAllowed) {
+ height = heightAllowed;
+ width = (int) (height + PANEL_SPACING + HUE_PANEL_WIDTH);
+ }
+ else {
+ width = widthAllowed;
+ }
+ }
+ else {
+
+ width = (int) (heightAllowed - ALPHA_PANEL_HEIGHT + HUE_PANEL_WIDTH);
+
+ if (width > widthAllowed) {
+ width = widthAllowed;
+ height = (int) (widthAllowed - HUE_PANEL_WIDTH + ALPHA_PANEL_HEIGHT);
+ }
+ else {
+ height = heightAllowed;
+ }
+
+ }
+
+ setMeasuredDimension(width, height);
+ }
+
+ private int chooseWidth(int mode, int size) {
+ if (mode == MeasureSpec.AT_MOST || mode == MeasureSpec.EXACTLY) {
+ return size;
+ } else { // (mode == MeasureSpec.UNSPECIFIED)
+ return getPrefferedWidth();
+ }
+ }
+
+ private int chooseHeight(int mode, int size) {
+ if (mode == MeasureSpec.AT_MOST || mode == MeasureSpec.EXACTLY) {
+ return size;
+ } else { // (mode == MeasureSpec.UNSPECIFIED)
+ return getPrefferedHeight();
+ }
+ }
+
+ private int getPrefferedWidth() {
+
+ int width = getPrefferedHeight();
+
+ if (mShowAlphaPanel) {
+ width -= (PANEL_SPACING + ALPHA_PANEL_HEIGHT);
+ }
+
+ return (int) (width + HUE_PANEL_WIDTH + PANEL_SPACING);
+
+ }
+
+ private int getPrefferedHeight() {
+
+ int height = (int) (200 * mDensity);
+
+ if (mShowAlphaPanel) {
+ height += PANEL_SPACING + ALPHA_PANEL_HEIGHT;
+ }
+
+ return height;
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+
+ mDrawingRect = new RectF();
+ mDrawingRect.left = mDrawingOffset + getPaddingLeft();
+ mDrawingRect.right = w - mDrawingOffset - getPaddingRight();
+ mDrawingRect.top = mDrawingOffset + getPaddingTop();
+ mDrawingRect.bottom = h - mDrawingOffset - getPaddingBottom();
+
+ setUpSatValRect();
+ setUpHueRect();
+ setUpAlphaRect();
+ }
+
+ private void setUpSatValRect() {
+
+ final RectF dRect = mDrawingRect;
+ float panelSide = dRect.height() - BORDER_WIDTH_PX * 2;
+
+ if (mShowAlphaPanel) {
+ panelSide -= PANEL_SPACING + ALPHA_PANEL_HEIGHT;
+ }
+
+ float left = dRect.left + BORDER_WIDTH_PX;
+ float top = dRect.top + BORDER_WIDTH_PX;
+ float bottom = top + panelSide;
+ float right = left + panelSide;
+
+ mSatValRect = new RectF(left, top, right, bottom);
+ }
+
+ private void setUpHueRect() {
+ final RectF dRect = mDrawingRect;
+
+ float left = dRect.right - HUE_PANEL_WIDTH + BORDER_WIDTH_PX;
+ float top = dRect.top + BORDER_WIDTH_PX;
+ float bottom = dRect.bottom - BORDER_WIDTH_PX
+ - (mShowAlphaPanel ? (PANEL_SPACING + ALPHA_PANEL_HEIGHT) : 0);
+ float right = dRect.right - BORDER_WIDTH_PX;
+
+ mHueRect = new RectF(left, top, right, bottom);
+ }
+
+ private void setUpAlphaRect() {
+
+ if (!mShowAlphaPanel)
+ return;
+
+ final RectF dRect = mDrawingRect;
+
+ float left = dRect.left + BORDER_WIDTH_PX;
+ float top = dRect.bottom - ALPHA_PANEL_HEIGHT + BORDER_WIDTH_PX;
+ float bottom = dRect.bottom - BORDER_WIDTH_PX;
+ float right = dRect.right - BORDER_WIDTH_PX;
+
+ mAlphaRect = new RectF(left, top, right, bottom);
+
+ mAlphaPattern = new AlphaPatternDrawable((int) (5 * mDensity));
+ mAlphaPattern.setBounds(Math.round(mAlphaRect.left), Math
+ .round(mAlphaRect.top), Math.round(mAlphaRect.right), Math
+ .round(mAlphaRect.bottom));
+
+ }
+
+ /**
+ * Set a OnColorChangedListener to get notified when the color selected by
+ * the user has changed.
+ *
+ * @param listener
+ */
+ public void setOnColorChangedListener(OnColorChangedListener listener) {
+ mListener = listener;
+ }
+
+ /**
+ * Set the color of the border surrounding all panels.
+ *
+ * @param color
+ */
+ public void setBorderColor(int color) {
+ mBorderColor = color;
+ invalidate();
+ }
+
+ /**
+ * Get the color of the border surrounding all panels.
+ */
+ public int getBorderColor() {
+ return mBorderColor;
+ }
+
+ /**
+ * Get the current color this view is showing.
+ *
+ * @return the current color.
+ */
+ public int getColor() {
+ return Color.HSVToColor(mAlpha, new float[] {
+ mHue, mSat, mVal
+ });
+ }
+
+ /**
+ * Set the color the view should show.
+ *
+ * @param color The color that should be selected.
+ */
+ public void setColor(int color) {
+ setColor(color, false);
+ }
+
+ /**
+ * Set the color this view should show.
+ *
+ * @param color The color that should be selected.
+ * @param callback If you want to get a callback to your
+ * OnColorChangedListener.
+ */
+ public void setColor(int color, boolean callback) {
+
+ int alpha = Color.alpha(color);
+ int red = Color.red(color);
+ int blue = Color.blue(color);
+ int green = Color.green(color);
+
+ float[] hsv = new float[3];
+
+ Color.RGBToHSV(red, green, blue, hsv);
+
+ mAlpha = alpha;
+ mHue = hsv[0];
+ mSat = hsv[1];
+ mVal = hsv[2];
+
+ if (callback && mListener != null) {
+ mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[] {
+ mHue, mSat, mVal
+ }));
+ }
+
+ invalidate();
+ }
+
+ /**
+ * Get the drawing offset of the color picker view. The drawing offset is
+ * the distance from the side of a panel to the side of the view minus the
+ * padding. Useful if you want to have your own panel below showing the
+ * currently selected color and want to align it perfectly.
+ *
+ * @return The offset in pixels.
+ */
+ public float getDrawingOffset() {
+ return mDrawingOffset;
+ }
+
+ /**
+ * Set if the user is allowed to adjust the alpha panel. Default is false.
+ * If it is set to false no alpha will be set.
+ *
+ * @param visible
+ */
+ public void setAlphaSliderVisible(boolean visible) {
+
+ if (mShowAlphaPanel != visible) {
+ mShowAlphaPanel = visible;
+
+ /*
+ * Reset all shader to force a recreation. Otherwise they will not
+ * look right after the size of the view has changed.
+ */
+ mValShader = null;
+ mSatShader = null;
+ mHueShader = null;
+ mAlphaShader = null;
+ ;
+
+ requestLayout();
+ }
+
+ }
+
+ public void setSliderTrackerColor(int color) {
+ mSliderTrackerColor = color;
+
+ mHueTrackerPaint.setColor(mSliderTrackerColor);
+
+ invalidate();
+ }
+
+ public int getSliderTrackerColor() {
+ return mSliderTrackerColor;
+ }
+
+ /**
+ * Set the text that should be shown in the alpha slider. Set to null to
+ * disable text.
+ *
+ * @param res string resource id.
+ */
+ public void setAlphaSliderText(int res) {
+ String text = getContext().getString(res);
+ setAlphaSliderText(text);
+ }
+
+ /**
+ * Set the text that should be shown in the alpha slider. Set to null to
+ * disable text.
+ *
+ * @param text Text that should be shown.
+ */
+ public void setAlphaSliderText(String text) {
+ mAlphaSliderText = text;
+ invalidate();
+ }
+
+ /**
+ * Get the current value of the text that will be shown in the alpha slider.
+ *
+ * @return
+ */
+ public String getAlphaSliderText() {
+ return mAlphaSliderText;
+ }
+}
View
220 src/com/android/settings/notificationlight/LightSettingsDialog.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2010 Daniel Nilsson
+ * Copyright (C) 2012 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.settings.notificationlight;
+
+import java.util.ArrayList;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.util.Pair;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+import android.widget.SpinnerAdapter;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.notificationlight.ColorPickerView.OnColorChangedListener;
+
+public class LightSettingsDialog extends AlertDialog implements
+ ColorPickerView.OnColorChangedListener {
+
+ private ColorPickerView mColorPicker;
+
+ private ColorPanelView mOldColor;
+ private ColorPanelView mNewColor;
+ private Spinner mPulseSpeedOn;
+ private Spinner mPulseSpeedOff;
+ private LayoutInflater mInflater;
+
+ private OnColorChangedListener mListener;
+
+ protected LightSettingsDialog(Context context, int initialColor, int initialSpeedOn,
+ int initialSpeedOff) {
+ super(context);
+
+ init(initialColor, initialSpeedOn, initialSpeedOff);
+ }
+
+ private void init(int color, int speedOn, int speedOff) {
+ // To fight color banding.
+ getWindow().setFormat(PixelFormat.RGBA_8888);