Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 30 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
A simple, minimalistic and beautiful dialog color picker for Android 4.1+ devices. This color picker is easy-to-use and easy-to-integrate in your application to let users of your app choose color in a simple way.

Features
- Get Hex & RGB color codes
- Set color using RGB values and get HEX codes
- Set colo using HEX value
- Get Hex and (A)RGB color codes
- Set color using (A)RGB values and get HEX codes
- Set color using HEX value
- Separate UI for portrait and landscape devices
- Support for pre-lollipop devices

Design inspired from [Dribbble](https://dribbble.com/shots/1858968-Material-Design-colorpicker?list=following&offset=4) by [Lucas Bonomi](http://lucasbonomi.com/)

Portrait

![portrait](/screenshots/main.jpg)
![Portrait RGB](screenshots/main_portrait_rgb.png)
![Portrait ARGB](screenshots/main_portrait_argb.png)

Landscape

![landscape](/screenshots/main_land.jpg)
![Landscape RGB](screenshots/main_landscape_rgb.png)
![Landscape ARGB](screenshots/main_landscape_argb.png)


## HOW TO USE IT
Expand All @@ -37,7 +39,7 @@ dependency in your `build.gradle`.
(module)
```groovy
dependencies {
compile 'com.pes.materialcolorpicker:library:1.0.+'
compile 'com.pes.materialcolorpicker:library:1.1.+'
}
```

Expand All @@ -54,45 +56,41 @@ Create a color picker dialog object
final ColorPicker cp = new ColorPicker(MainActivity.this, defaultColorR, defaultColorG, defaultColorB);
```

defaultColorR, defaultColorG, defaultColorB are 3 integer ( value 0-255) for the initialization of the color picker with your custom color value. If you don't want to start with a color set them to 0 or use only the first argument
defaultColorR, defaultColorG, defaultColorB are 3 integer (value 0-255) for the initialization of the color picker with your custom color value. If you don't want to start with a color set them to 0 or use only the first argument.

Then show the dialog (when & where you want) and save the selected color
The library also supports alpha values. If no color or only red, green, and blue are specified, the alpha value is set to 255 (0xFF) and no slider is shown.

```java
Use the following constructor to specify an alternative alpha channel value (0..255). As soon as the alpha value constructor is used, a fourth slider will appear above the RGB sliders and the text input field will change from six HEX characters to eight.

/* Show color picker dialog */
cp.show();

/* --- DEPRECATED, se below --- On Click listener for the dialog, when the user select the color */
Button okColor = (Button)cp.findViewById(R.id.okColorButton);
okColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
```java
final ColorPicker cp = new ColorPicker(MainActivity.this, defaultAlphaValue, defaultColorR, defaultColorG, defaultColorB);
```

/* You can get single channel (value 0-255) */
selectedColorR = cp.getRed();
selectedColorG = cp.getGreen();
selectedColorB = cp.getBlue();

/* Or the android RGB Color (see the android Color class reference) */
selectedColorRGB = cp.getColor();
Then show the dialog (when and where you want) and save the selected color

cp.dismiss();
}
});
```java
/* Show color picker dialog */
cp.show();

/* Set a new Listener called when user click "select" */
cp.setOnColorSelected(new OnColorSelected() {
cp.setCallback(new ColorPickerCallback() {
@Override
public void returnColor(int col) {
Log.d("Red", Integer.toString(Color.red(col)));
Log.d("Green", Integer.toString(Color.green(col)));
Log.d("Blue", Integer.toString(Color.blue(col)));
public void onColorChosen(@ColorInt int color) {
// Do whatever you want
}
});
```

That's all :)

### Transition from v1.0 to v1.1

Version 1.1 introduced some API changes---mainly a renaming of the `OnColorSelected` callback interface. This has been renamed to `ColorPickerCallback`.

The old interface is still in the library but will be removed in the next version update. It has been marked as deprecated and isn't called by the library, therefore no values will appear in your app if you still rely on the old interface.


## Translations

If you would like to help localise this library please fork the project, create and verify your language files, then create a pull request.
Expand All @@ -110,7 +108,7 @@ Example app that use Android Material Color Picker Dialog to let users choose th
```
The MIT License (MIT)

Copyright (c) 2016 Simone Pessotto (http://www.simonepessotto.it)
Copyright (c) 2017 Simone Pessotto (http://www.simonepessotto.it)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {

minSdkVersion 16
targetSdkVersion 25
versionCode 6
versionName "1.0.5"
versionCode 7
versionName "1.1.0"
}
buildTypes {
release {
Expand All @@ -27,7 +27,7 @@ def siteUrl = 'https://github.com/Pes8/android-material-color-picker-dialog/'
def gitUrl = 'https://github.com/Pes8/android-material-color-picker-dialog/' // Git repository URL
group = "com.pes.materialcolorpicker" // Maven Group ID for the artifact
// This is the library version used when deploying the artifact
version = "1.0.5"
version = "1.1.0"

install {
repositories.mavenInstaller {
Expand Down Expand Up @@ -84,7 +84,7 @@ task javadoc(type: Javadoc) {

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
from javadoc.getDestinationDir()

}
artifacts {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.pes.androidmaterialcolorpickerdialog;

import android.annotation.SuppressLint;
import android.support.annotation.IntRange;

final class ColorFormatHelper {
Expand All @@ -16,32 +15,47 @@ static int assertColorValueInRange(@IntRange(from = 0, to = 255) int colorValue)
}

/**
* Left-pads the specified color value with 0 to 2 spaces, depending on the color value length
* Formats individual RGB values to be output as a HEX string.
* <p>
* Beware: If color value is lower than 0 or higher than 255, it's reset to 0.
*
* @param colorValue Color value
* @return Left-padded (with Strings) color value as a String
* @param red Red color value
* @param green Green color value
* @param blue Blue color value
* @return HEX String containing the three values
*/
@SuppressLint("DefaultLocale")
static String leftPadColorValue(@IntRange(from = 0, to = 255) int colorValue) {
return String.format("%3d", colorValue);
static String formatColorValues(
@IntRange(from = 0, to = 255) int red,
@IntRange(from = 0, to = 255) int green,
@IntRange(from = 0, to = 255) int blue) {

return String.format("%02X%02X%02X",
assertColorValueInRange(red),
assertColorValueInRange(green),
assertColorValueInRange(blue)
);
}

/**
* Formats individual RGB values to be output as a HEX string.
* Formats individual ARGB values to be output as an 8 character HEX string.
* <p>
* Beware: If color value is lower than 0 or higher than 255, it's reset to 0.
* Beware: If any value is lower than 0 or higher than 255, it's reset to 0.
*
* @param alpha Alpha value
* @param red Red color value
* @param green Green color value
* @param blue Blue color value
* @return HEX String containing the three values
* @since v1.1.0
*/
static String formatRgbColorValues(
static String formatColorValues(
@IntRange(from = 0, to = 255) int alpha,
@IntRange(from = 0, to = 255) int red,
@IntRange(from = 0, to = 255) int green,
@IntRange(from = 0, to = 255) int blue) {

return String.format("%02X%02X%02X",
return String.format("%02X%02X%02X%02X",
assertColorValueInRange(alpha),
assertColorValueInRange(red),
assertColorValueInRange(green),
assertColorValueInRange(blue)
Expand Down
Loading