summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid van Tonder <david.vantonder@gmail.com>2013-04-20 05:37:18 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2013-04-20 05:37:19 -0700
commit584edec4bf6cb1f2474416f35ccc14347d078261 (patch)
treea36c30c1f460e981ef7f06b49f9f1b026bb88bd7
parente73c802881db66a8cd6280dff241f21560452ad2 (diff)
parent90864abc085e205dba5d47a07faa5318f86d5591 (diff)
downloadpackages_apps_Settings-584edec4bf6cb1f2474416f35ccc14347d078261.zip
packages_apps_Settings-584edec4bf6cb1f2474416f35ccc14347d078261.tar.gz
packages_apps_Settings-584edec4bf6cb1f2474416f35ccc14347d078261.tar.bz2
Merge "Led Settings : Hex input for colorpicker" into cm-10.1
-rw-r--r--res/layout/dialog_light_settings.xml19
-rw-r--r--src/com/android/settings/notificationlight/ColorPickerView.java4
-rw-r--r--src/com/android/settings/notificationlight/LightSettingsDialog.java65
3 files changed, 64 insertions, 24 deletions
diff --git a/res/layout/dialog_light_settings.xml b/res/layout/dialog_light_settings.xml
index aa78c39..c8c4224 100644
--- a/res/layout/dialog_light_settings.xml
+++ b/res/layout/dialog_light_settings.xml
@@ -37,24 +37,17 @@
android:layout_marginTop="4dp"
android:orientation="horizontal" >
- <com.android.settings.notificationlight.ColorPanelView
- android:id="@+id/old_color_panel"
+ <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" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_marginStart="10dp"
- android:layout_marginEnd="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:id="@+id/color_panel"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="0.5" />
diff --git a/src/com/android/settings/notificationlight/ColorPickerView.java b/src/com/android/settings/notificationlight/ColorPickerView.java
index 817e397..56bfa32 100644
--- a/src/com/android/settings/notificationlight/ColorPickerView.java
+++ b/src/com/android/settings/notificationlight/ColorPickerView.java
@@ -159,8 +159,9 @@ public class ColorPickerView extends View {
initPaintTools();
// Needed for receiving track ball motion events.
- setFocusable(true);
setFocusableInTouchMode(true);
+ setFocusable(true);
+ setClickable(true);
}
private void initPaintTools() {
@@ -511,6 +512,7 @@ public class ColorPickerView extends View {
}
if (update) {
+ requestFocus();
if (mListener != null) {
mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[] {
mHue, mSat, mVal
diff --git a/src/com/android/settings/notificationlight/LightSettingsDialog.java b/src/com/android/settings/notificationlight/LightSettingsDialog.java
index 1aa46c5..de8efa7 100644
--- a/src/com/android/settings/notificationlight/LightSettingsDialog.java
+++ b/src/com/android/settings/notificationlight/LightSettingsDialog.java
@@ -18,16 +18,24 @@
package com.android.settings.notificationlight;
import java.util.ArrayList;
+import java.util.IllegalFormatException;
+import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
+import android.graphics.Color;
import android.graphics.PixelFormat;
+import android.text.Editable;
+import android.text.TextWatcher;
import android.util.Pair;
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;
@@ -37,11 +45,13 @@ import com.android.settings.R;
import com.android.settings.notificationlight.ColorPickerView.OnColorChangedListener;
public class LightSettingsDialog extends AlertDialog implements
- ColorPickerView.OnColorChangedListener {
+ ColorPickerView.OnColorChangedListener, TextWatcher, OnFocusChangeListener {
+
+ private final static String HEX_CODE_BASE = "#FF";
private ColorPickerView mColorPicker;
- private ColorPanelView mOldColor;
+ private EditText mHexColorInput;
private ColorPanelView mNewColor;
private Spinner mPulseSpeedOn;
private Spinner mPulseSpeedOff;
@@ -96,17 +106,13 @@ public class LightSettingsDialog extends AlertDialog implements
View layout = mInflater.inflate(R.layout.dialog_light_settings, null);
mColorPicker = (ColorPickerView) layout.findViewById(R.id.color_picker_view);
- mOldColor = (ColorPanelView) layout.findViewById(R.id.old_color_panel);
- mNewColor = (ColorPanelView) layout.findViewById(R.id.new_color_panel);
-
- ((LinearLayout) mOldColor.getParent()).setPadding(Math
- .round(mColorPicker.getDrawingOffset()), 0, Math
- .round(mColorPicker.getDrawingOffset()), 0);
+ mHexColorInput = (EditText) layout.findViewById(R.id.hex_color_input);
+ mNewColor = (ColorPanelView) layout.findViewById(R.id.color_panel);
mColorPicker.setOnColorChangedListener(this);
- mOldColor.setColor(color);
mColorPicker.setColor(color, true);
+ mHexColorInput.setOnFocusChangeListener(this);
mPulseSpeedOn = (Spinner) layout.findViewById(R.id.on_spinner);
PulseSpeedAdapter pulseSpeedAdapter = new PulseSpeedAdapter(
R.array.notification_pulse_length_entries,
@@ -145,7 +151,7 @@ public class LightSettingsDialog extends AlertDialog implements
@Override
public void onColorChanged(int color) {
mNewColor.setColor(color);
-
+ mHexColorInput.setText(Integer.toHexString(color));
if (mListener != null) {
mListener.onColorChanged(color);
}
@@ -159,10 +165,12 @@ public class LightSettingsDialog extends AlertDialog implements
return mColorPicker.getColor();
}
+ @SuppressWarnings("unchecked")
public int getPulseSpeedOn() {
return ((Pair<String, Integer>) mPulseSpeedOn.getSelectedItem()).second;
}
+ @SuppressWarnings("unchecked")
public int getPulseSpeedOff() {
// return 0 if 'Always on' is selected
return getPulseSpeedOn() == 1 ? 0 : ((Pair<String, Integer>) mPulseSpeedOff.getSelectedItem()).second;
@@ -248,4 +256,41 @@ public class LightSettingsDialog extends AlertDialog implements
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(HEX_CODE_BASE + hexColor);
+ mColorPicker.setColor(color);
+ mNewColor.setColor(color);
+ if (mListener != null) {
+ mListener.onColorChanged(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);
+ }
+ }
}