Giter Site home page Giter Site logo

android-colorpicker's Introduction

#Android Stock Color Picker Library Build Status

This is an original color picker written by Google/Android.

Cloned from original source at https://android.googlesource.com/platform/frameworks/opt/colorpicker/ from the branch android-5.1.1_r2, which does not exist anymore.

A little bit adjusted for better development (imported into Android Studio, updated to newest build tools, etc).

###How does it look like? scr1 The color picker as it is per default, unmodified, with the test colors being all static colors in android.graphics.Color.*

###Usage ####Include library: Android Studio / Gradle Include this project (either manually or via git submodule) into your Android app project path. Let's say, you put it under <PROJECT_ROOT>/libs/android-colorpicker.

Add to your settings.gradle:

...
include ':android-colorpicker'
project(':android-colorpicker').projectDir = new File('libs/android-colorpicker/app')

Add to your module's build.gradle (i.e. in most cases <PROJECT_ROOT>/app/build.gradle):

...
dependencies {
    ...
    compile project(':android-colorpicker')
    ...
}
...

The package name of the library is com.woalk.apps.lib.colorpicker (may be different across different branches of this repo).

####Use ColorPickerDialog The simplest way to use the color picker:

mSelectedColor = Color.BLACK;

ColorPickerDialog dialog = ColorPickerDialog.newInstance(
       R.string.some_title_string, 
       new int[] { Color.BLACK, Color.RED, Color.GREEN, ... },
       mSelectedColor,
       5, // Number of columns
       ColorPickerDialog.SIZE_SMALL);

dialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener(){

       @Override
       public void onColorSelected(int color) {
           mSelectedColor = color;
       }

});

dialog.show(getFragmentManager(), "some_tag");

The OnColorSelectedListener will be called when the user clicks on a color. color will contain the selected color value (0xAARRGGBB).

You can add an EditText to enter a custom color hex code by adding true as the last value to the contructor. Clicking 'Done' on the keyboard will trigger the OnColorSelectedListener as usual.

####Use ColorPreference The library comes with a pre-written Preference class to use with a PreferenceScreen (i.e. PreferenceActivity or PreferenceFragment).

scr2

Simply add it like this to your preferences.xml:

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

    <com.woalk.apps.lib.colorpicker.ColorPreference
        android:key="pref_example"
        android:title="@string/example_title"
        android:summary="@string/example_summary"
        app:picker_dialogTitle="@string/example_dialog_title"
        app:picker_colors="@array/colors"
        app:picker_columns="3"
        app:picker_allowCustomColor="false"
        android:defaultValue="@color/bk" />

</PreferenceScreen>

You can name the namespace defined in the second line (xmlns:app...) as you like. You just have to name it everywhere in the file the same.

You should reference an integer-array for app:picker_colors, containing either full integer colors (0xAARRGGBB) or color references, like this:

<resources>
    <integer-array name="colors">
        <item>@color/bk</item>
        <item>@color/r</item>
        <item>@color/g</item>
        <item>@color/b</item>
        <item>@color/y</item>
        <item>@color/m</item>
        <item>@color/c</item>
        <item>@color/w</item>
    </integer-array>

    <color name="bk">#000</color>
    <color name="r">#f00</color>
    <color name="g">#0f0</color>
    <color name="b">#00f</color>
    <color name="y">#ff0</color>
    <color name="m">#f0f</color>
    <color name="c">#0ff</color>
    <color name="w">#fff</color>
</resources>

Change app:picker_allowCustomColors to true to enable the EditText for custom colors.

####Use other small things in this library #####parseColor(String) There is the static method ColorPickerDialog.parseColorString(colorString). It is a modified version of [Color.parseColor(colorString)](http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)), it is capable of parsing more color string types (#RGB, #ARGB`).

####There are string in this project that are not translated yet. Feel free to translate them in your language (or any other language you know well enough). It would be very nice if you would pull-request these additions to this project, so I can complete the translations. Thank you!

There will be extensions of the existing features in the future.

(C) 2013  The Android Open Source Project
    Licensed under Apache License v2.0.
    You can obtain a copy of the license at http://www.apache.org/licenses/LICENSE-2.0

(C) 2015  Woalk Software (http://woalk.com)
    Also, licensed under Apache License v2.0.
    You can obtain a copy of the license at http://www.apache.org/licenses/LICENSE-2.0

DISCLAIMER:
    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

woalk avatar

Stargazers

 avatar  avatar  avatar  avatar Ahsan Sheikh avatar Ondrej Komarek avatar Rory Bradford avatar  avatar Eric Lu avatar Justin Meiners avatar tianyu avatar Alessio Garzi avatar

Watchers

James Cloos avatar  avatar

android-colorpicker's Issues

Default color palette

If we don't specify a color array the app crashes (NPE). It would be good practice to use a default material design color palette instead.

Minimum API 15

I was very excited to use this library, but when compiling encountered the error saying my minimum SDK must be at least 15. That's not realistic for my app. Is there a way this could work with API 11? Also, it does not seem to use the support version of DialogFragment. This would greatly help with compatibility.

Transparent

If no color is selected then it directly applies Transparent Color..is there any way to set default color if no color is selected to be kept?

Publish to Maven

Could you please publish this library to Maven?
It would be so much more convenient!

Thanks!

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.