Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add outlineColor attribute, so it can be user defined #41

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fcd4597
Update SpectrumDialog for outline color support
ParkerK Jul 14, 2017
7efc130
Update ColorItem to support outline color
ParkerK Jul 14, 2017
a38c21e
Typo fix
ParkerK Jul 14, 2017
5e69ccf
Update SpectrumPreferenceColor for outline color
ParkerK Jul 14, 2017
3c57fde
Update to support outline color
ParkerK Jul 14, 2017
a13d2ec
Support outline color
ParkerK Jul 14, 2017
0aa7777
Use -1 instead of null
ParkerK Jul 14, 2017
d8ab799
Outline color
ParkerK Jul 14, 2017
045ed6c
Support outline color
ParkerK Jul 14, 2017
446ac4f
getInt to getColor
ParkerK Jul 14, 2017
98e61b8
getInt to getColor
ParkerK Jul 14, 2017
a2a05b3
coloroutline
ParkerK Jul 14, 2017
21c97d2
make jitpack happy
ParkerK Jul 14, 2017
4c640c9
Update SpectrumPalette.java
ParkerK Jul 14, 2017
6f970d1
Update SpectrumDialog.java
ParkerK Jul 14, 2017
9e11bc9
Update SpectrumDialog.java
ParkerK Jul 14, 2017
a4bc874
Forgot Colors can be < 0 , so just check != -1, probably a better way…
ParkerK Jul 14, 2017
e562573
Whoops colors can be < 0
ParkerK Jul 14, 2017
1538fc1
Update ColorItem.java
ParkerK Jul 14, 2017
8f3567f
revert gradle
Jul 14, 2017
f63672d
Updating the gradle to use latest stable plugin while I'm at it
Jul 15, 2017
6b036cb
Add two samples - one for black outlines, and one for pink as it's no…
Jul 15, 2017
d8a4b8c
Code review changes
Jul 15, 2017
bf68d4d
Added google() repo, as the support libraries wouldn't download for m…
Jul 15, 2017
0a21c3e
Updated the build.gradles to use the latest support libraries, feel f…
Jul 15, 2017
b8dc3ab
whoops, missing =
Jul 15, 2017
784869c
Finalize sample
Jul 15, 2017
44849d2
Green hurt my eyes, switching to purple
Jul 15, 2017
ea08282
remove google() repo
ParkerK Jul 16, 2017
dca0744
Typo fix
ParkerK Jul 18, 2017
a47f1e6
Update demo_dialog.xml
ParkerK Jul 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class SpectrumDialog extends DialogFragment implements SpectrumPalette.On
private static final String KEY_POSITIVE_BUTTON_TEXT = "positive_button_text";
private static final String KEY_NEGATIVE_BUTTON_TEXT = "negative_button_text";
private static final String KEY_OUTLINE_WIDTH = "border_width";
private static final String KEY_OUTLINE_COLOR = "border_color";
private static final String KEY_FIXED_COLUMN_COUNT = "fixed_column_count";
private static final String KEY_THEME_RES_ID = "theme_res_id";

Expand All @@ -39,6 +40,7 @@ public class SpectrumDialog extends DialogFragment implements SpectrumPalette.On
private boolean mShouldDismissOnColorSelected = true;
private OnColorSelectedListener mListener;
private int mOutlineWidth = 0;
private @ColorInt int mOutlineColor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to default this to -1.

private int mFixedColumnCount = -1;
private int mThemeResId = 0;

Expand Down Expand Up @@ -92,6 +94,18 @@ public Builder setOutlineWidth(int width) {
mArgs.putInt(KEY_OUTLINE_WIDTH, width);
return this;
}


/**
* Change the color of the outlining
*
* @param color
* @return This {@link Builder} for method chaining
*/
public Builder setOutlineColor(@ColorInt int color) {
mArgs.putInt(KEY_OUTLINE_COLOR, color);
return this;
}

