Code Monkey home page Code Monkey logo

ambilwarna's Introduction

Android Color Picker

Maven Central

aka AmbilWarna library ("Pick a Color" in Indonesian)

moved from http://code.google.com/p/yuku-android-util/

This is a small library for your application to enable the users to select an arbitrary color. It is used in the free Bible applications for Android (http://www.bibleforandroid.com).

It is also used by:

If your application has a feature to customize the color of some background, text, or maybe for a painting application where the user can select different colors for painting or filling, then AmbilWarna is suitable for you.

Adding it to your project

dependencies {
    compile 'com.github.yukuku:ambilwarna:2.0.1'
}

Screenshots

How to use the dialog

Create a color picker dialog by calling the following constructor, and then show it.

AmbilWarnaDialog(Context context, int color, OnAmbilWarnaListener listener)

Alpha is also supported by passing the 3rd parameter supportsAlpha:

AmbilWarnaDialog(Context context, int color, boolean supportsAlpha, OnAmbilWarnaListener listener)

Example:

// initialColor is the initially-selected color to be shown in the rectangle on the left of the arrow.
// for example, 0xff000000 is black, 0xff0000ff is blue. Please be aware of the initial 0xff which is the alpha.
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, initialColor, new OnAmbilWarnaListener() {
	@Override
	public void onOk(AmbilWarnaDialog dialog, int color) {
		// color is the color selected by the user.
	}
		
	@Override
	public void onCancel(AmbilWarnaDialog dialog) {
		// cancel was selected by the user
	}

dialog.show();

How to use it as a Preference

Very simple. It works like a DialogPreference that stores an Integer to the shared preferences file.

Just add the following to the preferences xml file.

<yuku.ambilwarna.widget.AmbilWarnaPreference
	android:key="your_preference_key"
	android:defaultValue="0xff6699cc" 
	android:title="Pick a color" />

To enable alpha, use the application attribute supportsAlpha, as follows:

<PreferenceScreen
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:app="http://schemas.android.com/apk/res-auto">
	
	<yuku.ambilwarna.widget.AmbilWarnaPreference
		android:key="your_preference_key"
		android:defaultValue="0xff6699cc" 
		app:supportsAlpha="true"
		android:title="Pick a color with alpha" />
</PreferenceScreen>

Contributors

  • Pascal Cans (noobs.com)
  • Justin Warner (One Rainboot Studio)

ambilwarna's People

Contributors

denisk20 avatar yukuku avatar bowotmf avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar Mohamed ismail 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.