@@ -87,10 +87,12 @@ public class ColorPickerView extends FrameLayout implements LifecycleObserver {
87
87
private ActionMode actionMode = ActionMode .ALWAYS ;
88
88
89
89
@ FloatRange (from = 0.0 , to = 1.0 )
90
- private float alpha_selector = 1.0f ;
90
+ private float selector_alpha = 1.0f ;
91
91
92
92
@ 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 ;
94
96
95
97
@ Px private int selectorSize = 0 ;
96
98
@@ -135,16 +137,20 @@ private void getAttrs(AttributeSet attrs) {
135
137
this .selectorDrawable = AppCompatResources .getDrawable (getContext (), resourceId );
136
138
}
137
139
}
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 );
141
143
}
142
144
if (a .hasValue (R .styleable .ColorPickerView_selector_size )) {
143
145
this .selectorSize =
144
146
a .getDimensionPixelSize (R .styleable .ColorPickerView_selector_size , selectorSize );
145
147
}
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 );
148
154
}
149
155
if (a .hasValue (R .styleable .ColorPickerView_actionMode )) {
150
156
int actionMode = a .getInteger (R .styleable .ColorPickerView_actionMode , 0 );
@@ -193,7 +199,7 @@ private void onCreate() {
193
199
}
194
200
selectorParam .gravity = Gravity .CENTER ;
195
201
addView (selector , selectorParam );
196
- selector .setAlpha (alpha_selector );
202
+ selector .setAlpha (selector_alpha );
197
203
198
204
getViewTreeObserver ()
199
205
.addOnGlobalLayoutListener (
@@ -260,8 +266,8 @@ protected void onCreateByBuilder(Builder builder) {
260
266
261
267
this .paletteDrawable = builder .paletteDrawable ;
262
268
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 ;
265
271
this .selectorSize = builder .selectorSize ;
266
272
this .debounceDuration = builder .debounceDuration ;
267
273
onCreate ();
@@ -429,10 +435,10 @@ public void fireColorListener(@ColorInt int color, final boolean fromUser) {
429
435
if (VISIBLE_FLAG ) {
430
436
VISIBLE_FLAG = false ;
431
437
if (this .selector != null ) {
432
- this .selector .setAlpha (alpha_selector );
438
+ this .selector .setAlpha (selector_alpha );
433
439
}
434
440
if (this .flagView != null ) {
435
- this .flagView .setAlpha (alpha_flag );
441
+ this .flagView .setAlpha (flag_alpha );
436
442
}
437
443
}
438
444
}
@@ -460,16 +466,23 @@ private void notifyToFlagView(Point point) {
460
466
if (flagView != null ) {
461
467
if (flagView .getFlagMode () == FlagMode .ALWAYS ) flagView .visible ();
462
468
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 {
464
482
flagView .setRotation (0 );
465
483
flagView .setX (posX );
466
484
flagView .setY (centerPoint .y - flagView .getHeight ());
467
485
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 ());
473
486
}
474
487
if (posX < 0 ) flagView .setX (0 );
475
488
if (posX + flagView .getMeasuredWidth () > getMeasuredWidth ()) {
@@ -541,7 +554,8 @@ public void setFlagView(@NonNull FlagView flagView) {
541
554
flagView .gone ();
542
555
addView (flagView );
543
556
this .flagView = flagView ;
544
- flagView .setAlpha (alpha_flag );
557
+ flagView .setAlpha (flag_alpha );
558
+ flagView .setFlipAble (flag_isFlipAble );
545
559
}
546
560
547
561
/**
@@ -775,11 +789,11 @@ public void setPaletteDrawable(Drawable drawable) {
775
789
if (!VISIBLE_FLAG ) {
776
790
VISIBLE_FLAG = true ;
777
791
if (selector != null ) {
778
- alpha_selector = selector .getAlpha ();
792
+ selector_alpha = selector .getAlpha ();
779
793
selector .setAlpha (0.0f );
780
794
}
781
795
if (flagView != null ) {
782
- alpha_flag = flagView .getAlpha ();
796
+ flag_alpha = flagView .getAlpha ();
783
797
flagView .setAlpha (0.0f );
784
798
}
785
799
}
@@ -959,10 +973,12 @@ public static class Builder {
959
973
@ ColorInt private int initialColor = 0 ;
960
974
961
975
@ FloatRange (from = 0.0 , to = 1.0 )
962
- private float alpha_selector = 1.0f ;
976
+ private float selector_alpha = 1.0f ;
963
977
964
978
@ 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 ;
966
982
967
983
@ Dp private int selectorSize = 0 ;
968
984
@ Dp private int width = LayoutParams .MATCH_PARENT ;
@@ -1015,12 +1031,17 @@ public Builder setActionMode(ActionMode actionMode) {
1015
1031
}
1016
1032
1017
1033
public Builder setSelectorAlpha (@ FloatRange (from = 0.0 , to = 1.0 ) float alpha ) {
1018
- this .alpha_selector = alpha ;
1034
+ this .selector_alpha = alpha ;
1019
1035
return this ;
1020
1036
}
1021
1037
1022
1038
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 ;
1024
1045
return this ;
1025
1046
}
1026
1047
0 commit comments