/**
* Tells the underlying palette to use a fixed number of columns during layout.
Expand Down Expand Up @@ -310,6 +324,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
if (args != null && args.containsKey(KEY_OUTLINE_WIDTH)) {
mOutlineWidth = args.getInt(KEY_OUTLINE_WIDTH);
}

if (args != null && args.containsKey(KEY_OUTLINE_COLOR)) {
mOutlineColor = args.getInt(KEY_OUTLINE_COLOR);
}

if (args != null && args.containsKey(KEY_FIXED_COLUMN_COUNT)) {
mFixedColumnCount = args.getInt(KEY_FIXED_COLUMN_COUNT);
Expand Down Expand Up @@ -375,6 +393,9 @@ public void onClick(DialogInterface dialog, int which) {
if (mOutlineWidth != 0) {
palette.setOutlineWidth(mOutlineWidth);
}
if (mOutlineColor != -1) {
palette.setOutlineColor(mOutlineColor);
}
if (mFixedColumnCount > 0) {
palette.setFixedColumnCount(mFixedColumnCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class SpectrumPalette extends LinearLayout {
private boolean mHasFixedColumnCount = false;
private int mFixedColumnCount = -1;
private int mOutlineWidth = 0;
private @ColorInt int mOutlineColor = -1;
private int mComputedVerticalPadding = 0;
private int mOriginalPaddingTop = 0;
private int mOriginalPaddingBottom = 0;
Expand Down Expand Up @@ -67,6 +68,7 @@ public SpectrumPalette(Context context, AttributeSet attrs) {

mAutoPadding = a.getBoolean(R.styleable.SpectrumPalette_spectrum_autoPadding, false);
mOutlineWidth = a.getDimensionPixelSize(R.styleable.SpectrumPalette_spectrum_outlineWidth, 0);
mOutlineColor = a.getColor(R.styleable.SpectrumPalette_spectrum_outlineColor, -1);
mFixedColumnCount = a.getInt(R.styleable.SpectrumPalette_spectrum_columnCount, -1);
if (mFixedColumnCount != -1) {
mHasFixedColumnCount = true;
Expand Down Expand Up @@ -279,6 +281,9 @@ private ColorItem createColorItem(int color, int selectedColor) {
if (mOutlineWidth != 0) {
view.setOutlineWidth(mOutlineWidth);
}
if (mOutlineColor != -1) {
view.setOutlineColor(mOutlineColor);
}
mItems.add(view);
return view;
}
Expand Down Expand Up @@ -324,6 +329,19 @@ public void setOutlineWidth(int width) {
}
}

/**
* Change the color of the outlining
*
* @param color
*/
public void setOutlineColor(@ColorInt int color) {
mOutlineColor = color;
for (ColorItem item : mItems) {
item.setOutlineColor(color);
}
}


/**
* Tells the palette to use a fixed number of columns during layout.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SpectrumPreference extends DialogPreference {
private boolean mValueSet = false;
private View mColorView;
private int mOutlineWidth = 0;
private @ColorInt int mOutlineColor = -1;
private int mFixedColumnCount = -1;

private SharedPreferences.OnSharedPreferenceChangeListener mListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
Expand All @@ -52,6 +53,7 @@ public SpectrumPreference(Context context, AttributeSet attrs) {
}
mCloseOnSelected = a.getBoolean(R.styleable.SpectrumPreference_spectrum_closeOnSelected, true);
mOutlineWidth = a.getDimensionPixelSize(R.styleable.SpectrumPalette_spectrum_outlineWidth, 0);
mOutlineColor = a.getColor(R.styleable.SpectrumPalette_spectrum_outlineColor, -1);
mFixedColumnCount = a.getInt(R.styleable.SpectrumPalette_spectrum_columnCount, -1);
} finally {
a.recycle();
Expand Down Expand Up @@ -163,6 +165,7 @@ private void updateColorView() {
}
ColorCircleDrawable drawable = new ColorCircleDrawable(mCurrentValue);
drawable.setOutlineWidth(mOutlineWidth);
drawable.setOutlineColor(mOutlineColor);
if (!isEnabled()) {
// Show just a gray circle outline
drawable.setColor(Color.BLACK);
Expand Down Expand Up @@ -191,6 +194,7 @@ protected void onBindDialogView(View view) {
mColorPalette.setColors(mColors);
mColorPalette.setSelectedColor(mCurrentValue);
mColorPalette.setOutlineWidth(mOutlineWidth);
mColorPalette.setOutlineColor(mOutlineColor);
mColorPalette.setFixedColumnCount(mFixedColumnCount);
mColorPalette.setOnColorSelectedListener(new SpectrumPalette.OnColorSelectedListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class SpectrumPreferenceCompat extends DialogPreference {
private boolean mValueSet = false;
private View mColorView;
private int mOutlineWidth = 0;
private @ColorInt int mOutlineColor;
private int mFixedColumnCount = -1;

private SharedPreferences.OnSharedPreferenceChangeListener mListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
Expand All @@ -75,6 +76,7 @@ public SpectrumPreferenceCompat(Context context, AttributeSet attrs) {
}
mCloseOnSelected = a.getBoolean(R.styleable.SpectrumPreference_spectrum_closeOnSelected, true);
mOutlineWidth = a.getDimensionPixelSize(R.styleable.SpectrumPalette_spectrum_outlineWidth, 0);
mOutlineWidth = a.getColor(R.styleable.SpectrumPalette_spectrum_outlineColor, -1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be mOutlineColor.

mFixedColumnCount = a.getInt(R.styleable.SpectrumPalette_spectrum_columnCount, -1);
} finally {
a.recycle();
Expand Down Expand Up @@ -157,6 +159,7 @@ private void updateColorView() {
}
ColorCircleDrawable drawable = new ColorCircleDrawable(mCurrentValue);
drawable.setOutlineWidth(mOutlineWidth);
drawable.setOutlineColor(mOutlineColor);
if (!isEnabled()) {
// Show just a gray circle outline
drawable.setColor(Color.WHITE);
Expand Down Expand Up @@ -207,6 +210,10 @@ public void setColor(@ColorInt int value) {
public int getOutlineWidth() {
return mOutlineWidth;
}

public int getOutlineColor() {
return mOutlineColor;
}

public int getFixedColumnCount() {
return mFixedColumnCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ColorCircleDrawable extends Drawable {
private final Paint mPaint;
private int mRadius = 0;
private int mOutlineWidth = 0;
private @ColorInt int mOutlineColor = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this isn't necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, forgot to remove that, that was before I realized there was already a setOutlineColor method in that class

private final Paint mOutlinePaint;

public ColorCircleDrawable(final @ColorInt int color) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ColorItem extends FrameLayout implements View.OnClickListener {
private @ColorInt int mColor;
private boolean mIsSelected = false;
private int mOutlineWidth = 0;
private @ColorInt int mOutlineColor = -1;

public ColorItem(Context context, @ColorInt int color, boolean isSelected, EventBus eventBus) {
super(context);
Expand Down Expand Up @@ -85,6 +86,16 @@ public void setOutlineWidth(int width) {
mOutlineWidth = width;
updateDrawables();
}

/**
* Force an outline color instead of setting
* to black or white (default behavior)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description should be able to fit on one line.

* @param color
*/
public void setOutlineColor(@ColorInt int color) {
mOutlineColor = color;
updateDrawables();
}

