A beautiful set of predefined colors and a set of color methods to make your Android development life easier.

Related tags

Utility Colours
Overview

ScreenShot

Colours is a port of the Colours Library for iOS made by my good friend Ben Gordon. You can find that project here.

Installation

Maven Central

Colours is available in Maven Central under the groupId com.github.matthewyork and the artifactId ColoursLibrary

Incorporate Colours via Gradle with:

compile 'com.github.matthewyork:ColoursLibrary:1.0.+@aar'

Manual Installation

  • Import the Colours library into your workspace, found in the ColoursLibrary Folder.
  • Right-click on your android project folder and click on the project properties.
  • Click on the "Android" tab and then "Add" under the Library section.
  • Select the ColoursLibrary project to link it with your project

Color Palette

infoBlueColor infoBlueColor successColor successColor warningColor warningColor
dangerColor dangerColor antiqueWhiteColor antiqueWhiteColor oldLaceColor oldLaceColor
ivoryColor ivoryColor seashellColor seashellColor ghostWhiteColor ghostWhiteColor
snowColor snowColor linenColor linenColor black25PercentColor black25PercentColor
black50PercentColor black50PercentColor black75PercentColor black75PercentColor warmGrayColor warmGrayColor
coolGrayColor coolGrayColor charcoalColor charcoalColor tealColor tealColor
steelBlueColor steelBlueColor robinEggColor robinEggColor pastelBlueColor pastelBlueColor
turquoiseColor turquoiseColor skyBlueColor skyBlueColor indigoColor indigoColor
denimColor denimColor blueberryColor blueberryColor cornflowerColor cornflowerColor
babyBlueColor babyBlueColor midnightBlueColor midnightBlueColor fadedBlueColor fadedBlueColor
icebergColor icebergColor waveColor waveColor emeraldColor emeraldColor
grassColor grassColor pastelGreenColor pastelGreenColor seafoamColor seafoamColor
paleGreenColor paleGreenColor cactusGreenColor cactusGreenColor chartreuseColor chartreuseColor
hollyGreenColor hollyGreenColor oliveColor oliveColor oliveDrabColor oliveDrabColor
moneyGreenColor moneyGreenColor honeydewColor honeydewColor limeColor limeColor
cardTableColor cardTableColor salmonColor salmonColor brickRedColor brickRedColor
easterPinkColor easterPinkColor grapefruitColor grapefruitColor pinkColor pinkColor
indianRedColor indianRedColor strawberryColor strawberryColor coralColor coralColor
maroonColor maroonColor watermelonColor watermelonColor tomatoColor tomatoColor
pinkLipstickColor pinkLipstickColor paleRoseColor paleRoseColor crimsonColor crimsonColor
eggplantColor eggplantColor pastelPurpleColor pastelPurpleColor palePurpleColor palePurpleColor
coolPurpleColor coolPurpleColor violetColor violetColor plumColor plumColor
lavenderColor lavenderColor raspberryColor raspberryColor fuschiaColor fuschiaColor
grapeColor grapeColor periwinkleColor periwinkleColor orchidColor orchidColor
goldenrodColor goldenrodColor yellowGreenColor yellowGreenColor bananaColor bananaColor
mustardColor mustardColor buttermilkColor buttermilkColor goldColor goldColor
creamColor creamColor lightCreamColor lightCreamColor wheatColor wheatColor
beigeColor beigeColor peachColor peachColor burntOrangeColor burntOrangeColor
pastelOrangeColor pastelOrangeColor cantaloupeColor cantaloupeColor carrotColor carrotColor
mandarinColor mandarinColor chiliPowderColor chiliPowderColor burntSiennaColor burntSiennaColor
chocolateColor chocolateColor coffeeColor coffeeColor cinnamonColor cinnamonColor
almondColor almondColor eggshellColor eggshellColor sandColor sandColor
mudColor mudColor siennaColor siennaColor dustColor dustColor

Note all of the colors in ActionBarCompat included Holo Colors.

Using Predefined Colors

Colours works exactly like the predefined Android colors. In fact, the Colour class is a subclass of android.graphics.Color, so you can actually use the Colour class where you normally use Color to gain access to the cool new methods of the Colour Library without losing any methods in the Color class.

XML

To use your HUGE new palette of colors in XML, reference a color just as you would a color in a local Color.xml resource file:

  <View
    .
    .
    .
    android:background="@color/seafoamColor" />

