Skip to content

Commit 1e1494a

Browse files
authored
Merge pull request #72 from skydoves/update/notifyToFlagView
Update : notify to flag view
2 parents e123025 + 00c3894 commit 1e1494a

File tree

4 files changed

+57
-37
lines changed

4 files changed

+57
-37
lines changed

colorpickerview/src/main/java/com/skydoves/colorpickerview/ColorPickerView.java

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ public class ColorPickerView extends FrameLayout implements LifecycleObserver {
8787
private ActionMode actionMode = ActionMode.ALWAYS;
8888

8989
@FloatRange(from = 0.0, to = 1.0)
90-
private float alpha_selector = 1.0f;
90+
private float selector_alpha = 1.0f;
9191

9292
@FloatRange(from = 0.0, to = 1.0)
93-
private float alpha_flag = 1.0f;
93+
private float flag_alpha = 1.0f;
94+
95+
private boolean flag_isFlipAble = true;
9496

9597
@Px private int selectorSize = 0;
9698

@@ -135,16 +137,20 @@ private void getAttrs(AttributeSet attrs) {
135137
this.selectorDrawable = AppCompatResources.getDrawable(getContext(), resourceId);
136138
}
137139
}
138-
if (a.hasValue(R.styleable.ColorPickerView_alpha_selector)) {
139-
this.alpha_selector =
140-
a.getFloat(R.styleable.ColorPickerView_alpha_selector, alpha_selector);
140+
if (a.hasValue(R.styleable.ColorPickerView_selector_alpha)) {
141+
this.selector_alpha =
142+
a.getFloat(R.styleable.ColorPickerView_selector_alpha, selector_alpha);
141143
}
142144
if (a.hasValue(R.styleable.ColorPickerView_selector_size)) {
143145
this.selectorSize =
144146
a.getDimensionPixelSize(R.styleable.ColorPickerView_selector_size, selectorSize);
145147
}
146-
if (a.hasValue(R.styleable.ColorPickerView_alpha_flag)) {
147-
this.alpha_flag = a.getFloat(R.styleable.ColorPickerView_alpha_flag, alpha_flag);
148+
if (a.hasValue(R.styleable.ColorPickerView_flag_alpha)) {
149+
this.flag_alpha = a.getFloat(R.styleable.ColorPickerView_flag_alpha, flag_alpha);
150+
}
151+
if (a.hasValue(R.styleable.ColorPickerView_flag_isFlipAble)) {
152+
this.flag_isFlipAble =
153+
a.getBoolean(R.styleable.ColorPickerView_flag_isFlipAble, flag_isFlipAble);
148154
}
149155
if (a.hasValue(R.styleable.ColorPickerView_actionMode)) {
150156
int actionMode = a.getInteger(R.styleable.ColorPickerView_actionMode, 0);
@@ -193,7 +199,7 @@ private void onCreate() {
193199
}
194200
selectorParam.gravity = Gravity.CENTER;
195201
addView(selector, selectorParam);
196-
selector.setAlpha(alpha_selector);
202+
selector.setAlpha(selector_alpha);
197203

198204
getViewTreeObserver()
199205
.addOnGlobalLayoutListener(
@@ -260,8 +266,8 @@ protected void onCreateByBuilder(Builder builder) {
260266

261267
this.paletteDrawable = builder.paletteDrawable;
262268
this.selectorDrawable = builder.selectorDrawable;
263-
this.alpha_selector = builder.alpha_selector;
264-
this.alpha_flag = builder.alpha_flag;
269+
this.selector_alpha = builder.selector_alpha;
270+
this.flag_alpha = builder.flag_alpha;
265271
this.selectorSize = builder.selectorSize;
266272
this.debounceDuration = builder.debounceDuration;
267273
onCreate();
@@ -429,10 +435,10 @@ public void fireColorListener(@ColorInt int color, final boolean fromUser) {
429435
if (VISIBLE_FLAG) {
430436
VISIBLE_FLAG = false;
431437
if (this.selector != null) {
432-
this.selector.setAlpha(alpha_selector);
438+
this.selector.setAlpha(selector_alpha);
433439
}
434440
if (this.flagView != null) {
435-
this.flagView.setAlpha(alpha_flag);
441+
this.flagView.setAlpha(flag_alpha);
436442
}
437443
}
438444
}
@@ -460,16 +466,23 @@ private void notifyToFlagView(Point point) {
460466
if (flagView != null) {
461467
if (flagView.getFlagMode() == FlagMode.ALWAYS) flagView.visible();
462468
int posX = centerPoint.x - flagView.getWidth() / 2 + selector.getWidth() / 2;
463-
if (centerPoint.y - flagView.getHeight() > 0) {
469+
if (flagView.isFlipAble()) {
470+
if (centerPoint.y - flagView.getHeight() > 0) {
471+
flagView.setRotation(0);
472+
flagView.setX(posX);
473+
flagView.setY(centerPoint.y - flagView.getHeight());
474+
flagView.onRefresh(getColorEnvelope());
475+
} else {
476+
flagView.setRotation(180);
477+
flagView.setX(posX);
478+
flagView.setY(centerPoint.y + flagView.getHeight() - selector.getHeight() * 0.5f);
479+
flagView.onRefresh(getColorEnvelope());
480+
}
481+
} else {
464482
flagView.setRotation(0);
465483
flagView.setX(posX);
466484
flagView.setY(centerPoint.y - flagView.getHeight());
467485
flagView.onRefresh(getColorEnvelope());
468-
} else if (flagView.isFlipAble()) {
469-
flagView.setRotation(180);
470-
flagView.setX(posX);
471-
flagView.setY(centerPoint.y + flagView.getHeight() - selector.getHeight() * 0.5f);
472-
flagView.onRefresh(getColorEnvelope());
473486
}
474487
if (posX < 0) flagView.setX(0);
475488
if (posX + flagView.getMeasuredWidth() > getMeasuredWidth()) {
@@ -541,7 +554,8 @@ public void setFlagView(@NonNull FlagView flagView) {
541554
flagView.gone();
542555
addView(flagView);
543556
this.flagView = flagView;
544-
flagView.setAlpha(alpha_flag);
557+
flagView.setAlpha(flag_alpha);
558+
flagView.setFlipAble(flag_isFlipAble);
545559
}
546560

547561
/**
@@ -775,11 +789,11 @@ public void setPaletteDrawable(Drawable drawable) {
775789
if (!VISIBLE_FLAG) {
776790
VISIBLE_FLAG = true;
777791
if (selector != null) {
778-
alpha_selector = selector.getAlpha();
792+
selector_alpha = selector.getAlpha();
779793
selector.setAlpha(0.0f);
780794
}
781795
if (flagView != null) {
782-
alpha_flag = flagView.getAlpha();
796+
flag_alpha = flagView.getAlpha();
783797
flagView.setAlpha(0.0f);
784798
}
785799
}
@@ -959,10 +973,12 @@ public static class Builder {
959973
@ColorInt private int initialColor = 0;
960974

961975
@FloatRange(from = 0.0, to = 1.0)
962-
private float alpha_selector = 1.0f;
976+
private float selector_alpha = 1.0f;
963977

964978
@FloatRange(from = 0.0, to = 1.0)
965-
private float alpha_flag = 1.0f;
979+
private float flag_alpha = 1.0f;
980+
981+
private boolean flag_isFlipAble = false;
966982

967983
@Dp private int selectorSize = 0;
968984
@Dp private int width = LayoutParams.MATCH_PARENT;
@@ -1015,12 +1031,17 @@ public Builder setActionMode(ActionMode actionMode) {
10151031
}
10161032

10171033
public Builder setSelectorAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) {
1018-
this.alpha_selector = alpha;
1034+
this.selector_alpha = alpha;
10191035
return this;
10201036
}
10211037

10221038
public Builder setFlagAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) {
1023-
this.alpha_flag = alpha;
1039+
this.flag_alpha = alpha;
1040+
return this;
1041+
}
1042+
1043+
public Builder setFlagIsFlipAble(boolean isFlipAble) {
1044+
this.flag_isFlipAble = isFlipAble;
10241045
return this;
10251046
}
10261047

colorpickerview/src/main/res/values/attrs_colorpicker.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
<!-- sets a width/height square size of the selector. -->
99
<attr name="selector_size" format="dimension" />
1010
<!-- sets an alpha of thr selector. -->
11-
<attr name="alpha_selector" format="float" />
11+
<attr name="selector_alpha" format="float" />
1212
<!-- sets an alpha of the flag. -->
13-
<attr name="alpha_flag" format="float" />
13+
<attr name="flag_alpha" format="float" />
14+
<!-- sets a is flip-able or not of the flag. -->
15+
<attr name="flag_isFlipAble" format="boolean" />
1416
<!-- sets a preference name for persisting and restoring status of the selector and slideBars. -->
1517
<attr name="preferenceName" format="string" />
1618
<!-- sets a debounce duration of the invoking color listener. -->

dependencies.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
ext.versions = [
1616
minSdk : 15,
1717
compileSdk : 30,
18-
versionoCode : 27,
19-
versionName : '2.2.3',
18+
versionoCode : 28,
19+
versionName : '2.2.4',
2020

21-
gradleBuildTool : '4.1.1',
22-
spotlessGradle : '5.9.0',
21+
gradleBuildTool : '4.1.3',
22+
spotlessGradle : '5.12.4',
2323
ktlintGradle : '0.40.0',
24-
dokkaGradle : '1.4.20',
25-
mavenPublish : '0.13.0',
24+
dokkaGradle : '1.4.32',
25+
mavenPublish : '0.15.1',
2626

27-
kotlin : '1.4.20',
27+
kotlin : '1.4.32',
2828
androidxAppcompat: '1.2.0',
2929

3030
// for demo

gradle.properties

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,3 @@ POM_LICENCE_DIST=repo
4949
POM_DEVELOPER_ID=skydoves
5050
POM_DEVELOPER_NAME=Jaewoong Eum
5151
POM_DEVELOPER_URL=https://github.com/skydoves/
52-
53-
RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2/
54-
SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots/

0 commit comments

Comments
 (0)