Skip to content

Commit 8741bd0

Browse files
committed
Implement attributes functionalities in AbstractSlider
1 parent c8c7586 commit 8741bd0

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

colorpickerview/src/main/java/com/skydoves/colorpickerview/sliders/AbstractSlider.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@
3333
import android.widget.FrameLayout;
3434
import android.widget.ImageView;
3535
import androidx.annotation.ColorInt;
36+
import androidx.annotation.ColorRes;
37+
import androidx.annotation.DimenRes;
38+
import androidx.annotation.DrawableRes;
3639
import androidx.annotation.FloatRange;
40+
import androidx.core.content.ContextCompat;
41+
import androidx.core.content.res.ResourcesCompat;
3742
import com.skydoves.colorpickerview.ActionMode;
3843
import com.skydoves.colorpickerview.ColorPickerView;
3944

4045
/** AbstractSlider is the abstract class for implementing sliders. */
46+
@SuppressWarnings("unused")
4147
public abstract class AbstractSlider extends FrameLayout {
4248

4349
public ColorPickerView colorPickerView;
@@ -219,6 +225,68 @@ public void onGlobalLayout() {
219225
});
220226
}
221227

228+
/**
229+
* sets a drawable of the selector.
230+
*
231+
* @param drawable drawable of the selector.
232+
*/
233+
public void setSelectorDrawable(Drawable drawable) {
234+
this.selectorDrawable = drawable;
235+
this.selector.setImageDrawable(drawable);
236+
}
237+
238+
/**
239+
* sets a drawable resource of the selector.
240+
*
241+
* @param resource a drawable resource of the selector.
242+
*/
243+
public void setSelectorDrawableRes(@DrawableRes int resource) {
244+
Drawable drawable = ResourcesCompat.getDrawable(getContext().getResources(), resource, null);
245+
setSelectorDrawable(drawable);
246+
}
247+
248+
/**
249+
* sets a color of the slider border.
250+
*
251+
* @param color color of the slider border.
252+
*/
253+
public void setBorderColor(@ColorInt int color) {
254+
this.borderColor = color;
255+
this.borderPaint.setColor(color);
256+
invalidate();
257+
}
258+
259+
/**
260+
* sets a color resource of the slider border.
261+
*
262+
* @param resource color resource of the slider border.
263+
*/
264+
public void setBorderColorRes(@ColorRes int resource) {
265+
int color = ContextCompat.getColor(getContext(), resource);
266+
setBorderColor(color);
267+
}
268+
269+
/**
270+
* sets a size of the slide border.
271+
*
272+
* @param borderSize ize of the slide border.
273+
*/
274+
public void setBorderSize(int borderSize) {
275+
this.borderSize = borderSize;
276+
this.borderPaint.setStrokeWidth(borderSize);
277+
invalidate();
278+
}
279+
280+
/**
281+
* sets a size of the slide border using dimension resource.
282+
*
283+
* @param resource a size of the slide border.
284+
*/
285+
public void setBorderSizeRes(@DimenRes int resource) {
286+
int borderSize = (int) getContext().getResources().getDimension(resource);
287+
setBorderSize(borderSize);
288+
}
289+
222290
/** called when the inflating finished. */
223291
public abstract void onInflateFinished();
224292

0 commit comments

Comments
 (0)