HSV-Alpha Color Picker


Source link: https://github.com/martin-stone/hsv-alpha-color-picker-android

HSV-Alpha Color Picker for Android

This library implements a color picker and a color preference for use in Android applications.

Features

I couldn't find this combination of features in an existing library, which is why I wrote this one:

  • Alpha slider.
  • Text field to copy and paste hex color values.
  • Old and new colors displayed side by side.
  • Optional selection of "no color".
  • Proper behavior when orientation changes.
  • Up-to-date design.

In addition, the Hue-Saturation picker...

  • gives higher hue precision than a square picker of the same size.
  • allows easier selection of pure white than a circular picker.

Demo App

A demo is available on the Play Store. Source code for the app is in the demo_app folder in this repo.

Using the Library

Add the library dependency to your app module's build.gradle:

 dependencies {

compile 'com.rarepebble:colorpicker:2.2.0'
  
}

Add jcenter() to your repository list if it isn't there already.

ColorPreference Usage

Add the ColorPreference to your preference screen xml. Don't forget the extra xmlns: declaration if using the custom attributes described below.

 <PreferenceScreen

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto">

 <com.rarepebble.colorpicker.ColorPreference

 android:key="simplePreference"

 android:title="@string/pref_title"

 android:defaultValue="#f00"

 />

</PreferenceScreen>

XML Preference Attributes

The standard preference attributes apply as normal, including defaultValue, which can be a hex color, as in the example above, or a reference to a color defined elsewhere.

In addition, the following custom attributes may be used. They should be prefixed with the namespace used for res-auto, as in the example below.

colorpicker_selectNoneButtonText

If set, this text will appear on a third button on the color picker dialog. This resets the color setting to the defaultValue if set. If there is no defaultValue, any saved color setting is removed. Apps can use this to implement "no color selected" logic. Use SharedPreference.contains("myOptionalColorKey") to test for that.

colorpicker_noneSelectedSummaryText

This text displays as the preference summary text if no color has been selected.

colorpicker_showAlpha

Set this to false to hide the alpha slider.

colorpicker_showHex

Set this to false to hide the hex value field.

colorpicker_showPreview

Set this to false to hide the color preview field.

Note: colorpicker_defaultColor was removed in version 2, in favour of android:defaultValue. If upgrading, just switch to using android:defaultValue instead.

 <PreferenceScreen

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto">

 <com.rarepebble.colorpicker.ColorPreference

 android:key="myOptionalColor"

 android:title="@string/pref_optional_color"

 app:colorpicker_selectNoneButtonText="@string/no_color"

 app:colorpicker_noneSelectedSummaryText="@string/no_color_selected"

 />
  </PreferenceScreen>

There are further examples in the demo app.

ColorPickerView Usage

In many cases, the ColorPreference will be all that's needed, but if you wish to use the ColorPickerView directly, it can be constructed like any other view, either in code or in XML. Set the initial color with setColor() and retrieve the view's current color with getColor():

 final ColorPickerView picker = new ColorPickerView(getContext());

  picker.setColor(0xff12345);

  ...
  final int color = picker.getColor();

Refer to the ColorPreference source for a fuller example.

XML View Attributes

The custom attributes above should be prefixed with the namespace used for res-auto, just like the preference attributes. See the view demo source for an example.

colorpicker_showAlpha

Set to false to hide the alpha slider. (Default is visible.)

colorpicker_showHex

Set to false to hide the hex value field. (Default is visible.)

colorpicker_showPreview

Set to false to hide the color preview field. (Default is visible.)

ColorPickerView methods

public int getColor()

Gets the current color.

public void setColor(int color)

Sets the original color swatch and the current color to the specified value.

public void setOriginalColor(int color)

Sets the original color swatch without changing the current color.

public void setCurrentColor(int color)

Updates the current color without changing the original color swatch.

public void showAlpha(boolean showAlpha)

Shows or hides the alpha slider.

public void showHex(boolean showHex)

Shows or hides the hex value field.

public void showPreview(boolean showPreview)

Shows or hides the color preview field.

public void addColorObserver(ColorObserver observer)

Allows an object to receive notifications when the color changes.

Bugs

Please report bugs in the GitHub issue tracker.

License

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.

Resources

Kotlin Adaptor for RxJava.

Kotlin has support for SAM (Single Abstract Method) Interfaces as Functions (i.e. Java 8 Lambdas). So you could use Kotlin in RxJava without this adaptor

The gradle plugin to add proguard snippets to your proguard setting file quickly.

This plugin pulls the proguard information from the krschultz/android-proguard-snippets.
If you wanna add the snippets, PR to android-proguard-snippets!

Android UI logger library.

Main features:

  • Always on the screen, even if app is paused. It can be destroyed after direct command call.
  • You can drag it to the any place of the screen.
  • Font and background colors can be changed by double tap.
  • You can re-size main log window by dragging down right corner * of the log window.
  • Clear the screen by clicking on the right upper corner.
  • Easy use. Only three API methods.
  • Easy link with Gradle.

Wizard encapsulates navigation operations between fragments of an activity using BackStack.

ExceptionWear is very simple library to solve problem of not passing exceptions from Android Wear devices to the phone. So if you release an app for smart-watches to Google Play and it will crash (and it will) you won't get any information about it.

ASignature is a library for drawing smooth signatures. It uses variable width Bézier curve interpolation based on Smoother Signatures. It works from API 8+ and doesn't depend on any external libraries.

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