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 30 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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-beta1'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
Expand Down
23 changes: 15 additions & 8 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
compileSdkVersion 25
buildToolsVersion '25.0.3'

defaultConfig {
applicationId "com.thebluealliance.spectrum"
minSdkVersion 15
targetSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
Expand All @@ -27,10 +27,17 @@ repositories {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:preference-v7:23.2.1'
compile 'com.android.support:preference-v14:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.wada811:android-material-design-colors:3.0.0'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:preference-v7:25.4.0'
compile 'com.android.support:preference-v14:25.4.0'
compile 'com.android.support:design:25.4.0'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.android.support:support-annotations:25.4.0'

// We already have appcompat, so we can ignore the older version
// that's used in this library
compile ('com.wada811:android-material-design-colors:3.0.0'){
exclude group: 'com.android.support'
}
compile project(':spectrum')
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.thebluealliance.spectrum.SpectrumDialog;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.v7.preference.Preference;
Expand Down Expand Up @@ -51,6 +52,14 @@ public class DialogDemoFragment extends PreferenceFragmentCompat {
return true;
}
});

findPreference("demo_dialog_6").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showDialog6();
return true;
}
});
}

private void showDialog1() {
Expand Down Expand Up @@ -135,4 +144,23 @@ private void showDialog5() {
}
}).build().show(getFragmentManager(), "dialog_demo_5");
}

private void showDialog6() {
new SpectrumDialog.Builder(getContext())
.setColors(R.array.demo_colors)
.setSelectedColorRes(R.color.md_blue_500)
.setDismissOnColorSelected(true)
.setOutlineWidth(6)
.setOutlineColor(getResources().getColor(R.color.md_purple_300))
.setOnColorSelectedListener(new SpectrumDialog.OnColorSelectedListener() {
@Override public void onColorSelected(boolean positiveResult, @ColorInt int color) {
if (positiveResult) {
Toast.makeText(getContext(), "Color selected: #" + Integer.toHexString(color).toUpperCase(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getContext(), "Dialog cancelled", Toast.LENGTH_SHORT).show();
}
}
}).build().show(getFragmentManager(), "dialog_demo_7");
}

}
5 changes: 5 additions & 0 deletions sample/src/main/res/xml/demo_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
android:summary="This dialog won't close automatically when a color is selected; you have to press OK"
android:title="Click for another dialog" />

<Preference
android:key="demo_dialog_6"
android:summary="This dialog has purple outlines, you can set the outline to any color though"
android:title="Click for a dialog with colored outlines"/>

<Preference
android:key="demo_dialog_3"
android:summary="This demonstrates Spectrum's behavior with a range of light and dark colors"
Expand Down
12 changes: 11 additions & 1 deletion sample/src/main/res/xml/demo_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
app:spectrum_outlineWidth="2dp"
app:spectrum_colors="@array/demo_colors_expanded" />

<com.thebluealliance.spectrum.SpectrumPreferenceCompat
android:defaultValue="@color/md_indigo_500"
android:key="demo_preference_6"
android:summary="You can make all the colors have the same color border of your choosing"
android:title="Color preference with custom outline color"
app:spectrum_colors="@array/demo_colors"
app:spectrum_outlineWidth="2dp"
app:spectrum_outlineColor="@color/md_purple_300"
/>

<com.thebluealliance.spectrum.SpectrumPreferenceCompat
android:defaultValue="@color/md_red_500"
android:key="demo_preference_3"
Expand Down Expand Up @@ -52,4 +62,4 @@
android:title="Color preference"
app:spectrum_colors="@array/demo_colors"/>

</PreferenceScreen>
</PreferenceScreen>
14 changes: 7 additions & 7 deletions spectrum/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ ext {
}

android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
compileSdkVersion 25
buildToolsVersion '25.0.3'

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
targetSdkVersion 25
versionCode libraryVersionCode
versionName libraryVersion
consumerProguardFiles 'proguard-rules.pro'
Expand All @@ -47,10 +47,10 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:preference-v7:23.4.0'
compile 'com.android.support:support-annotations:23.4.0'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:preference-v7:25.4.0'
compile 'com.android.support:support-annotations:25.4.0'
compile 'org.greenrobot:eventbus:3.0.0'
}

Expand Down
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 = -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 = -1;
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);
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 @@ -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 @@ -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();
}

/**
* Override the default outline color
*
* @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,11 @@ 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 {
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
Loading