public void setChecked(boolean checked) {
boolean oldChecked = mIsSelected;
Expand Down Expand Up @@ -163,7 +174,12 @@ private Drawable createBackgroundDrawable() {
GradientDrawable mask = new GradientDrawable();
mask.setShape(GradientDrawable.OVAL);
if (mOutlineWidth != 0) {
mask.setStroke(mOutlineWidth, ColorUtil.isColorDark(mColor) ? Color.WHITE : Color.BLACK);
if (mOutlineColor != -1) {
mask.setStroke(mOutlineWidth, mOutlineColor);
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep your else on the same line as the preceding curly brace to match our coding style :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man that hurts to look at - this is the last time I make changes with the Github online editor :)

mask.setStroke(mOutlineWidth, ColorUtil.isColorDark(mColor) ? Color.WHITE : Color.BLACK);
}
}
mask.setColor(mColor);
return mask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected void onBindDialogView(View view) {
mColorPalette.setColors(getSpectrumPreference().getColors());
mColorPalette.setSelectedColor(mCurrentValue);
mColorPalette.setOutlineWidth(getSpectrumPreference().getOutlineWidth());
mColorPalette.setOutlineColor(getSpectrumPreference().getOutlineColor());
mColorPalette.setFixedColumnCount(getSpectrumPreference().getFixedColumnCount());
mColorPalette.setOnColorSelectedListener(new SpectrumPalette.OnColorSelectedListener() {
@Override
Expand Down
5 changes: 4 additions & 1 deletion spectrum/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
<resources>
<attr name="spectrum_colors" format="reference" />
<attr name="spectrum_outlineWidth" format="dimension" />
<attr name="spectrum_outlineColor" format="color" />
<attr name="spectrum_columnCount" format="integer" />

<declare-styleable name="SpectrumPalette">
<attr name="spectrum_colors" />
<attr name="spectrum_outlineWidth" />
<attr name="spectrum_outlineColor" />
<attr name="spectrum_columnCount" />
<attr name="spectrum_autoPadding" format="boolean" />
</declare-styleable>

<declare-styleable name="SpectrumPreference">
<attr name="spectrum_colors" />
<attr name="spectrum_outlineWidth" />
<attr name="spectrum_outlineColor" />
<attr name="spectrum_columnCount" />
<attr name="spectrum_closeOnSelected" format="boolean" />
</declare-styleable>
</resources>
</resources>