• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple dialog making it quick and easy to add color picking functionality to any app.

ColorPickerDialog JitPack Gradle Build Discord

ColorPickerDialog is a simple dialog making it quick and easy to add a color picker functionality to any app.

For testing and experimentation purposes, a sample apk can be downloaded here.

RGB(A) Picker HSV Picker Preset Picker Image Picker (Tab) Image Picker (Images) Dark Theme
Screenshot Screenshot Screenshot Screenshot Screenshot Screenshot

Usage

Setup

This project is published on JitPack, which you can add to your project by copying the following to your root build.gradle at the end of "repositories".

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

To add the dependency, copy this line into your app module's build.gradle file.

implementation 'me.jfenn.ColorPickerDialog:base:0.2.2'

Creating a Dialog

The basic requirements for the dialog are a default color and a listener, and though none of them have to be specified, it is usually a good idea. You can create a simple dialog fragment using the snippet below:

new ColorPickerDialog()
  .withColor(color) // the default / initial color
  .withListener(new OnColorPickedListener<ColorPickerDialog>() {
    @Override
    public void onColorPicked(@Nullable ColorPickerDialog dialog, int color) {
      // a color has been picked; use it
    }
  })
  .show(getSupportFragmentManager(), "colorPicker");

Alternatively, if you are creating the dialog from a fragment, you should use getChildFragmentManager() instead of getSupportFragmentManager().

Alpha

You can call .withAlpha(boolean) to specify whether you want the color's alpha channel to be configurable by the user (if not, all output colors will be fully opaque). This option is enabled by default. A somewhat unnecessary example:

new ColorPickerDialog(this)
  .withAlphaEnabled(false) // disable the alpha channel
  .withListener(...)
  .show();

Alternative Pickers

By default, the dialog gives the user three ways to enter a color; they can use RGB sliders, HSV sliders, or enter the hex value into the text box at the top.

There are also some alternative pickers that can be enabled to serve a few different purposes.

Presets

The .withPresets() method will enable the "preset" color picker, which simply displays a grid of preset colors for the user to choose from. These colors can be configured by passing them (either as an array or varargs) to the .withPresets() method, like below:

new ColorPickerDialog()
    .withPresets(Color.RED, Color.GREEN, Color.BLUE)
    .withListener(...)
    .show(getSupportFragmentManager(), "colorPicker");

Images

There is an optional dependency that adds image picking functionality to the color picker; the user can select an image and then select a color from the image they have chosen.

To enable it, add the following to your build.gradle file along with the dependency from before:

implementation 'me.jfenn.ColorPickerDialog:imagepicker:0.2.2'

Next, you will need to declare the following permissions in your AndroidManifest.xml (the library does not do it for you).

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Now you should be able to add an image picker to your dialog by calling .withPicker(ImagePickerView.class) like below:

new ColorPickerDialog()
    .withPicker(ImagePickerView.class)
    .withListener(...)
    .show(getSupportFragmentManager(), "colorPicker");

Theming

You can theme this dialog by passing your custom theme to .withTheme(int). Support for full "runtime" theming may come later, but now is not later, so you can't do that yet. Here's an example of a ColorPickerDialog with a basic dark theme, demonstrating some of the options that you can specify.

new ColorPickerDialog()
    .withTheme(R.style.ColorPickerDialog_Dark)
    .show(getSupportFragmentManager(), "colorPicker");
<style name="ColorPickerDialog.Dark" parent="Theme.AppCompat.Dialog">
  <item name="redColor">#FF5252</item>
  <item name="greenColor">#FF5252</item>
  <item name="blueColor">#536DFE</item>
  <item name="neutralColor">#FFFFFF</item>
</style>

The redColor, greenColor, and blueColor attributes affect the RGB sliders, and the neutralColor attribute changes the "neutral" colors of the others, including the alpha slider and the handles of the sliders in the HSL picker.

Rounded Corners

The dialog also supports custom values for the rounded corners, which you can specify by calling .withCornerRadius(float) with the dp measurement of the corner radius, or .withCornerRadiusPx(int) with a pixel measurement.

Other Documentation

Not only am I lazy, I also miss things, so this page may not describe every feature that this library is capable of. However, the majority of this library's documentation is actually written as javadocs within the source code. You can find the generated documentation pages for it here.

Proguard / Minification

For those using the R8 compiler, this library's proguard rules should be conveniently bundled with the library already - otherwise, you will need to add them to your app's proguard-rules.pro file yourself to prevent running into any issues with minifyEnabled and the like.

More Repositories

1

Alarmio

A simple alarm clock focused on design, readability, and internet radio.
Java
338
star
2

ScreenshotMaker

A small java applet to generate uniform Play Store screenshots with titles and descriptions.
Java
130
star
3

Status

A no-root status bar replacement for Android.
Java
127
star
4

Attribouter

A lightweight "about screen" library to allow quick but customizable attribution in Android apps.
Kotlin
115
star
5

Metronome-Android

A lightweight, well designed metronome app for Android.
Java
111
star
6

Pasta-for-Spotify

