Skip to content

Commit

Permalink
Merge pull request #6 from fennifith/develop
Browse files Browse the repository at this point in the history
Version 0.1.0
  • Loading branch information
fennifith authored Nov 8, 2018
2 parents a91d4d2 + 2a46512 commit be66e9f
Show file tree
Hide file tree
Showing 52 changed files with 2,024 additions and 908 deletions.
Binary file added .github/images/darktheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed .github/images/dialog.png
Binary file not shown.
Binary file added .github/images/noalpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/picker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 49 additions & 39 deletions README.md
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.
22 changes: 9 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "james.colorpickerdialogsample"
applicationId "me.jfenn.colorpickerdialogsample"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 28
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -20,11 +20,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile project(path: ':colorpickerdialog')
testCompile 'junit:junit:4.12'
}
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation project(path: ':colorpickerdialog')
}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="james.colorpickerdialogsample">
package="me.jfenn.colorpickerdialogsample">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name="me.jfenn.colorpickerdialogsample.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
59 changes: 0 additions & 59 deletions app/src/main/java/james/colorpickerdialogsample/MainActivity.java

This file was deleted.

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();
}
}
40 changes: 14 additions & 26 deletions app/src/main/res/layout/activity_main.xml
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>
6 changes: 6 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
<item name="colorButtonNormal">@color/colorAccent</item>
</style>

<style name="ColorDialog.Dark" parent="Theme.AppCompat.Dialog">
<item name="redColor">#FF5252</item>
<item name="greenColor">#69F0AE</item>
<item name="blueColor">#536DFE</item>
</style>

</resources>
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.2.1'
}
}

allprojects {
repositories {
google()
jcenter()
}
}
Expand Down
Loading

0 comments on commit be66e9f

Please sign in to comment.