Coder Social home page Coder Social logo

android-colorpicker's Introduction

🎨Color Picker Library for Android

Releases API Language PRWelcome Twitter

Built with ❤︎ by Dhaval Patel and contributors

Yet another Color Picker Library for Android. It is highly customizable and easy to use. Pick the color from wheel or select Material Colors from dialog. The original ColorPickerView was written by Hong Duan.

🐱‍🏍Features:

  • Color Picker View
  • Color Picker Dialog with Recent Color Option
  • Material Color Picker Alert Dialog
  • Material Color Picker BottomSheet Dialog

🎬Preview

Color Picker Material Color Picker

💻Usage

  1. Gradle dependency:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
    implementation 'com.github.Dhaval2404:ColorPicker:2.3'
  2. The ColorPicker configuration is created using the builder pattern.

    // Kotlin Code
    ColorPickerDialog
        .Builder(this)        				// Pass Activity Instance
        .setTitle("Pick Theme")           	// Default "Choose Color"
        .setColorShape(ColorShape.SQAURE)   // Default ColorShape.CIRCLE
        .setDefaultColor(mDefaultColor)     // Pass Default Color
        .setColorListener { color, colorHex ->
        	// Handle Color Selection
        }
        .show()
    // Java Code
    new ColorPickerDialog
        .Builder(this)
        .setTitle("Pick Theme")
        .setColorShape(ColorShape.SQAURE)
        .setDefaultColor(mDefaultColor)
        .setColorListener(new ColorListener() {
            @Override
            public void onColorSelected(int color, @NotNull String colorHex) {
                // Handle Color Selection
            }
        })
        .show();
  3. The MaterialColorPicker configuration is created using the builder pattern.

    // Kotlin Code
    MaterialColorPickerDialog
        .Builder(this)        					// Pass Activity Instance
        .setTitle("Pick Theme")           		// Default "Choose Color"
        .setColorShape(ColorShape.SQAURE)   	// Default ColorShape.CIRCLE
        .setColorSwatch(ColorSwatch._300)   	// Default ColorSwatch._500
        .setDefaultColor(mDefaultColor) 		// Pass Default Color
        .setColorListener { color, colorHex ->
       		// Handle Color Selection
        }
        .show()
    // Java Code
    new MaterialColorPickerDialog
        .Builder(this)
        .setTitle("Pick Theme")
        .setColorShape(ColorShape.SQAURE)
        .setColorSwatch(ColorSwatch._300)
        .setDefaultColor(mDefaultColor)
        .setColorListener(new ColorListener() {
            @Override
            public void onColorSelected(int color, @NotNull String colorHex) {
            	// Handle Color Selection
            }
        })
        .show();

🎨Customization

  • You can change the color or Positive and Negative Button Text Color. Add Following parameters in your colors.xml file.

    <resources>
        <!-- Here you can add color of your choice  -->
        <color name="positiveButtonTextColor">@color/colorAccent</color>
        <color name="negativeButtonTextColor">@color/colorAccent</color>
        <color name="bottomSheetDividerColor">#F5F5F5</color>
    </resources>
  • You can provide predefine colors for the MaterialColorPicker

    // Kotlin Code
    MaterialColorPickerDialog
       .Builder(activity!!)
    
       // Option 1: Pass Hex Color Codes
       //.setColors(arrayListOf("#f6e58d", "#ffbe76", "#ff7979", "#badc58", "#dff9fb", "#7ed6df", "#e056fd", "#686de0", "#30336b", "#95afc0"))
    
       // Option 2: Pass Hex Color Codes from string.xml
       //.setColors(resources.getStringArray(R.array.themeColorHex))
    
       // Option 3: Pass color array from colors.xml
       .setColorRes(resources.getIntArray(R.array.themeColors))
    
       .setColorListener { color, colorHex ->
         // Handle Color Selection
       }
       .show()
    // Java Code
    String[] colorArray = new String[]{"#f6e58d", "#ffbe76", "#ff7979",
        "#badc58", "#dff9fb", "#7ed6df", "#e056fd", "#686de0", "#30336b", "#95afc0"};
    
    new MaterialColorPickerDialog
        .Builder(requireActivity())
    
        // Option 1: Pass Hex Color Codes
        //.setColors(colorArray)
    
        // Option 2: Pass Hex Color Codes from string.xml
        //.setColors(getResources().getStringArray(R.array.themeColorHex))
    
        // Option 3: Pass color array from colors.xml
        .setColorRes(getResources().getIntArray(R.array.themeColors))
        
        .setColorListener(object : ColorListener {
            override fun onColorSelected(color: Int, colorHex: String) {
                // Handle Color Selection
            }
        })
        .show();

    Where R.array.themeColors and R.array.themeColorHex are defined as below

    <array name="themeColors">
      <item>@color/green_500</item>
      <item>@color/blue_500</item>
      <item>@color/red_500</item>
      <item>@color/grey_500</item>
      <item>@color/orange_500</item>
    </array>
    
    <string-array name="themeColorHex">
      <item>#f6e58d</item>
      <item>#ffbe76</item>
      <item>#ff7979</item>
      <item>#badc58</item>
      <item>#dff9fb</item>
      <item>#7ed6df</item>
      <item>#e056fd</item>
      <item>#686de0</item>
      <item>#30336b</item>
      <item>#95afc0</item>
    </string-array>
  • You can set the Dismiss listener

    ColorPicker

    // Kotlin Code
     ColorPickerDialog
        .Builder(requireActivity())
        .setDismissListener {
            // Handle Dismiss Event
        }
        .show()
    // Java Code
    new ColorPickerDialog
        .Builder(this)
        .setDismissListener(new DismissListener() {
            @Override
            public void onDismiss() {
                // Handle Dismiss Event
            }
        })
        .show();

    MaterialColorPicker

    // Kotlin Code
    MaterialColorPickerDialog
        .Builder(this)
        .setDismissListener {
            // Handle Dismiss Event
        }
        .show()
    // Java Code
    new MaterialColorPickerDialog
        .Builder(this)
        .setDismissListener(new DismissListener() {
            @Override
            public void onDismiss() {
                // Handle Dismiss Event
            }
        })
        .show();
  • You can set the Tick color for each card. This will come handy when color list include black or white colors. By default tick color will be either black or white based on the color darkness. If more dark colors the tick color will be white else black.

     // Kotlin Code
     MaterialColorPickerDialog
         .Builder(this)
         .setTickColorPerCard(true)     // Default will be false
         .show()
     // Java Code
     new MaterialColorPickerDialog
         .Builder(this)
         .setTickColorPerCard(true)     // Default will be false
         .show();

💥Compatibility

  • Library - Android Lollipop 5.0+ (API 21)
  • Sample - Android Lollipop 5.0+ (API 21)

✔️Changelog

Version: 2.2/2.3

  • Fixed duplicate class found with FlexBox issue #24

Version: 2.1

  • Upgrade gradle dependency
  • Added Android 12 support

Version: 2.0

  • Added Java compatibility #8
  • Added option to set tick color per color card #12
  • Added dialog dismiss listener #13

Version: 1.2

  • Added Dark mode support & German translation #4

Version: 1.1

  • Added option to change positive and negative button text color #2

Version: 1.0

  • Initial Build

📃 Libraries Used

🌟 Credits

Let us know!

We'll be really happy if you sent us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding the library.

License

Copyright 2020-2021, Dhaval Patel

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.

android-colorpicker's People

Contributors

deadman96385 avatar dhaval2404 avatar jstokke avatar marcauberer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.