From 095076110193dad66aac06de448ce359cbda8eb7 Mon Sep 17 00:00:00 2001 From: Alex Cruz Date: Sun, 26 Nov 2017 00:14:37 -0500 Subject: [PATCH] Improve color picker layout / cleaned up some of the code - Fixed possible NPE with calling getWindow() - Remove unnecessary panel of preset colors underneath the color picker - Changed dialog to AlertDialog to match LED color picker While this doesn't look EXACTLY like the LED color picker, this along with the commit below bring it closer than ever before. http://gerrit.dirtyunicorns.com/#/c/1199/ Change-Id: I13bc40d1882676d92e5c4ae4bfcf25865e88dad1 Signed-off-by: xyyx --- res/layout-land/dui_dialog_color_picker.xml | 83 +++--------- res/layout/dui_dialog_color_picker.xml | 91 +++---------- .../colorpicker/ColorPickerDialog.java | 120 +++++------------- 3 files changed, 66 insertions(+), 228 deletions(-) diff --git a/res/layout-land/dui_dialog_color_picker.xml b/res/layout-land/dui_dialog_color_picker.xml index 486cf16..10d95f4 100644 --- a/res/layout-land/dui_dialog_color_picker.xml +++ b/res/layout-land/dui_dialog_color_picker.xml @@ -19,106 +19,54 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="5dp" - android:paddingRight="5dp" + android:layout_marginStart="36dp" + android:layout_marginEnd="36dp" + android:padding="@dimen/alert_dialog_padding_material" android:orientation="horizontal"> + android:textSize="20sp" /> + android:layout_height="wrap_content" + android:hint="@string/hex_hint" /> - - - - - - - - - - - - - - - - - + android:layout_marginStart="10dp" + android:background="@android:color/transparent" + android:gravity="center" + android:src="@drawable/ic_action_set" /> - diff --git a/res/layout/dui_dialog_color_picker.xml b/res/layout/dui_dialog_color_picker.xml index 207c755..0dbd2bb 100644 --- a/res/layout/dui_dialog_color_picker.xml +++ b/res/layout/dui_dialog_color_picker.xml @@ -19,97 +19,46 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="5dp" - android:paddingRight="5dp" + android:layout_marginStart="36dp" + android:layout_marginEnd="36dp" + android:padding="@dimen/alert_dialog_padding_material" android:orientation="vertical"> + + + android:textSize="20sp" /> + android:layout_height="wrap_content" + android:hint="@string/hex_hint" /> - - - - - - - - - - - - - - - - - - + android:layout_marginStart="10dp" + android:background="@android:color/transparent" + android:gravity="center" + android:src="@drawable/ic_action_set" /> @@ -118,8 +67,8 @@ android:layout_height="wrap_content" android:text="@string/press_color_to_apply" android:gravity="center" - android:layout_marginTop="20dp" - android:layout_marginBottom="5dp" + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp" android:textAppearance="?android:attr/textAppearanceSmall" /> { + String text = mHex.getText().toString(); + try { + int newColor = ColorPickerPreference.convertToColorInt(text); + mColorPicker.setColor(newColor, true); + } catch (Exception ignored) { } }); } + + setView(layout); } @Override @@ -145,40 +107,20 @@ public class ColorPickerDialog if (mHex != null) { mHex.setText(ColorPickerPreference.convertToARGB(color)); } - } catch (Exception e) { - + } catch (Exception ignored) { } - /* - * if (mListener != null) { mListener.onColorChanged(color); } - */ - } - public void setAlphaSliderVisible(boolean visible) { + void setAlphaSliderVisible(boolean visible) { mColorPicker.setAlphaSliderVisible(visible); } - public void setColorAndClickAction(ColorPickerPanelView previewRect, final int color) { - if (previewRect != null) { - previewRect.setColor(color); - previewRect.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - try { - mColorPicker.setColor(color, true); - } catch (Exception e) { - } - } - }); - } - } - /** * Set a OnColorChangedListener to get notified when the color selected by the user has changed. * * @param listener */ - public void setOnColorChangedListener(OnColorChangedListener listener) { + void setOnColorChangedListener(OnColorChangedListener listener) { mListener = listener; } @@ -196,6 +138,7 @@ public class ColorPickerDialog dismiss(); } + @NonNull @Override public Bundle onSaveInstanceState() { Bundle state = super.onSaveInstanceState(); @@ -205,10 +148,9 @@ public class ColorPickerDialog } @Override - public void onRestoreInstanceState(Bundle savedInstanceState) { + public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); mOldColor.setColor(savedInstanceState.getInt("old_color")); mColorPicker.setColor(savedInstanceState.getInt("new_color"), true); } - }