Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .github/workflows/publish-snapshot.yml

This file was deleted.

14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,7 @@ Add the dependency below to your module's `build.gradle` file:

```gradle
dependencies {
implementation "com.github.skydoves:colorpickerview:2.3.0"
}
```

## SNAPSHOT
[![ColorPickerView](https://img.shields.io/static/v1?label=snapshot&message=ColorPickerView&logo=apache%20maven&color=C71A36)](https://oss.sonatype.org/content/repositories/snapshots/com/github/skydoves/colorpickerview/) <br>
Snapshots of the current development version of ColorPickerView are available, which track [the latest versions](https://oss.sonatype.org/content/repositories/snapshots/com/github/skydoves/colorpickerview/).

```Gradle
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
implementation("com.github.skydoves:colorpickerview:2.3.0")
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class ColorPickerView extends FrameLayout implements LifecycleObserver {
private boolean VISIBLE_FLAG = false;

private String preferenceName;
private boolean selectorPointValidation = true;
private final ColorPickerPreferenceManager preferenceManager =
ColorPickerPreferenceManager.getInstance(getContext());

Expand Down Expand Up @@ -173,6 +174,10 @@ private void getAttrs(AttributeSet attrs) {
if (a.hasValue(R.styleable.ColorPickerView_initialColor)) {
setInitialColor(a.getColor(R.styleable.ColorPickerView_initialColor, Color.WHITE));
}
if (a.hasValue(R.styleable.ColorPickerView_selectorPointValidation)) {
this.selectorPointValidation =
a.getBoolean(R.styleable.ColorPickerView_selectorPointValidation, selectorPointValidation);
}
} finally {
a.recycle();
}
Expand Down Expand Up @@ -278,6 +283,7 @@ protected void onCreateByBuilder(Builder builder) {
if (builder.preferenceName != null) setPreferenceName(builder.preferenceName);
if (builder.initialColor != 0) setInitialColor(builder.initialColor);
if (builder.lifecycleOwner != null) setLifecycleOwner(builder.lifecycleOwner);
this.selectorPointValidation = builder.selectorPointValidation;
}

@SuppressLint("ClickableViewAccessibility")
Expand Down Expand Up @@ -929,6 +935,33 @@ public void setPreferenceName(@Nullable String preferenceName) {
}
}

/**
* Returns whether selector point validation (approximation) is enabled.
*
* <p>When enabled, the selector point is approximated to find the nearest valid color,
* which handles edge cases where users touch outside the image matrix.
* When disabled, exact coordinates are used without approximation.
*
* @return true if selector point validation is enabled, false otherwise.
*/
public boolean isSelectorPointValidationEnabled() {
return selectorPointValidation;
}

/**
* Sets whether selector point validation (approximation) is enabled.
*
* <p>When enabled (default), the selector point is approximated to find the nearest valid color,
* which handles edge cases where users touch outside the image matrix.
* When disabled, exact coordinates are used without approximation, which is useful
* when precise point restoration is needed (e.g., saving and restoring selector positions).
*
* @param enabled true to enable validation, false to disable.
*/
public void setSelectorPointValidation(boolean enabled) {
this.selectorPointValidation = enabled;
}

/**
* sets the {@link LifecycleOwner}.
*
Expand Down Expand Up @@ -990,6 +1023,7 @@ public static class Builder {
private int height = LayoutParams.MATCH_PARENT;
private String preferenceName;
private LifecycleOwner lifecycleOwner;
private boolean selectorPointValidation = true;

public Builder(Context context) {
this.context = context;
Expand Down Expand Up @@ -1085,6 +1119,11 @@ public Builder setLifecycleOwner(LifecycleOwner lifecycleOwner) {
return this;
}

public Builder setSelectorPointValidation(boolean enabled) {
this.selectorPointValidation = enabled;
return this;
}

public ColorPickerView build() {
ColorPickerView colorPickerView = new ColorPickerView(context);
colorPickerView.onCreateByBuilder(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected static Point getColorPoint(ColorPickerView colorPickerView, Point poin
Point center =
new Point(colorPickerView.getWidth() / 2, colorPickerView.getMeasuredHeight() / 2);
if (colorPickerView.isHuePalette()) return getHuePoint(colorPickerView, point);
if (!colorPickerView.isSelectorPointValidationEnabled()) return point;
return approximatedPoint(colorPickerView, point, center);
}

Expand Down
4 changes: 3 additions & 1 deletion colorpickerview/src/main/res/values/attrs_colorpicker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<attr name="selector" format="integer" />
<!-- sets a width/height square size of the selector. -->
<attr name="selector_size" format="dimension" />
<!-- sets an alpha of thr selector. -->
<!-- sets an alpha of the selector. -->
<attr name="selector_alpha" format="float" />
<!-- sets an alpha of the flag. -->
<attr name="flag_alpha" format="float" />
Expand All @@ -41,6 +41,8 @@
<!-- trigger the listener only the last color when user release tapping. -->
<enum name="last" value="1" />
</attr>
<!-- enables selector point validation (approximation to find valid color). when disabled, uses exact coordinates without approximation. -->
<attr name="selectorPointValidation" format="boolean" />
</declare-styleable>
<declare-styleable name="AlphaSlideBar">
<!-- sets a customized selector drawable. -->
Expand Down