Huzzah! Colours automagically integrates all of its colors to your project, just as if you had defined them yourself. (You can tell all your friends that you made them. We won't tell!)

Code

Let's say, however, that you would like to set the color of something in code. Colours has you covered. Every single color available in XML is also avalable as a static method, much like the android system colors. To retrieve a predefined color's int representation, simply call it's corresponding method:

int seashellColor = Colour.seashellColor();

Color Spaces

Android comes pre-baked with RGB and HSV color space methods. However, this may not be enough. This library adds CMYK, which is normally used for printing, and CIE_LAB, a color space meant for modeling an equal space between each color. You can access these methods like so:

float[] cmyk = Colour.colorToCMYK(inputColor);
int color = Colour.CMYKToColor(cmyk);
float[] cie_lab = Colour.colorToCIE_LAB(inputColor);
int color = Colour.CIE_LABToColor(cie_lab);

Color Helper Methods

Beyond giving you a list of a ton of colors with no effort, this category also gives you some methods that allow different color manipulations and translations. Here's how you use these:

Generating white or black that contrasts with a Color

A lot of times you may want to put text on top of a view that is a certain color, and you want to be sure that it will look good on top of it. With this method you will return either white or black, depending on the how well each of them contrast on top of it. Here's how you use this:

int contrastingColor = Colour.blackOrWhiteContrastingColor(inputColor)

Generating a complementary color

This method will create a color int that is the exact opposite color from another color int on the color wheel. The same saturation and brightness are preserved, only the hue is changed.

int complementaryColor = Colour.complementaryColor(inputColor);

Distance between 2 Colors

Detecting a difference in two colors is not as trivial as it sounds. One's first instinct is to go for a difference in RGB values, leaving you with a sum of the differences of each point. It looks great! Until you actually start comparing colors. Why do these two reds have a different distance than these two blues in real life vs computationally? Human visual perception is next in the line of things between a color and your brain. Some colors are just perceived to have larger variants inside of their respective areas than others, so we need a way to model this human variable to colors. Enter CIELAB. This color formulation is supposed to be this model. So now we need to standardize a unit of distance between any two colors that works independent of how humans visually perceive that distance. Enter CIE76,94,2000. These are methods that use user-tested data and other mathematically and statistically significant correlations to output this info. You can read the wiki articles below to get a better understanding historically of how we moved to newer and better color distance formulas, and what their respective pros/cons are.

Finding Distance

double distance = Colour.distanceBetweenColorsWithFormula(colorA, colorB, ColorDistanceFormulaCIE94);
boolean isNoticablySimilar = distance < threshold;

Resources

Generating Color Schemes

You can create a 5-color scheme based off of a color using the following method. It takes in a color int and one of the ColorSchemeTypes defined in Colours. It returns an int[] of 4 new colors to create a pretty nice color scheme that complements the root color you passed in.

int[] complementaryColors = Colour.colorSchemeOfType(inputColor, ColorScheme.ColorSchemeComplementary);

ColorSchemeTypes

  • ColorSchemeAnalagous
  • ColorSchemeMonochromatic
  • ColorSchemeTriad
  • ColorSchemeComplementary

Here are the different examples starting with a color scheme based off of Colour.seafoamColor().

ColorSchemeAnalagous

Analagous

ColorSchemeMonochromatic

Monochromatic

ColorSchemeTriad

Triad

ColorSchemeComplementary

Complementary

Credits

  • Matthew York - Author of Colours for Android
  • Ben Gordon - Author of original iOS version of Colours
  • Aaron Fleshner - Teaching me Android and being awesome like that. (Also adding holo to the mix)

I would also like to thank God through whom all things live and move and have their being. Acts 17:28

License

The MIT License (MIT)

Copyright (c) 2014 Matthew York

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...
Speed up your Android development

Caffeine Speed up your Android development! A collection of utility classes that help make Android development faster (and safer!) Examples No more un

Utility tool to make you a computer ninja.

Cmd Window Never spend 6 minutes doing something by hand when you can spend 6 hours failing to automate it - Zhuowej Zhang What is this about? This to

Access and process various types of personal data in Android with a set of easy, uniform, and privacy-friendly APIs.
Access and process various types of personal data in Android with a set of easy, uniform, and privacy-friendly APIs.

PrivacyStreams PrivacyStreams is an Android library for easy and privacy-friendly personal data access and processing. It offers a functional programm

Matches incoming and/or outgoing text messages against set rules and sends them over to webhook.

Textmatic If you ever wanted a tool to simply push the SMS (or text messages) from your phone to somewhere remote, this is it. This app matches all in

A set of helper classes for using dagger 1 with Android components such as Applications, Activities, Fragments, BroadcastReceivers, and Services.

##fb-android-dagger A set of helper classes for using dagger with Android components such as Applications, Activities, Fragments, BroadcastReceivers,

A set of lint rules to check for common mistakes when styling and theming on Android
A set of lint rules to check for common mistakes when styling and theming on Android

A set of lint rules to check for common mistakes when styling and theming on Android

Collection of source codes, utilities, templates and snippets for Android development.

Android Templates and Utilities [DEPRECATED] Android Templates and Utilities are deprecated. I started with this project in 2012. Android ecosystem ha

Various useful utilities for Android apps development

Android Commons Various useful utilities for Android apps development. API documentation provided as Javadoc. Usage Add dependency to your build.gradl

A collection of Android libraries for simplifying development

Andromeda A collection of Android libraries for simplifying development Usage Andromeda uses Jitpack for distribution, the following gradle dependency

Comments
  • Gradle build files

    Gradle build files

    This PR doesn't change any functionality -- just adds full Gradle support to the build, short of publishing the resulting AAR to Maven Central (which I can help with too, if you'd like).

    Build with:

    ./gradlew assemble
    
    opened by avram 4
  • Remove unnecesary files to reduce library size and fix gradle settings

    Remove unnecesary files to reduce library size and fix gradle settings

    Size change of ColoursLibrary/build/libs/ColoursLibrary.aar

    Before: 39190 After: 8179

    79% less and happy face :-)

    Test Plan:

    1. ./gradlew clean installDebug
    2. run the sample app
    opened by frankdu 1
  • Color Spaces & Distance

    Color Spaces & Distance

    • Added CMYK color space methods to go from values <-> color
    • Added CIE_LAB color space methods to go from values <-> color
    • Added Color Distance methods for CIE{76,94,2000} formulas
    opened by bennyguitar 0
  • @aar is deprecated in gradle and will be removed in 2.0 which is released

    @aar is deprecated in gradle and will be removed in 2.0 which is released

    compile 'xxx:xx:1.0.0@aar' is deprecated in gradle and will be removed in 2.0 which is released

    The pom you are generating should have a tag

    <package>aar</package>

    opened by SemonCat 0
