[2/3] omnigears: battery light settings
Also did a small layout change for notification lights
Change-Id: I9e80ce24a55083761a99fdb354d509b5574ad17f
diff --git a/res/layout/dialog_battery_settings.xml b/res/layout/dialog_battery_settings.xml
new file mode 100644
index 0000000..cea2c90
--- /dev/null
+++ b/res/layout/dialog_battery_settings.xml
@@ -0,0 +1,96 @@
+<?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="match_parent"
+ android:layout_height="match_parent" >
+
+ <org.omnirom.omnigears.ui.ColorPickerView
+ android:id="@+id/color_picker_view"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_marginStart="10dp"
+ android:layout_marginEnd="10dp" />
+
+ <LinearLayout
+ android:id="@+id/color_panel_view"
+ android:layout_width="match_parent"
+ android:layout_height="40dp"
+ android:layout_alignStart="@id/color_picker_view"
+ android:layout_alignEnd="@id/color_picker_view"
+ android:layout_below="@id/color_picker_view"
+ android:layout_marginBottom="4dp"
+ android:layout_marginTop="4dp"
+ android:orientation="horizontal" >
+
+ <EditText
+ android:id="@+id/hex_color_input"
+ android:layout_width="0px"
+ android:maxLength="6"
+ android:digits="0123456789ABCDEFabcdef"
+ android:inputType="textNoSuggestions"
+ android:layout_height="match_parent"
+ android:layout_weight="0.5" />
+
+ <org.omnirom.omnigears.ui.ColorPanelView
+ android:id="@+id/color_panel"
+ android:layout_width="0px"
+ android:layout_height="match_parent"
+ android:layout_weight="0.5" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/color_list_view"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/color_panel_view"
+ android:layout_marginStart="10dp"
+ android:layout_marginEnd="10dp"
+ android:layout_marginTop="4dp"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="4dp"
+ android:text="@string/color_list_title"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingBottom="4dip" >
+
+ <Spinner
+ android:id="@+id/color_list_spinner"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" />
+
+ <View
+ android:layout_width="8dip"
+ android:layout_height="match_parent" />
+
+ <org.omnirom.omnigears.ui.ColorPanelView
+ android:id="@+id/color_list_panel"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_weight="1" />
+ </LinearLayout>
+ </LinearLayout>
+</RelativeLayout>
diff --git a/res/layout/dialog_light_settings.xml b/res/layout/dialog_light_settings.xml
index 52d2bdb..e619ceb 100644
--- a/res/layout/dialog_light_settings.xml
+++ b/res/layout/dialog_light_settings.xml
@@ -18,7 +18,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" >
- <org.omnirom.omnigears.notificationlight.ColorPickerView
+ <org.omnirom.omnigears.ui.ColorPickerView
android:id="@+id/color_picker_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -46,7 +46,7 @@
android:layout_height="match_parent"
android:layout_weight="0.5" />
- <org.omnirom.omnigears.notificationlight.ColorPanelView
+ <org.omnirom.omnigears.ui.ColorPanelView
android:id="@+id/color_panel"
android:layout_width="0px"
android:layout_height="match_parent"
@@ -86,7 +86,7 @@
android:layout_width="8dip"
android:layout_height="match_parent" />
- <org.omnirom.omnigears.notificationlight.ColorPanelView
+ <org.omnirom.omnigears.ui.ColorPanelView
android:id="@+id/color_list_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/res/layout/preference_battery_light.xml b/res/layout/preference_battery_light.xml
new file mode 100644
index 0000000..95d4e5a
--- /dev/null
+++ b/res/layout/preference_battery_light.xml
@@ -0,0 +1,49 @@
+<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: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_alignStart="@android:id/title"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="?android:attr/textColorSecondary"
+ android:maxLines="1" />
+ </RelativeLayout>
+
+ <ImageView
+ android:id="@+id/light_color"
+ android:layout_width="32dip"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center" />
+
+</LinearLayout>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index ce949ee..c1377ae 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -61,9 +61,7 @@
<string name="dialog_test_button">Dismiss</string>
<!-- Lights settings screen, notification light settings -->
- <string name="display_lights_settings_title">Display & lights</string>
- <string name="lights_category_title">Lights</string>
- <string name="notification_pulse_title">Notification light</string>
+ <string name="notification_light_enable">Enable</string>
<string name="notification_light_general_title">General</string>
<string name="notification_light_applist_title">Applications</string>
<string name="notification_light_phonelist_title">Phone</string>
@@ -91,12 +89,14 @@
<string name="led_color_red">Red</string>
<!-- Battery light settings -->
- <string name="battery_light_title">Battery light</string>
+ <string name="battery_light_enable">Enable</string>
<string name="battery_low_pulse_title">Pulse if battery low</string>
<string name="battery_light_list_title">Colors</string>
<string name="battery_light_low_color_title">Battery low</string>
<string name="battery_light_medium_color_title">Charging</string>
- <string name="battery_light_full_color_title">Fully charged</string>
+ <string name="battery_light_full_color_title">Charged (90%)</string>
+ <string name="battery_light_really_full_color_title">Charged (100%)</string>
+ <string name="edit_battery_settings">Edit battery settings</string>
<!-- brightness settings -->
<string name="brightness_settings_title">Brightness setup</string>
diff --git a/res/xml/battery_light_settings.xml b/res/xml/battery_light_settings.xml
index d5fda1e..b3d73c6 100644
--- a/res/xml/battery_light_settings.xml
+++ b/res/xml/battery_light_settings.xml
@@ -17,16 +17,16 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+ <SwitchPreference
+ android:key="battery_light_enabled"
+ android:title="@string/battery_light_enable"
+ android:defaultValue="true" />
+
<PreferenceCategory
android:key="general_section"
android:title="@string/notification_light_general_title">
<CheckBoxPreference
- android:key="battery_light_enabled"
- android:title="@string/battery_light_title"
- android:defaultValue="true" />
-
- <CheckBoxPreference
android:key="battery_light_pulse"
android:title="@string/battery_low_pulse_title"
android:defaultValue="true"
@@ -39,21 +39,26 @@
android:title="@string/battery_light_list_title"
android:dependency="battery_light_enabled" >
- <org.omnirom.omnigears.notificationlight.ApplicationLightPreference
+ <org.omnirom.omnigears.batterylight.BatteryLightPreference
android:key="low_color"
android:title="@string/battery_light_low_color_title"
android:persistent="false" />
- <org.omnirom.omnigears.notificationlight.ApplicationLightPreference
+ <org.omnirom.omnigears.batterylight.BatteryLightPreference
android:key="medium_color"
android:title="@string/battery_light_medium_color_title"
android:persistent="false" />
- <org.omnirom.omnigears.notificationlight.ApplicationLightPreference
+ <org.omnirom.omnigears.batterylight.BatteryLightPreference
android:key="full_color"
android:title="@string/battery_light_full_color_title"
android:persistent="false" />
+ <org.omnirom.omnigears.batterylight.BatteryLightPreference
+ android:key="really_full_color"
+ android:title="@string/battery_light_really_full_color_title"
+ android:persistent="false" />
+
</PreferenceCategory>
</PreferenceScreen>
diff --git a/res/xml/notification_light_settings.xml b/res/xml/notification_light_settings.xml
index e40c970..1c7f73e 100644
--- a/res/xml/notification_light_settings.xml
+++ b/res/xml/notification_light_settings.xml
@@ -17,25 +17,19 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+ <SwitchPreference
+ android:key="notification_light_pulse"
+ android:title="@string/notification_light_enable" />
+
<PreferenceCategory
android:key="general_section"
android:title="@string/notification_light_general_title">
- <CheckBoxPreference
- android:key="notification_light_pulse"
- android:title="@string/notification_pulse_title" />
-
<org.omnirom.omnigears.notificationlight.ApplicationLightPreference
android:key="default"
android:title="@string/notification_light_default_value"
android:persistent="false"
android:dependency="notification_light_pulse" />
-
- <CheckBoxPreference
- android:key="notification_light_pulse_custom_enable"
- android:title="@string/notification_light_use_custom"
- android:dependency="notification_light_pulse" />
-
</PreferenceCategory>
<PreferenceCategory
@@ -56,6 +50,11 @@
</PreferenceCategory>
+ <SwitchPreference
+ android:key="notification_light_pulse_custom_enable"
+ android:title="@string/notification_light_use_custom"
+ android:dependency="notification_light_pulse" />
+
<PreferenceCategory
android:key="applications_list"
android:title="@string/notification_light_applist_title"
diff --git a/src/org/omnirom/omnigears/batterylight/BatteryLightDialog.java b/src/org/omnirom/omnigears/batterylight/BatteryLightDialog.java
new file mode 100644
index 0000000..062ed11
--- /dev/null
+++ b/src/org/omnirom/omnigears/batterylight/BatteryLightDialog.java
@@ -0,0 +1,291 @@
+/*
+ * 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 org.omnirom.omnigears.batterylight;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.graphics.Color;
+import android.graphics.PixelFormat;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.text.InputFilter;
+import android.text.InputFilter.LengthFilter;
+import android.util.Pair;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnFocusChangeListener;
+import android.view.ViewGroup;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+import android.widget.SpinnerAdapter;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import org.omnirom.omnigears.ui.ColorPanelView;
+import org.omnirom.omnigears.ui.ColorPickerView;
+import org.omnirom.omnigears.ui.ColorPickerView.OnColorChangedListener;
+
+import java.util.ArrayList;
+import java.util.IllegalFormatException;
+import java.util.Locale;
+
+public class BatteryLightDialog extends AlertDialog implements
+ ColorPickerView.OnColorChangedListener, TextWatcher, OnFocusChangeListener {
+
+ private static final String TAG = "BatteryLightDialog";
+ private final static String STATE_KEY_COLOR = "BatteryLightDialog:color";
+
+ private ColorPickerView mColorPicker;
+
+ private EditText mHexColorInput;
+ private ColorPanelView mNewColor;
+ private LayoutInflater mInflater;
+ private boolean mMultiColor = true;
+ private Spinner mColorList;
+ private LinearLayout mColorListView;
+ private LinearLayout mColorPanelView;
+ private ColorPanelView mNewListColor;
+ private LedColorAdapter mLedColorAdapter;
+
+ protected BatteryLightDialog(Context context, int initialColor) {
+ super(context);
+
+ mMultiColor = getContext().getResources().getBoolean(R.bool.config_has_multi_color_led);
+ init(initialColor);
+ }
+
+ private void init(int color) {
+ // To fight color banding.
+ getWindow().setFormat(PixelFormat.RGBA_8888);
+ setUp(color);
+ }
+
+ /**
+ * This function sets up the dialog with the proper values. If the speedOff parameters
+ * has a -1 value disable both spinners
+ *
+ * @param color - the color to set
+ * @param speedOn - the flash time in ms
+ * @param speedOff - the flash length in ms
+ */
+ private void setUp(int color) {
+ mInflater = (LayoutInflater) getContext()
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View layout = mInflater.inflate(R.layout.dialog_battery_settings, null);
+
+ mColorPicker = (ColorPickerView) layout.findViewById(R.id.color_picker_view);
+ mHexColorInput = (EditText) layout.findViewById(R.id.hex_color_input);
+ mNewColor = (ColorPanelView) layout.findViewById(R.id.color_panel);
+ mColorPanelView = (LinearLayout) layout.findViewById(R.id.color_panel_view);
+
+ mColorListView = (LinearLayout) layout.findViewById(R.id.color_list_view);
+ mColorList = (Spinner) layout.findViewById(R.id.color_list_spinner);
+ mNewListColor = (ColorPanelView) layout.findViewById(R.id.color_list_panel);
+
+ mColorPicker.setOnColorChangedListener(this);
+ mColorPicker.setColor(color, true);
+
+ mHexColorInput.setOnFocusChangeListener(this);
+
+ mColorList = (Spinner) layout.findViewById(R.id.color_list_spinner);
+ mLedColorAdapter = new LedColorAdapter(
+ R.array.entries_led_colors,
+ R.array.values_led_colors);
+ mColorList.setAdapter(mLedColorAdapter);
+ mColorList.setSelection(mLedColorAdapter.getColorPosition(color));
+ mColorList.setOnItemSelectedListener(mColorListListener);
+
+ setView(layout);
+ setTitle(R.string.edit_battery_settings);
+
+ // show and hide the correct UI depending if we have multi-color led or not
+ if (mMultiColor){
+ mColorListView.setVisibility(View.GONE);
+ mColorPicker.setVisibility(View.VISIBLE);
+ mColorPanelView.setVisibility(View.VISIBLE);
+ } else {
+ mColorListView.setVisibility(View.VISIBLE);
+ mColorPicker.setVisibility(View.GONE);
+ mColorPanelView.setVisibility(View.GONE);
+ }
+ }
+
+ private AdapterView.OnItemSelectedListener mColorListListener = new AdapterView.OnItemSelectedListener() {
+
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ int color = mLedColorAdapter.getColor(position);
+ mNewListColor.setColor(color);
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ }
+ };
+
+ @Override
+ public Bundle onSaveInstanceState() {
+ Bundle state = super.onSaveInstanceState();
+ state.putInt(STATE_KEY_COLOR, getColor());
+ return state;
+ }
+
+ @Override
+ public void onRestoreInstanceState(Bundle state) {
+ super.onRestoreInstanceState(state);
+ mColorPicker.setColor(state.getInt(STATE_KEY_COLOR), true);
+ }
+
+ @Override
+ public void onColorChanged(int color) {
+ final boolean hasAlpha = mColorPicker.isAlphaSliderVisible();
+ final String format = hasAlpha ? "%08x" : "%06x";
+ final int mask = hasAlpha ? 0xFFFFFFFF : 0x00FFFFFF;
+
+ mNewColor.setColor(color);
+ mHexColorInput.setText(String.format(Locale.US, format, color & mask));
+ }
+
+ public void setAlphaSliderVisible(boolean visible) {
+ mHexColorInput.setFilters(new InputFilter[] { new InputFilter.LengthFilter(visible ? 8 : 6) } );
+ mColorPicker.setAlphaSliderVisible(visible);
+ }
+
+ public int getColor() {
+ if (mMultiColor){
+ return mColorPicker.getColor();
+ } else {
+ return mNewListColor.getColor();
+ }
+ }
+
+ class LedColorAdapter extends BaseAdapter implements SpinnerAdapter {
+ private ArrayList<Pair<String, Integer>> mColors;
+
+ public LedColorAdapter(int ledColorResource, int ledValueResource) {
+ mColors = new ArrayList<Pair<String, Integer>>();
+
+ String[] color_names = getContext().getResources().getStringArray(ledColorResource);
+ String[] color_values = getContext().getResources().getStringArray(ledValueResource);
+
+ for(int i = 0; i < color_values.length; ++i) {
+ try {
+ int color = Color.parseColor(color_values[i]);
+ mColors.add(new Pair<String, Integer>(color_names[i], color));
+ } catch (IllegalArgumentException ex) {
+ // Number format is incorrect, ignore entry
+ }
+ }
+ }
+
+ /**
+ * Will return the position of the spinner entry with the specified
+ * color. Returns 0 if there is no such entry.
+ */
+ public int getColorPosition(int color) {
+ for (int position = 0; position < getCount(); ++position) {
+ if (getItem(position).second.equals(color)) {
+ return position;
+ }
+ }
+
+ return 0;
+ }
+
+ public int getColor(int position) {
+ Pair<String, Integer> item = getItem(position);
+ if (item != null){
+ return item.second;
+ }
+
+ // -1 is white
+ return -1;
+ }
+
+ @Override
+ public int getCount() {
+ return mColors.size();
+ }
+
+ @Override
+ public Pair<String, Integer> getItem(int position) {
+ return mColors.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View view, ViewGroup parent) {
+ if (view == null) {
+ view = mInflater.inflate(R.layout.led_color_item, null);
+ }
+
+ Pair<String, Integer> entry = getItem(position);
+ ((TextView) view.findViewById(R.id.textViewName)).setText(entry.first);
+
+ return view;
+ }
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ String hexColor = mHexColorInput.getText().toString();
+ if (!hexColor.isEmpty()) {
+ try {
+ int color = Color.parseColor('#' + hexColor);
+ if (!mColorPicker.isAlphaSliderVisible()) {
+ color |= 0xFF000000; // set opaque
+ }
+ mColorPicker.setColor(color);
+ mNewColor.setColor(color);
+ } catch (IllegalArgumentException ex) {
+ // Number format is incorrect, ignore
+ }
+ }
+ }
+
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (!hasFocus) {
+ mHexColorInput.removeTextChangedListener(this);
+ InputMethodManager inputMethodManager = (InputMethodManager) getContext()
+ .getSystemService(Activity.INPUT_METHOD_SERVICE);
+ inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
+ } else {
+ mHexColorInput.addTextChangedListener(this);
+ }
+ }
+}
diff --git a/src/org/omnirom/omnigears/batterylight/BatteryLightPreference.java b/src/org/omnirom/omnigears/batterylight/BatteryLightPreference.java
new file mode 100644
index 0000000..90e6f8f
--- /dev/null
+++ b/src/org/omnirom/omnigears/batterylight/BatteryLightPreference.java
@@ -0,0 +1,133 @@
+/*
+ * 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 org.omnirom.omnigears.batterylight;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+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.os.Bundle;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.android.settings.R;
+
+public class BatteryLightPreference extends DialogPreference {
+
+ private static String TAG = "BatteryLightPreference";
+ public static final int DEFAULT_COLOR = 0xFFFFFF; //White
+
+ private ImageView mLightColorView;
+ private Resources mResources;
+ private int mColorValue;
+
+ /**
+ * @param context
+ * @param attrs
+ */
+ public BatteryLightPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mColorValue = DEFAULT_COLOR;
+ init();
+ }
+
+ public BatteryLightPreference(Context context, int color) {
+ super(context, null);
+ mColorValue = color;
+ init();
+ }
+
+ private void init() {
+ setLayoutResource(R.layout.preference_battery_light);
+ mResources = getContext().getResources();
+ }
+
+ public void setColor(int color) {
+ mColorValue = color;
+ updatePreferenceViews();
+ }
+
+ public int getColor() {
+ return mColorValue;
+ }
+
+ @Override
+ protected void onBindView(View view) {
+ super.onBindView(view);
+
+ mLightColorView = (ImageView) view.findViewById(R.id.light_color);
+
+ 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));
+ }
+ }
+
+ @Override
+ protected void showDialog(Bundle state) {
+ super.showDialog(state);
+ }
+
+ @Override
+ protected Dialog createDialog() {
+ final BatteryLightDialog d = new BatteryLightDialog(getContext(),
+ 0xFF000000 + mColorValue);
+ d.setAlphaSliderVisible(false);
+
+ d.setButton(AlertDialog.BUTTON_POSITIVE, mResources.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
+ updatePreferenceViews();
+ callChangeListener(this);
+ }
+ });
+ d.setButton(AlertDialog.BUTTON_NEGATIVE, mResources.getString(R.string.cancel),
+ (DialogInterface.OnClickListener) null);
+
+ return d;
+ }
+
+ 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;
+ }
+}
diff --git a/src/org/omnirom/omnigears/notificationlight/BatteryLightSettings.java b/src/org/omnirom/omnigears/batterylight/BatteryLightSettings.java
similarity index 61%
rename from src/org/omnirom/omnigears/notificationlight/BatteryLightSettings.java
rename to src/org/omnirom/omnigears/batterylight/BatteryLightSettings.java
index 63b1da1..9e5bc2d 100644
--- a/src/org/omnirom/omnigears/notificationlight/BatteryLightSettings.java
+++ b/src/org/omnirom/omnigears/batterylight/BatteryLightSettings.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.omnirom.omnigears.notificationlight;
+package org.omnirom.omnigears.batterylight;
import android.content.ContentResolver;
import android.content.res.Resources;
@@ -23,6 +23,7 @@
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuInflater;
@@ -38,14 +39,20 @@
private static final String LOW_COLOR_PREF = "low_color";
private static final String MEDIUM_COLOR_PREF = "medium_color";
private static final String FULL_COLOR_PREF = "full_color";
+ private static final String REALLY_FULL_COLOR_PREF = "really_full_color";
+ private static final String BATTERY_LIGHT_PREF = "battery_light_enabled";
+ private static final String BATTERY_PULSE_PREF = "battery_light_pulse";
private boolean mMultiColorLed;
- private CheckBoxPreference mEnabledPref;
+ private SwitchPreference mEnabledPref;
+ private CheckBoxPreference mPulsePref;
private PreferenceGroup mColorPrefs;
- private ApplicationLightPreference mLowColorPref;
- private ApplicationLightPreference mMediumColorPref;
- private ApplicationLightPreference mFullColorPref;
+ private BatteryLightPreference mLowColorPref;
+ private BatteryLightPreference mMediumColorPref;
+ private BatteryLightPreference mFullColorPref;
+ private BatteryLightPreference mReallyFullColorPref;
private static final int MENU_RESET = Menu.FIRST;
+ private int mLowBatteryWarningLevel;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -53,20 +60,36 @@
addPreferencesFromResource(R.xml.battery_light_settings);
PreferenceScreen prefSet = getPreferenceScreen();
+ ContentResolver resolver = getContentResolver();
+
+ mLowBatteryWarningLevel = getResources().getInteger(
+ com.android.internal.R.integer.config_lowBatteryWarningLevel);
+
+ mEnabledPref = (SwitchPreference)prefSet.findPreference(BATTERY_LIGHT_PREF);
+ mEnabledPref.setChecked(Settings.System.getInt(resolver,
+ Settings.System.BATTERY_LIGHT_ENABLED, 1) != 0);
+ mEnabledPref.setOnPreferenceChangeListener(this);
+
+ mPulsePref = (CheckBoxPreference)prefSet.findPreference(BATTERY_PULSE_PREF);
+ mPulsePref.setChecked(Settings.System.getInt(resolver,
+ Settings.System.BATTERY_LIGHT_PULSE, 1) != 0);
// Does the Device support changing battery LED colors?
if (getResources().getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed)) {
setHasOptionsMenu(true);
// Low, Medium and full color preferences
- mLowColorPref = (ApplicationLightPreference) prefSet.findPreference(LOW_COLOR_PREF);
+ mLowColorPref = (BatteryLightPreference) prefSet.findPreference(LOW_COLOR_PREF);
mLowColorPref.setOnPreferenceChangeListener(this);
- mMediumColorPref = (ApplicationLightPreference) prefSet.findPreference(MEDIUM_COLOR_PREF);
+ mMediumColorPref = (BatteryLightPreference) prefSet.findPreference(MEDIUM_COLOR_PREF);
mMediumColorPref.setOnPreferenceChangeListener(this);
- mFullColorPref = (ApplicationLightPreference) prefSet.findPreference(FULL_COLOR_PREF);
+ mFullColorPref = (BatteryLightPreference) prefSet.findPreference(FULL_COLOR_PREF);
mFullColorPref.setOnPreferenceChangeListener(this);
+
+ mReallyFullColorPref = (BatteryLightPreference) prefSet.findPreference(REALLY_FULL_COLOR_PREF);
+ mReallyFullColorPref.setOnPreferenceChangeListener(this);
} else {
prefSet.removePreference(prefSet.findPreference("colors_list"));
}
@@ -85,19 +108,25 @@
if (mLowColorPref != null) {
int lowColor = Settings.System.getInt(resolver, Settings.System.BATTERY_LIGHT_LOW_COLOR,
res.getInteger(com.android.internal.R.integer.config_notificationsBatteryLowARGB));
- mLowColorPref.setAllValues(lowColor, 0, 0, false);
+ mLowColorPref.setColor(lowColor);
}
if (mMediumColorPref != null) {
int mediumColor = Settings.System.getInt(resolver, Settings.System.BATTERY_LIGHT_MEDIUM_COLOR,
res.getInteger(com.android.internal.R.integer.config_notificationsBatteryMediumARGB));
- mMediumColorPref.setAllValues(mediumColor, 0, 0, false);
+ mMediumColorPref.setColor(mediumColor);
}
if (mFullColorPref != null) {
int fullColor = Settings.System.getInt(resolver, Settings.System.BATTERY_LIGHT_FULL_COLOR,
res.getInteger(com.android.internal.R.integer.config_notificationsBatteryFullARGB));
- mFullColorPref.setAllValues(fullColor, 0, 0, false);
+ mFullColorPref.setColor(fullColor);
+ }
+
+ if (mReallyFullColorPref != null) {
+ int reallyFullColor = Settings.System.getInt(resolver, Settings.System.BATTERY_LIGHT_REALLY_FULL_COLOR,
+ res.getInteger(com.android.internal.R.integer.config_notificationsBatteryFullARGB));
+ mReallyFullColorPref.setColor(reallyFullColor);
}
}
@@ -116,6 +145,8 @@
Settings.System.putInt(resolver, Settings.System.BATTERY_LIGHT_MEDIUM_COLOR, color);
} else if (key.equals(FULL_COLOR_PREF)) {
Settings.System.putInt(resolver, Settings.System.BATTERY_LIGHT_FULL_COLOR, color);
+ } else if (key.equals(REALLY_FULL_COLOR_PREF)) {
+ Settings.System.putInt(resolver, Settings.System.BATTERY_LIGHT_REALLY_FULL_COLOR, color);
}
}
@@ -148,14 +179,35 @@
res.getInteger(com.android.internal.R.integer.config_notificationsBatteryMediumARGB));
Settings.System.putInt(resolver, Settings.System.BATTERY_LIGHT_FULL_COLOR,
res.getInteger(com.android.internal.R.integer.config_notificationsBatteryFullARGB));
+ Settings.System.putInt(resolver, Settings.System.BATTERY_LIGHT_REALLY_FULL_COLOR,
+ res.getInteger(com.android.internal.R.integer.config_notificationsBatteryFullARGB));
refreshDefault();
}
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
- ApplicationLightPreference lightPref = (ApplicationLightPreference) preference;
- updateValues(lightPref.getKey(), lightPref.getColor());
-
+ if (preference == mEnabledPref) {
+ boolean value = (Boolean) objValue;
+ Settings.System.putInt(getActivity().getContentResolver(),
+ Settings.System.BATTERY_LIGHT_ENABLED, value ? 1:0);
+ } else {
+ BatteryLightPreference lightPref = (BatteryLightPreference) preference;
+ updateValues(lightPref.getKey(), lightPref.getColor());
+ }
return true;
}
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ if (preference == mPulsePref) {
+ boolean checked = ((CheckBoxPreference)preference).isChecked();
+ Settings.System.putInt(getActivity().getContentResolver(),
+ Settings.System.BATTERY_LIGHT_PULSE, checked ? 1:0);
+
+ return true;
+ }
+
+ return super.onPreferenceTreeClick(preferenceScreen, preference);
+ }
+
}
diff --git a/src/org/omnirom/omnigears/notificationlight/LightSettingsDialog.java b/src/org/omnirom/omnigears/notificationlight/LightSettingsDialog.java
index 93e1296..e58125b 100644
--- a/src/org/omnirom/omnigears/notificationlight/LightSettingsDialog.java
+++ b/src/org/omnirom/omnigears/notificationlight/LightSettingsDialog.java
@@ -43,7 +43,9 @@
import android.widget.TextView;
import com.android.settings.R;
-import org.omnirom.omnigears.notificationlight.ColorPickerView.OnColorChangedListener;
+import org.omnirom.omnigears.ui.ColorPanelView;
+import org.omnirom.omnigears.ui.ColorPickerView;
+import org.omnirom.omnigears.ui.ColorPickerView.OnColorChangedListener;
import java.util.ArrayList;
import java.util.IllegalFormatException;
diff --git a/src/org/omnirom/omnigears/notificationlight/NotificationLightSettings.java b/src/org/omnirom/omnigears/notificationlight/NotificationLightSettings.java
index 70019bb..6bdb57b 100644
--- a/src/org/omnirom/omnigears/notificationlight/NotificationLightSettings.java
+++ b/src/org/omnirom/omnigears/notificationlight/NotificationLightSettings.java
@@ -35,6 +35,7 @@
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
@@ -91,8 +92,8 @@
private int mDefaultLedOff;
private PackageManager mPackageManager;
private PreferenceGroup mApplicationPrefList;
- private CheckBoxPreference mEnabledPref;
- private CheckBoxPreference mCustomEnabledPref;
+ private SwitchPreference mEnabledPref;
+ private SwitchPreference mCustomEnabledPref;
private ApplicationLightPreference mDefaultPref;
private ApplicationLightPreference mCallPref;
private ApplicationLightPreference mVoicemailPref;
@@ -114,12 +115,12 @@
mDefaultLedOff = resources.getInteger(
com.android.internal.R.integer.config_defaultNotificationLedOff);
- mEnabledPref = (CheckBoxPreference)
+ mEnabledPref = (SwitchPreference)
findPreference(Settings.System.NOTIFICATION_LIGHT_PULSE);
mEnabledPref.setChecked(Settings.System.getInt(getContentResolver(),
Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0);
mEnabledPref.setOnPreferenceChangeListener(this);
- mCustomEnabledPref = (CheckBoxPreference)
+ mCustomEnabledPref = (SwitchPreference)
findPreference(Settings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE);
mCustomEnabledPref.setChecked(Settings.System.getInt(getContentResolver(),
Settings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE, 0) != 0);
diff --git a/src/org/omnirom/omnigears/notificationlight/AlphaPatternDrawable.java b/src/org/omnirom/omnigears/ui/AlphaPatternDrawable.java
similarity index 98%
rename from src/org/omnirom/omnigears/notificationlight/AlphaPatternDrawable.java
rename to src/org/omnirom/omnigears/ui/AlphaPatternDrawable.java
index a527151..110912e 100644
--- a/src/org/omnirom/omnigears/notificationlight/AlphaPatternDrawable.java
+++ b/src/org/omnirom/omnigears/ui/AlphaPatternDrawable.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.omnirom.omnigears.notificationlight;
+package org.omnirom.omnigears.ui;
import android.graphics.Bitmap;
import android.graphics.Canvas;
diff --git a/src/org/omnirom/omnigears/notificationlight/ColorPanelView.java b/src/org/omnirom/omnigears/ui/ColorPanelView.java
similarity index 98%
rename from src/org/omnirom/omnigears/notificationlight/ColorPanelView.java
rename to src/org/omnirom/omnigears/ui/ColorPanelView.java
index 59eb56d..45fc109 100644
--- a/src/org/omnirom/omnigears/notificationlight/ColorPanelView.java
+++ b/src/org/omnirom/omnigears/ui/ColorPanelView.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.omnirom.omnigears.notificationlight;
+package org.omnirom.omnigears.ui;
import android.content.Context;
import android.graphics.Canvas;
diff --git a/src/org/omnirom/omnigears/notificationlight/ColorPickerView.java b/src/org/omnirom/omnigears/ui/ColorPickerView.java
similarity index 99%
rename from src/org/omnirom/omnigears/notificationlight/ColorPickerView.java
rename to src/org/omnirom/omnigears/ui/ColorPickerView.java
index ec2e2c7..72316f3 100644
--- a/src/org/omnirom/omnigears/notificationlight/ColorPickerView.java
+++ b/src/org/omnirom/omnigears/ui/ColorPickerView.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.omnirom.omnigears.notificationlight;
+package org.omnirom.omnigears.ui;
import android.content.Context;
import android.graphics.Canvas;