A material design Spotify client for Android
Java
110
star
7

Pasta-Music

(unmaintained) A material design music player for Android, based off Pasta for Spotify
Java
106
star
8

SlideActionView

An Android view which provides a nice slide-to-left/right interaction.
Java
70
star
9

SignalStrengths

A library and sample application with the purpose of getting an accurate signal strength on different Android phones.
Java
53
star
10

MediaNotification

Slightly unstable attempt to replace all media notifications with Android O styled copies.
Java
45
star
11

Asteroid

A simple Android game based on avoiding incoming asteroids
Java
41
star
12

AdaptiveIconView

A library to allow easy implementation of pre-Oreo adaptive icon support in Android launchers.
Java
29
star
13

Crasher

An easy to use crash reporting library for Android.
Java
29
star
14

Cleaner

The only storage saving app that actually works! :D
Java
28
star
15

Calculator

(unmaintained) An attempt to make a decent calculator capable of complex functions without sacrificing design.
Java
27
star
16

Feedage

A basic "news reader" that sorts posts from various RSS feeds into categories.
Java
23
star
17

WearColorPicker

A lightweight color picker library for Android Wear.
Java
23
star
18

PaletteGetter

A library that can get the color scheme of any app.
Java
21
star
19

declarativ

A declarative HTML rendering library that is definitely not JSX.
TypeScript
20
star
20

RadialLayout

A scrollable-ish view that arranges images in circles extending from the center of the screen.
Java
19
star
21

mdjavadoc

A script that generates markdown javadocs for use in Jekyll and GitHub Pages.
JavaScript
18
star
22

fennifith.github.io

My personal website.
SCSS
16
star
23

Tooltips

(unmaintained) A small tooltips library for Android based on Material Design.
Java
15
star
24

TimeDatePicker

A simple Android library containing several time/date pickers and dialogs.
Java
15
star
25

Scrurl

Scrolling urls, a.k.a. the second worst website I've ever made.
HTML
15
star
26

Asciimg

A command line tool to display images in ASCII.
JavaScript
14
star
27

Cronhub-Monitor

A native CronHub notification client for Android.
Java
14
star
28

Bagels

A live wallpaper that blurs the screen after a period of time without any actions.
Java
14
star
29

Rocket

(unmaintained) A basic tap-to-fly game experimenting with view animation.
Java
13
star
30

APReader

A small app that displays Android Police articles without waiting for the website to load.
Java
10
star
31

WearLocker

A basic lock screen that prevents accidental touches on Android Wear 2.0.
Java
10
star
32

SunriseSunsetView

A lightweight Android view used for displaying and/or editing sunrise and sunset times.
Java
9
star
33

Wallpapers

(unmaintained) A material design wallpaper dashboard template
Java
9
star
34

AndroidUtils

A bunch of util classes that I use in almost every project I write.
Kotlin
9
star
35

MonkeyTester

Determines whether a user is a monkey, a goat, or both, based on values obtained from android's ActivityManager and UserManager.
Java
9
star
36

ExceptionalTraveler

An implementation of the Traveling Salesperson Problem using the fundamentals of Exceptional Programming.
Java
8
star
37

PortAuthorityFeedbackReporter

A small application to make it easier for riders to report issues to the Pittsburgh Port Authority bus system.
Java
8
star
38

Monochrome

A monochromatic pixelated adventure game.
Java
7
star
39

FelixLauncher

(unmaintained) Dark-themed launcher that supposedly saves a lot of battery.
Java
6
star
40

AAH

A basic cmdline program for Linux to help me do basic things I should already know. Ex: "AAH drive mount"
Go
6
star
41

Paper-Tales

A modified version of Fornax that gets its content from Wordpress articles.
Java
5
star
42

ChargeScreen

(Unmaintained) An annoying screen that pops up when you plug your phone in.
Java
5
star
43

dotfiles

My "generic Linux distro" dotfiles. Used to sync stuff between laptops and not much else.
Shell
4
star
44

bugiver

A small website that gives you an issue to fix when there is nothing to do.
HTML
4
star
45

Blackboard

(unstable) An HTML scraping, JavaScript injecting, spaghettificating, massive heap of Blackboard parsing mobile client.
Java
3
star
46

Robotics

Documentation of stuff done in my robotics class.
C
2
star
47

photos

A collection of my photography, published under the Creative Commons License.
HTML
2
star
48

styles

A collection of all my CSS styles, organized and documented.
HTML
2
star
49

HackNA-Notes

A small sample project created for a workshop at HackNA.
Java
2
star
50

discord-github-thing-doer

A Discord bot that automates github-related tasks for my server.
JavaScript
1
star
51

Music

A collection of my piano compositions and other music-related projects.
HTML
1
star
52

music-automata-api

An Rx-based interface for programming musical automata in JavaScript. (WIP)
JavaScript
1
star
53

pixularautomaton

A basic cellular automaton that makes pretty animations from images.
HTML
1
star
54

MarkdownToJupyter

NodeJS script to execute & convert code blocks in markdown files to a JupyterLab Notebook.
JavaScript
1
star