Color picker library


Source link: https://github.com/enricocid/Color-picker-library

Color picker library

Features

  • Live color preview;
  • Change color using A(alpha) R(red) G(green) B(blue) seekbars;
  • Change colors by editing HEX|RGB's A (alpha) R (red) G (green) B (blue) edit texts;
  • Built-in material palette;

Sample Project

You can download the latest sample APK from this repo here: https://github.com/enricocid/Color-picker-library/blob/master/app/app-release.apk

The source code is also available: https://github.com/enricocid/Color-picker-library/tree/master/app

#F-Droid

Gradle Dependency

Repository

The Gradle dependency is available via jCenter. jCenter is the default Maven repository used by Android Studio.

The minimum API level supported by this library is API 16 (Jelly Bean).

Download

Add the following dependency to your projects build.gradle:

dependencies {

  // ... other dependencies here
  compile 'com.github.enricocid:cpl:1.0.3' 
}

Usage

###To display a color picker DialogFragment:

colorDialog.showColorPicker(AppCompatActivity activity, int tag);

tag: it's an integer tag assigned to the dialog, for example 1.

If You wanna use multiple dialog in Your activity You can use progressive numbers (1,2,3 ...).

###The Activity showing the color picker dialog must implement ColorSelectedListener:

public class YourActivity extends AppCompatActivity implements colorDialog.ColorSelectedListener {

// ...

@Override

public void onColorSelection(DialogFragment dialogFragment, int color) {

 // Do Your shiz on color selection

// ...

 // Set the picker's dialog color         colorDialog.setPickerColor(YourActivity.this, int tag, int color);

  
}
 
}

###If You have multiple dialogs you can take advantage of tags. For example, if we have created four dialogs (1,2,3,4):

public class YourActivity extends AppCompatActivity implements colorDialog.ColorSelectedListener {

// ...

@Override

public void onColorSelection(DialogFragment dialogFragment, int color) {

 int tag;

 // get tag number from fragment

tag = Integer.valueOf(dialogFragment.getTag());

 switch (tag) {

 case 1:

  // do your shiz with selected color from dialog 1

 // ...

  //Set the picker dialog's color             colorDialog.setPickerColor(YourActivity.this, 1, color);

  break;

 case 2:

  // do your shiz with selected color from dialog 2

 // ...

  //Set the picker dialog's color

 colorDialog.setPickerColor(YourActivity.this, 2, color);

  break;

 case 3:

  // do your shiz with selected color from dialog 3

 // ...

  //Set the picker dialog's color

 colorDialog.setPickerColor(YourActivity.this, 3, color);

  break;

 case 4:

  // do your shiz with selected color from dialog 4

 // ...

  //Set the picker dialog's color

 colorDialog.setPickerColor(YourActivity.this, 4, color);

  break;

}

  
}
 
}

Usage instructions for Preferences

If you're developing for Android 3.0 (API level 11) and higher, you should use a PreferenceFragment to display your list of Preference objects as recommended by Google ( https://developer.android.com/guide/topics/ui/settings.html#Fragment)

###To display a color picker DialogFragment on Preference click:

public static class YourPreferenceFragment extends PreferenceFragment {

    //retrieve AppCompatActivity     final AppCompatActivity appCompatActivity = (AppCompatActivity) getActivity();
  

  //your preference     Preference yourPreference;

// ...

@Override

public void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);

 //get yourPreference

yourPreference = findPreference("yourPreferenceKey");

 //on click show colorDialog

yourPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

  @Override

  public boolean onPreferenceClick(Preference preference) {

               colorDialog.showColorPicker(appCompatActivity, int tag);

return false;

 
}

}
);

  
}
 
}

###PreferenceActivity must implement colorSelectedListener:

public class YourPreferenceActivity extends AppCompatActivity implements colorDialog.ColorSelectedListener {

// ...

@Override

public void onColorSelection(DialogFragment dialogFragment, int color) {

 // Do Your shiz on color selection

// ...

 //Set the picker's dialog color

colorDialog.setPickerColor(YourPreferenceActivity.this, int tag, color);

  
}
 
}

###To retrieve the dialog color on app's resume by tag number(on onCreate or onResume)You can use

colorDialog.getPickerColor(AppCompatActivity activity, int tag);
public static class YourPreferenceFragment extends PreferenceFragment {

//your preference
  static Preference yourPreference;

// ...

@Override

public void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);

 //retrieve the color

int color = colorDialog.getPickerColor(getActivity(), int tag);

  
}
 
}

###(Optional) Set a custom preference

We are going to access the preference in a static method. In Your Preference fragment let's define the preference:

public static class YourPreferenceFragment extends PreferenceFragment {

//your preference
  static Preference yourPreference;

// ...

@Override

public void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);

 //Get yourPreference

yourPreference = findPreference("yourPreferenceKey");

  
}
 
}

###onColorSelection method we are going to set custom Preference:

public class PreferenceActivity extends AppCompatActivity implements colorDialog.ColorSelectedListener {

import static com.yourPackage.YourPreferenceActivity.YourPreferenceFragment.yourPreference;

// ...

@Override

public void onColorSelection(DialogFragment dialogFragment, int color) {

  // ...

 //Set the picker dialog's color

colorDialog.setPickerColor(YourPreferenceActivity.this, int tag, color);

 //set custom preference summary

colorDialog.setColorPreferenceSummary(yourPreference, color, YourPreferenceActivity.this, getResources());

  
}
 
}

###You can use switch case statement if You have multiple dialogs in Your preferences (as explained above):

switch (tag) {
  case 1:

//Set the picker dialog's color
  colorDialog.setPickerColor(YourPreferenceActivity.this, 1, color);

//set preference style
  colorDialog.setColorPreferenceSummary(yourPreference, color, YourPreferenceActivity.this, getResources());

break;  case 2:

// ...
  break;  case 3:

// ...
  break;  case ...
  // ...
  break;

case ...
 
}

###To mantain the circle and summary colors on app's resume You can use:

colorDialog.getPickerColor(AppCompatActivity activity, int tag);

In YourPreferenceFragment:

public static class YourPreferenceFragment extends PreferenceFragment {

// ...

 //color picker preferences
  static Preference yourPreference;

@Override
  public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

 //get charge color preference

yourPreference = findPreference("yourPreferenceKey");

 //get preferences colors

int color = colorDialog.getPickerColor(getActivity(), int tag);

 //set preferences colors

colorDialog.setColorPreferenceSummary(yourPreference, color, getActivity(), getResources());

  
}
 
}

#Utilities

Color picker library contains two color utilities that You can use in Your app.

###shiftColor(int color, float fraction)

Returns shifted down color by the selected fraction

Example usage for color #FF673AB7:

colorDialog.shiftColor(color, 0.9f);

###getComplementaryColor(int colorToInvert)

Returns inverted color

Example usage for color #FF673AB7:

colorDialog.getComplementaryColor(color)

Resources

An Android library for pattern lock.

Localify is a small library which allows to load a content from files which are stored under assets and/or raw directory. It can be useful when you have to load some init data or during tests to load mock data.

Session is a easy to use Persistence Library which save datas into SharedPreference.

TextViewOverflowing is a custom android view that allows reflowing from one TextView to another.

Do you want to customize what you share, depending on what the user wants to share it with?

Let's say you want to add a "via @theTwitterAccountOfYourProduct" if the content is being shared with a Twitter client.

BOOM! That's what Yeti does.

Android password-based encryption (PBE) implementation.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes