Browse Source

Fixed a bug in the color chooser, added custom user input feature to color chooser

Aidan Follestad 9 years ago
parent
commit
1de1782eb9

+ 20 - 2
README.md

@@ -54,6 +54,7 @@
 
 1. [Color Chooser Dialogs](https://github.com/afollestad/material-dialogs#color-chooser-dialogs)
     1. [Finding Visible Dialogs](https://github.com/afollestad/material-dialogs#finding-visible-dialogs)
+    2. [User Color Input](https://github.com/afollestad/material-dialogs#user-color-input)
 2. [Folder Selector Dialogs](https://github.com/afollestad/material-dialogs#folder-selector-dialogs)
 3. [Preference Dialogs](https://github.com/afollestad/material-dialogs#preference-dialogs)
 4. [Simple List Dialogs](https://github.com/afollestad/material-dialogs#simple-list-dialogs) 
@@ -97,7 +98,10 @@ You can create basic, list, single/multi choice, progress, input, etc. dialogs w
 
 ```gradle
 dependencies {
-    compile('com.afollestad.material-dialogs:core:0.8.4.0@aar') {
+
+    // ... other dependencies here
+    
+    compile('com.afollestad.material-dialogs:core:0.8.4.1@aar') {
         transitive = true
     }
 }
@@ -110,7 +114,10 @@ The *commons* module contains extensions to the library that not everyone may ne
 
 ```gradle
 dependencies {
-    compile('com.afollestad.material-dialogs:commons:0.8.3.0@aar') {
+
+    // ... other dependencies here
+    
+    compile('com.afollestad.material-dialogs:commons:0.8.4.1@aar') {
         transitive = true
     }
 }
@@ -1153,6 +1160,17 @@ ColorChooserDialog accent = ColorChooserDialog.findVisible(this, ColorChooserDia
 ColorChooserDialog custom = ColorChooserDialog.findVisible(this, ColorChooserDialog.TAG_CUSTOM);
 ```
 
+## User Color Input
+
+By default, color chooser dialogs allow the user to input a custom color using RGB sliders or a Hexadecimal input field.
+This can be disabled if you don't want users to be able to use it:
+
+```java
+new ColorChooserDialog.Builder(this, R.string.color_palette)
+    .allowUserColorInput(false)
+    .show();
+```
+
 ---
 
 # Preference Dialogs

+ 1 - 1
commons/build.gradle

@@ -11,7 +11,7 @@ android {
         minSdkVersion 8
         targetSdkVersion 23
         versionCode 1
-        versionName "0.8.4.0"
+        versionName "0.8.4.1"
     }
     lintOptions {
         abortOnError false

+ 150 - 28
commons/src/main/java/com/afollestad/materialdialogs/color/ColorChooserDialog.java

@@ -3,6 +3,7 @@ package com.afollestad.materialdialogs.color;
 import android.app.Activity;
 import android.app.Dialog;
 import android.content.DialogInterface;
+import android.graphics.Color;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.annotation.ArrayRes;
@@ -15,13 +16,15 @@ import android.support.v4.app.DialogFragment;
 import android.support.v4.app.Fragment;
 import android.support.v4.content.res.ResourcesCompat;
 import android.support.v7.app.AppCompatActivity;
-import android.util.DisplayMetrics;
-import android.util.TypedValue;
-import android.view.Gravity;
+import android.text.Editable;
+import android.text.TextWatcher;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
+import android.widget.EditText;
 import android.widget.GridView;
+import android.widget.SeekBar;
+import android.widget.TextView;
 
 import com.afollestad.materialdialogs.DialogAction;
 import com.afollestad.materialdialogs.MaterialDialog;
@@ -80,6 +83,19 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
     private ColorCallback mCallback;
     private GridView mGrid;
 
+    private View mColorChooserCustomFrame;
+    private EditText mCustomColorHex;
+    private View mCustomColorIndicator;
+    private TextWatcher mCustomColorTextWatcher;
+    private SeekBar mCustomSeekR;
+    private TextView mCustomSeekRValue;
+    private SeekBar mCustomSeekG;
+    private TextView mCustomSeekGValue;
+    private SeekBar mCustomSeekB;
+    private TextView mCustomSeekBValue;
+    private SeekBar.OnSeekBarChangeListener mCustomColorRgbListener;
+    private int mSelectedCustomColor;
+
     @Override
     public void onAttach(Activity activity) {
         super.onAttach(activity);
@@ -142,7 +158,7 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
             } else {
                 topIndex(index);
                 if (mColorsSub != null && index < mColorsSub.length) {
-                    dialog.setActionButton(DialogAction.NEUTRAL, builder.mBackBtn);
+                    dialog.setActionButton(DialogAction.NEGATIVE, builder.mBackBtn);
                     isInSub(true);
                 }
             }
@@ -158,12 +174,15 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
             final MaterialDialog dialog = (MaterialDialog) getDialog();
             int selectedColor = getSelectedColor();
             dialog.getActionButton(DialogAction.POSITIVE).setTextColor(selectedColor);
-            dialog.getActionButton(DialogAction.NEUTRAL).setTextColor(selectedColor);
+            dialog.getActionButton(DialogAction.NEGATIVE).setTextColor(selectedColor);
         }
     }
 
     @ColorInt
     private int getSelectedColor() {
+        if (mColorChooserCustomFrame != null && mColorChooserCustomFrame.getVisibility() == View.VISIBLE)
+            return mSelectedCustomColor;
+
         int color = 0;
         if (subIndex() > -1)
             color = mColorsSub[topIndex()][subIndex()];
@@ -183,9 +202,9 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
     }
 
     private void findSubIndexForColor(int topIndex, int color) {
-        if (getBuilder().mColorsSub == null || getBuilder().mColorsSub.length - 1 < topIndex)
+        if (mColorsSub == null || mColorsSub.length - 1 < topIndex)
             return;
-        int[] subColors = getBuilder().mColorsSub[topIndex];
+        int[] subColors = mColorsSub[topIndex];
         for (int subIndex = 0; subIndex < subColors.length; subIndex++) {
             if (subColors[subIndex] == color) {
                 subIndex(subIndex);
@@ -208,7 +227,7 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
                     topIndex(topIndex);
                     if (getBuilder().mAccentMode) {
                         subIndex(2);
-                    } else if (getBuilder().mColorsSub != null) {
+                    } else if (mColorsSub != null) {
                         findSubIndexForColor(topIndex, preselectColor);
                     } else {
                         subIndex(5);
@@ -231,29 +250,16 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
             }
         }
 
-        final DisplayMetrics dm = getResources().getDisplayMetrics();
-        mCircleSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, dm);
-        mGrid = new GridView(getContext());
-        mGrid.setLayoutParams(new ViewGroup.LayoutParams(
-                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
-        mGrid.setColumnWidth(mCircleSize);
-        mGrid.setNumColumns(GridView.AUTO_FIT);
-        final int eightDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm);
-        mGrid.setVerticalSpacing(eightDp);
-        mGrid.setHorizontalSpacing(eightDp);
-        final int sixteenDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, dm);
-        mGrid.setPadding(sixteenDp, sixteenDp, sixteenDp, sixteenDp);
-        mGrid.setClipToPadding(false);
-        mGrid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
-        mGrid.setGravity(Gravity.CENTER);
+        mCircleSize = getResources().getDimensionPixelSize(R.dimen.md_colorchooser_circlesize);
+        final Builder builder = getBuilder();
 
-        Builder builder = getBuilder();
         MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
                 .title(getTitle())
                 .autoDismiss(false)
-                .customView(mGrid, false)
-                .neutralText(builder.mCancelBtn)
+                .customView(R.layout.md_dialog_colorchooser, false)
+                .negativeText(builder.mCancelBtn)
                 .positiveText(builder.mDoneBtn)
+                .neutralText(builder.mAllowUserCustom ? builder.mCustomBtn : 0)
                 .onPositive(new MaterialDialog.SingleButtonCallback() {
                     @Override
                     public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
@@ -261,11 +267,11 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
                         dismiss();
                     }
                 })
-                .onNeutral(new MaterialDialog.SingleButtonCallback() {
+                .onNegative(new MaterialDialog.SingleButtonCallback() {
                     @Override
                     public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                         if (isInSub()) {
-                            dialog.setActionButton(DialogAction.NEUTRAL, getBuilder().mCancelBtn);
+                            dialog.setActionButton(DialogAction.NEGATIVE, getBuilder().mCancelBtn);
                             isInSub(false);
                             invalidate();
                         } else {
@@ -273,6 +279,12 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
                         }
                     }
                 })
+                .onNeutral(new MaterialDialog.SingleButtonCallback() {
+                    @Override
+                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
+                        toggleCustom(dialog);
+                    }
+                })
                 .showListener(new DialogInterface.OnShowListener() {
                     @Override
                     public void onShow(DialogInterface dialog) {
@@ -280,10 +292,105 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
                     }
                 })
                 .build();
+
+        final View v = dialog.getCustomView();
+        mGrid = (GridView) v.findViewById(R.id.grid);
+
+        if (builder.mAllowUserCustom) {
+            mColorChooserCustomFrame = v.findViewById(R.id.colorChooserCustomFrame);
+            mCustomColorHex = (EditText) v.findViewById(R.id.hexInput);
+            mCustomColorIndicator = v.findViewById(R.id.colorIndicator);
+            mCustomSeekR = (SeekBar) v.findViewById(R.id.colorR);
+            mCustomSeekRValue = (TextView) v.findViewById(R.id.colorRValue);
+            mCustomSeekG = (SeekBar) v.findViewById(R.id.colorG);
+            mCustomSeekGValue = (TextView) v.findViewById(R.id.colorGValue);
+            mCustomSeekB = (SeekBar) v.findViewById(R.id.colorB);
+            mCustomSeekBValue = (TextView) v.findViewById(R.id.colorBValue);
+        }
+
         invalidate();
         return dialog;
     }
 
+    private void toggleCustom(MaterialDialog dialog) {
+        if (mGrid.getVisibility() == View.VISIBLE) {
+            dialog.setTitle(getBuilder().mCustomBtn);
+            dialog.setActionButton(DialogAction.NEUTRAL, getBuilder().mBackBtn);
+            mGrid.setVisibility(View.GONE);
+            mColorChooserCustomFrame.setVisibility(View.VISIBLE);
+            mCustomColorTextWatcher = new TextWatcher() {
+                @Override
+                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+                }
+
+                @Override
+                public void onTextChanged(CharSequence s, int start, int before, int count) {
+                    try {
+                        mSelectedCustomColor = Color.parseColor("#" + s.toString());
+                    } catch (IllegalArgumentException e) {
+                        mSelectedCustomColor = Color.BLACK;
+                    }
+                    mCustomColorIndicator.setBackgroundColor(mSelectedCustomColor);
+                    int red = Color.red(mSelectedCustomColor);
+                    mCustomSeekR.setProgress(red);
+                    mCustomSeekRValue.setText(String.format("%d", red));
+                    int green = Color.green(mSelectedCustomColor);
+                    mCustomSeekG.setProgress(green);
+                    mCustomSeekGValue.setText(String.format("%d", green));
+                    int blue = Color.blue(mSelectedCustomColor);
+                    mCustomSeekB.setProgress(blue);
+                    mCustomSeekBValue.setText(String.format("%d", blue));
+                }
+
+                @Override
+                public void afterTextChanged(Editable s) {
+                }
+            };
+            mCustomColorHex.addTextChangedListener(mCustomColorTextWatcher);
+            mCustomColorHex.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+                @Override
+                public void onFocusChange(View v, boolean hasFocus) {
+                    mCustomColorHex.selectAll();
+                }
+            });
+            mCustomColorRgbListener = new SeekBar.OnSeekBarChangeListener() {
+                @Override
+                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                    if (fromUser) {
+                        int color = Color.rgb(mCustomSeekR.getProgress(),
+                                mCustomSeekG.getProgress(),
+                                mCustomSeekB.getProgress());
+                        mCustomColorHex.setText(String.format("%06X", 0xFFFFFF & color));
+                    }
+                }
+
+                @Override
+                public void onStartTrackingTouch(SeekBar seekBar) {
+                }
+
+                @Override
+                public void onStopTrackingTouch(SeekBar seekBar) {
+                }
+            };
+            mCustomSeekR.setOnSeekBarChangeListener(mCustomColorRgbListener);
+            mCustomSeekG.setOnSeekBarChangeListener(mCustomColorRgbListener);
+            mCustomSeekB.setOnSeekBarChangeListener(mCustomColorRgbListener);
+            mCustomColorHex.setText(String.format("%06X", 0xFFFFFF & getBuilder().mPreselect));
+        } else {
+            dialog.setTitle(getBuilder().mTitle);
+            dialog.setActionButton(DialogAction.NEUTRAL, getBuilder().mCustomBtn);
+            mGrid.setVisibility(View.VISIBLE);
+            mColorChooserCustomFrame.setVisibility(View.GONE);
+            mCustomColorHex.removeTextChangedListener(mCustomColorTextWatcher);
+            mCustomColorHex.setOnFocusChangeListener(null);
+            mCustomColorTextWatcher = null;
+            mCustomSeekR.setOnSeekBarChangeListener(null);
+            mCustomSeekG.setOnSeekBarChangeListener(null);
+            mCustomSeekB.setOnSeekBarChangeListener(null);
+            mCustomColorRgbListener = null;
+        }
+    }
+
     private void invalidate() {
         if (mGrid.getAdapter() == null) {
             mGrid.setAdapter(new ColorGridAdapter());
@@ -349,6 +456,8 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
         protected int mBackBtn = R.string.md_back_label;
         @StringRes
         protected int mCancelBtn = R.string.md_cancel_label;
+        @StringRes
+        protected int mCustomBtn = R.string.md_custom_label;
         @Nullable
         protected int[] mColorsTop;
         @Nullable
@@ -356,6 +465,7 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
 
         protected boolean mAccentMode = false;
         protected boolean mDynamicButtonColor = true;
+        protected boolean mAllowUserCustom = true;
 
         public <ActivityType extends AppCompatActivity & ColorCallback> Builder(@NonNull ActivityType context, @StringRes int title) {
             mContext = context;
@@ -398,6 +508,12 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
             return this;
         }
 
+        @NonNull
+        public Builder customButton(@StringRes int text) {
+            mCustomBtn = text;
+            return this;
+        }
+
         @NonNull
         public Builder dynamicButtonColor(boolean enabled) {
             mDynamicButtonColor = enabled;
@@ -418,6 +534,12 @@ public class ColorChooserDialog extends DialogFragment implements View.OnClickLi
             return this;
         }
 
+        @NonNull
+        public Builder allowUserColorInput(boolean allow) {
+            mAllowUserCustom = allow;
+            return this;
+        }
+
         @NonNull
         public ColorChooserDialog build() {
             ColorChooserDialog dialog = new ColorChooserDialog();

+ 13 - 0
commons/src/main/res/layout/md_dialog_colorchooser.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <include layout="@layout/md_stub_colorchooser_grid" />
+
+    <include
+        layout="@layout/md_stub_colorchooser_custom"
+        android:visibility="gone" />
+
+</FrameLayout>

+ 186 - 0
commons/src/main/res/layout/md_stub_colorchooser_custom.xml

@@ -0,0 +1,186 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/colorChooserCustomFrame"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:paddingBottom="@dimen/md_title_frame_margin_bottom"
+    android:paddingTop="@dimen/md_title_frame_margin_bottom">
+
+    <View
+        android:id="@+id/colorIndicator"
+        android:layout_width="match_parent"
+        android:layout_height="120dp"
+        tools:background="@color/md_material_blue_600" />
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_horizontal"
+        android:layout_marginTop="@dimen/md_title_frame_margin_bottom"
+        android:gravity="center">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="2dp"
+            android:layout_marginRight="2dp"
+            android:text="#"
+            android:textColor="?android:textColorPrimary"
+            android:textColorHint="?android:textColorSecondary"
+            android:textSize="@dimen/md_title_textsize"
+            tools:ignore="HardcodedText" />
+
+        <EditText
+            android:id="@+id/hexInput"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:hint="0099CC"
+            android:maxLength="6"
+            android:textSize="@dimen/md_title_textsize"
+            tools:ignore="HardcodedText" />
+
+    </LinearLayout>
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="@dimen/md_title_frame_margin_bottom"
+        android:paddingLeft="@dimen/md_dialog_frame_margin"
+        android:paddingRight="@dimen/md_dialog_frame_margin">
+
+        <!-- Red -->
+
+        <TextView
+            android:id="@+id/colorRLabel"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignBottom="@+id/colorR"
+            android:layout_alignTop="@+id/colorR"
+            android:layout_marginEnd="4dp"
+            android:layout_marginRight="4dp"
+            android:text="R"
+            android:textColor="?android:textColorPrimary"
+            android:textSize="@dimen/md_content_textsize"
+            tools:ignore="HardcodedText" />
+
+        <SeekBar
+            android:id="@+id/colorR"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="@dimen/md_title_frame_margin_bottom"
+            android:layout_toEndOf="@+id/colorRLabel"
+            android:layout_toLeftOf="@+id/colorRValue"
+            android:layout_toRightOf="@+id/colorRLabel"
+            android:layout_toStartOf="@+id/colorRValue"
+            android:max="255" />
+
+        <TextView
+            android:id="@+id/colorRValue"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignBottom="@+id/colorR"
+            android:layout_alignParentEnd="true"
+            android:layout_alignParentRight="true"
+            android:layout_alignTop="@+id/colorR"
+            android:layout_marginLeft="4dp"
+            android:layout_marginStart="4dp"
+            android:gravity="center"
+            android:minWidth="24dp"
+            android:text="0"
+            android:textColor="?android:textColorPrimary"
+            android:textSize="@dimen/md_content_textsize"
+            tools:ignore="HardcodedText" />
+
+        <!-- Green -->
+
+        <TextView
+            android:id="@+id/colorGLabel"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignBottom="@+id/colorG"
+            android:layout_alignTop="@+id/colorG"
+            android:layout_marginEnd="4dp"
+            android:layout_marginRight="4dp"
+            android:text="G"
+            android:textColor="?android:textColorPrimary"
+            android:textSize="@dimen/md_content_textsize"
+            tools:ignore="HardcodedText" />
+
+        <SeekBar
+            android:id="@+id/colorG"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@+id/colorR"
+            android:layout_marginTop="@dimen/md_title_frame_margin_bottom"
+            android:layout_toEndOf="@+id/colorGLabel"
+            android:layout_toLeftOf="@+id/colorGValue"
+            android:layout_toRightOf="@+id/colorGLabel"
+            android:layout_toStartOf="@+id/colorGValue"
+            android:max="255" />
+
+        <TextView
+            android:id="@+id/colorGValue"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignBottom="@+id/colorG"
+            android:layout_alignParentEnd="true"
+            android:layout_alignParentRight="true"
+            android:layout_alignTop="@+id/colorG"
+            android:layout_marginLeft="4dp"
+            android:layout_marginStart="4dp"
+            android:gravity="center"
+            android:minWidth="24dp"
+            android:text="0"
+            android:textColor="?android:textColorPrimary"
+            android:textSize="@dimen/md_content_textsize"
+            tools:ignore="HardcodedText" />
+
+        <!-- Blue -->
+
+        <TextView
+            android:id="@+id/colorBLabel"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignBottom="@+id/colorB"
+            android:layout_alignTop="@+id/colorB"
+            android:layout_marginEnd="4dp"
+            android:layout_marginRight="4dp"
+            android:text="B"
+            android:textColor="?android:textColorPrimary"
+            android:textSize="@dimen/md_content_textsize"
+            tools:ignore="HardcodedText" />
+
+        <SeekBar
+            android:id="@+id/colorB"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@+id/colorG"
+            android:layout_marginTop="@dimen/md_title_frame_margin_bottom"
+            android:layout_toEndOf="@+id/colorBLabel"
+            android:layout_toLeftOf="@+id/colorBValue"
+            android:layout_toRightOf="@+id/colorBLabel"
+            android:layout_toStartOf="@+id/colorBValue"
+            android:max="255" />
+
+        <TextView
+            android:id="@+id/colorBValue"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignBottom="@+id/colorB"
+            android:layout_alignParentEnd="true"
+            android:layout_alignParentRight="true"
+            android:layout_alignTop="@+id/colorB"
+            android:layout_marginLeft="4dp"
+            android:layout_marginStart="4dp"
+            android:gravity="center"
+            android:minWidth="24dp"
+            android:text="0"
+            android:textColor="?android:textColorPrimary"
+            android:textSize="@dimen/md_content_textsize"
+            tools:ignore="HardcodedText" />
+
+    </RelativeLayout>
+
+</LinearLayout>

+ 14 - 0
commons/src/main/res/layout/md_stub_colorchooser_grid.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<GridView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/grid"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:clipToPadding="false"
+    android:columnWidth="@dimen/md_colorchooser_circlesize"
+    android:gravity="center"
+    android:horizontalSpacing="8dp"
+    android:numColumns="auto_fit"
+    android:orientation="vertical"
+    android:padding="16dp"
+    android:stretchMode="columnWidth"
+    android:verticalSpacing="8dp" />

+ 1 - 0
commons/src/main/res/values/dimens.xml

@@ -7,5 +7,6 @@
     <dimen name="md_simplelist_textsize">18sp</dimen>
 
     <dimen name="md_preference_content_inset">20dp</dimen>
+    <dimen name="md_colorchooser_circlesize">56dp</dimen>
 
 </resources>

+ 1 - 0
commons/src/main/res/values/strings.xml

@@ -6,4 +6,5 @@
     <string name="md_choose_label">Choose</string>
     <string name="md_error_label">Error</string>
     <string name="md_storage_perm_error">Your app has not been granted the READ_EXTERNAL_STORAGE permission.</string>
+    <string name="md_custom_label">Custom</string>
 </resources>

+ 1 - 1
core/build.gradle

@@ -11,7 +11,7 @@ android {
         minSdkVersion 8
         targetSdkVersion 23
         versionCode 1
-        versionName "0.8.4.0"
+        versionName "0.8.4.1"
         consumerProguardFiles 'progress-proguard.txt'
     }
     lintOptions {

+ 2 - 2
sample/build.gradle

@@ -17,8 +17,8 @@ android {
         applicationId "com.afollestad.materialdialogssample"
         minSdkVersion 9
         targetSdkVersion 23
-        versionCode 146
-        versionName "0.8.4.0"
+        versionCode 147
+        versionName "0.8.4.1"
     }
     lintOptions {
         abortOnError false

+ 3 - 0
sample/src/main/java/com/afollestad/materialdialogssample/MainActivity.java

@@ -93,7 +93,10 @@ public class MainActivity extends AppCompatActivity implements
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         ButterKnife.bind(this);
+
         mHandler = new Handler();
+        primaryPreselect = DialogUtils.resolveColor(this, R.attr.colorPrimary);
+        accentPreselect = DialogUtils.resolveColor(this, R.attr.colorAccent);
     }
 
     @Override