-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from fennifith/develop
Version 0.1.0
- Loading branch information
Showing
52 changed files
with
2,024 additions
and
908 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,76 @@ | ||
ColorPickerDialog is a simple dialog making it quick and easy to add a color picker functionality to any app. | ||
|
||
[![](https://jitpack.io/v/me.jfenn/ColorPickerDialog.svg)](https://jitpack.io/#me.jfenn/ColorPickerDialog) | ||
|
||
For testing and experimentation purposes, a sample apk can be downloaded [here](https://jfenn.me/projects/colorpickerdialog). | ||
|
||
|Color Picker|Image Color Picker| | ||
|--------|--------| | ||
|![img](./.github/images/dialog.png?raw=true)|![img](./.github/images/image.png?raw=true)| | ||
|Color Picker|No Alpha|Dark Theme| | ||
|--------|--------|--------| | ||
|![img](./.github/images/picker.png?raw=true)|![img](./.github/images/noalpha.png?raw=true)|![img](./.github/images/darktheme.png?raw=true)| | ||
|
||
## Usage | ||
|
||
### Setup | ||
|
||
The Gradle dependency is available through jCenter, which is used by default in Android Studio. To add the module to your project, copy this line into the dependencies section of your build.gradle file. | ||
``` gradle | ||
compile 'james.colorpickerdialog:colorpickerdialog:0.0.4' | ||
This project is published on [JitPack](https://jitpack.io), which you can add to your project by copying the following to your root build.gradle at the end of "repositories". | ||
|
||
```gradle | ||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
``` | ||
|
||
### Creating a Dialog | ||
To add the dependency, copy this line into your app module's build.gradle file. | ||
|
||
The basic requirements for the dialog are a context, color, and listener. You must handle storage of the color yourself, as the library will not do it for you. | ||
```gradle | ||
implementation 'me.jfenn:ColorPickerDialog:0.1.0' | ||
``` | ||
|
||
``` java | ||
new ColorPickerDialog(this) //context | ||
.setPreference(color) //the current stored color value | ||
.setListener(new PreferenceDialog.OnPreferenceListener<Integer>() { | ||
@Override | ||
public void onPreference(PreferenceDialog dialog, Integer preference) { | ||
//called when a color is chosen - this is where you would update a stored value | ||
} | ||
### Creating a Dialog | ||
|
||
The basic requirements for the dialog are a context, color, and listener, though none of them _have_ to be specified. If you don't specify a listener, though, you can't do anything with the color picked by the dialog, which is not very good. | ||
|
||
```java | ||
new ColorPickerDialog(this) // context | ||
.withColor(color) // the default / initial color | ||
.withListener(new ColorPickerDialog.OnColorPickedListener() { | ||
@Override | ||
public void onCancel(PreferenceDialog dialog) { | ||
//called if the dialog is dismissed | ||
public void onColorPicked(ColorPickerDialog dialog, int color) { | ||
// a color has been picked; use it | ||
} | ||
}) | ||
.show(); | ||
``` | ||
|
||
### Image Picker | ||
### Alpha | ||
|
||
By default, the dialog will allow the user to pick a color from an image. To enable or disable this feature, use the `ColorPickerDialog.setImagePickerEnabled(boolean)` method. | ||
You can also call `.withAlpha(boolean)` to specify whether you want the colors' alpha to be configurable by the user (if not, all output colors will be fully opaque). This option is enabled by default. A somewhat unnecessary example: | ||
|
||
### Default Colors | ||
|
||
To add a default color, use the `ColorPickerDialog.setDefaultPreference(Integer)` method. This will cause a reset button to display when the current preference isn't equal to the default one. If a current preference isn't specified, the dialog will use the default one, but if neither are specified it will cause a `NullPointerException`. | ||
```java | ||
new ColorPickerDialog(this) | ||
.withAlphaEnabled(false) // disable the alpha | ||
.withListener(...) | ||
.show(); | ||
``` | ||
|
||
### Using The Image Picker Dialog Separately | ||
### Theming | ||
|
||
The image picker function included in this library is currently limited to getting images from the gallery on the device. To use the dialog with a different image, you can create the dialog manually like below. | ||
You can theme this dialog the same as any other: by passing a second parameter (a style resource) to its constructor. Full "runtime" theming will come later, but now is not later, so you can't do that yet. Here's an example of a `ColorPickerDialog` with a basic dark theme, demonstrating all of the options you can specify. | ||
|
||
``` java | ||
new ImageColorPickerDialog(getContext(), bitmap) //context, image | ||
.setDefaultPreference(Color.BLACK) //default color in case the user doesn't pick a value | ||
.setListener(new PreferenceDialog.OnPreferenceListener<Integer>() { | ||
@Override | ||
public void onPreference(PreferenceDialog dialog, Integer preference) { | ||
//called when a color is chosen | ||
} | ||
```java | ||
new ColorPickerDialog(this, R.style.ColorPickerTheme).show(); | ||
``` | ||
|
||
@Override | ||
public void onCancel(PreferenceDialog dialog) { | ||
//called if the dialog is dismissed | ||
} | ||
}) | ||
.show(); | ||
```xml | ||
<style name="ColorDialog.Dark" parent="Theme.AppCompat.Dialog"> | ||
<item name="redColor">#FF5252</item> | ||
<item name="greenColor">#FF5252</item> | ||
<item name="blueColor">#536DFE</item> | ||
<item name="neutralColor">#FFFFFF</item> | ||
</style> | ||
``` | ||
|
||
The `redColor`, `greenColor`, and `blueColor` attributes affect the RGB sliders, and the `neutralColor` attribute changes the "neutral" colors of the others, including the alpha slider and the handles of the sliders in the HSL picker. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
app/src/main/java/james/colorpickerdialogsample/MainActivity.java
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
app/src/main/java/me/jfenn/colorpickerdialogsample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package me.jfenn.colorpickerdialogsample; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import me.jfenn.colorpickerdialog.dialogs.ColorPickerDialog; | ||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
private int color = Color.BLUE; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
findViewById(R.id.normal).setOnClickListener(this); | ||
findViewById(R.id.normalAlpha).setOnClickListener(this); | ||
findViewById(R.id.dark).setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
new ColorPickerDialog(this, v.getId() == R.id.dark ? R.style.ColorDialog_Dark : 0) | ||
.withColor(color) | ||
.withAlphaEnabled(v.getId() != R.id.normal) | ||
.withListener(new ColorPickerDialog.OnColorPickedListener() { | ||
@Override | ||
public void onColorPicked(ColorPickerDialog dialog, int color) { | ||
MainActivity.this.color = color; | ||
Toast.makeText(MainActivity.this, String.format("#%08X", color), Toast.LENGTH_SHORT).show(); | ||
} | ||
}) | ||
.show(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:gravity="center"> | ||
|
||
<android.support.v7.widget.AppCompatButton | ||
android:text="@string/default_amp_no_image_picker" | ||
<androidx.appcompat.widget.AppCompatButton | ||
android:text="Normal" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/noDefaultAndImage" | ||
android:layout_centerHorizontal="true" | ||
android:id="@+id/defaultAndNoImage" /> | ||
android:id="@+id/normal" /> | ||
|
||
<android.support.v7.widget.AppCompatButton | ||
android:text="@string/no_default_amp_no_image_picker" | ||
<androidx.appcompat.widget.AppCompatButton | ||
android:text="Normal + Alpha" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/defaultAndNoImage" | ||
android:layout_centerHorizontal="true" | ||
android:id="@+id/noDefaultAndNoImage" /> | ||
android:id="@+id/normalAlpha" /> | ||
|
||
<android.support.v7.widget.AppCompatButton | ||
android:text="@string/no_default_amp_image_picker" | ||
<androidx.appcompat.widget.AppCompatButton | ||
android:text="Dark Theme" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/noDefaultAndImage" | ||
android:layout_centerVertical="true" | ||
android:layout_centerHorizontal="true" /> | ||
android:id="@+id/dark" /> | ||
|
||
<android.support.v7.widget.AppCompatButton | ||
android:text="@string/default_amp_image_picker" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/defaultAndImage" | ||
android:layout_above="@+id/noDefaultAndImage" | ||
android:layout_centerHorizontal="true" /> | ||
|
||
</RelativeLayout> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.