Added Color Picker button in Photo Editor.

- Little changes in color line.
 - Added black color to left side of color line.
This commit is contained in:
23rd 2018-11-11 14:24:21 +03:00 committed by NekoInverter
parent 0314e2b8ad
commit c3da4abed9
No known key found for this signature in database
GPG Key ID: 280D6CCCF95715F9
7 changed files with 89 additions and 5 deletions

View File

@ -47,6 +47,8 @@ public class RenderView extends TextureView {
private boolean shuttingDown;
public boolean isColorPicker = false;
public RenderView(Context context, Painting paint, Bitmap b, int rotation) {
super(context);
@ -156,6 +158,8 @@ public class RenderView extends TextureView {
if (internal == null || !internal.initialized || !internal.ready)
return true;
if (isColorPicker) return true;
input.process(event);
return true;
}

View File

@ -9,6 +9,8 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
@ -31,6 +33,7 @@ public class ColorPicker extends FrameLayout {
void onFinishedColorPicking();
void onSettingsPressed();
void onUndoPressed();
boolean onColorPicker();
}
private ColorPickerDelegate delegate;
@ -40,12 +43,13 @@ public class ColorPicker extends FrameLayout {
private OvershootInterpolator interpolator = new OvershootInterpolator(1.02f);
private static final int[] COLORS = new int[]{
0xffea2739,
0xff000000,
0xffff0000,
0xffdb3ad2,
0xff3051e3,
0xff49c5ed,
0xff80c864,
0xfffcde65,
0xffffff00,
0xfffc964d,
0xff000000,
0xffffffff
@ -53,6 +57,7 @@ public class ColorPicker extends FrameLayout {
private static final float[] LOCATIONS = new float[]{
0.0f,
0.07f,
0.14f,
0.24f,
0.39f,
@ -63,6 +68,8 @@ public class ColorPicker extends FrameLayout {
1.0f
};
private PorterDuffColorFilter colorPickerFilter = new PorterDuffColorFilter(0xff51bdf3, PorterDuff.Mode.MULTIPLY);
private ImageView colorPickerButton;
private ImageView settingsButton;
private ImageView undoButton;
private Drawable shadowDrawable;
@ -99,6 +106,25 @@ public class ColorPicker extends FrameLayout {
}
});
colorPickerButton = new ImageView(context);
colorPickerButton.setScaleType(ImageView.ScaleType.CENTER);
colorPickerButton.setImageResource(R.drawable.photo_color_picker);
addView(colorPickerButton, LayoutHelper.createFrame(60, 52));
colorPickerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (delegate != null) {
boolean p = delegate.onColorPicker();
PorterDuffColorFilter f = null;
if (p) f = colorPickerFilter;
colorPickerButton.setColorFilter(f);
colorPickerButton.setImageResource(R.drawable.photo_color_picker);
}
}
});
undoButton = new ImageView(context);
undoButton.setScaleType(ImageView.ScaleType.CENTER);
undoButton.setImageResource(R.drawable.photo_undo);
@ -190,6 +216,13 @@ public class ColorPicker extends FrameLayout {
return Color.argb(255, r, g, b);
}
public void setSwatchPaintColor(int color) {
findColorLocation(color);
swatchPaint.setColor(color);
swatchStrokePaint.setColor(color);
invalidate();
}
public void setLocation(float value) {
int color = colorForLocation(location = value);
swatchPaint.setColor(color);
@ -271,12 +304,14 @@ public class ColorPicker extends FrameLayout {
int width = right - left;
int height = bottom - top;
gradientPaint.setShader(new LinearGradient(AndroidUtilities.dp(56), 0, width - AndroidUtilities.dp(56), 0, COLORS, LOCATIONS, Shader.TileMode.REPEAT));
gradientPaint.setShader(new LinearGradient(AndroidUtilities.dp(56), 0, width - AndroidUtilities.dp(52) * 2, 0, COLORS, LOCATIONS, Shader.TileMode.REPEAT));
int y = height - AndroidUtilities.dp(32);
rectF.set(AndroidUtilities.dp(56), y, width - AndroidUtilities.dp(56), y + AndroidUtilities.dp(12));
rectF.set(AndroidUtilities.dp(56), y, width - AndroidUtilities.dp(52) * 2, y + AndroidUtilities.dp(12));
settingsButton.layout(width - settingsButton.getMeasuredWidth(), height - AndroidUtilities.dp(52), width, height);
// Move settingButton left after coloPickerButton.
settingsButton.layout(width - settingsButton.getMeasuredWidth() * 2 - AndroidUtilities.dp(30), height - AndroidUtilities.dp(52), width, height);
undoButton.layout(0, height - AndroidUtilities.dp(52), settingsButton.getMeasuredWidth(), height);
colorPickerButton.layout(width - colorPickerButton.getMeasuredWidth(), height - AndroidUtilities.dp(52), width, height);
}
@Override
@ -325,4 +360,15 @@ public class ColorPicker extends FrameLayout {
setDraggingFactor(target);
}
}
private void findColorLocation(int color) {
for (float i = 0; i <= 1; i += 0.001f) {
int colorOnLine = colorForLocation(i);
if (Math.abs(color - colorOnLine) < 10000) {
setLocation(i);
return;
}
}
}
}

View File

@ -126,6 +126,34 @@ public class PhotoPaintView extends FrameLayout implements EntityView.EntityView
addView(curtainView);
renderView = new RenderView(context, new Painting(getPaintingSize()), bitmap, orientation);
renderView.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if (!renderView.isColorPicker) return false;
int x = (int)event.getX();
int y = (int)event.getY();
if (x >= v.getWidth()) return false;
if (y >= v.getHeight()) return false;
if (x <= 0) return false;
if (y <= 0) return false;
int finalX;
int finalY;
if (!isSidewardOrientation()) {
finalX = (int)((float)x / (float)v.getWidth() * bitmap.getWidth());
finalY = (int)((float)y / (float)v.getHeight() * bitmap.getHeight());
} else {
finalY = (int)((float)(v.getWidth() - x) / (float)v.getWidth() * bitmap.getHeight());
finalX = (int)((float)y / (float)v.getHeight() * bitmap.getWidth());
}
int pixel = bitmap.getPixel(finalX, finalY);
renderView.setColor(pixel);
colorPicker.setSwatchPaintColor(pixel);
return false;
}
});
renderView.setDelegate(new RenderView.RenderViewDelegate() {
@Override
@ -236,6 +264,12 @@ public class PhotoPaintView extends FrameLayout implements EntityView.EntityView
public void onUndoPressed() {
undoStore.undo();
}
@Override
public boolean onColorPicker() {
renderView.isColorPicker = !renderView.isColorPicker;
return renderView.isColorPicker;
}
});
toolsView = new FrameLayout(context);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB