GithubHelp home page GithubHelp logo

irmobydick / color-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dmfs/color-picker

0.0 1.0 0.0 1.03 MB

Just another color picker for Android

License: Apache License 2.0

Java 100.00%

color-picker's Introduction

color-picker

Just another color picker for Android

This is a nice and simple color picker for Android. It allows to show any number of different palettes with any (reasonable) number of colors. Palettes can be stored in an array or generated on the fly.

Requirements

Example code

Use as a dialog

To show the dialog, just get an instance, add a number of palettes and call the show method.

		ColorPickerDialogFragment d = new ColorPickerDialogFragment();

		// set the palettes
		d.setPalettes(new AbstractPalette[]
		{
			ArrayPalette.fromResources(this, "basecolors", R.string.base_palette_name, R.array.base_palette_colors, R.array.base_palette_color_names),
			new FactoryPalette("rainbow", "Rainbow", ColorFactory.RAINBOW, 16)
		});
		
		d.show(getSupportFragmentManager(), tag);

The calling activity or fragment should implement ColorPickerDialogFragment.ColorDialogResultListener to get the result like:

		@Override
		public void onColorChanged(int color, String colorName, String paletteName)
		{
			// do something with color
		}

		@Override
		public void onColorDialogCancelled()
		{
			// handle cancelled color picker dialog
		}

Use via Intent

Alternatively you can use the picker via Intent. To do so just include the following dependency

implementation "com.github.dmfs.color-picker:colorpicker-activity:1.1"

and call the dialog like:

		ColorPickerActivity.start(context, CODE_PICK_COLOR);

This will call an intent with the action org.openintents.action.PICK_COLOR allowing the user to use his preferred color picker (if it supports the Open Intent).

In onActivityResult(int, int, Intent) you can get the picked color like this:

		@Override
		protected void onActivityResult(int code, int result, Intent data)
		{
			if (result == RESULT_OK && code == CODE_PICK_COLOR)
			{
				Integer color = ColorPickerActivity.getColor(data);
			}
		}

Screen shots

TODO

  • fix landscape mode on smaller screens
  • fix selected/focused backgrounds
  • allow to customize color shapes
  • allow to preselect a specific color
  • add support for other fragment types, like hex input or color wheels

License

Copyright (c) dmfs GmbH 2017, licensed under Apache 2 (see LICENSE).

color-picker's People

Contributors

dmfs avatar ravidsrk avatar

Watchers

MAY3AM 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.