Skip to content

Commit 80fe3e2

Browse files
authored
Update README.md
1 parent 8449308 commit 80fe3e2

1 file changed

Lines changed: 116 additions & 69 deletions

File tree

README.md

Lines changed: 116 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,32 @@ Add following XML namespace inside your XML layout file.
2828
xmlns:app="http://schemas.android.com/apk/res-auto"
2929
```
3030

31-
### ColorPickerView in layout
31+
32+
### ColorPickerView in XML layout
33+
We can use `ColorPickerView` without any customized attributes.<br>
34+
This `ColorPickerView` will be initialized with the default HSV color palette and default selector.
3235
```gradle
3336
<com.skydoves.colorpickerview.ColorPickerView
34-
android:id="@+id/colorPickerView"
35-
android:layout_width="300dp"
36-
android:layout_height="300dp"
37-
app:palette="@drawable/palette"
38-
app:selector="@drawable/wheel" />
37+
android:id="@+id/colorPickerView"
38+
android:layout_width="300dp"
39+
android:layout_height="300dp" />
3940
```
4041

4142
### Attribute descriptions
43+
We can customize the palette image and selector or various options using the below attributes.
4244
```gradle
43-
app:palette="@drawable/palette" // sets palette image.
44-
app:selector="@drawable/wheel" // sets selector image.
45-
app:alpha_selector="0.8" // sets selector's alpha.
46-
app:alpha_flag="0.8" // sets flag's alpha.
47-
app:actionMode="last" // sets action mode "always" or "last".
48-
app:preferenceName="MyColorPicker" // sets preference name.
45+
app:palette="@drawable/palette" // sets a custom palette image.
46+
app:selector="@drawable/wheel" // sets a custom selector image.
47+
app:selector_size="32dp" // sets a width & height size of the selector.
48+
app:alpha_selector="0.8" // sets an alpha of thr selector.
49+
app:alpha_flag="0.8" // sets an alpha of the flag.
50+
app:actionMode="last" // sets action mode 'always' or 'last'.
51+
app:preferenceName="MyColorPicker" // sets a preference name.
52+
app:debounceDuration="200" // sets a debounce duration of the invoking color listener.
4953
```
5054

5155
### ColorListener
52-
ColorListener is invoked whenever tapped by a user or selecting position manually.
56+
`ColorListener` is invoked when tapped by a user or selected a position by a function.
5357
```java
5458
colorPickerView.setColorListener(new ColorListener() {
5559
@Override
@@ -60,8 +64,17 @@ colorPickerView.setColorListener(new ColorListener() {
6064
});
6165
```
6266

67+
### ColorEnvelope
68+
`ColorEnvelope` is a wrapper class of color models for providing more variety of color models.<br>
69+
We can get HSV color value, Hex string code, ARGB value from the `ColorEnvelope`.
70+
```java
71+
colorEnvelope.getColor() // returns a integer color.
72+
colorEnvelope.getHexCode() // returns a hex code string.
73+
colorEnvelope.getArgb() // returns a argb integer array.
74+
```
75+
6376
### ColorEnvelope Listener
64-
ColorEnvelopeListener provides hsv color, hex code, argb by `ColorEnvelope`.
77+
`ColorEnvelopeListener` extends `ColorListener` and it provides `ColorEnvelope` as a parameter.
6578
```java
6679
colorPickerView.setColorListener(new ColorEnvelopeListener() {
6780
@Override
@@ -72,18 +85,38 @@ colorPickerView.setColorListener(new ColorEnvelopeListener() {
7285
});
7386
```
7487

75-
### ColorEnvelope
76-
ColorEnvelope is a wrapper class of colors for provide various forms of color.
88+
### Palette
89+
If we do not set any customized palette, the default palette drawable is the `ColorHsvPalette`.<br>
90+
We can move and select a point on the palette using a specific color using the below methods.
7791
```java
78-
colorEnvelope.getColor() // returns a integer color.
79-
colorEnvelope.getHexCode() // returns a hex code string.
80-
colorEnvelope.getArgb() // returns a argb integer array.
92+
colorPickerView.selectByHsvColor(color);
93+
colorPickerView.selectByHsvColorRes(R.color.colorPrimary);
94+
```
95+
We can change the default palette as a desired image drawable using the below method.<br>
96+
But if we change the palette using another drawable, we can not use the `selectByHsvColor` method.
97+
```java
98+
colorPickerView.setPaletteDrawable(drawable);
99+
```
100+
If we want to change back to the default palette, we can change it using the below method.
101+
```java
102+
colorPickerView.setHsvPaletteDrawable();
81103
```
82104

83105
### ActionMode
84-
ActionMode controls an action about `ColorListener` invoking.
106+
`ActionMode` is an option restrict to invoke the `ColorListener` by user actions.
107+
```java
108+
colorPickerView.setActionMode(ActionMode.LAST); // ColorListener will be invoked when the finger is released.
109+
```
110+
111+
### Debounce
112+
Only emits color values to the listener if a particular timespan has passed without it emitting using `debounceDuration` attribute.
113+
We can set the `debounceDuration` on our xml layout file.
114+
```xml
115+
app:debounceDuration="150"
116+
```
117+
Or we can set it programmatically.
85118
```java
86-
colorPickerView.setActionMode(ActionMode.LAST); // the listener will be invoked only when finger released.
119+
colorPickerView.setDebounceDuration(150);
87120
```
88121

89122
### Create using builder
@@ -102,49 +135,49 @@ ColorPickerView colorPickerView = new ColorPickerView.Builder(context)
102135
```
103136

104137
### Restore and save
105-
This is how to restore the status for `ColorPickerView`.<br>
106-
Using `setPreferenceName()` method restores all of the saved statuses automatically.
138+
This is how to restore the state of `ColorPickerView`.<br>
139+
`setPreferenceName()` method restores all of the saved states (selector, color) automatically.
107140

108141
```java
109142
colorPickerView.setPreferenceName("MyColorPicker");
110143
```
111144

112-
This is how to save the status for `ColorPickerView`.<br>
113-
Using `setLifecycleOwner()` method saves all of the statuses when the lifecycleOwner's destroy automatically.
145+
This is how to save the states of `ColorPickerView`.<br>
146+
`setLifecycleOwner()` method saves all of the states automatically when the lifecycleOwner is destroy.
114147
```java
115-
colorPickerView.setLifecycleOwner(this); // this means activity or fragment.
148+
colorPickerView.setLifecycleOwner(this);
116149
```
117-
Or we can save the status manually regardless lifecycle using below method.
150+
Or we can save the states manually using the below method.
118151
```java
119152
ColorPickerPreferenceManager.getInstance(this).saveColorPickerData(colorPickerView);
120153
```
121154

122155
### Manipulate and clear
123-
We can manipulate and clear the saved statuses using `ColorPickerPreferenceManager`.
156+
We can manipulate and clear the saved states using `ColorPickerPreferenceManager`.
124157
```java
125158
ColorPickerPreferenceManager manager = ColorPickerPreferenceManager.getInstance(this);
126159
manager.setColor("MyColorPicker", Color.RED); // manipulates the saved color data.
127160
manager.setSelectorPosition("MyColorPicker", new Point(120, 120)); // manipulates the saved selector's position data.
128-
manager.clearSavedAllData(); // clears all of the statuses.
161+
manager.clearSavedAllData(); // clears all of the states.
129162
manager.clearSavedColor("MyColorPicker"); // clears only saved color data.
130-
manager.restoreColorPickerData(colorPickerView); // restores the saved statuses manually.
163+
manager.restoreColorPickerData(colorPickerView); // restores the saved states manually.
131164
```
132165

133-
### Pallette from Gallery
134-
Here is how to get bitmap drawable from the desired gallery image and set to the palette.<br><br>
166+
### Palette from Gallery
167+
Here is how to get a bitmap drawable from the gallery image and set it to the palette.<br><br>
135168
<img src="https://user-images.githubusercontent.com/24237865/52941911-313dc000-33ad-11e9-8264-6d78f4ad613a.jpg" align="left" width="35%">
136169

137-
Firstly, declare below permission on your `AndroidManifest.xml` file.
170+
Declare below permission on your `AndroidManifest.xml` file.
138171
```gradle
139172
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
140173
```
141-
startActivityForResult for getting an image from the Gallery.
174+
The below codes will start the Gallery and we can choose the desired image.
142175
```java
143176
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
144177
photoPickerIntent.setType("image/*");
145178
startActivityForResult(photoPickerIntent, REQUEST_CODE_GALLERY);
146179
```
147-
On the onActivityResult, we can get a bitmap drawable from the gallery and set it as the palette.
180+
In the `onActivityResult`, we can get a bitmap drawable from the gallery and set it as the palette. And We can change the palette image of the `ColorPickerView` using the `setPaletteDrawable` method.
148181
```java
149182
try {
150183
final Uri imageUri = data.getData();
@@ -176,63 +209,63 @@ ColorPickerPreference is used in PreferenceScreen and shows ColorPickerDialog if
176209

177210
#### customizing
178211
If you want to customizing ColorPickerDialog in ColorPickerPreference, you could get ColorPickerDialog.Builder
179-
using getColorPickerDialogBuilder() method.
212+
using `getColorPickerDialogBuilder()` method.
180213
```java
181214
ColorPickerPreference colorPickerPreference_toolbar = (ColorPickerPreference) findPreference(getActivity().getString(R.string.ToolbarColorPickerPreference));
182215
ColorPickerDialog.Builder builder_toolbar = colorPickerPreference_toolbar.getColorPickerDialogBuilder();
183216
builder_toolbar.setFlagView(new CustomFlag(getActivity(), R.layout.layout_flag));
184217
```
185218

186-
## AlphaSlideBar(Optional)
219+
## AlphaSlideBar
187220
AlphaSlideBar changes the transparency of the selected color. <br><br>
188-
<img src="https://user-images.githubusercontent.com/24237865/52943592-d1e1af00-33b0-11e9-9e3c-9a1190ae969e.gif" align="left" width="31%">
221+
<img src="https://user-images.githubusercontent.com/24237865/90913596-6ea66200-e417-11ea-893a-467e93189c2b.gif" align="left" width="31%">
189222

190-
`AlphaSlideBar` on xml layout
223+
`AlphaSlideBar` in XML layout
191224
```gradle
192225
<com.skydoves.colorpickerview.sliders.AlphaSlideBar
193226
android:id="@+id/alphaSlideBar"
194227
android:layout_width="match_parent"
195228
android:layout_height="wrap_content"
196-
app:selector_AlphaSlideBar="@drawable/wheel" // sets the selector drawable.
197-
app:borderColor_AlphaSlideBar="@android:color/darker_gray" // sets the border color.
198-
app:borderSize_AlphaSlideBar="5"/> // sets the border size.
229+
app:selector_AlphaSlideBar="@drawable/wheel" // sets a customized selector drawable.
230+
app:borderColor_AlphaSlideBar="@android:color/darker_gray" // sets a color of the border.
231+
app:borderSize_AlphaSlideBar="5"/> // sets a size of the border.
199232
```
200-
`attachAlphaSlider` method connects slider to the `ColorPickerView`.
233+
We can attach and connect the `AlphaSlideBar` to our `ColorPickerView` using `attachAlphaSlider` method.
201234

202235
```java
203236
AlphaSlideBar alphaSlideBar = findViewById(R.id.alphaSlideBar);
204237
colorPickerView.attachAlphaSlider(alphaSlideBar);
205238
```
206-
If you want to implement vertically, use below attributes.
239+
We can make it vertically using the below attributes.
207240
```gradle
208-
android:layout_width="280dp" // width should be set manually
241+
android:layout_width="280dp" // width must set a specific width size.
209242
android:layout_height="wrap_content"
210243
android:rotation="90"
211244
```
212245

213-
## BrightnessSlideBar(Optional)
246+
## BrightnessSlideBar
214247
BrightnessSlideBar changes the brightness of the selected color. <br><br>
215-
<img src="https://user-images.githubusercontent.com/24237865/52943593-d1e1af00-33b0-11e9-813a-557760e172ed.gif" align="left" width="31%">
248+
<img src="https://user-images.githubusercontent.com/24237865/90913583-6c440800-e417-11ea-8645-c5f6d1bf97df.gif" align="left" width="31%">
216249

217-
`BrightnessSlideBar` on xml layout
250+
`BrightnessSlideBar` in XML layout
218251
```gradle
219252
<com.skydoves.colorpickerview.sliders.BrightnessSlideBar
220253
android:id="@+id/brightnessSlide"
221254
android:layout_width="match_parent"
222255
android:layout_height="wrap_content"
223-
app:selector_BrightnessSlider="@drawable/wheel" // sets the selector drawable.
224-
app:borderColor_BrightnessSlider="@android:color/darker_gray" // sets the border color.
225-
app:borderSize_BrightnessSlider="5"/> // sets the border size.
256+
app:selector_BrightnessSlider="@drawable/wheel" // sets a customized selector drawable.
257+
app:borderColor_BrightnessSlider="@android:color/darker_gray" // sets a color of the border.
258+
app:borderSize_BrightnessSlider="5"/> // sets a size of the border.
226259
```
227-
`attachBrightnessSlider` method connects slider to the `ColorPickerView`.
260+
We can attach and connect the `BrightnessSlideBar` to our `ColorPickerView` using `attachBrightnessSlider` method.
228261

229262
```java
230263
BrightnessSlideBar brightnessSlideBar = findViewById(R.id.brightnessSlide);
231264
colorPickerView.attachBrightnessSlider(brightnessSlideBar);
232265
```
233-
If you want to implement vertically, use below attributes.
266+
We can make it vertically using the below attributes.
234267
```gradle
235-
android:layout_width="280dp" // width should be set manually
268+
android:layout_width="280dp" // width must set a specific width size.
236269
android:layout_height="wrap_content"
237270
android:rotation="90"
238271
```
@@ -241,11 +274,10 @@ android:rotation="90"
241274
![dialog0](https://user-images.githubusercontent.com/24237865/45362890-0d619b80-b611-11e8-857b-e12f82978b53.jpg)
242275
![dialog1](https://user-images.githubusercontent.com/24237865/45362892-0d619b80-b611-11e8-9cc5-25518a9d392a.jpg) <br>
243276

244-
ColorPickerDialog can be used just like using AlertDialog and provides colors from any drawables. <br>
245-
ColorPickerDialog extends `AlertDialog`. So we can customize themes also. <br>
277+
`ColorPickerDialog` can be used just like an AlertDialog and it provides colors by tapping from any drawable. <br>
246278

247279
```java
248-
new ColorPickerDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_DARK)
280+
new ColorPickerDialog.Builder(this)
249281
.setTitle("ColorPicker Dialog")
250282
.setPreferenceName("MyColorPickerDialog")
251283
.setPositiveButton(getString(R.string.confirm),
@@ -255,31 +287,42 @@ new ColorPickerDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_DARK)
255287
setLayoutColor(envelope);
256288
}
257289
})
258-
setNegativeButton(getString(R.string.cancel),
290+
.setNegativeButton(getString(R.string.cancel),
259291
new DialogInterface.OnClickListener() {
260292
@Override
261293
public void onClick(DialogInterface dialogInterface, int i) {
262294
dialogInterface.dismiss();
263295
}
264296
})
265-
.attachAlphaSlideBar(true) // default is true. If false, do not show the AlphaSlideBar.
266-
.attachBrightnessSlideBar(true) // default is true. If false, do not show the BrightnessSlideBar.
297+
.attachAlphaSlideBar(true) // the default value is true.
298+
.attachBrightnessSlideBar(true) // the default value is true.
299+
.setBottomSpace(12) // set a bottom space between the last slidebar and buttons.
267300
.show();
268301
```
269302

270-
If you need to customize the `ColorpickerView` on the dialog, you can get the instance of `ColorPickerView` from the `ColorpickerView.Builder`. but it should be done before shows dialog using `show()` method.
303+
we can get an instance of `ColorPickerView` from the `ColorPickerView.Builder` and we can customize it. <br>
271304
```java
272305
ColorPickerView colorPickerView = builder.getColorPickerView();
273306
colorPickerView.setFlagView(new CustomFlag(this, R.layout.layout_flag)); // sets a custom flagView
274307
builder.show(); // shows the dialog
275308
```
276309

277-
## FlagView(Optional)
310+
## FlagView
311+
We can implement showing a `FlagView` above and below on the selector.<br>
312+
This library provides `BubbleFlagView` by default as we can see the [previews](https://github.com/skydoves/ColorPickerView#colorpickerview).<br>
313+
Here is the example code for implementing it.
314+
315+
```java
316+
BubbleFlag bubbleFlag = new BubbleFlag(this);
317+
bubbleFlag.setFlagMode(FlagMode.FADE);
318+
colorPickerView.setFlagView(bubbleFlag);
319+
```
320+
321+
We can also fully customize the `FlagView` like below.<br>
278322
![flag0](https://user-images.githubusercontent.com/24237865/45364191-75fe4780-b614-11e8-81a5-04690a4392db.jpg)
279323
![flag1](https://user-images.githubusercontent.com/24237865/45364194-75fe4780-b614-11e8-844c-136d14c91560.jpg) <br>
280324

281-
FlgaView implements showing a flag above a selector. This is optional.<br><br>
282-
First, create a layout for `FlagView` as your taste like below.
325+
First, We need a customized layout like below.
283326
```gradle
284327
<?xml version="1.0" encoding="utf-8"?>
285328
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
@@ -313,7 +356,7 @@ First, create a layout for `FlagView` as your taste like below.
313356
</LinearLayout>
314357
```
315358

316-
Second, create a custom class extending `FlagView`. This is an example code.
359+
Second, we need to create a class that extends `FlagView`. Here is an example code.
317360
```java
318361
public class CustomFlag extends FlagView {
319362

@@ -334,22 +377,23 @@ public class CustomFlag extends FlagView {
334377
}
335378
```
336379

337-
The last, set `FlagView` on the `ColorPickerView` using `setFlagView` method.
380+
And last, set the `FlagView` to the `ColorPickerView` using the `setFlagView` method.
338381

339382
```java
340383
colorPickerView.setFlagView(new CustomFlag(this, R.layout.layout_flag));
341384
```
342385

343386
### FlagMode
344-
FlagMode decides the `FlagView`'s visibility action.
387+
`FlagMode` is an option to decides the visibility action of the `FlagView`.
345388
```java
346389
colorPickerView.setFlagMode(FlagMode.ALWAYS); // showing always by tapping and dragging.
347390
colorPickerView.setFlagMode(FlagMode.LAST); // showing only when finger released.
348391
```
349392

350393
## AlphaTileView
351394
![alphatileview](https://user-images.githubusercontent.com/24237865/45364416-09377d00-b615-11e8-9707-b83f55053480.jpg) <br>
352-
AlphaTileView visualizes ARGB color on the view. If you want to visualizes ARGB color on the general view, it will not be shown accurately. because it will be mixed with the parent view's background color. so if you want to visualize ARGB color accurately, should use `AlphaTileView`.<br>
395+
`AlphaTileView` visualizes ARGB colors over the view.<br>
396+
If we need to represent ARGB colors on the general view, it will not be showing accurately. Because a color will be mixed with the parent view's background color. so if we need to represent ARGB colors accurately, we can use the `AlphaTileView`.
353397

354398
```gradle
355399
<com.skydoves.colorpickerview.AlphaTileView
@@ -369,9 +413,12 @@ getColorEnvelope() | ColorEnvelope | gets the `ColorEnvelope` of the last select
369413
setPaletteDrawable(Drawable drawable) | void | changes palette drawable manually.
370414
setSelectorDrawable(Drawable drawable) | void | changes selector drawable manually.
371415
setSelectorPoint(int x, int y) | void | selects the specific coordinate of the palette manually.
416+
selectByHsvColor(@ColorInt int color) | void | changes selector's selected point by a specific color.
417+
selectByHsvColorRes(@ColorRes int resource) | void | changes selector's selected point by a specific color using a color resource.
418+
setHsvPaletteDrawable() | void | changes the palette drawable as the default drawable (ColorHsvPalette).
372419
selectCenter() | void | selects the center of the palette manually.
373420
setActionMode(ActionMode) | void | sets the color listener's trigger action mode.
374-
setFlagView(FlagView flagview) | void | sets `FlagView` on `ColorPickerView`.
421+
setFlagView(FlagView flagView) | void | sets `FlagView` on `ColorPickerView`.
375422
attachAlphaSlider | void | linking an `AlphaSlideBar` on the `ColorPickerView`.
376423
attachBrightnessSlider | void | linking an `BrightnessSlideBar` on the `ColorPickerView`.
377424

0 commit comments

Comments
 (0)