-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Musenkishi/feature-improved-swatch
Feature improved swatch
- Loading branch information
Showing
29 changed files
with
800 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nkishi/paletteloader/ApplicationTest.java → ...m/musenkishi/atelier/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
414 changes: 256 additions & 158 deletions
414
...senkishi/paletteloader/PaletteLoader.java → .../java/com/musenkishi/atelier/Atelier.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (C) 2015 Freddie (Musenkishi) Lust-Hed | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.musenkishi.atelier; | ||
|
||
/** | ||
* An enum representing the different colors available in a | ||
* {@link android.support.v7.graphics.Palette.Swatch} | ||
* <p>Created by Freddie (Musenkishi) Lust-Hed on 04/06/15.</p> | ||
*/ | ||
public enum ColorType { | ||
BACKGROUND, | ||
TEXT_BODY, | ||
TEXT_TITLE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2015 Freddie (Musenkishi) Lust-Hed | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.musenkishi.atelier; | ||
|
||
import android.content.res.ColorStateList; | ||
import android.graphics.Color; | ||
|
||
/** | ||
* General class containing helpful functions regarding colors. | ||
* <p>Created by Freddie (Musenkishi) Lust-Hed on 08/06/15.</p> | ||
*/ | ||
public class ColorUtils { | ||
|
||
/** | ||
* Will generate a {@link ColorStateList} based on the color provided. | ||
* The generated {@link ColorStateList} will contain 3 different colors based on the provided; | ||
* a regular, a greyed out (disabled state), and a darkened (pressed state). | ||
* @param color The color you want the ColorStateList based on | ||
* @return a ColorStateList based on provided color | ||
*/ | ||
public static ColorStateList generateColorStateList(int color) { | ||
int[][] states = new int[][] { | ||
new int[] { android.R.attr.state_enabled}, // enabled | ||
new int[] {-android.R.attr.state_enabled}, // disabled | ||
new int[] {-android.R.attr.state_checked}, // unchecked | ||
new int[] { android.R.attr.state_pressed} // pressed | ||
}; | ||
|
||
int[] colors = new int[] { | ||
color, | ||
greyOutColor(color), | ||
color, | ||
darkenColor(color) | ||
}; | ||
|
||
return new ColorStateList(states, colors); | ||
} | ||
|
||
private static int darkenColor(int color) { | ||
float[] hsv = new float[3]; | ||
Color.colorToHSV(color, hsv); | ||
hsv[2] *= 0.6f; | ||
return Color.HSVToColor(hsv); | ||
} | ||
|
||
private static int greyOutColor(int color) { | ||
float[] hsv = new float[3]; | ||
Color.colorToHSV(color, hsv); | ||
hsv[1] *= 0.6f; | ||
return Color.HSVToColor(hsv); | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
lib/src/main/java/com/musenkishi/atelier/swatch/AbstractSwatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (C) 2015 Freddie (Musenkishi) Lust-Hed | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.musenkishi.atelier.swatch; | ||
|
||
import android.graphics.Color; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.graphics.Palette; | ||
|
||
import com.musenkishi.atelier.ColorType; | ||
|
||
/** | ||
* An abstract class containing functions that should be available for all child classes. | ||
* <p>Created by Freddie (Musenkishi) Lust-Hed on 04/06/15.</p> | ||
*/ | ||
abstract class AbstractSwatch implements Swatch { | ||
|
||
private ColorType colorType; | ||
|
||
public AbstractSwatch(@NonNull ColorType colorType) { | ||
this.colorType = colorType; | ||
} | ||
|
||
protected ColorType getColorType() { | ||
return this.colorType; | ||
} | ||
|
||
protected int getSwatchColor(@NonNull Palette palette, @Nullable Palette.Swatch swatch) { | ||
|
||
swatch = ensureSwatchIsNotNull(palette, swatch); | ||
|
||
switch (getColorType()) { | ||
case BACKGROUND: | ||
return swatch.getRgb(); | ||
|
||
case TEXT_BODY: | ||
return swatch.getBodyTextColor(); | ||
|
||
case TEXT_TITLE: | ||
return swatch.getTitleTextColor(); | ||
} | ||
|
||
return Color.GRAY; | ||
} | ||
|
||
/** | ||
* A function that ensures a non-null {@link android.support.v7.graphics.Palette.Swatch} is | ||
* returned, whether from the {@link Palette} or a new based on Color.GRAY. | ||
* @param palette The desired {@link Palette} | ||
* @param nullableSwatch The {@link Palette.Swatch} that could be null. | ||
* @return A non-null {@link Palette.Swatch} from the | ||
* {@link Palette}, or a new {@link Palette.Swatch} | ||
* based on Color.GRAY. | ||
*/ | ||
@NonNull | ||
public Palette.Swatch ensureSwatchIsNotNull(@NonNull Palette palette, @Nullable Palette.Swatch nullableSwatch) { | ||
|
||
if (nullableSwatch != null) { | ||
return nullableSwatch; | ||
} | ||
//nullableSwatch was null, fall back to a swatch that isn't null. | ||
for (Palette.Swatch swatch : palette.getSwatches()) { | ||
if (swatch != null) { | ||
return swatch; | ||
} | ||
} | ||
|
||
return new Palette.Swatch(Color.GRAY, 1); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
lib/src/main/java/com/musenkishi/atelier/swatch/DarkMutedSwatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2015 Freddie (Musenkishi) Lust-Hed | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.musenkishi.atelier.swatch; | ||
|
||
import android.support.v7.graphics.Palette; | ||
|
||
import com.musenkishi.atelier.ColorType; | ||
|
||
/** | ||
* A Swatch delegate representing the {@link android.support.v7.graphics.Palette.Swatch} | ||
* from {@link Palette}.getDarkMutedSwatch(). | ||
* <p>Created by Freddie (Musenkishi) Lust-Hed on 04/06/15.</p> | ||
*/ | ||
public class DarkMutedSwatch extends AbstractSwatch { | ||
|
||
public DarkMutedSwatch(ColorType colorType) { | ||
super(colorType); | ||
} | ||
|
||
@Override | ||
public int getColor(Palette palette) { | ||
return getSwatchColor(palette, palette.getDarkMutedSwatch()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
lib/src/main/java/com/musenkishi/atelier/swatch/DarkVibrantSwatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2015 Freddie (Musenkishi) Lust-Hed | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.musenkishi.atelier.swatch; | ||
|
||
import android.support.v7.graphics.Palette; | ||
|
||
import com.musenkishi.atelier.ColorType; | ||
|
||
/** | ||
* A Swatch delegate representing the {@link android.support.v7.graphics.Palette.Swatch} | ||
* from {@link Palette}.getDarkVibrantSwatch(). | ||
* <p>Created by Freddie (Musenkishi) Lust-Hed on 04/06/15.</p> | ||
*/ | ||
public class DarkVibrantSwatch extends AbstractSwatch { | ||
|
||
public DarkVibrantSwatch(ColorType colorType) { | ||
super(colorType); | ||
} | ||
|
||
@Override | ||
public int getColor(Palette palette) { | ||
return getSwatchColor(palette, palette.getDarkVibrantSwatch()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
lib/src/main/java/com/musenkishi/atelier/swatch/LightMutedSwatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2015 Freddie (Musenkishi) Lust-Hed | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.musenkishi.atelier.swatch; | ||
|
||
import android.support.v7.graphics.Palette; | ||
|
||
import com.musenkishi.atelier.ColorType; | ||
|
||
/** | ||
* A Swatch delegate representing the {@link android.support.v7.graphics.Palette.Swatch} | ||
* from {@link Palette}.getLightMutedSwatch(). | ||
* <p>Created by Freddie (Musenkishi) Lust-Hed on 04/06/15.</p> | ||
*/ | ||
public class LightMutedSwatch extends AbstractSwatch { | ||
|
||
public LightMutedSwatch(ColorType colorType) { | ||
super(colorType); | ||
} | ||
|
||
@Override | ||
public int getColor(Palette palette) { | ||
return getSwatchColor(palette, palette.getLightMutedSwatch()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
lib/src/main/java/com/musenkishi/atelier/swatch/LightVibrantSwatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2015 Freddie (Musenkishi) Lust-Hed | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.musenkishi.atelier.swatch; | ||
|
||
import android.support.v7.graphics.Palette; | ||
|
||
import com.musenkishi.atelier.ColorType; | ||
|
||
/** | ||
* A Swatch delegate representing the {@link android.support.v7.graphics.Palette.Swatch} | ||
* from {@link Palette}.getLightVibrantSwatch(). | ||
* <p>Created by Freddie (Musenkishi) Lust-Hed on 04/06/15.</p> | ||
*/ | ||
public class LightVibrantSwatch extends AbstractSwatch { | ||
|
||
public LightVibrantSwatch(ColorType colorType) { | ||
super(colorType); | ||
} | ||
|
||
@Override | ||
public int getColor(Palette palette) { | ||
return getSwatchColor(palette, palette.getLightVibrantSwatch()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
lib/src/main/java/com/musenkishi/atelier/swatch/MutedSwatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2015 Freddie (Musenkishi) Lust-Hed | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.musenkishi.atelier.swatch; | ||
|
||
import android.support.v7.graphics.Palette; | ||
|
||
import com.musenkishi.atelier.ColorType; | ||
|
||
/** | ||
* A Swatch delegate representing the {@link android.support.v7.graphics.Palette.Swatch} | ||
* from {@link Palette}.getMutedSwatch(). | ||
* <p>Created by Freddie (Musenkishi) Lust-Hed on 04/06/15.</p> | ||
*/ | ||
public class MutedSwatch extends AbstractSwatch { | ||
|
||
public MutedSwatch(ColorType colorType) { | ||
super(colorType); | ||
} | ||
|
||
@Override | ||
public int getColor(Palette palette) { | ||
return getSwatchColor(palette, palette.getMutedSwatch()); | ||
} | ||
} |
Oops, something went wrong.