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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ app:actionMode="last" // sets action mode 'always' or 'last'.
app:initialColor="@color/colorPrimary"
app:preferenceName="MyColorPicker" // sets a preference name.
app:debounceDuration="200" // sets a debounce duration of the invoking color listener.
app:zoomEnabled="true" // enables the pinch zoom gesture. This attribute will work with only a bitmap palette.
app:maxZoom="5.0" // sets the maximum scale of the zoom gesture.
```

### ColorListener
Expand Down
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ android {
versionName = Configuration.versionName
}

buildFeatures {
viewBinding = true
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.skydoves.colorpickerview.AlphaTileView;
import com.skydoves.colorpickerview.ColorEnvelope;
import com.skydoves.colorpickerview.ColorPickerDialog;
import com.skydoves.colorpickerview.ColorPickerView;
import com.skydoves.colorpickerview.flag.BubbleFlag;
import com.skydoves.colorpickerview.flag.FlagMode;
import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener;
import com.skydoves.colorpickerview.sliders.AlphaSlideBar;
import com.skydoves.colorpickerview.sliders.BrightnessSlideBar;
import com.skydoves.colorpickerviewdemo.databinding.ActivityMainBinding;
import com.skydoves.powermenu.OnMenuItemClickListener;
import com.skydoves.powermenu.PowerMenu;
import com.skydoves.powermenu.PowerMenuItem;
Expand All @@ -50,6 +47,7 @@

public class MainActivity extends AppCompatActivity {

private ActivityMainBinding binding;
private ColorPickerView colorPickerView;

private boolean FLAG_PALETTE = false;
Expand All @@ -75,6 +73,9 @@ public void onItemClick(int position, PowerMenuItem item) {
case 3:
dialog();
break;
case 4:
zoom();
break;
}
powerMenu.dismiss();
}
Expand All @@ -83,11 +84,12 @@ public void onItemClick(int position, PowerMenuItem item) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

powerMenu = PowerMenuUtils.getPowerMenu(this, this, powerMenuItemClickListener);

colorPickerView = findViewById(R.id.colorPickerView);
colorPickerView = binding.colorPickerView;
BubbleFlag bubbleFlag = new BubbleFlag(this);
bubbleFlag.setFlagMode(FlagMode.FADE);
colorPickerView.setFlagView(bubbleFlag);
Expand All @@ -99,12 +101,10 @@ protected void onCreate(Bundle savedInstanceState) {
});

// attach alphaSlideBar
final AlphaSlideBar alphaSlideBar = findViewById(R.id.alphaSlideBar);
colorPickerView.attachAlphaSlider(alphaSlideBar);
colorPickerView.attachAlphaSlider(binding.alphaSlideBar);

// attach brightnessSlideBar
final BrightnessSlideBar brightnessSlideBar = findViewById(R.id.brightnessSlide);
colorPickerView.attachBrightnessSlider(brightnessSlideBar);
colorPickerView.attachBrightnessSlider(binding.brightnessSlide);
colorPickerView.setLifecycleOwner(this);
}

Expand All @@ -115,11 +115,8 @@ protected void onCreate(Bundle savedInstanceState) {
*/
@SuppressLint("SetTextI18n")
private void setLayoutColor(ColorEnvelope envelope) {
TextView textView = findViewById(R.id.textView);
textView.setText("#" + envelope.getHexCode());

AlphaTileView alphaTileView = findViewById(R.id.alphaTileView);
alphaTileView.setPaintColor(envelope.getColor());
binding.textView.setText("#" + envelope.getHexCode());
binding.alphaTileView.setPaintColor(envelope.getColor());
}

/**
Expand Down Expand Up @@ -162,6 +159,16 @@ private void selector() {
FLAG_SELECTOR = !FLAG_SELECTOR;
}

/**
* enables or disables the pinch zoom gesture of the palette. the zoom gesture works with only a
* bitmap palette, which can be changed by the Palette menu.
*/
private void zoom() {
boolean enabled = !colorPickerView.isZoomEnabled();
colorPickerView.setZoomEnabled(enabled);
Timber.d("zoom enabled: %s", enabled);
}

/**
* shows ColorPickerDialog
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static PowerMenu getPowerMenu(
.addItem(new PowerMenuItem("Palette(Gallery)", false))
.addItem(new PowerMenuItem("Selector", false))
.addItem(new PowerMenuItem("Dialog", false))
.addItem(new PowerMenuItem("Zoom", false))
.setLifecycleOwner(lifecycleOwner)
.setAnimation(MenuAnimation.SHOWUP_TOP_LEFT)
.setCircularEffect(CircularEffect.BODY)
Expand Down
18 changes: 18 additions & 0 deletions colorpickerview/api/colorpickerview.api
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class com/skydoves/colorpickerview/AlphaTileView : android/view/View {
protected fun onSizeChanged (IIII)V
public fun setBackgroundColor (I)V
public fun setPaintColor (I)V
public fun setStrokeColor (I)V
public fun setStrokeColorRes (I)V
public fun setStrokeSize (F)V
public fun setStrokeSizeRes (I)V
}

public class com/skydoves/colorpickerview/ColorEnvelope {
Expand Down Expand Up @@ -77,10 +81,14 @@ public class com/skydoves/colorpickerview/ColorPickerDialog$Builder : androidx/a
public fun setNegativeButton (ILandroid/content/DialogInterface$OnClickListener;)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public synthetic fun setNegativeButton (Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroidx/appcompat/app/AlertDialog$Builder;
public fun setNegativeButton (Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public fun setNegativeButtonTextColor (I)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public fun setNegativeButtonTextColorRes (I)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public synthetic fun setNeutralButton (ILandroid/content/DialogInterface$OnClickListener;)Landroidx/appcompat/app/AlertDialog$Builder;
public fun setNeutralButton (ILandroid/content/DialogInterface$OnClickListener;)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public synthetic fun setNeutralButton (Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroidx/appcompat/app/AlertDialog$Builder;
public fun setNeutralButton (Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public fun setNeutralButtonTextColor (I)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public fun setNeutralButtonTextColorRes (I)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public synthetic fun setOnCancelListener (Landroid/content/DialogInterface$OnCancelListener;)Landroidx/appcompat/app/AlertDialog$Builder;
public fun setOnCancelListener (Landroid/content/DialogInterface$OnCancelListener;)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public synthetic fun setOnDismissListener (Landroid/content/DialogInterface$OnDismissListener;)Landroidx/appcompat/app/AlertDialog$Builder;
Expand All @@ -95,6 +103,8 @@ public class com/skydoves/colorpickerview/ColorPickerDialog$Builder : androidx/a
public synthetic fun setPositiveButton (Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroidx/appcompat/app/AlertDialog$Builder;
public fun setPositiveButton (Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public fun setPositiveButton (Ljava/lang/CharSequence;Lcom/skydoves/colorpickerview/listeners/ColorPickerViewListener;)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public fun setPositiveButtonTextColor (I)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public fun setPositiveButtonTextColorRes (I)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public fun setPreferenceName (Ljava/lang/String;)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
public synthetic fun setSingleChoiceItems (IILandroid/content/DialogInterface$OnClickListener;)Landroidx/appcompat/app/AlertDialog$Builder;
public fun setSingleChoiceItems (IILandroid/content/DialogInterface$OnClickListener;)Lcom/skydoves/colorpickerview/ColorPickerDialog$Builder;
Expand Down Expand Up @@ -132,22 +142,26 @@ public class com/skydoves/colorpickerview/ColorPickerView : android/widget/Frame
protected fun getColorFromBitmap (FF)I
public fun getDebounceDuration ()J
public fun getFlagView ()Lcom/skydoves/colorpickerview/flag/FlagView;
public fun getMaxZoom ()F
public fun getPreferenceName ()Ljava/lang/String;
public fun getPureColor ()I
public fun getSelectedPoint ()Landroid/graphics/Point;
public fun getSelector ()Landroid/widget/ImageView;
public fun getSelectorX ()F
public fun getSelectorY ()F
public fun getZoomScale ()F
public fun isHuePalette ()Z
public fun isResetBrightnessOnLowSaturationEnabled ()Z
public fun isSelectorPointValidationEnabled ()Z
public fun isSyncSlidersWithPaletteColorEnabled ()Z
public fun isZoomEnabled ()Z
public fun moveSelectorPoint (III)V
protected fun onCreateByBuilder (Lcom/skydoves/colorpickerview/ColorPickerView$Builder;)V
public fun onDestroy ()V
protected fun onSizeChanged (IIII)V
public fun onTouchEvent (Landroid/view/MotionEvent;)Z
public fun removeLifecycleOwner (Landroidx/lifecycle/LifecycleOwner;)V
public fun resetZoom ()V
public fun selectByHsvColor (I)V
public fun selectByHsvColorRes (I)V
public fun selectCenter ()V
Expand All @@ -162,6 +176,7 @@ public class com/skydoves/colorpickerview/ColorPickerView : android/widget/Frame
public fun setInitialColor (I)V
public fun setInitialColorRes (I)V
public fun setLifecycleOwner (Landroidx/lifecycle/LifecycleOwner;)V
public fun setMaxZoom (F)V
public fun setPaletteDrawable (Landroid/graphics/drawable/Drawable;)V
public fun setPreferenceName (Ljava/lang/String;)V
public fun setPureColor (I)V
Expand All @@ -170,6 +185,7 @@ public class com/skydoves/colorpickerview/ColorPickerView : android/widget/Frame
public fun setSelectorPoint (II)V
public fun setSelectorPointValidation (Z)V
public fun setSyncSlidersWithPaletteColor (Z)V
public fun setZoomEnabled (Z)V
}

public class com/skydoves/colorpickerview/ColorPickerView$Builder {
Expand All @@ -187,6 +203,7 @@ public class com/skydoves/colorpickerview/ColorPickerView$Builder {
public fun setInitialColor (I)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
public fun setInitialColorRes (I)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
public fun setLifecycleOwner (Landroidx/lifecycle/LifecycleOwner;)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
public fun setMaxZoom (F)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
public fun setPaletteDrawable (Landroid/graphics/drawable/Drawable;)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
public fun setPreferenceName (Ljava/lang/String;)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
public fun setResetBrightnessOnLowSaturation (Z)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
Expand All @@ -196,6 +213,7 @@ public class com/skydoves/colorpickerview/ColorPickerView$Builder {
public fun setSelectorSize (I)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
public fun setSyncSlidersWithPaletteColor (Z)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
public fun setWidth (I)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
public fun setZoomEnabled (Z)Lcom/skydoves/colorpickerview/ColorPickerView$Builder;
}

public class com/skydoves/colorpickerview/FadeUtils {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DimenRes;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import com.skydoves.colorpickerview.sliders.AlphaTileDrawable;

/** AlphaTileView visualizes ARGB color on the canvas using {@link AlphaTileDrawable}. */
@SuppressWarnings("unused")
public class AlphaTileView extends View {

private Paint colorPaint;
private Paint strokePaint;
private Bitmap backgroundBitmap;
private float strokeSize = 0f;
private final AlphaTileDrawable.Builder builder = new AlphaTileDrawable.Builder();

public AlphaTileView(Context context) {
Expand Down Expand Up @@ -64,6 +70,9 @@ public AlphaTileView(

private void onCreate() {
this.colorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
this.strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
this.strokePaint.setStyle(Paint.Style.STROKE);
this.strokePaint.setColor(Color.TRANSPARENT);
this.setBackgroundColor(Color.WHITE);
}

Expand All @@ -81,6 +90,13 @@ private void getAttrs(AttributeSet attrs) {
builder.setTileEvenColor(
a.getInt(R.styleable.AlphaTileView_tileEvenColor, builder.getTileEvenColor()));
}
if (a.hasValue(R.styleable.AlphaTileView_tileStrokeColor)) {
strokePaint.setColor(
a.getColor(R.styleable.AlphaTileView_tileStrokeColor, strokePaint.getColor()));
}
if (a.hasValue(R.styleable.AlphaTileView_tileStrokeSize)) {
setStrokeSize(a.getDimension(R.styleable.AlphaTileView_tileStrokeSize, strokeSize));
}
} finally {
a.recycle();
}
Expand Down Expand Up @@ -110,13 +126,63 @@ protected void onDraw(Canvas canvas) {
canvas.drawBitmap(backgroundBitmap, 0, 0, null);
}
canvas.drawRect(0, 0, getWidth(), getMeasuredHeight(), colorPaint);
drawStroke(canvas);
}

/** draws the stroke inside of the view, so it isn't covered by the painted color. */
private void drawStroke(Canvas canvas) {
if (strokeSize <= 0 || Color.alpha(strokePaint.getColor()) == 0) return;

float half = strokeSize * 0.5f;
canvas.drawRect(
half, half, getWidth() - half, getMeasuredHeight() - half, strokePaint);
}

public void setPaintColor(int color) {
colorPaint.setColor(color);
invalidate();
}

/**
* sets a color of the stroke, which is drawn on the edge of the view. it can be used for
* distinguishing the painted color from the background.
*
* @param color a color of the stroke.
*/
public void setStrokeColor(@ColorInt int color) {
strokePaint.setColor(color);
invalidate();
}

/**
* sets a color resource of the stroke, which is drawn on the edge of the view.
*
* @param resource a color resource of the stroke.
*/
public void setStrokeColorRes(@ColorRes int resource) {
setStrokeColor(ContextCompat.getColor(getContext(), resource));
}

/**
* sets a size of the stroke in pixels, which is drawn on the edge of the view.
*
* @param strokeSize a size of the stroke in pixels.
*/
public void setStrokeSize(float strokeSize) {
this.strokeSize = Math.max(0f, strokeSize);
this.strokePaint.setStrokeWidth(this.strokeSize);
invalidate();
}

/**
* sets a size of the stroke using a dimension resource.
*
* @param resource a dimension resource of the stroke size.
*/
public void setStrokeSizeRes(@DimenRes int resource) {
setStrokeSize(getContext().getResources().getDimension(resource));
}

@Override
public void setBackgroundColor(int color) {
setPaintColor(color);
Expand Down
Loading
Loading