Releases(v1.0.1)
Owner
Matthew York
Matthew York
CloudStorageUtil - An Android library to make sync on Google Cloud Storage easier

gCloud Storage Utils An Android library to make sync on Google Cloud Storage eas

Evolve Asia 0 Jul 13, 2022
Useful helpers that make it easier to implement maven-plugin mojos with kotlin

A library that makes writing powerful maven plugins even easier by providing kotlin extensions and convenience functions for common use cases.

TOOListicon 1 Nov 4, 2022
Access to 1000+ colors on android!

Colorize Android quick access to 1000+ pre-loaded @colors! Install Add the dependency to your build.gradle dependencies { compile 'com.cesarferrei

César Ferreira 407 Nov 14, 2022
Thrift for Android that saves you methods

Thrifty Thrifty is an implementation of the Apache Thrift software stack for Android, which uses 1/4 of the method count taken by the Apache Thrift co

Microsoft 528 Dec 28, 2022
Generate helper methods for compose navigation using KSP

Compose NavGen Generate helper methods for compose navigation using KSP. ?? You can try it now, but it's still under development. ?? TODO Support defa

Kenji Abe 6 Feb 5, 2022
KDoctor - A command-line tool that helps to set up the environment for Kotlin Multiplatform Mobile app development

KDoctor is a command-line tool that helps to set up the environment for Kotlin Multiplatform Mobile app development.

Kotlin 331 Dec 29, 2022
XClipper is a clipboard manager for Windows & Android which helps to track clipboard activities and makes it easier to interact with them.

XClipper XClipper is a clipboard manager for Windows & Android which helps to track clipboard activities and makes it easier to interact with them ❤️

Kaustubh Patange 134 Dec 31, 2022
iTunes 11-style color matching code for Android

##About ColorArt is a library that uses an image to create a themed image/text display. It's a port of the idea found on the Panic Blog to work on And

Michael Evans 896 Jan 8, 2023
⚙ A beautiful and extensible API for bulding preferences screen

Material Preferences ?? Installation Add this in app's build.gradle file: implementation 'com.imangazaliev.material-prefs:core:<version>' implementati

Mahach Imangazaliev 59 Jul 26, 2022
compaKTset is a small library aimed at providing you with the most memory efficient Set implementation for any particular data type of your choosing.

compaKTset is a small library aimed at providing you with the most memory efficient Set implementation for any particular data type of your choosing.

Ignat Beresnev 3 Nov 16, 2021