@@ -104,6 +104,7 @@ public class ColorPickerView extends FrameLayout implements LifecycleObserver {
104104 private boolean VISIBLE_FLAG = false ;
105105
106106 private String preferenceName ;
107+ private boolean selectorPointValidation = true ;
107108 private final ColorPickerPreferenceManager preferenceManager =
108109 ColorPickerPreferenceManager .getInstance (getContext ());
109110
@@ -173,6 +174,10 @@ private void getAttrs(AttributeSet attrs) {
173174 if (a .hasValue (R .styleable .ColorPickerView_initialColor )) {
174175 setInitialColor (a .getColor (R .styleable .ColorPickerView_initialColor , Color .WHITE ));
175176 }
177+ if (a .hasValue (R .styleable .ColorPickerView_selectorPointValidation )) {
178+ this .selectorPointValidation =
179+ a .getBoolean (R .styleable .ColorPickerView_selectorPointValidation , selectorPointValidation );
180+ }
176181 } finally {
177182 a .recycle ();
178183 }
@@ -278,6 +283,7 @@ protected void onCreateByBuilder(Builder builder) {
278283 if (builder .preferenceName != null ) setPreferenceName (builder .preferenceName );
279284 if (builder .initialColor != 0 ) setInitialColor (builder .initialColor );
280285 if (builder .lifecycleOwner != null ) setLifecycleOwner (builder .lifecycleOwner );
286+ this .selectorPointValidation = builder .selectorPointValidation ;
281287 }
282288
283289 @ SuppressLint ("ClickableViewAccessibility" )
@@ -929,6 +935,33 @@ public void setPreferenceName(@Nullable String preferenceName) {
929935 }
930936 }
931937
938+ /**
939+ * Returns whether selector point validation (approximation) is enabled.
940+ *
941+ * <p>When enabled, the selector point is approximated to find the nearest valid color,
942+ * which handles edge cases where users touch outside the image matrix.
943+ * When disabled, exact coordinates are used without approximation.
944+ *
945+ * @return true if selector point validation is enabled, false otherwise.
946+ */
947+ public boolean isSelectorPointValidationEnabled () {
948+ return selectorPointValidation ;
949+ }
950+
951+ /**
952+ * Sets whether selector point validation (approximation) is enabled.
953+ *
954+ * <p>When enabled (default), the selector point is approximated to find the nearest valid color,
955+ * which handles edge cases where users touch outside the image matrix.
956+ * When disabled, exact coordinates are used without approximation, which is useful
957+ * when precise point restoration is needed (e.g., saving and restoring selector positions).
958+ *
959+ * @param enabled true to enable validation, false to disable.
960+ */
961+ public void setSelectorPointValidation (boolean enabled ) {
962+ this .selectorPointValidation = enabled ;
963+ }
964+
932965 /**
933966 * sets the {@link LifecycleOwner}.
934967 *
@@ -990,6 +1023,7 @@ public static class Builder {
9901023 private int height = LayoutParams .MATCH_PARENT ;
9911024 private String preferenceName ;
9921025 private LifecycleOwner lifecycleOwner ;
1026+ private boolean selectorPointValidation = true ;
9931027
9941028 public Builder (Context context ) {
9951029 this .context = context ;
@@ -1085,6 +1119,11 @@ public Builder setLifecycleOwner(LifecycleOwner lifecycleOwner) {
10851119 return this ;
10861120 }
10871121
1122+ public Builder setSelectorPointValidation (boolean enabled ) {
1123+ this .selectorPointValidation = enabled ;
1124+ return this ;
1125+ }
1126+
10881127 public ColorPickerView build () {
10891128 ColorPickerView colorPickerView = new ColorPickerView (context );
10901129 colorPickerView .onCreateByBuilder (this );
0 commit comments